Ex24: Fractional Conductance

Slow K channel with gateFractional, custom rate types, and cell morphology

Model: Fractional Conductance

Demonstrates <gateFractional> with <subGate> — the slow potassium channel uses a fractional conductance formalism where gate b is composed of two sub-gates (bb, bb1), each contributing 50 % of the total conductance with independent time courses.

The channel also includes:

  • Custom rate types (kslow_a_alpha_rate, kslow_a_beta_rate) — built from equations
  • Custom time course types (kslow_b_tau, kslow_b1_tau) — built from equations
  • Q10 temperature scaling at 34 °C (experimentalTemp = 21 °C)
  • cell type with single-segment cylinder morphology and channelDensity

TVBO defines all of this declaratively using the composition tree (components: key). Standard NeuroML types use iri: neuroml:* shortcuts; custom types use derived_variables: to build LEMS <ComponentType> definitions from equations.


1. Define in TVBO

from tvbo import SimulationExperiment

exp = SimulationExperiment.from_string("""
label: "NeuroML Ex24: Fractional Conductance"
dynamics:
  name: hhtest
  iri: neuroml:cell
  parameters:
    diameter:            { value: 10 }
    length:              { value: 20 }
    specificCapacitance: { value: 1.0, unit: uF_per_cm2 }
    initMembPotential:   { value: -65.0, unit: mV }
    spikeThresh:         { value: 0, unit: mV }
    resistivity:         { value: 0.1, unit: kohm_cm }
    network_temperature: { value: 34, unit: degC }
  components:
    # ── Slow K channel with fractional conductance ──
    k_slow:
      name: k_slow
      iri: neuroml:ionChannelHH
      parameters:
        conductance: { value: 10, unit: pS }
        species:     { description: k }
        condDensity: { value: 0.036, unit: S_per_cm2 }
        erev:        { value: -77, unit: mV }
        ion:         { description: k }
      components:
        a:
          name: a
          iri: neuroml:gateHHrates
          parameters:
            instances: { value: 2 }
          components:
            q10Settings:
              name: q10Settings
              iri: neuroml:q10ExpTemp
              parameters:
                q10Factor:        { value: 2.3 }
                experimentalTemp: { value: 21, unit: degC }
            forwardRate:
              name: forwardRate
              iri: neuroml:kslow_a_alpha_rate
              parameters:
                a0: { value: 0.0052 }
                a1: { value: 11.1 }
                a2: { value: 13.1 }
                a3: { value: 0.01938 }
                a4: { value: -1.27 }
                a5: { value: 71 }
                a6: { value: -0.0053 }
              derived_variables:
                V: { equation: { rhs: "v / VOLT_SCALE" } }
                r: { equation: { rhs: "(a0*(V-a1)/(1-exp(-(V-a1)/a2))) / TIME_SCALE" } }
            reverseRate:
              name: reverseRate
              iri: neuroml:kslow_a_beta_rate
              parameters:
                a0: { value: 0.0052 }
                a1: { value: 11.1 }
                a2: { value: 13.1 }
                a3: { value: 0.01938 }
                a4: { value: -1.27 }
                a5: { value: 71 }
                a6: { value: -0.0053 }
              derived_variables:
                V: { equation: { rhs: "v / VOLT_SCALE" } }
                r: { equation: { rhs: "(a3*exp(-(V-a4)/a5)+a6) / TIME_SCALE" } }
        b:
          name: b
          iri: neuroml:gateFractional
          parameters:
            instances: { value: 1 }
          components:
            bb:
              name: bb
              iri: neuroml:subGate
              parameters:
                fractionalConductance: { value: 0.5 }
              components:
                steadyState:
                  name: steadyState
                  iri: neuroml:HHSigmoidVariable
                  parameters:
                    rate:     { value: 1 }
                    midpoint: { value: -58, unit: mV }
                    scale:    { value: -11, unit: mV }
                timeCourse:
                  name: timeCourse
                  iri: neuroml:kslow_b_tau
                  parameters:
                    v05b: { value: -58 }
                    b0:   { value: 360 }
                    b11:  { value: 1010 }
                    b2:   { value: -75 }
                    b3:   { value: 48 }
                    b4:   { value: 23.7 }
                    b5:   { value: -54 }
                  derived_variables:
                    V: { equation: { rhs: "v / VOLT_SCALE" } }
                    t: { equation: { rhs: "(b0+(b11+b4*(V-b5))*exp(-(V-b2)*(V-b2)/(b3*b3))) * TIME_SCALE" } }
            bb1:
              name: bb1
              iri: neuroml:subGate
              parameters:
                fractionalConductance: { value: 0.5 }
              components:
                steadyState:
                  name: steadyState
                  iri: neuroml:HHSigmoidVariable
                  parameters:
                    rate:     { value: 1 }
                    midpoint: { value: -58, unit: mV }
                    scale:    { value: -11, unit: mV }
                timeCourse:
                  name: timeCourse
                  iri: neuroml:kslow_b1_tau
                  parameters:
                    bb0: { value: 2350 }
                    bb1: { value: 1380 }
                    bb2: { value: 0.01118 }
                    bb3: { value: -210 }
                    bb4: { value: 0.0306 }
                  derived_variables:
                    V: { equation: { rhs: "v / VOLT_SCALE" } }
                    t: { equation: { rhs: "(bb0+bb1*exp(-bb2*V)+bb3*exp(-bb4*V)) * TIME_SCALE" } }
    # ── Standard K channel ──
    k:
      name: k
      iri: neuroml:ionChannelHH
      parameters:
        conductance: { value: 10, unit: pS }
        species:     { description: k }
        condDensity: { value: 0.036, unit: S_per_cm2 }
        erev:        { value: -77, unit: mV }
        ion:         { description: k }
      components:
        n:
          name: n
          iri: neuroml:gateHHrates
          parameters:
            instances: { value: 4 }
          components:
            forwardRate:
              name: forwardRate
              iri: neuroml:HHExpLinearRate
              parameters:
                rate:     { value: 0.1, unit: per_ms }
                midpoint: { value: -55, unit: mV }
                scale:    { value: 10, unit: mV }
            reverseRate:
              name: reverseRate
              iri: neuroml:HHExpRate
              parameters:
                rate:     { value: 0.125, unit: per_ms }
                midpoint: { value: -65, unit: mV }
                scale:    { value: -80, unit: mV }
    # ── Leak channel ──
    leak:
      name: leak
      iri: neuroml:ionChannelPassive
      parameters:
        conductance: { value: 10, unit: pS }
        condDensity: { value: 0.0003, unit: S_per_cm2 }
        erev:        { value: -54.3, unit: mV }
        ion:         { description: non_specific }
    # ── Na channel ──
    na:
      name: na
      iri: neuroml:ionChannelHH
      parameters:
        conductance: { value: 10, unit: pS }
        species:     { description: na }
        condDensity: { value: 0.12, unit: S_per_cm2 }
        erev:        { value: 50, unit: mV }
        ion:         { description: na }
      components:
        m:
          name: m
          iri: neuroml:gateHHrates
          parameters:
            instances: { value: 3 }
          components:
            forwardRate:
              name: forwardRate
              iri: neuroml:HHExpLinearRate
              parameters:
                rate:     { value: 1, unit: per_ms }
                midpoint: { value: -40, unit: mV }
                scale:    { value: 10, unit: mV }
            reverseRate:
              name: reverseRate
              iri: neuroml:HHExpRate
              parameters:
                rate:     { value: 4, unit: per_ms }
                midpoint: { value: -65, unit: mV }
                scale:    { value: -18, unit: mV }
        h:
          name: h
          iri: neuroml:gateHHrates
          parameters:
            instances: { value: 1 }
          components:
            forwardRate:
              name: forwardRate
              iri: neuroml:HHExpRate
              parameters:
                rate:     { value: 0.07, unit: per_ms }
                midpoint: { value: -65, unit: mV }
                scale:    { value: -20, unit: mV }
            reverseRate:
              name: reverseRate
              iri: neuroml:HHSigmoidRate
              parameters:
                rate:     { value: 1, unit: per_ms }
                midpoint: { value: -35, unit: mV }
                scale:    { value: 10, unit: mV }
    # ── Inputs ──
    IClamp1:
      name: IClamp1
      iri: neuroml:pulseGenerator
      parameters:
        delay:     { value: 25, unit: ms }
        duration:  { value: 50, unit: ms }
        amplitude: { value: 0.1, unit: nA }
    IClamp2:
      name: IClamp2
      iri: neuroml:pulseGenerator
      parameters:
        delay:     { value: 100, unit: ms }
        duration:  { value: 50, unit: ms }
        amplitude: { value: -0.1, unit: nA }
integration:
  step_size: 0.01
  duration: 200.0
  time_scale: ms
""")
print(f"Model: {exp.dynamics.name if exp.dynamics else 'network'}")
print(f"Components: {list(exp.dynamics.modes.keys())}")
Model: hhtest
Components: ['IClamp1', 'IClamp2', 'k', 'k_slow', 'leak', 'na']

