NML2_SingleCompHHCell.nml
The recommended way to define a HH cell in NeuroML2: using the <cell> element with explicit morphology (segment), membrane properties (channel densities), and intracellular properties.
This is the canonical example for compatibility with multi-simulator export (NEURON, Brian2, NEST) via pyNeuroML.
from pathlib import Path
nml_file = Path.home() / "work_data/toolboxes/NeuroML2/examples/NML2_SingleCompHHCell.nml"
text = nml_file.read_text()
# Show key structure
in_cell = False
for line in text.split(' \n ' ):
stripped = line.strip()
if '<cell ' in stripped or '<morphology' in stripped or \
'<biophysicalProperties' in stripped or '<channelDensity' in stripped or \
'<specificCapacitance' in stripped or '<initMembPotential' in stripped or \
'</cell>' in stripped:
print (stripped[:120 ])
<cell id="hhcell">
<morphology id="morph1">
<biophysicalProperties id="bioPhys1">
<channelDensity id="leak" ionChannel="passiveChan" condDensity="3.0 S_per_m2" erev="-54.3mV" ion="non_specific"/>
<channelDensity id="naChans" ionChannel="naChan" condDensity="120.0 mS_per_cm2" erev="50.0 mV" ion="na"/>
<channelDensity id="kChans" ionChannel="kChan" condDensity="360 S_per_m2" erev="-77mV" ion="k"/>
<specificCapacitance value="1.0 uF_per_cm2"/>
<initMembPotential value="-65mV"/>
</cell>
TVBO Equivalent
See Ex1_HH.qmd and Ex5_DetCell.qmd for the equivalent TVBO HH model with numerical comparison.
The key difference: NeuroML’s <cell> format separates morphology, channels, and biophysics into composable elements. TVBO’s Dynamics flattens everything into a single ODE system.
<cell> → <biophysicalProperties> → <channelDensity>
Dynamics.state_variables + derived_variables
<morphology> → <segment>
Not represented (point neuron)
<ionChannelHH> → <gateHHrates> → <forwardRate>
derived_variables.alpha_m etc.
from tvbo import SimulationExperiment
exp = SimulationExperiment.from_string("""
label: "NML2 SingleCompHHCell"
dynamics:
name: HodgkinHuxley
parameters:
C: { value: 10.0 }
g_Na: { value: 1200.0 }
g_K: { value: 360.0 }
g_L: { value: 3.0 }
E_Na: { value: 50.0 }
E_K: { value: -77.0 }
E_L: { value: -54.3 }
I_ext: { value: 0.08 }
derived_variables:
alpha_m:
equation:
rhs: "Piecewise((1.0, Eq(v, -40.0)), (0.1*(v + 40.0)/(1.0 - exp(-(v + 40.0)/10.0)), True))"
beta_m:
equation: { rhs: "4.0*exp(-(v + 65.0)/18.0)" }
alpha_h:
equation: { rhs: "0.07*exp(-(v + 65.0)/20.0)" }
beta_h:
equation: { rhs: "1.0/(1.0 + exp(-(v + 35.0)/10.0))" }
alpha_n:
equation:
rhs: "Piecewise((0.1, Eq(v, -55.0)), (0.01*(v + 55.0)/(1.0 - exp(-(v + 55.0)/10.0)), True))"
beta_n:
equation: { rhs: "0.125*exp(-(v + 65.0)/80.0)" }
state_variables:
v:
equation:
rhs: "(-g_Na*m**3*h*(v - E_Na) - g_K*n**4*(v - E_K) - g_L*(v - E_L) + I_ext*1000) / C"
initial_value: -65.0
variable_of_interest: true
m:
equation: { rhs: "alpha_m*(1 - m) - beta_m*m" }
initial_value: 0.05
h:
equation: { rhs: "alpha_h*(1 - h) - beta_h*h" }
initial_value: 0.6
n:
equation: { rhs: "alpha_n*(1 - n) - beta_n*n" }
initial_value: 0.32
network:
number_of_nodes: 1
integration:
method: euler
step_size: 0.01
duration: 150.0
time_scale: ms
""" )
xml = exp.render("lems" )
print (xml[:800 ])
<Lems>
<!-- Tell jLEMS/jNeuroML which component is the simulation entry point. -->
<Target component="sim_NML2_SingleCompHHCell"/>
<!-- ════════════════════════════════════════════════════════════════
Dimensions & Units (inline — no external includes needed)
════════════════════════════════════════════════════════════════ -->
<!-- Dimensions -->
<Dimension name="none"/>
<Dimension name="time" t="1"/>
<Dimension name="voltage" m="1" l="2" t="-3" i="-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="resistance" m="1" l="2" t="-3" i="-2"/>
<Dimension name="concentration" l="-3" n="1"/>
<Dimen
Run TVBO
import numpy as np
import matplotlib.pyplot as plt
result = exp.run("neuroml" )
da = result.integration.data
t = da.coords['time' ].values
v = da.values[:, 0 ]
fig, ax = plt.subplots(figsize= (10 , 4 ))
ax.plot(t, v)
ax.set_xlabel("Time (ms)" )
ax.set_ylabel("Voltage (mV)" )
ax.set_title("NML2 SingleCompHHCell: HH via TVBO" )
ax.grid(True , alpha= 0.3 )
plt.tight_layout()
plt.show()