Interactive single Izhikevich neuron NeuroML example

To run this interactive Jupyter Notebook, please click on the rocket icon 🚀 in the top panel. For more information, please see how to use this documentation. Please uncomment the line below if you use the Google Colab (it does not include these packages by default).

#%pip install pyneuroml neuromllite NEURON
from neuroml import NeuroMLDocument
from neuroml import Izhikevich2007Cell
from neuroml import Population
from neuroml import Network
from neuroml import PulseGenerator
from neuroml import ExplicitInput
import neuroml.writers as writers
from neuroml.utils import validate_neuroml2
from pyneuroml import pynml
from pyneuroml.lems import LEMSSimulation
import numpy as np

Declaring the NeuroML model

Create a NeuroML document

nml_doc = NeuroMLDocument(id="IzhSingleNeuron")

Define the Izhikevich cell and add it to the model

izh0 = Izhikevich2007Cell(
    id="izh2007RS0", v0="-60mV", C="100pF", k="0.7nS_per_mV", vr="-60mV",
    vt="-40mV", vpeak="35mV", a="0.03per_ms", b="-2nS", c="-50.0mV", d="100pA")

Create a network and add it to the model

net = Network(id="IzhNet")

Create a population of defined cells and add it to the model

size0 = 1
pop0 = Population(id="IzhPop0",, size=size0)

Define an external stimulus and add it to the model

pg = PulseGenerator(
    id="pulseGen_%i" % 0, delay="0ms", duration="1000ms",
    amplitude="0.07 nA"
exp_input = ExplicitInput(target="%s[%i]" % (, 0),

Write the NeuroML model to a file

nml_file = 'izhikevich2007_single_cell_network.nml'
writers.NeuroMLWriter.write(nml_doc, nml_file)
print("Written network file to: " + nml_file)
Written network file to: izhikevich2007_single_cell_network.nml

Validate the NeuroML model

Validating izhikevich2007_single_cell_network.nml against /Users/padraig/anaconda/envs/py37/lib/python3.7/site-packages/libNeuroML-0.2.56-py3.7.egg/neuroml/nml/NeuroML_v2.2.xsd
It's valid!

Simulating the model

Create a simulation instance of the model

simulation_id = "example-single-izhikevich2007cell-sim"
simulation = LEMSSimulation(sim_id=simulation_id,
                            duration=1000, dt=0.1, simulation_seed=123)

Define the output file to store simulation outputs

Here, we record the neuron’s membrane potential to the specified data file.

    "output0", "%s.v.dat" % simulation_id
simulation.add_column_to_output_file("output0", 'IzhPop0[0]', 'IzhPop0[0]/v')

Save the simulation to a file

lems_simulation_file = simulation.save_to_file()
pyNeuroML >>> Written LEMS Simulation example-single-izhikevich2007cell-sim to file: LEMS_example-single-izhikevich2007cell-sim.xml

Run the simulation using the jNeuroML simulator

    lems_simulation_file, max_memory="2G", nogui=True, plot=False

Plot the recorded data

# Load the data from the file and plot the graph for the membrane potential
# using the pynml generate_plot utility function.
data_array = np.loadtxt("%s.v.dat" % simulation_id)
    [data_array[:, 0]], [data_array[:, 1]],
    "Membrane potential", show_plot_already=True,
    xaxis="time (s)", yaxis="membrane potential (V)"
pyNeuroML >>> Generating plot: Membrane potential
<AxesSubplot:xlabel='time (s)', ylabel='membrane potential (V)'>