Hodgkin-Huxley current models¶
The module myokit.lib.hh contains functions for working with Hodgkin-Huxley
models of ion channel currents.
- The class
HHModelcan 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
AnalyticalSimulationclass, 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-statex_inf[i]and time constanttau_x[i], whereVis the membrane potential,pis a set of parameters,fis 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. Initial values written as expressions are evaluated when the model is made.
The current variable is optional.
Arguments:
modelThe
myokit.Modelto extract a current model from.statesAn ordered list of state variables (or state variable names) from
model. All remaining state variables will be frozen in place.parameters=NoneA list of parameters to maintain in their symbolic form.
current=NoneThe current model’s current variable, or
None.vm=NoneThe 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('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 Hodgkin-Huxley style channel 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 HH model’s default membrane potential value.
- default_parameters()¶
Returns this HH model’s default parameter values
- default_state()¶
Returns this HH 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 (non-nested) constant in the component is a parameter.
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.
The model contains a variable labeled “membrane_potential”.
Any of the automatically set variables can be overridden using the keyword arguments
states,parameters,currentandvm.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
y0is a sequence containing the state values at time 0, wheretis a scalar or numpy array of times at which to evaluate, wherep1, p2, p3, ...are the model parameters, and whereVis the membrane potential.The function output is always a tuple
(states, current). Iftis a single time, thenstateswill be a list of values (one per model state) and current will be a scalar (orNoneif no current variable was specified). Iftis a numpy array of times thenstateswill be a list of numpy arrays, and current will be a numpy array (orNoneif 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_potentialThe value to use for the membrane potential, or
Noneto use the value from the originalmyokit.Model.parametersThe 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), orNoneto 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
protocolcan 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
durationtime 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
durationtime units.After the simulation:
The simulation time will be increased by
durationtime units.The simulation state will be updated to the last reached state.
Arguments:
durationThe number of time units to simulate.
logA log from a previous run can be passed in, in which case the results will be appended to this one.
log_intervalThe time between logged points.
log_timesA pre-defined sequence of times to log at. If set,
log_intervalwill be ignored.
Returns a
myokit.DataLogwith 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:
timesA series of times, where each time must be some
t >= 0.
For models with a current variable, this method returns a tuple
(state, current)wherestateis a matrix of shape(len(states), len(times))andcurrentis a vector of lengthlen(times).For models without a current variable, only
stateis 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.Modelfor Hodgkin-Huxley style states written in “alpha-beta form”, and converts them to “inf-tau form”.For any state
xwritten in the formdot(x) = alpha * (1 - x) - beta * xthis 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_infandtau_xare the new variables.See also:
get_alpha_and_beta().Arguments:
modelA
myokit.Modelobject to convert.vAn 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
xis a state variable with an expression of the form(1 - x) * alpha - x * beta, wherealphaandbetarepresent the forward and backward reaction rates forx.If the optional argument
vis given, the method will (1) check that bothalphaandbetadepend onv, and (2) check that they don’t depend on any state variables (not countingv).Note that this method performs a shallow check of the equation’s shape, and does not perform any simplification or rewriting to see if the expression can be made to fit the required form.
Arguments:
xThe
myokit.Variableto check.vAn optional
myokit.Variablerepresenting the membrane potential.
Returns
Trueif the alpha-beta form is found,Falseif not.
- myokit.lib.hh.has_inf_tau_form(x, v=None)¶
Tests if the given
xis a state variable with an expression of the form(x_inf - x) / tau_x, wherex_infandtau_xrepresent the steady-state and time constant ofx.If the optional argument
vis given, the method will (1) check that bothx_infandtau_xdepend onv, and (2) check that they don’t depend on any state variables (not countingv).Note that this method performs a shallow check of the equation’s shape, and does not perform any simplification or rewriting to see if the expression can be made to fit the required form.
Arguments:
xThe
myokit.Variableto check.vAn optional
myokit.Variablerepresenting the membrane potential.
Returns
Trueif the inf-tau form is found,Falseif not.
- myokit.lib.hh.get_alpha_and_beta(x, v=None)¶
Tests if the given
xis a state variable with an expression of the form(1 - x) * alpha - x * beta, and returns the variables foralphaandbetaif 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.Note that this method performs a shallow check of the equation’s shape, and does not perform any simplification or rewriting to see if the expression can be made to fit the required form.
Arguments:
xThe
myokit.Variableto check.vAn optional
myokit.Variablerepresenting the membrane potential. If not given, the labelmembrane_potentialwill be used to determinev. Ifv=Noneand 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, orNoneif not. Bothalphaandbetaaremyokit.Variableobjects.
- myokit.lib.hh.get_inf_and_tau(x, v=None)¶
Tests if the given
xis a state variable with an expression of the form(x_inf - x) / tau_x, and returns the variables forx_infandx_tauif so.Here,
x_infandtau_xrepresent the steady-state and time constant ofx. Both may depend onv, but not on any (other) state variable.Note that this method performs a shallow check of the equation’s shape, and does not perform any simplification or rewriting to see if the expression can be made to fit the required form.
Arguments:
xThe
myokit.Variableto check.vAn optional
myokit.Variablerepresenting the membrane potential. If not given, the labelmembrane_potentialwill be used to determinev. Ifv=Noneand 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, orNoneif not. The returnedx_infandtau_xaremyokit.Variableobjects.
- myokit.lib.hh.get_rl_expression(x, dt, v=None)¶
For states
xwith RHS expressions written in the “inf-tau form” (seehas_inf_tau_form()) this returns a Rush-Larsen (RL) update expression of the formx_inf + (x - x_inf) * exp(-(dt / tau_x)).If the state does not have the “inf-tau form”,
Noneis returned.Arguments:
xA state variable for which to return the RL update expression.
dtA
myokit.Nameexpression to use for the time step in the RL expression.vAn optional variable representing the membrane potential.
Returns a
myokit.Expressionif succesful, orNoneif 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