code: #!/usr/bin/env python3
  """
  Simulating a regular spiking Izhikevich neuron with NeuroML.
  
  File: izhikevich-single-neuron.py
  """
  
  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
  
  
  # Create a new NeuroML model document
  nml_doc = NeuroMLDocument(id="IzhSingleNeuron")
  
  # Define the Izhikevich cell and add it to the model in the document
  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")
  nml_doc.izhikevich2007_cells.append(izh0)
  
  # Create a network and add it to the model
  net = Network(id="IzhNet")
  nml_doc.networks.append(net)
  
  # Create a population of defined cells and add it to the model
  size0 = 1
  pop0 = Population(id="IzhPop0", component=izh0.id, size=size0)
  net.populations.append(pop0)
  
  # Define an external stimulus and add it to the model
  pg = PulseGenerator(
      id="pulseGen_%i" % 0, delay="0ms", duration="1000ms",
      amplitude="0.07 nA"
  )
  nml_doc.pulse_generators.append(pg)
  exp_input = ExplicitInput(target="%s[%i]" % (pop0.id, 0), input=pg.id)
  net.explicit_inputs.append(exp_input)
  
  # 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)
  
  # Validate the NeuroML model against the NeuroML schema
  validate_neuroml2(nml_file)
  
  ################################################################################
  ## The NeuroML file has now been created and validated. The rest of the code
  ## involves writing a LEMS simulation file to run 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)
  simulation.assign_simulation_target(net.id)
  simulation.include_neuroml2_file(nml_file)
  
  # Define the output file to store simulation outputs
  # we record the neuron's membrane potential
  simulation.create_output_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()
  
  # Run the simulation using the jNeuroML simulator
  pynml.run_lems_with_jneuroml(
      lems_simulation_file, max_memory="2G", nogui=True, plot=False
  )
  
  # 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)
  pynml.generate_plot(
      [data_array[:, 0]], [data_array[:, 1]],
      "Membrane potential", show_plot_already=False,
      save_figure_to="%s-v.png" % simulation_id,
      xaxis="time (s)", yaxis="membrane potential (V)"
  )
  
apis: numpy.loadtxt