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>

  <!-- Tell jLEMS/jNeuroML which component is the simulation entry point. -->
  <Target component="sim_NeuroML_Ex19__Gap_Junctions"/>

  <!-- ════════════════════════════════════════════════════════════════
       Standard NeuroML2 type includes for network mode.
       Provides all standard dimensions, units, synapse types, input
       types, network infrastructure, and simulation types.
       ════════════════════════════════════════════════════════════════ -->
  <Include file="Cells.xml"/>
  <Include file="Networks.xml"/>
  <Include file="Simulation.xml"/>

  <!-- ════════════════════════════════════════════════════════════════
       Dynamics ComponentType & Component instances
       ════════════════════════════════════════════════════════════════ -->


  <!-- ── ComponentType: iaf ── -->
  <ComponentType name="iaf" extends="baseCellMembPot">
    <Parameter name="tau" dimension="none"/>
    <Parameter name="leakReversal" dimension="voltage"/>
    <Parameter name="thresh" dimension="voltage"/>
    <Parameter name="reset" dimension="voltage"/>
    <Parameter name="C" dimension="capacitance"/>
    <Parameter name="leakConductance" dimension="conductance"/>
    <Parameter name="refract" dimension="time"/>
    <Parameter name="v_0" dimension="none" />
    <!-- Dynamically attached synapses/inputs from network connections -->
    <Attachments name="synapses" type="basePointCurrent"/>

    <Dynamics>
      <StateVariable name="v" dimension="none" exposure="v"/>
      <StateVariable name="lastSpikeTime" dimension="time"/>
      <ConditionalDerivedVariable name="I_ext" dimension="none">
        <Case condition="t .geq. 0.1 .and. t .lt. 0.2" value="0.300000000000000"/>
        <Case value="0.0"/>
      </ConditionalDerivedVariable>
      <!-- ── Regime-based dynamics (spike model) ── -->
      <OnStart>
        <StateAssignment variable="v" value="v_0"/>
      </OnStart>

      <Regime name="integrating" initial="true">
        <TimeDerivative variable="v" value

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}")
pyNeuroML >>> 17:18:22 - INFO - Loading LEMS file: tvbo_lems_sim.xml and running with jNeuroML
pyNeuroML >>> 17:18:22 - 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/tmphlxgaq81
pyNeuroML >>> 17:18:23 - INFO - Command completed successfully!
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")