Ex19: Gap Junctions

Electrical synapses (gap junctions) between integrate-and-fire cells

Model: Gap Junctions

Two iafCells connected by a gap junction (electrical synapse), each driven by a separate pulseGenerator at different times. Demonstrates bidirectional current flow.

Reference: NeuroML2 LEMS_NML2_Ex19_GapJunctions.xml


1. Define Network in TVBO

from tvbo import SimulationExperiment

exp = SimulationExperiment.from_string("""
label: "NeuroML Ex19: Gap Junctions"
dynamics:
  name: iafCell
  iri: neuroml:iafCell
network:
  dynamics:
    iaf:
      name: iaf
      iri: neuroml:iafCell
      parameters:
        leakConductance: {value: 0.2, unit: nS}
        leakReversal: {value: -70, unit: mV}
        thresh: {value: -55, unit: mV}
        reset: {value: -70, unit: mV}
        C: {value: 3.2, unit: pF}
    pg1:
      name: pg1
      iri: neuroml:pulseGenerator
      parameters:
        delay: {value: 50, unit: ms}
        duration: {value: 200, unit: ms}
        amplitude: {value: 0.0032, unit: nA}
    pg2:
      name: pg2
      iri: neuroml:pulseGenerator
      parameters:
        delay: {value: 400, unit: ms}
        duration: {value: 200, unit: ms}
        amplitude: {value: 0.0032, unit: nA}
  nodes:
    - {id: 0, dynamics: iaf}
    - {id: 1, dynamics: iaf}
    - {id: 10, dynamics: pg1}
    - {id: 11, dynamics: pg2}
  edges:
    - source: 0
      target: 1
      coupling: gapJunction
      parameters:
        conductance: {value: 10, unit: pS}
    - {source: 10, target: 0}
    - {source: 11, target: 1}
integration:
  method: euler
  step_size: 0.01
  duration: 700.0
  time_scale: ms
""")
print(f"Model: {exp.dynamics.name if exp.dynamics else 'network'}")
Model: iafCell

2. Render LEMS XML

xml = exp.render("lems")
print(xml[:2000])
<Lems>
  <Target component="sim_NeuroML_Ex19__Gap_Junctions"/>

  <Include file="Cells.xml"/>
  <Include file="Networks.xml"/>
  <Include file="Inputs.xml"/>
  <Include file="Simulation.xml"/>

    <iafCell id="iaf" C="3.2 pF" leakConductance="0.2 nS" leakReversal="-70 mV" reset="-70 mV" thresh="-55 mV"/>

    <pulseGenerator id="pg1" amplitude="0.0032 nA" delay="50.0 ms" duration="200.0 ms"/>

    <pulseGenerator id="pg2" amplitude="0.0032 nA" delay="400.0 ms" duration="200.0 ms"/>

    <gapJunction id="gapJunction" conductance="10.0 pS"/>

    <network id="net1">
        <population id="iaf_pop" component="iaf" size="2"/>
        <electricalProjection id="elecProj_0" presynapticPopulation="iaf_pop" postsynapticPopulation="iaf_pop">
            <electricalConnection id="0" preCell="0" postCell="1" synapse="gapJunction"/>
        </electricalProjection>
        <explicitInput target="iaf_pop[0]" input="pg1" destination="synapses"/>
        <explicitInput target="iaf_pop[1]" input="pg2" destination="synapses"/>
    </network>

    <Simulation id="sim_NeuroML_Ex19__Gap_Junctions" length="700.0ms" step="0.01ms" target="net1">
        <OutputFile id="of0" fileName="results/iaf.dat">
            <OutputColumn id="iaf_pop_0_v" quantity="iaf_pop[0]/v"/>
            <OutputColumn id="iaf_pop_1_v" quantity="iaf_pop[1]/v"/>
        </OutputFile>
    </Simulation>

</Lems>

3. Run Reference

from tvbo.adapters.neuroml import run_lems_example

ref_outputs = run_lems_example("LEMS_NML2_Ex19_GapJunctions.xml")
for name, arr in ref_outputs.items():
    print(f"  {name}: shape={arr.shape}")
  ex19_v.dat: shape=(70001, 3)

4. Run TVBO

result = exp.run("neuroml")
da = result.integration.data
print(f"TVBO: {da.dims}, shape={da.shape}")
TVBO: ('time', 'quantity'), shape=(70001, 2)

5. Compare & Plot

from tvbo.adapters.neuroml import plot_lems_comparison
plot_lems_comparison("LEMS_NML2_Ex19_GapJunctions.xml", ref_outputs, result.integration.data, title_prefix="Ex19")