HodgkinHuxley current models¶
The module myokit.lib.hh
contains functions for working with HodgkinHuxley
models of ion channel currents.
 The class
HHModel
can be used to extract a current model from a Myokit  model.
 By fixing the voltage and all other states that aren’t part of the current
 model a linear system is created.
 Fast simulations can then be performed using the
AnalyticalSimulation
class, which is particularly useful when trying to estimate a current model’s parameters from a piecewiselinear voltage protocol (e.g. a voltage step protocol).
In addition, several methods are provided to find and manipulate HodgkinHuxley style gating variables.
Analytical simulation¶

class
myokit.lib.hh.
HHModel
(model, states, parameters=None, current=None, vm=None)¶ Represents a HodgkinHuxley (HH)style model of an ion channel, extracted from a
myokit.Model
.The class assumes the HH model can be (re)written as:
I = prod(x[i]**n[i]) * f(V, p) dot(x[i]) = (x_inf[i](V, p)  x[i]) / tau_x[i](V, p)
for any number of states
x[i]
with steadystatex_inf[i]
and time constanttau_x[i]
, whereV
is the membrane potential,p
is a set of parameters,f
is an arbitrary function (for exampleg_max * (V  E_rev)
).The model variables to treat as parameter are specified by the user when the model is created. Any other variables, for example state variables such as intercellular calcium or constants such as temperature, are fixed when the current model is created and can no longer be changed.
The current variable is optional.
Arguments:
model
 The
myokit.Model
to extract a current model from. states
 An ordered list of state variables (or state variable names) from
model
. All remaining state variables will be frozen in place. parameters=None
 A list of parameters to maintain in their symbolic form.
current=None
 The current model’s current variable, or
None
. vm=None
 The variable indicating membrane potential. If set to
None
(default) the method will search for a variable with the labelmembrane_potential
.
Example:
import myokit import myokit.lib.hh as hh # Load a model from disk model = myokit.load_model('somemodel.mmt') # Select the relevant states and parameters states = [ 'ina.C1', 'ina.C2', 'ina.O', ... ] parameters = [ 'ina.p1', 'ina.p2', ... ] current = 'ina.INa' # Extract an ion current model mm = hh.HHModel(model, states, parameters, current)
Alternatively, a HHModel can be constructed based on a single component using the method
from_component()
:import myokit import myokit.lib.hh as hh # Load a model from disk model = myokit.load_model('somemodel.mmt') # Extract a markov model mm = hh.HHModel.from_component(model.get('ina'))

current
()¶ Returns the name of the current variable used by this model, or None if no current variable was specified.

default_membrane_potential
()¶ Returns this markov model’s default membrane potential value.

default_parameters
()¶ Returns this markov model’s default parameter values

default_state
()¶ Returns this markov model’s default state values.

static
from_component
(component, states=None, parameters=None, current=None, vm=None)¶ Creates a current model from a component, using the following rules:
 Every state in the component is a state in the current model.
 Every (nonnested) constant in the component is a parameter.
 The component should contain exactly one nonnested intermediary variable whose value depends on the model states, this will be used as the current variable.
 The model contains a variable labeled “membrane_potential”.
Any of the automatically set variables can be overridden using the keyword arguments
states
,parameters
,current
andvm
.The parameters, if determined automatically, will be specified in alphabetical order (using a natural sort).

function
()¶ Returns a function that evaluates the state values at any time.
The returned function has the signature:
f(y0, t, p1, p2, p3, ..., V) > (states, current)
where
y0
is a sequence containing the state values at time 0, wheret
is a scalar or numpy array of times at which to evaluate, wherep1, p2, p3, ...
are the model parameters, and whereV
is the membrane potential.The function output is always a tuple
(states, current)
. Ift
is a single time, thenstates
will be a list of values (one per model state) and current will be a scalar (orNone
if no current variable was specified). Ift
is a numpy array of times thenstates
will be a list of numpy arrays, and current will be a numpy array (orNone
if no current variable was specified).

membrane_potential
()¶ Returns the name of the membrane potential variable used by this model.

parameters
()¶ Returns the names of the parameter variables used by this model.

reduced_model
()¶ Returns a reduced
myokit.Model
, containing only the parts necessary to calculate the specified states and current.

states
()¶ Returns the names of the state variables used by this model.

