Interoperability · NeuroML / LEMS
NML2_FullCell.nml
Combines morphology and biophysics in a complete cell definition, ready for multi-compartment simulation. Includes:
Detailed morphology with soma, axon, and dendritic segments
Channel densities assigned to segment groups
Specific capacitance and initial membrane potential
import urllib.request
url = "https://raw.githubusercontent.com/NeuroML/NeuroML2/master/examples/NML2_FullCell.nml"
with urllib.request.urlopen(url) as resp:
text = resp.read().decode()
# Count segments and channels
import re
n_segments = len (re.findall(r'<segment ' , text))
n_channels = len (re.findall(r'<channelDensity' , text))
n_groups = len (re.findall(r'<segmentGroup' , text))
print (f"Segments: { n_segments} , Channel densities: { n_channels} , Segment groups: { n_groups} " )
# Show cell structure
for line in text.split(' \n ' ):
stripped = line.strip()
if any (tag in stripped for tag in ['<cell ' , '<morphology' , '<biophysical' ,
'<channelDensity' , '<specificCapacitance' , '</cell>' ]):
print (stripped[:120 ])
Segments: 4, Channel densities: 2, Segment groups: 3
<cell id="SpikingCell" metaid="HippoCA1Cell">
<morphology id="SpikingCell_morphology">
<biophysicalProperties id="bio_cell">
<channelDensity id="pasChans" ionChannel="pas" condDensity="3.0 S_per_m2" erev="-70mV" ion="non_specific"/> <!-- no segm
<channelDensity id="naChansSoma" ionChannel="NaConductance" segmentGroup="soma_group" condDensity="120.0 mS_per_cm2" ere
<specificCapacitance segmentGroup="soma_group" value="1.0 uF_per_cm2"/>
<specificCapacitance segmentGroup="dendrite_group" value="2.0 uF_per_cm2"/>
</cell>
TVBO Representation: HH Cell
from tvbo import SimulationExperiment
exp = SimulationExperiment.from_string("""
label: "NML2 FullCell: HH"
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 ])
* Owlready2 * Warning: ignoring cyclic subclass of/subproperty of, involving:
http://uri.interlex.org/tgbugs/uris/readable/atlas/Space
<Lems>
<!-- Tell jLEMS/jNeuroML which component is the simulation entry point. -->
<Target component="sim_NML2_FullCell__HH"/>
<Include file="Cells.xml"/>
<Include file="Networks.xml"/>
<Include file="Simulation.xml"/>
<!-- ════════════════════════════════════════════════════════════════
Dynamics ComponentType & Component instances
════════════════════════════════════════════════════════════════ -->
<!-- ════════════════════════════════════════════════════════════════
ComponentType: HodgkinHuxley
Generated from TVBO Dynamics: HodgkinHuxley
════════════════════════════════════════════════════════════════ -->
<ComponentType name="HodgkinHuxley">
<!-- Parameters -->
<Parameter name="C" dimension="none"/>
<Parameter name="E_K"
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 FullCell: HH Cell via TVBO" )
ax.grid(True , alpha= 0.3 )
plt.tight_layout()
plt.show()
pyNeuroML >>> 13:08:18 - INFO - Loading LEMS file: tvbo_lems_sim.xml and running with jNeuroML
pyNeuroML >>> 13:08:18 - INFO - Executing: (java -Xmx400M -Djava.awt.headless=true -jar "/Users/leonmartin_bih/tools/tvbo/.venv/lib/python3.12/site-packages/pyneuroml/utils/./../lib/jNeuroML-0.14.0-jar-with-dependencies.jar" tvbo_lems_sim.xml -nogui -I '') in directory: /var/folders/ym/9kw1g21j1nd7kwfn8c0z3st40000gn/T/tmp2prto3wh
pyNeuroML >>> 13:08:19 - INFO - Command completed successfully!