Examples illustrating NeuroML 2 concepts
LEMS can be used as a basis for specifying models of many types of dynamical systems. NeuroML version 1 contained some type definitions such as <channel_type>, <channel_type> etc. which were defined implicitly. LEMS ComponentTypes can be used to define the behaviour of a core set of entities which can form the basis for the NeuroML 2 specification, at the very least for channel and synapse types, and most likely network elements too.
More details on the relationship between LEMS and NeuroML 2 are here.
Ex0: Simple Integrate and Fire cell
Ex1: Simple Hodgkin Huxley example
Ex2: Bursting and tonic Izhikevich cells
Ex3: Network connection between HH cells
Ex4: Kinetic scheme description for K+ channel
Ex5: Using "pure" NeuroML v2 files with LEMS
Ex6: NMDA-R mediated synapse
Ex7: Short Term Plasticity
Ex8: Adaptive exponential integrate-and-fire model
Ex9: FitzHugh-Nagumo model
Ex0: Simple Integrate and Fire cell
This example imports a number of files which define the LEMS ComponentTypes allowed in a NeuroML version 2 file. The core dimension/unit definitions (NeuroMLCoreDimensions.xml), a file defining channel ComponentTypes (Channels.xml), one for synpase ComponentTypes (Synapses.xml), a number of simple cell definitions (Cells.xml), definition of network related ComponentTypes (Networks.xml) and some stimuli definitions (Inputs.xml). Also imported is a set of simulation ComponentType definitions (Simulation.xml) which won't be part of NeuroML version 2 (SED-ML will be used for this), but are convenient for executing the examples.
A ComponentType iafTau is defined in Cells.xml, which is a simple I&F cell which tends to a leakReversal potential with characteristic time tau. Note that iafTau extends a basic I&F cell type which has parameter thresh and reset.
<Parameter name="thresh" dimension="voltage" />
<Parameter name="reset" dimension="voltage" />
</ComponentType>
<Parameter name="leakReversal" dimension="voltage" />
<Parameter name="tau" dimension="time" />
<EventPort name="a" direction="out" />
<Exposure name="V" dimension="voltage" />
<Behavior>
<StateVariable name="V" exposure="V" dimension="voltage" />
<TimeDerivative variable="V" value="(leakReversal - V) / tau" />
<OnStart>
<StateAssignment variable="V" value="reset" />
</OnStart>
<OnCondition test="V .gt. thresh">
<StateAssignment variable="V" value="reset" />
<EventOut port="a" />
</OnCondition>
</Behavior>
</ComponentType>
A Component of this cell type can be created, and a population of those components with the following (note leakReversal > thresh so the cell is spontaneously active, so no external input is needed):
<population id="iafPop" component="iaf" size="1" />
</network>
The output of this example is shown below.
The full code for this example can be found here.
Ex1: Simple Hodgkin Huxley example
In Channels.xml there are definitions of a number of ComponentTypes which can be used for specifying HH like ion channels. Once this file is included, the ComponentTypes can be used to define Components which have a form similar to those proposed for NeuroML version 2:
<gateHH id="m" instances="3">
<forwardRate type="HHExpLinearRate" rate="1per_ms" midpoint="-40mV" scale="10mV" />
<reverseRate type="HHExpRate" rate="4per_ms" midpoint="-65mV" scale="-18mV" />
</gateHH>
<gateHH id="h" instances="1">
<forwardRate type="HHExpRate" rate="0.07per_ms" midpoint="-65mV" scale="-20mV" />
<reverseRate type="HHSigmoidRate" rate="1per_ms" midpoint="-35mV" scale="10mV" />
</gateHH>
</ionChannel>
Cells can also be created based on the types in Cells.xml, and stimuli based on those in Inputs.xml:
<channelPopulation id="leak" ionChannel="passive" number="300" erev="-54.3mV" />
<channelPopulation id="naChans" ionChannel="na" number="120000" erev="50mV" />
<channelPopulation id="kChans" ionChannel="k" number="36000" erev="-77mV" />
</abstractCell>
A simple network of one cell is created:
<population id="hhpop" component="hhcell" size="1" />
<explicitInput target="hhpop[0]" input="pulseGen1" />
</network>
A simulation can be run and a number of the variables of the model plotted, including membrane potential and the m, h, n gating variables of the Na+ and K+ channels. The data cann also be saved using the save attribute.
<Simulation id="sim1" length="300ms" step="0.01ms" target="net1">
<Display id="d1" title="Ex1: Simple HH example: Voltage" timeScale="1ms">
<Line id="l1" quantity="hhpop[0]/v" scale="1mV" color="#ffffff" save="hh_v.dat" />
</Display>
<Display id="d2" title="Ex1: Simple HH example: rate variables" timeScale="1ms"> <!-- Lines in extra Displays will only be plotted if saved! -->
<Line id="l2" quantity="hhpop[0]/naChans/na/m/q" scale="1" color="#000000" save="hh_m.dat" />
<Line id="l3" quantity="hhpop[0]/naChans/na/h/q" scale="1" color="#ff0000" save="hh_h.dat" />
<Line id="l4" quantity="hhpop[0]/kChans/k/n/q" scale="1" color="#0000ff" save="hh_n.dat" />
</Display>
</Simulation>
The output of this example is shown below. The membrane potential trace is shown on top and the values of m, h, n are plotted below.
The full code for this example can be found here.
Ex2: Bursting and tonic Izhikevich cells
An example of the Izhikevich simple spiking neuron model specified as a ComponentType in LEMS. The ComponentType for the cell follows (taken from Cells.xml):
<Parameter name="v0" dimension="voltage" />
<Parameter name="a" dimension="none" />
<Parameter name="b" dimension="none" />
<Parameter name="c" dimension="none" />
<Parameter name="d" dimension="none" />
<Parameter name="thresh" dimension="voltage" />
<Parameter name="Iamp" dimension="none" />
<Parameter name="Idel" dimension="time" />
<Parameter name="Idur" dimension="time" /> <!-- The following are needed to ensure a, b, c, d, U & I remain dimensionless... -->
<Constant name="tscale" dimension="per_time" value="1per_ms" />
<Constant name="vscale" dimension="voltage" value="1mV" />
<Constant name="pervscale" dimension="per_voltage" value="1per_mV" />
<EventPort name="a" direction="out" />
<Exposure name="U" dimension="none" />
<Exposure name="I" dimension="none" />
<Behavior>
<StateVariable name="v" dimension="voltage" exposure="v" />
<StateVariable name="U" dimension="none" exposure="U" />
<StateVariable name="I" dimension="none" exposure="I" />
<OnStart>
<StateAssignment variable="v" value="v0" />
<StateAssignment variable="U" value="v0 * b * pervscale" />
<StateAssignment variable="I" value="0" />
</OnStart>
<OnCondition test="v .gt. thresh">
<StateAssignment variable="v" value="c*vscale" />
<StateAssignment variable="U" value="U+d" />
<EventOut port="a" />
</OnCondition>
<OnCondition test="t .gt. Idel .and. t .lt. Idel+Idur">
<StateAssignment variable="I" value="Iamp" />
</OnCondition>
<OnCondition test="t .gt. Idel+Idur">
<StateAssignment variable="I" value="0" />
</OnCondition>
<TimeDerivative variable="v" value="vscale*tscale * (0.04*v*v*pervscale*pervscale + 5*v*pervscale + 140.0 - U + I)" />
<TimeDerivative variable="U" value="tscale * a * (b*v*pervscale - U)" />
</Behavior>
</ComponentType>
This allows a very concise specification of a cell model when used in a network (here 3 cells with different spiking behaviour are created):
<population id="izpopBurst" component="izBurst" size="1" />
<population id="izpopTonic" component="izTonic" size="1" />
<population id="izpopMixed" component="izMixed" size="1" />
</network>
The plots below shows the evolution of the v and U variables in 2 of the cells.
The full code for this example can be found here.
Ex3: Network connection between HH cells
This examples uses user defined ComponentTypes for synapses in Synapses.xml, which can be instantiated with:
The plots below shows the source cell firing and the post synaptic membrane response.
The full code for this example can be found here.
Ex4: Kinetic scheme description for K+ channel
This examples contains a K+ channel specified using a Kinetic scheme description which will probably be the preferred format for channels in NeuroML version 2:
<gate id="n" power="1" deltaV="0.1mV">
<closedState id="c1" />
<openState id="o1" />
<vHalfTransition from="c1" to="o1" vHalf="0mV" z="1.5" gamma="0.75" tau="3.2ms" tauMin="0.3ms" />
</gate>
</ionChannel>
The full code for this example can be found here.
Ex5: Using "pure" NeuroML v2 files with LEMS
The examples above have used files mixing LEMS specific elements (e.g. <Lems>, <Simulation>, <Display>) with NeuroML 2 elements (e.g. <ionChannel>, <network>). This example shows how all NeuroML 2 elements can be removed to separate files (valid according to the latest NeuroML 2 draft schema) and include these in the main LEMS file. This allows testing through LEMS of "pure" NeuroML v2 files, which may have been generated by applications without any reference to the LEMS framework.
In the main LEMS file, the NeuroML file is included as any other LEMS file
<Simulation id="sim1" length="300ms" step="0.01ms" target="net1"> <!-- Subelements omitted for clarity -->
</Simulation>
The contents of the NeuroML file follow. Note the <neuroml> elements are stripped by the LEMS interpreter on including the file.
<ionChannel id="passive" type="ionChannelPassive" conductance="10pS">
<notes>Leak conductance
</notes>
</ionChannel>
<ionChannel id="na" type="ionChannelHH" conductance="10pS" species="na">
<notes>Na channel
</notes>
<gateHH id="m" instances="3">
<forwardRate type="HHExpLinearRate" rate="1per_ms" midpoint="-40mV" scale="10mV" />
<reverseRate type="HHExpRate" rate="4per_ms" midpoint="-65mV" scale="-18mV" />
</gateHH>
<gateHH id="h" instances="1">
<forwardRate type="HHExpRate" rate="0.07per_ms" midpoint="-65mV" scale="-20mV" />
<reverseRate type="HHSigmoidRate" rate="1per_ms" midpoint="-35mV" scale="10mV" />
</gateHH>
</ionChannel>
<ionChannel id="k" type="ionChannelHH" conductance="10pS" species="k">
<gateHH id="n" instances="4">
<forwardRate type="HHExpLinearRate" rate="0.1per_ms" midpoint="-55mV" scale="10mV" />
<reverseRate type="HHExpRate" rate="0.125per_ms" midpoint="-65mV" scale="-80mV" />
</gateHH>
</ionChannel>
<cell id="hhcell">
<notes>A NeuroML 2 cell...
</notes>
<morphology id="morph1">
<segment id="0" name="soma">
<proximal x="0" y="0" z="0" diameter="17.841242" /> <!--Gives a convenient surface area of 1000.0 ?m�-->
<distal x="0" y="0" z="0" diameter="17.841242" />
</segment>
<segmentGroup id="soma_group">
<member segment="0" />
</segmentGroup>
</morphology>
<biophysicalProperties id="bioPhys1">
<membraneProperties>
<channelDensity id="leak" ionChannel="passive" condDensity="3.0 S_per_m2" erev="-54.3mV" />
<channelDensity id="naChans" ionChannel="na" condDensity="120.0 mS_per_cm2" erev="50.0 mV" />
<channelDensity id="kChans" ionChannel="k" condDensity="360 S_per_m2" erev="-77mV" />
<spikeThresh value="-20mV" />
<specificCapacitance value="1.0 uF_per_cm2" />
<initMembPotential value="-65mV" />
</membraneProperties>
<intracellularProperties>
<resistivity value="0.03 kohm_cm" /> <!-- Note: not used in single compartment simulations -->
</intracellularProperties>
</biophysicalProperties>
</cell>
<pulseGenerator id="pulseGen1" delay="100ms" duration="100ms" amplitude="0.08nA" />
<network id="net1">
<population id="hhpop" component="hhcell" size="1" />
<explicitInput target="hhpop[0]" input="pulseGen1" />
</network>
</neuroml>
Note: only single compartment cells are supported at the moment, i.e. only one <segment> element allowed in <morphology>!
Ex6: NMDA-R mediated synapse
This example shows how the basic synapse mechanism can be extended to allow addition of a voltage (and Magnesium concentration) dependent synaptic block component (e.g. for NMDA (N-Methyl-D-aspartic acid) receptor mediated synapses). The code below shows the NeuroML 2 form for an NMDA synapse:
<block type="VoltageConcDepBlock" species="mg" blockConcentration="1.2 mM" scalingConc="1.920544 mM" scalingVolt="16.129 mV" />
</nmdaSynapse>
The plots below show a passive cell (left) receiving synaptic input from an NMDAR synapse. The membrane potential is stepped at 200ms with a current clamp. The right plot shows the conductance waveform of the synapse. At more depolarised membrane potentials the synaptic response is higher.
The full code for this example can be found here, and the definition of the nmdaSyn ComponentType is in the Synapses.xml file.
Ex7: Short Term Plasticity
This example shows an implementation of Short Term Plasticity roughly along the lines of Tsodyks M, Uziel A, Markram H: Synchrony generation in recurrent networks with frequency-dependent synapses. J Neurosci 2000. NeuroML 2 elements for a fixed, depressing and facilitating synapse are shown below:
<plasticity initReleaseProb="0.5" tauFac="0 ms" tauRec="120 ms" />
</stpSynapse>
<plasticity initReleaseProb="0.5" tauFac="300 ms" tauRec="0 ms" />
</stpSynapse>
The figure below shows the behavour of the conductances of each of these 3 synapses (top plot), and the internal scaling variables (R and U) of the facilitating and depressing synapses (bottom).
The full code for this example can be found here, and the definition of the stpSynapse ComponentType is in the Synapses.xml file.
Ex8: Adaptive exponential integrate-and-fire model
This is a 2 variable spiking neuron model developed by Brette and Gernstner in 2005. For more details see here. NeuroML 2 elements for creating 4 cells with different types of spiking behaviour is shown below:
<population id="adExPop1" component="adExBurst2" size="1" />
<population id="adExPop2" component="adExBurst4" size="1" />
<population id="adExPop3" component="adExBurstChaos" size="1" />
<population id="adExPop4" component="adExRebound" size="1" />
</network>
The full code for this example can be found here, and the definition of the adExIaFCell ComponentType is in the Cells.xml file. The section related to the time derivative of the V and w state variables is shown below:
The figure below shows v and w for 3 of the cells described above. The left plots show the traces as run by the LEMS interpreter, and the right plots show the traces when NEURON code is generated from the LEMS definitions. The NEURON Python and mod files are generated using:
./lems nml2-examples/NeuroML2_Ex8_AdEx.xml -neuron
After generation the mod files should be compiled in the usual way, and NeuroML2_Ex8_AdEx_nrn.py run using the NEURON Python interpreter.
Ex8: FitzHugh-Nagumo model
This is version of the simplified HH model by FitzHugh and Nagumo, see here. The 2 equations that define the behaviour of the state variables V and W of this model are:
Note: tscale is a <Constant> with value 1 s-1, added to ensure consistency of units if V and W are dimensionless.
The full code for the example below can be found here, and the definition of the fitzHughNagumoCell ComponentType is in the Cells.xml file. The screenshost below are the model running on (from the top): LEMS; the model mapped to SBML and run using CellDesigner.