steady_state
(membrane_potential=None, parameters=None)¶ Returns the steady state solution for this model.
Arguments:
membrane_potential
 The value to use for the membrane potential, or
None
to use the value from the originalmyokit.Model
. parameters
 The values to use for the parameters, given in the order they were
originally specified in (if the model was created using
from_component()
, this will be alphabetical order), orNone
to use the values from the original model.
Returns a list of steady state values.

class
myokit.lib.hh.
HHModelError
(message)¶ Raised for issues with constructing or using a
LinearModel
.

class
myokit.lib.hh.
AnalyticalSimulation
(model, protocol=None)¶ Analytically evaluates a
HHModel
’s state for a given set of points in time.Each simulation object maintains an internal state consisting of
 The current simulation time
 The current state
 The default state
When a simulation is created, the simulation time is set to zero and both the current and default state are initialized using the
HHModel
. After each call torun()
the time and current state are updated, so that each successive call to run continues where the previous simulation left off.A
protocol
can be used to set the membrane potential during the simulation, or the membrane potential can be adjusted manually between runs.Example:
import myokit import myokit.lib.hh as hh # Create an ion current model m = myokit.load_model('luo1991.mmt') m = hh.HHModel.from_component(m.get('ina')) # Create an analytical simulation object s = hh.AnalyticalSimulation(m) # Run a simulation s.set_membrane_potential(30) d = s.run(10) # Show the results import matplotlib.pyplot as plt plt.figure() plt.subplot(211) for state in m.states(): plt.plot(d.time(), d[state], label=state) plt.legend(loc='center right') plt.subplot(212) plt.plot(d.time(), d[m.current()]) plt.show()

default_state
()¶ Returns the default state used by this simulation.

membrane_potential
()¶ Returns the currently set membrane potential.

parameters
()¶ Returns the currently set parameter values.

pre
(duration)¶ Performs an unlogged simulation for
duration
time units and uses the final state as the new default state.After the simulation:
 The simulation time is not affected
 The current state and the default state are updated to the final state reached in the simulation.
Calls to
reset()
after usingpre()
will set the current state to this new default state.

reset
()¶ Resets the simulation:
 The time variable is set to zero.
 The state is set to the default state.

run
(duration, log=None, log_interval=0.01, log_times=None)¶ Runs a simulation for
duration
time units.After the simulation:
 The simulation time will be increased by
duration
time units.  The simulation state will be updated to the last reached state.
Arguments:
duration
 The number of time units to simulate.
log
 A log from a previous run can be passed in, in which case the results will be appended to this one.
log_interval
 The time between logged points.
log_times
 A predefined sequence of times to log at. If set,
log_interval
will be ignored.
Returns a
myokit.DataLog
with the simulation results. The simulation time will be increased by

set_constant
(variable, value)¶ Updates a single parameter to a new value.

set_default_state
(state)¶ Changes this simulation’s default state.

set_membrane_potential
(v)¶ Changes the membrane potential used in this simulation.

set_parameters
(parameters)¶ Changes the parameter values used in this simulation.

set_state
(state)¶ Changes the initial state used by in this simulation.

solve
(times)¶ Evaluates and returns the states at the given times.
In contrast to
run()
, this method simply evaluates the states (and current) at the given times, using the last known settings for the state and membrane potential. It does not use a protocol and does not take into account the simulation time. After running this method, the state and simulation time are not updated.Arguments:
times
 A series of times, where each time must be some
t >= 0
.
For models with a current variable, this method returns a tuple
(state, current)
wherestate
is a matrix of shape(len(states), len(times))
andcurrent
is a vector of lengthlen(times)
.For models without a current variable, only
state
is returned.

state
()¶ Returns the initial state used by this simulation.
Finding and manipulating HHstates¶

myokit.lib.hh.
convert_hh_states_to_inf_tau_form
(model, v=None)¶ Scans a
myokit.Model
for HodgkinHuxley style states written in “alphabeta form”, and converts them to “inftau form”.For any state
x
written in the formdot(x) = alpha * (1  x)  beta * x
this method will calculate the steady state and time constant, and add variables for both. Next, the state RHS will be replaced by an expression of the formdot(x) = (x_inf  x) / tau_x
, wherex_inf
andtau_x
are the new variables.Arguments:
model
 A
myokit.Model
object to convert. v
 An optional
