Example 2: tidying up example 1

This models is the same as in example 1, except that the definitions have been split out into several self-contained files. The files can be downloaded together as examples.zip.

The main file, included below, uses the Include element to include definitions from other files. Each file is only read once, even if several files include it. Because some of these files, such as the HH channel definitions, are intended to be used on their own, they include all the dimension definitions they need. These may also occur in other files with the same dimension names. This is fine as long as the dimensions being declared are the same. An error will be reported if a new definition is supplied that changes any of the values. The same applies for Unit definitions. For other element types names and ids must be unique. An id or name can't appear twice, even if the content of the elements is the same.

The main model

This defines a few components, then a network that uses them and a simulation to run it all. The HHCell component refers to channel types coming from the included hhmodels.xml file which in turn depends on hhcell.xml and hhchannel.xml.

example2.xml (xml)
<Lems>  
   <Target component="simset" />  
   <Include file="ex2dims.xml" />
   <Include file="hhchannel.xml" />   
   <Include file="hhcell.xml" />
   <Include file="spikegenerators.xml" />
   <Include file="hhmodels.xml" />
   <Include file="misciaf.xml" /> 
   <Include file="SimpleNetwork.xml" />
   <Include file="MultiRunSimulation.xml" />

   <HHCell id="hhcell_1" capacitance="1pF" injection="4pA" v0="-60mV">     
      <ChannelPopulation channel="na" number="6000" erev="50mV" />     
      <ChannelPopulation channel="k" number="1800" erev="-77mV" />
   </HHCell>  

   <Component id="gen1" type="spikeGenerator" period="30ms" />

   <Component id="gen2" type="spikeGenerator2" period="32ms" />

   <Component id="iaf3cpt" type="iaf3" leakReversal="-50mV" deltaV="50mV" threshold="-30mV" leakConductance="50pS" refractoryPeriod="4ms" capacitance="1pF" />

   <Network id="net1">     
      <Population id="p1" component="gen1" size="1" />     
      <Population id="p2" component="gen2" size="1" />     
      <Population id="p3" component="iaf3cpt" size="1" />         
      <Population id="hhpop" component="hhcell_1" size="1" />              
      <EventConnectivity id="p1-p3" source="p1" target="p3">         
         <Connections type="AllAll" />     
      </EventConnectivity>
   </Network>
   <SimulationSet id="simset">
      <Display id="disp1" title="Example2" xmin="0" xmax="80" ymin="-80" ymax="50" />

      <Simulation id="sim1" length="80ms" step="0.04ms" target="net1" display="disp1">      
         <DisplayList timeScale="1ms" title="0.04 ms">         
            <Line id="tsince-a" quantity="p1[0]/tsince" scale="1ms" timeScale="1ms" color="#00c000" />              
            <Line id="p3v-a" quantity="p3[0]/v" scale="1mV" timeScale="1ms" color="#0000f0" />         
            <Line id="p0v-a" quantity="hhpop[0]/v" scale="1mV" timeScale="1ms" color="#ff4040" />     
         </DisplayList>
      </Simulation>   
   </SimulationSet>
</Lems>

Included files

ex2dims.xml (xml)
<Lems>      
   <Dimension name="voltage" m="1" l="2" t="-3" i="-1" />     
   <Dimension name="time" t="1" />     
   <Dimension name="per_time" t="-1" />     
   <Dimension name="conductance" m="-1" l="-2" t="3" i="2" />     
   <Dimension name="capacitance" m="-1" l="-2" t="4" i="2" />     
   <Dimension name="current" i="1" />
   <Dimension name="temperature" k="1" />     
   <Unit symbol="mV" dimension="voltage" power="-3" />      
   <Unit symbol="ms" dimension="time" power="-3" />      
   <Unit symbol="pS" dimension="conductance" power="-12" />     
   <Unit symbol="nS" dimension="conductance" power="-9" />     
   <Unit symbol="uF" dimension="capacitance" power="-6" />     
   <Unit symbol="nF" dimension="capacitance" power="-9" />     
   <Unit symbol="pF" dimension="capacitance" power="-12" />     
   <Unit symbol="per_ms" dimension="per_time" power="3" />     
   <Unit symbol="pA" dimension="current" power="-12" />     
   <Unit symbol="nA" dimension="current" power="-9" />
   <Unit symbol="degC" dimension="temperature" offset="273.15" />
</Lems>

The file hhchannel.xml contains complete definitions of a fairly general HH-style channel model with any number of gates based on the three standard types used in the original HH work.

