NML2_InstanceBasedNetwork.nml
Demonstrates <instance> elements within a population, giving each cell explicit 3D coordinates for spatial positioning:
<population id="pop0" component="iaf0" size="3" type="populationList">
<instance id="0"> <location x="0" y="0" z="0"/> </instance>
<instance id="1"> <location x="100" y="0" z="0"/> </instance>
<instance id="2"> <location x="0" y="100" z="0"/> </instance>
</population>
from pathlib import Path
nml_file = Path.home() / "work_data/toolboxes/NeuroML2/examples/NML2_InstanceBasedNetwork.nml"
text = nml_file.read_text()
# Show network structure
in_network = False
for line in text.split('\n'):
if '<network' in line:
in_network = True
if in_network:
print(line.rstrip()[:100])
if '</network' in line:
break
<network id="InstanceBasedNetwork">
<population id="iafCells" type="populationList" component="iaf" size="3">
<instance id="0">
<location x="120" y="230" z="567"/>
</instance>
<instance id="1">
<location x="270" y="450" z="56"/>
</instance>
<instance id="2">
<location x="54" y="234" z="89"/>
</instance>
</population>
<projection id="internal1" presynapticPopulation="iafCells" postsynapticPopulation="iafCells
<!--TODO: Fix! want to define synapse in here, so that multiple synapses per connection
<synapseComponent component="syn1"/>-->
<!--TODO: Fix! want to use preCellId="0" -->
<connection id="0" preCellId="../iafCells/0/iaf" postCellId="../iafCells/1/iaf"/>
</projection>
<projection id="internal2" presynapticPopulation="iafCells" postsynapticPopulation="iafCells
<connection id="0" preCellId="../iafCells/0/iaf" postCellId="../iafCells/2/iaf"/>
</projection>
<inputList id="stimInput" component="pulseGen1" population="iafCells">
<!--TODO: Fix! want to use target="0" -->
<input id="0" target="../iafCells/0/iaf" destination="synapses"/>
</inputList>
</network>
TVBO Representation: IaF Cell
from tvbo import SimulationExperiment
exp = SimulationExperiment.from_string("""
label: "NML2 InstanceBasedNetwork: IaF Cell"
dynamics:
name: IntegrateAndFire
parameters:
leakReversal: { value: -50.0 }
tau: { value: 30.0 }
thresh: { value: -55.0 }
reset: { value: -70.0 }
state_variables:
v:
equation: { rhs: "(leakReversal - v) / tau" }
initial_value: -50.0
variable_of_interest: true
events:
spike:
condition: { rhs: "v > thresh" }
affect: { rhs: "v = reset" }
network:
number_of_nodes: 1
integration:
method: euler
step_size: 0.005
duration: 300.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_InstanceBasedNetwork__IaF_Cell"/>
<!-- ════════════════════════════════════════════════════════════════
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=
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 InstanceBasedNetwork: IaF Cell via TVBO")
ax.grid(True, alpha=0.3)
plt.tight_layout()
plt.show()