myokit.Variable`
representing the membrane potential. If not given, the method will search for a variable labelledmembrane_potential
. An error is raised if no membrane potential variable can be found.
Returns an updated copy of the given model.

myokit.lib.hh.
has_alpha_beta_form
(x, v=None)¶ Tests if the given
x
is a state variable with an expression of the form(1  x) * alpha  x * beta
, wherealpha
andbeta
represent the forward and backward reaction rates forx
.If the optional argument
v
is given, the method will (1) check that bothalpha
andbeta
depend onv
, and (2) check that they don’t depend on any state variables (not countingv
).Arguments:
x
 The
myokit.Variable
to check. v
 An optional
myokit.Variable
representing the membrane potential.
Returns
True
if the alphabeta form is found,False
if not.

myokit.lib.hh.
has_inf_tau_form
(x, v=None)¶ Tests if the given
x
is a state variable with an expression of the form(x_inf  x) / tau_x
, wherex_inf
andtau_x
represent the steadystate and time constant ofx
.If the optional argument
v
is given, the method will (1) check that bothx_inf
andtau_x
depend onv
, and (2) check that they don’t depend on any state variables (not countingv
).Arguments:
x
 The
myokit.Variable
to check. v
 An optional
myokit.Variable
representing the membrane potential.
Returns
True
if the inftau form is found,False
if not.

myokit.lib.hh.
get_alpha_and_beta
(x, v=None)¶ Tests if the given
x
is a state variable with an expression of the form(1  x) * alpha  x * beta
, and returns the variables foralpha
andbeta
if so.Here,
alpha(v)
andbeta(v)
represent the forward and backward reaction rates forx
. Both may depend onv
, but not on any (other) state variable.Arguments:
x
 The
myokit.Variable
to check. v
 An optional
myokit.Variable
representing the membrane potential. If not given, the labelmembrane_potential
will be used to determinev
. Ifv=None
and no membrane potential can be found an error will be raised. Membrane potential is typically specified as a state, but this is not a requirement.
Returns a tuple
(alpha, beta)
if successful, orNone
if not. Bothalpha
andbeta
aremyokit.Variable
objects.

myokit.lib.hh.
get_inf_and_tau
(x, v=None)¶ Tests if the given
x
is a state variable with an expression of the form(x_inf  x) / tau_x
, and returns the variables forx_inf
andx_tau
if so.Here,
x_inf
andtau_x
represent the steadystate and time constant ofx
. Both may depend onv
, but not on any (other) state variable.Arguments:
x
 The
myokit.Variable
to check. v
 An optional
myokit.Variable
representing the membrane potential. If not given, the labelmembrane_potential
will be used to determinev
. Ifv=None
and no membrane potential can be found an error will be raised. Membrane potential is typically specified as a state, but this is not a requirement.
Returns:
A tuple
(x_inf, tau_x)
if successful, orNone
if not. The returnedx_inf
andtau_x
aremyokit.Variable
objects.

myokit.lib.hh.
get_rl_expression
(x, dt, v=None)¶ For states
x
with RHS expressions written in the “inftau form” (seehas_inf_tau_form()
) this returns a RushLarsen (RL) update expression of the formx_inf + (x  x_inf) * exp((dt / tau_x))
.If the state does not have the “inftau form”,
None
is returned.Arguments:
x
 A state variable for which to return the RL update expression.
dt
 A
myokit.Name
expression to use for the time step in the RL expression. v
 An optional variable representing the membrane potential.
Returns a
myokit.Expression
if succesful, orNone
if not.Example:
# Load a Myokit model model = myokit.load_model(‘example’) v = model.get(‘membrane.V’)
# Get a copy where all HHstate variables are written in inftau form model = myokit.lib.hh.convert_hh_states_to_inf_tau_form(model, v)
# Create an expression for the time step dt = myokit.Name(‘dt’)
# Show an RLupdate for the variable ina.h h = model.get(‘ina.h’) e = myokit.lib.hh.get_rl_expression(h, dt, v) print(‘h[t + dt] = ‘ + str(e))
See:
[1] Rush, Larsen (1978) A Practical Algorithm for Solving Dynamic Membrane Equations. IEEE Transactions on Biomedical Engineering, https://doi.org/10.1109/TBME.1978.326270
[2] Marsh, Ziaratgahi, Spiteri (2012) The secrets to the success of the RushLarsen method and its generalization. IEEE Transactions on Biomedical Engineering, https://doi.org/10.1109/TBME.2012.2205575