Hodgkin-Huxley current models

The module myokit.lib.hh contains functions for working with Hodgkin-Huxley 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 piecewise-linear voltage protocol (e.g. a voltage step protocol).

In addition, several methods are provided to find and manipulate Hodgkin-Huxley style gating variables.

Analytical simulation

class myokit.lib.hh.HHModel(model, states, parameters=None, current=None, vm=None)

Represents a Hodgkin-Huxley (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 steady-state x_inf[i] and time constant tau_x[i], where V is the membrane potential, p is a set of parameters, f is an arbitrary function (for example g_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 label membrane_potential.

Example:

import myokit
import myokit.lib.hh as hh

# Load a model from disk
model = myokit.load_model('some-model.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('some-model.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:

  1. Every state in the component is a state in the current model.
  2. Every (non-nested) constant in the component is a parameter.
  3. The component should contain exactly one non-nested intermediary variable whose value depends on the model states, this will be used as the current variable.
  4. The model contains a variable labeled “membrane_potential”.

Any of the automatically set variables can be overridden using the keyword arguments states, parameters, current and vm.

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, where t is a scalar or numpy array of times at which to evaluate, where p1, p2, p3, ... are the model parameters, and where V is the membrane potential.

The function output is always a tuple (states, current). If t is a single time, then states will be a list of values (one per model state) and current will be a scalar (or None if no current variable was specified). If t is a numpy array of times then states will be a list of numpy arrays, and current will be a numpy array (or None 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 original myokit.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), or None 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 to run() 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('luo-1991.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 using pre() 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 pre-defined sequence of times to log at. If set, log_interval will be ignored.

Returns a myokit.DataLog with the simulation results.

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) where state is a matrix of shape (len(states), len(times)) and current is a vector of length len(times).

For models without a current variable, only state is returned.

state()

Returns the initial state used by this simulation.

Finding and manipulating HH-states

myokit.lib.hh.convert_hh_states_to_inf_tau_form(model, v=None)

Scans a myokit.Model for Hodgkin-Huxley style states written in “alpha-beta form”, and converts them to “inf-tau form”.

For any state x written in the form dot(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 form dot(x) = (x_inf - x) / tau_x, where x_inf and tau_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 labelled membrane_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, where alpha and beta represent the forward and backward reaction rates for x.

If the optional argument v is given, the method will (1) check that both alpha and beta depend on v, and (2) check that they don’t depend on any state variables (not counting v).

Arguments:

x
The myokit.Variable to check.
v
An optional myokit.Variable representing the membrane potential.

Returns True if the alpha-beta 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, where x_inf and tau_x represent the steady-state and time constant of x.

If the optional argument v is given, the method will (1) check that both x_inf and tau_x depend on v, and (2) check that they don’t depend on any state variables (not counting v).

Arguments:

x
The myokit.Variable to check.
v
An optional myokit.Variable representing the membrane potential.

Returns True if the inf-tau 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 for alpha and beta if so.

Here, alpha(v) and beta(v) represent the forward and backward reaction rates for x. Both may depend on v, 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 label membrane_potential will be used to determine v. If v=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, or None if not. Both alpha and beta are myokit.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 for x_inf and x_tau if so.

Here, x_inf and tau_x represent the steady-state and time constant of x. Both may depend on v, 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 label membrane_potential will be used to determine v. If v=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, or None if not. The returned x_inf and tau_x are myokit.Variable objects.

myokit.lib.hh.get_rl_expression(x, dt, v=None)

For states x with RHS expressions written in the “inf-tau form” (see has_inf_tau_form()) this returns a Rush-Larsen (RL) update expression of the form x_inf + (x - x_inf) * exp(-(dt / tau_x)).

If the state does not have the “inf-tau 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, or None if not.

Example:

# Load a Myokit model model = myokit.load_model(‘example’) v = model.get(‘membrane.V’)

# Get a copy where all HH-state variables are written in inf-tau 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 RL-update 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 Rush-Larsen method and its generalization. IEEE Transactions on Biomedical Engineering, https://doi.org/10.1109/TBME.2012.2205575