2. Render LEMS XML

xml = exp.render("lems", use_standard_types=True)
print(xml[:3000])

<Lems>
  <Target component="sim_NeuroML_Ex24__Fractional_Conductance"/>

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

    <ComponentType name="kslow_a_alpha_rate" extends="baseVoltageDepRate">
        <Constant name="TIME_SCALE" dimension="time" value="1 ms"/>
        <Constant name="VOLT_SCALE" dimension="voltage" value="1 mV"/>
        <Constant name="a0" dimension="none" value="0.0052"/>
        <Constant name="a1" dimension="none" value="11.1"/>
        <Constant name="a2" dimension="none" value="13.1"/>
        <Constant name="a3" dimension="none" value="0.01938"/>
        <Constant name="a4" dimension="none" value="-1.27"/>
        <Constant name="a5" dimension="none" value="71"/>
        <Constant name="a6" dimension="none" value="-0.0053"/>
        <Dynamics>
            <DerivedVariable name="V" dimension="none" value="v / VOLT_SCALE"/>
            <DerivedVariable name="r" exposure="r" dimension="per_time" value="(a0*(V-a1)/(1-exp(-(V-a1)/a2))) / TIME_SCALE"/>
        </Dynamics>
    </ComponentType>

    <ComponentType name="kslow_a_beta_rate" extends="baseVoltageDepRate">
        <Constant name="TIME_SCALE" dimension="time" value="1 ms"/>
        <Constant name="VOLT_SCALE" dimension="voltage" value="1 mV"/>
        <Constant name="a0" dimension="none" value="0.0052"/>
        <Constant name="a1" dimension="none" value="11.1"/>
        <Constant name="a2" dimension="none" value="13.1"/>
        <Constant name="a3" dimension="none" value="0.01938"/>
        <Constant name="a4" dimension="none" value="-1.27"/>
        <Constant name="a5" dimension="none" value="71"/>
        <Constant name="a6" dimension="none" value="-0.0053"/>
        <Dynamics>
            <DerivedVariable name="V" dimension="none" value="v / VOLT_SCALE"/>
            <DerivedVariable name="r" exposure="r" dimension="per_time" value="(a3*exp(-(V-a4)/a5)+a6) / TIME_SCALE"/>
        </Dynamics>
    </ComponentType>

    <ComponentType name="kslow_b_tau" extends="baseVoltageDepTime">
        <Constant name="TIME_SCALE" dimension="time" value="1 ms"/>
        <Constant name="VOLT_SCALE" dimension="voltage" value="1 mV"/>
        <Constant name="b0" dimension="none" value="360"/>
        <Constant name="b11" dimension="none" value="1010"/>
        <Constant name="b2" dimension="none" value="-75"/>
        <Constant name="b3" dimension="none" value="48"/>
        <Constant name="b4" dimension="none" value="23.7"/>
        <Constant name="b5" dimension="none" value="-54"/>
        <Constant name="v05b" dimension="none" value="-58"/>
        <Dynamics>
            <DerivedVariable name="V" dimension="none" value="v / VOLT_SCALE"/>
            <DerivedVariable name="t" exposure="t" dimension="time" value="(b0+(b11+b4*(V-b5))*exp(-(V-b2)*(V-b2)/(b3*b3))) * TIME_SCALE"/>
        </Dynamics>
    </ComponentType>

    <ComponentType name="kslow_b1_tau" extends="baseVoltageDepTime">
        <Cons

3. Run Reference

from tvbo.adapters.neuroml import run_lems_example

ref_outputs = run_lems_example("LEMS_NML2_Ex24_FractionalConductance.xml")
for name, arr in ref_outputs.items():
    print(f"  {name}: shape={arr.shape}")
  ex24_k.dat: shape=(20001, 2)
  ex24_v.dat: shape=(20001, 2)

4. Run TVBO

result = exp.run("neuroml")
da = result.integration.data
print(f"TVBO: {da.dims}, shape={da.shape}")
TVBO: ('time', 'variable'), shape=(20001, 1)

5. Compare & Plot

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