About
Introduction
Elements
Download
Example 1
Example 2
Example 3
Example 4
Example 5
Example 6
Example 7
Regimes example
NeuroML 2 etc.
Example n
Canonical form
Discussion

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.

<Include file="NeuroML2CoreTypes/Cells.xml" />
<!-- The above file includes NeuroMLCoreDimensions.xml, Channels.xml, Synapses.xml and Inputs.xml-->
<Include file="NeuroML2CoreTypes/Networks.xml" />
<Include file="NeuroML2CoreTypes/Simulation.xml" />

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.

<ComponentType name="iafBase" extends="abstractCellVolt">     
   <Parameter name="thresh" dimension="voltage" />     
   <Parameter name="reset" dimension="voltage" />
</ComponentType>
<ComponentType name="iafTau" extends="iafBase">     
   <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):

<iafTau id="iaf" leakReversal="-50mV" thresh="-55mV" reset="-70mV" tau="30ms" />
<network id="net1">     
   <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:

<ionChannel id="na" type="ionChannelHH" conductance="10pS">    
   <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:

<abstractCell id="hhcell" type="pointCellCondBased" capacitance="10pF" v0="-65mV" thresh="20mV">     
   <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>
<pulseGenerator id="pulseGen1" delay="100ms" duration="100ms" amplitude="0.08 nA" />

A simple network of one cell is created:

<network id="net1">     
   <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):

<ComponentType name="izhikevichCell" extends="abstractCellMembPot">
   <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):

<izhikevichCell id="izBurst" v0="-70mV" thresh="30mV" a="0.02" b="0.2" c="-50.0" d="2" Iamp="15" Idel="22ms" Idur="2000ms" />
<izhikevichCell id="izTonic" v0="-70mV" thresh="30mV" a="0.02" b="0.2" c="-65.0" d="6" Iamp="14" Idel="20ms" Idur="2000ms" />
<izhikevichCell id="izMixed" v0="-70mV" thresh="30mV" a="0.02" b="0.2" c="-55.0" d="4" Iamp="10" Idel="20ms" Idur="2000ms" />
<network id="net1">     
   <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:

<expOneSynapse id="sy1" gbase="0.5nS" erev="0mV" tau="3ms" />
<expTwoSynapse id="sy2" gbase="0.5nS" erev="0mV" tauRise="1ms" tauDecay="2ms" />

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:

<ionChannel id="k_vh" conductance="8pS">     
   <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

<Include file="NeuroML2CoreTypes/NeuroMLCoreDimensions.xml" />
<Include file="NeuroML2CoreTypes/Cells.xml" />
<Include file="NeuroML2CoreTypes/Networks.xml" />
<Include file="NeuroML2CoreTypes/Simulation.xml" />
<!-- Including file with a <neuroml> root, a "real" NeuroML 2 file -->
<Include file="DetailedHHCell.nml" />

<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.

DetailedHHCell.nml (xml)
<neuroml xmlns="http://www.neuroml.org/schema/neuroml2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.neuroml.org/schema/neuroml2 ../Schemas/NeuroML2/NeuroML_v2alpha.xsd" id="DetailedHHCell"> <!-- A file containing only NeuroML2 elements. Valid according to draft schema http://neuroml.svn.sourceforge.net/viewvc/neuroml/DemoVer2.0/lems/Schemas/NeuroML2/NeuroML_v2alpha.xsd -->         
   <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:

<nmdaSynapse id="nmdaSyn" gbase="0.5nS" erev="0mV" tauRise="2ms" tauDecay="8ms">             
   <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:

<expTwoSynapse id="noStpSyn" gbase="1nS" erev="0mV" tauRise="0.1ms" tauDecay="2ms" />
<stpSynapse id="stpSynDep" gbase="1nS" erev="0mV" tauRise="0.1ms" tauDecay="2ms">                 
   <plasticity initReleaseProb="0.5" tauFac="0 ms" tauRec="120 ms" />         
</stpSynapse>
<stpSynapse id="stpSynFac" gbase="1nS" erev="0mV" tauRise="0.1ms" tauDecay="2ms">                 
   <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:

<adExIaFCell id="adExBurst2" C="281pF" gL="30nS" EL="-70.6mV" reset="-48.5mV" VT="-50.4mV" thresh="-40.4mV" delT="2mV" tauw="40ms" a="4nS" b="0.08nA" Iamp="0.8nA" Idel="0ms" Idur="2000ms" />
<adExIaFCell id="adExBurst4" C="281pF" gL="30nS" EL="-70.6mV" reset="-47.2mV" VT="-50.4mV" thresh="-40.4mV" delT="2mV" tauw="40ms" a="4nS" b="0.08nA" Iamp="0.8nA" Idel="0ms" Idur="2000ms" />
<adExIaFCell id="adExBurstChaos" C="281pF" gL="30nS" EL="-70.6mV" reset="-48mV" VT="-50.4mV" thresh="-40.4mV" delT="2mV" tauw="40ms" a="4nS" b="0.08nA" Iamp="0.8nA" Idel="0ms" Idur="2000ms" />
<adExIaFCell id="adExRebound" C="281pF" gL="30nS" EL="-60mV" reset="-51mV" VT="-54mV" thresh="-30mV" delT="2mV" tauw="150ms" a="200nS" b="0.1nA" Iamp="-0.5nA" Idel="150ms" Idur="50ms" />
<network id="net1">     
   <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:

<TimeDerivative variable="v" value="(-1*gL*(v-EL) + gL*delT*exp((v - VT)/delT) - w + I)/C" />
<TimeDerivative variable="w" value="(a*(v-EL) - w) / tauw" />

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:

<TimeDerivative variable="V" value="tscale * (V - V^3 - W + I)" />
<TimeDerivative variable="W" value="tscale * (0.08 * (V + 0.7 - W))" />

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.