{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Example using Hodgkin-Huxley neuron\n\nThis example produces a rate-response (FI) curve of the Hodgkin-Huxley\nneuron ``hh_psc_alpha`` in response to a range of different current (DC) stimulations.\nThe result is plotted using matplotlib.\n\nSince a DC input affects only the neuron's channel dynamics, this routine\ndoes not yet check correctness of synaptic response.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import nest\nimport numpy as np\nimport matplotlib.pyplot as plt\n\nnest.set_verbosity('M_WARNING')\nnest.ResetKernel()\n\nsimtime = 1000\n\n# Amplitude range, in pA\ndcfrom = 0\ndcstep = 20\ndcto = 2000\n\nh = 0.1  # simulation step size in mS\n\nneuron = nest.Create('hh_psc_alpha')\nsr = nest.Create('spike_recorder')\n\nsr.record_to = 'memory'\n\nnest.Connect(neuron, sr, syn_spec={'weight': 1.0, 'delay': h})\n\n# Simulation loop\nn_data = int(dcto / float(dcstep))\namplitudes = np.zeros(n_data)\nevent_freqs = np.zeros(n_data)\nfor i, amp in enumerate(range(dcfrom, dcto, dcstep)):\n    neuron.I_e = float(amp)\n    print(f\"Simulating with current I={amp} pA\")\n    nest.Simulate(1000)  # one second warm-up time for equilibrium state\n    sr.n_events = 0  # then reset spike counts\n    nest.Simulate(simtime)  # another simulation call to record firing rate\n\n    n_events = sr.n_events\n    amplitudes[i] = amp\n    event_freqs[i] = n_events / (simtime / 1000.)\n\nplt.plot(amplitudes, event_freqs)\nplt.show()"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.8.6"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}