hhchannel.xml (xml)
<Lems>
   <Dimension name="voltage" m="1" l="2" t="-3" i="-1" />
   <Dimension name="time" t="1" />
   <Dimension name="per_time" t="-1" />
   <Dimension name="conductance" m="-1" l="-2" t="3" i="2" />
   <Dimension name="capacitance" m="-1" l="-2" t="4" i="2" />
   <Dimension name="current" i="1" />  
   <ComponentType name="HHRate">     
      <Parameter name="rate" dimension="per_time" />     
      <Parameter name="midpoint" dimension="voltage" />     
      <Parameter name="scale" dimension="voltage" />     
      <Requirement name="v" dimension="voltage" />     
      <Exposure name="r" dimension="per_time" />
   </ComponentType>
   <ComponentType name="HHExpRate" extends="HHRate">     
      <Dynamics>         
         <DerivedVariable name="r" exposure="r" value="rate * exp((v - midpoint)/scale)" />     
      </Dynamics>
   </ComponentType>
   <ComponentType name="HHSigmoidRate" extends="HHRate">     
      <Dynamics>         
         <DerivedVariable name="r" exposure="r" value="rate / (1 + exp( -(v - midpoint)/scale))" />     
      </Dynamics>
   </ComponentType>  
   <ComponentType name="HHExpLinearRate" extends="HHRate">     
      <Dynamics>         
         <DerivedVariable name="x" value="(v - midpoint) / scale" />         
         <DerivedVariable name="r" exposure="r" value="rate * x / (1 - exp(-x))" />     
      </Dynamics>
   </ComponentType>  
   <ComponentType name="HHGate0">     
      <Parameter name="power" dimension="none" />      
      <Child name="Forward" type="HHRate" />     
      <Child name="Reverse" type="HHRate" />     
      <Requirement name="v" dimension="voltage" />     
      <Exposure name="fcond" dimension="none" />          
      <Dynamics simultaneous="true">         
         <StateVariable name="q" dimension="none" />         
         <DerivedVariable dimension="per_time" name="rf" select="Forward/r" />         
         <DerivedVariable dimension="per_time" name="rr" select="Reverse/r" />          
         <TimeDerivative variable="q" value="rf * (1 - q) - rr * q" />         
         <DerivedVariable name="fcond" exposure="fcond" value="q^power" />     
      </Dynamics>    
   </ComponentType>
   <Include file="hhaltgate.xml" />
   <ComponentType name="HHChannel">     
      <Parameter name="conductance" dimension="conductance" />     
      <Children name="gates" type="HHGate" />     
      <Exposure name="g" dimension="conductance" />     
      <Dynamics simultaneous="false">         
         <DerivedVariable name="gatefeff" dimension="none" select="gates[*]/fcond" reduce="multiply" />         
         <DerivedVariable name="g" exposure="g" dimension="conductance" value="conductance * gatefeff" />     
      </Dynamics>
   </ComponentType>  
</Lems>

As mentioned in example1, the numerics are too feeble to cope with this gate definition though, so a change of variables is employed instead:

hhaltgate.xml (xml)
<Lems>  
   <ComponentType name="HHGate">     
      <Parameter name="power" dimension="none" />      
      <Child name="Forward" type="HHRate" />     
      <Child name="Reverse" type="HHRate" />     
      <Requirement name="v" dimension="voltage" />     
      <Exposure name="fcond" dimension="none" />              
      <Dynamics simultaneous="false">         
         <StateVariable name="x" dimension="none" />         
         <DerivedVariable name="ex" dimension="none" value="exp(x)" />         
         <DerivedVariable name="q" dimension="none" value="ex / (1 + ex)" />         
         <DerivedVariable name="rf" dimension="per_time" select="Forward/r" />         
         <DerivedVariable name="rr" dimension="per_time" select="Reverse/r" />                   
         <TimeDerivative variable="x" value="(1 + ex)^2 / ex * (rf * (1 - q) - rr * q)" />                
         <DerivedVariable name="fcond" exposure="fcond" value="q^power" />     
      </Dynamics>    
   </ComponentType>
</Lems>

The file hhcell.xml defines a simple cell model with some populations of HH channels.

hhcell.xml (xml)
<Lems>
   <Include file="hhchannel.xml" />
   <Dimension name="voltage" m="1" l="2" t="-3" i="-1" />
   <Dimension name="capacitance" m="-1" l="-2" t="4" i="2" />
   <Dimension name="current" i="1" />  
   <ComponentType name="ChannelPopulation">     
      <ComponentReference name="channel" type="HHChannel" />     
      <Parameter name="number" dimension="none" />     
      <Parameter name="erev" dimension="voltage" />     
      <Requirement name="v" dimension="voltage" />     
      <Exposure name="current" dimension="current" />     
      <Exposure name="geff" dimension="conductance" />                   
      <Structure>         
         <ChildInstance component="channel" />     
      </Structure>           
      <Dynamics simultaneous="false">         
         <DerivedVariable name="channelg" dimension="conductance" select="channel/g" />         
         <DerivedVariable name="geff" exposure="geff" value="channelg * number" />         
         <DerivedVariable name="current" exposure="current" value="geff * (erev - v)" />     
      </Dynamics>     
   </ComponentType>
   <ComponentType name="HHCell">     
      <Parameter name="capacitance" dimension="capacitance" />     
      <Children name="populations" type="ChannelPopulation" />     
      <Parameter name="injection" dimension="current" />     
      <Parameter name="v0" dimension="voltage" />     
      <Exposure name="v" dimension="voltage" />          
      <Dynamics simultaneous="true">         
         <OnStart>              
            <StateAssignment variable="v" value="v0" />         
         </OnStart>             
         <DerivedVariable name="totcurrent" dimension="current" select="populations[*]/current" reduce="add" />         
         <StateVariable name="v" exposure="v" dimension="voltage" />          
         <TimeDerivative variable="v" value="(totcurrent + injection) / capacitance" />     
      </Dynamics>
   </ComponentType>  
