{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# One neuron example\n\nThis script simulates a neuron driven by a constant external current\nand records its membrane potential.\n\n## See Also\n\n:doc:`twoneurons`\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "First, we import all necessary modules for simulation, analysis and\nplotting. Additionally, we set the verbosity to suppress info\nmessages and reset the kernel.\nResetting the kernel allows you to execute the script several\ntimes in a Python shell without interferences from previous NEST\nsimulations. Thus, without resetting the kernel the network status\nincluding connections between nodes, status of neurons, devices and\nintrinsic time clocks, is kept and influences the next simulations.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import nest\nimport nest.voltage_trace\nimport matplotlib.pyplot as plt\n\nnest.set_verbosity(\"M_WARNING\")\nnest.ResetKernel()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Second, the nodes (neurons and devices) are created using ``Create``.\nWe store the returned handles in variables for later reference.\nThe ``Create`` function also allow you to create multiple nodes\ne.g. ``nest.Create('iaf_psc_alpha',5)``\nAlso default parameters of the model can be configured using ``Create``\nby including a list of parameter dictionaries\ne.g. `nest.Create(\"iaf_psc_alpha\", params=[{'I_e':376.0}])`.\nIn this example we will configure these parameters in an additional\nstep, which is explained in the third section.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "neuron = nest.Create(\"iaf_psc_alpha\")\nvoltmeter = nest.Create(\"voltmeter\")"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Third, we set the external current of the neuron.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "neuron.I_e = 376.0"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Fourth, the neuron is connected to the voltmeter. The command\n``Connect`` has different variants. Plain ``Connect`` just takes the\nhandles of pre- and postsynaptic nodes and uses the default values\nfor weight and delay. Note that the connection direction for the voltmeter is\nreversed compared to the spike recorder, because it observes the\nneuron instead of receiving events from it. Thus, ``Connect``\nreflects the direction of signal flow in the simulation kernel\nrather than the physical process of inserting an electrode into the\nneuron. The latter semantics is presently not available in NEST.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "nest.Connect(voltmeter, neuron)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Now we simulate the network using ``Simulate``, which takes the\ndesired simulation time in milliseconds.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "nest.Simulate(1000.0)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Finally, we plot the neuron's membrane potential as a function of\ntime and display the plot using pyplot.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "nest.voltage_trace.from_device(voltmeter)\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
}