</Lems>

A couple of spike generators.

spikegenerators.xml (xml)
<Lems>
   <Dimension name="time" t="1" />  
   <ComponentType name="spikeGenerator">     
      <Parameter name="period" dimension="time" />     
      <EventPort name="a" direction="out" />     
      <Exposure name="tsince" dimension="time" />     
      <Dynamics>         
         <StateVariable name="tsince" exposure="tsince" dimension="time" />         
         <TimeDerivative variable="tsince" value="1" />         
         <OnCondition test="tsince .gt. period">             
            <StateAssignment variable="tsince" value="0" />             
            <EventOut port="a" />         
         </OnCondition>     
      </Dynamics>
   </ComponentType>
   <ComponentType name="spikeGenerator2" extends="spikeGenerator">     
      <Dynamics>         
         <DerivedVariable name="tsince" exposure="tsince" value="t - tlast" />         
         <StateVariable name="tlast" dimension="time" />         
         <OnCondition test="t - tlast .gt. period">             
            <StateAssignment variable="tlast" value="t" />             
            <EventOut port="a" />         
         </OnCondition>     
      </Dynamics>
   </ComponentType>  
</Lems>

And now the components themselves. These are the standard HH sodium and potassium channels (as used in Rallpack3).

hhmodels.xml (xml)
<Lems>     
   <Include file="hhchannel.xml" />     
   <Unit symbol="mV" dimension="voltage" power="-3" />      
   <Unit symbol="per_ms" dimension="per_time" power="3" />     
   <Unit symbol="pS" dimension="conductance" power="-12" />          

   <HHChannel id="na" conductance="20pS">         
      <HHGate id="m" power="3">             
         <Forward type="HHExpLinearRate" rate="1.per_ms" midpoint="-40mV" scale="10mV" />             
         <Reverse type="HHExpRate" rate="4per_ms" midpoint="-65mV" scale="-18mV" />        
      </HHGate>             
      <HHGate id="h" power="1">            
         <Forward type="HHExpRate" rate="0.07per_ms" midpoint="-65.mV" scale="-20.mV" />            
         <Reverse type="HHSigmoidRate" rate="1per_ms" midpoint="-35mV" scale="10mV" />        
      </HHGate>     
   </HHChannel>     

   <HHChannel id="k" conductance="20pS">         
      <HHGate id="n" power="4">             
         <Forward type="HHExpLinearRate" rate="0.1per_ms" midpoint="-55mV" scale="10mV" />             
         <Reverse type="HHExpRate" rate="0.125per_ms" midpoint="-65mV" scale="-80mV" />         
      </HHGate>     
   </HHChannel>
</Lems>

Some miscellaneous iaf models.

misciaf.xml (xml)
<Lems>     
   <Include file="elecdims.xml" />    
   <ComponentType name="iaf1">     
      <Parameter name="threshold" dimension="voltage" />     
      <Parameter name="refractoryPeriod" dimension="time" />     
      <Parameter name="capacitance" dimension="capacitance" />
   </ComponentType>
   <ComponentType name="iaf3" extends="iaf1">     
      <Parameter name="leakConductance" dimension="conductance" />     
      <Parameter name="leakReversal" dimension="voltage" />     
      <Parameter name="deltaV" dimension="voltage" />     
      <EventPort name="spikes-in" direction="in" />     
      <Exposure name="v" dimension="voltage" />     
      <Dynamics>        
         <StateVariable name="v" exposure="v" dimension="voltage" />        
         <TimeDerivative variable="v" value="leakConductance * (leakReversal - v) / capacitance" />                      
         <OnEvent port="spikes-in">             
            <StateAssignment variable="v" value="v + deltaV" />        
         </OnEvent>           
      </Dynamics>
   </ComponentType>  
</Lems>

Finally, a small collection of dimension definitions useful for things like the miscellaneous iaf cell definitions.

elecdims.xml (xml)
<Lems>     
   <Dimension name="voltage" m="1" l="2" t="-3" i="-1" />     
   <Dimension name="time" t="1" />     
   <Dimension name="conductance" m="-1" l="-2" t="3" i="2" />     
   <Dimension name="capacitance" m="-1" l="-2" t="4" i="2" />     
   <Dimension name="current" i="1" />     
</Lems>