neuromodels.models.HodgkinHuxley¶
- class neuromodels.models.HodgkinHuxley(V_rest=- 65.0, Cm=1.0, gbar_K=36.0, gbar_Na=120.0, gbar_L=0.3, E_K=- 77.0, E_Na=50.0, E_L=- 54.4, degC=6.3)[source]¶
Class for representing the original Hodgkin-Huxley model.
The Hodgkin–Huxley model describes how action potentials in neurons are initiated and propagated. From a biophysical point of view, action potentials are the result of currents that pass through ion channels in the cell membrane. In an extensive series of experiments on the giant axon of the squid, Hodgkin and Huxley succeeded to measure these currents and to describe their dynamics in terms of differential equations.
This class implements the original Hodgkin-Huxley model for the sodium, potassium and leakage channels found in the squid giant axon membrane. Membrane voltage is in absolute mV and has been reversed in polarity from the original HH convention and shifted to reflect a resting potential of -65 mV.
All model parameters can be accessed (get or set) as class attributes. Solutions are available as class attributes after calling the class method
solve().- Parameters
- V_rest
float Resting potential of neuron in units \(mV\), default=-65.0.
- Cm
float Membrane capacitance in units \(\mu F/cm^2\), default=1.0.
- gbar_K
float Potassium conductance in units \(mS/cm^2\), default=36.0.
- gbar_Na
float Sodium conductance in units \(mS/cm^2\), default=120.0.
- gbar_L
float Leak conductance in units \(mS/cm^2\), default=0.3.
- E_K
float Potassium reversal potential in units \(mV\), default=-77.0.
- E_Na
float Sodium reversal potential in units \(mV\), default=50.0.
- E_L
float Leak reversal potential in units \(mV\), default=-54.4.
- degC
float Temperature when recording (should be to set a squid-appropriate temperature) in units \(^{\circ}C\), default=6.3.
- V_rest
Notes
Default parameter values as given by Hodgkin and Huxley [1].
References
- 1
A. L. Hodgkin, A. F. Huxley, “A quantitative description of membrane current and its application to conduction and excitation in nerve”, J. Physiol. 117, pp. 500-544, 1952.
Examples
import matplotlib.pyplot as plt import neuromodels as nm # Initialize the Hodgkin-Huxley system; model parameters can either # be set in the constructor or accessed as class attributes: hh = nm.HodgkinHuxley(V_rest=-70) hh.gbar_K = 36 # The simulation parameters needed are the simulation time T, the time # step dt, and the input stimulus, the latter either as a constant, # callable with call signature `(t)` or ndarray with `shape=(int(T/dt)+1,)`: T = 50. dt = 0.025 def stimulus(t): return 10 if 10 <= t <= 40 else 0 # The system is solved by calling the class method `solve` and the # solutions can be accessed as class attributes: hh.solve(stimulus, T, dt) t = hh.t V = hh.V plt.plot(t, V) plt.xlabel('Time [ms]') plt.ylabel('Membrane potential [mV]') plt.show()
Attributes
V_rest
(
float) Model parameter: Resting potential.Cm
(
float) Model parameter: Membrane capacitance.gbar_K
(
float) Model parameter: Potassium conductance.gbar_Na
(
float) Model parameter: Sodium conductance.gbar_L
(
float) Model parameter: Leak conductance.E_K
(
float) Model parameter: Potassium reversal potential.E_Na
(
float) Model parameter: Sodium reversal potential.E_L
(
float) Model parameter: Leak reversal potential.degC
(
float) Model parameter: Temperature when recording in degrees Celsius.t
(ndarray) Solution: Array of time points
t.V
(ndarray) Solution: Array of voltage values
Vatt.n
(ndarray) Solution: Array of state variable values
natt.m
(ndarray) Solution: Array of state variable values
matt.h
(ndarray) Solution: Array of state variable values
hatt.Methods
I_K(V, n)Potassium current.
I_L(V)Leak current.
I_Na(V, m, h)Sodium current.
__call__(t, y)RHS of the Hodgkin-Huxley ODEs.
alpha_h(V)Sodium channel inactivation forward reaction rate.
alpha_m(V)Sodium channel activation forward reaction rate.
alpha_n(V)Potassium channel activation forward reaction rate.
beta_h(V)Sodium channel inactivation backward reaction rate.
beta_m(V)Sodium channel activation backward reaction rate.
beta_n(V)Potassium channel activation backward reaction rate.
h_inf(V)Sodium channel inactivation steady state.
m_inf(V)Sodium channel activation steady state.
n_inf(V)Potassium channel activation steady state.
solve(stimulus, T, dt[, y0, method])Solve the Hodgkin-Huxley equations.
tau_h(V)Sodium channel inactivation time constant.
tau_m(V)Sodium channel activation time constant.
tau_n(V)Potassium channel activation time constant.
- alpha_n(V)[source]¶
Potassium channel activation forward reaction rate.
Uses the
vtrap()function to trap for zero in denominator of rate equation.
- alpha_m(V)[source]¶
Sodium channel activation forward reaction rate.
Uses the
vtrap()function to trap for zero in denominator of rate equation.
- solve(stimulus, T, dt, y0=None, method='RK45', **kwargs)[source]¶
Solve the Hodgkin-Huxley equations.
The equations are solved on the interval
(0, T]and the solutions evaluted at a given interval. The solutions are not returned, but stored as class attributes.If multiple calls to solve are made, they are treated independently, with the newest one overwriting any old solution data.
The solver only accepts
stimulusas either a scalar (intorfloat),callableor ndarray. Ifcallable, the call signature must be one and only one positional argument, e.g.(t). Kewword arguments are allowed in passed callables. When passed as ndarray, stimulus must have shape(int(T/dt)+1).- Parameters
- stimulus{
int,float},callableor ndarray, shape=(int(T/dt)+1,) Input stimulus in units \(\mu A/cm^2\). If callable, the call signature must be
(t).- T
float End time in milliseconds (\(ms\)).
- dt
float Time step where solutions are evaluated.
- y0array_like, shape=(4,)
Initial state of state variables
V,n,m,h. If None, the default Hodgkin-Huxley model’s initial conditions will be used; \(y_0 = (V_0, n_0, m_0, h_0) = (V_{rest}, n_\infty(V_0), m_\infty(V_0), h_\infty(V_0))\).- method
str Integration method to use. Description from the
scipy.integrate.solve_ivpdocumentation:‘RK45’ (default): Explicit Runge-Kutta method of order 5(4) [1]. The error is controlled assuming accuracy of the fourth-order method, but steps are taken using the fifth-order accurate formula (local extrapolation is done). A quartic interpolation polynomial is used for the dense output [2]. Can be applied in the complex domain.
‘RK23’: Explicit Runge-Kutta method of order 3(2) [3]. The error is controlled assuming accuracy of the second-order method, but steps are taken using the third-order accurate formula (local extrapolation is done). A cubic Hermite polynomial is used for the dense output. Can be applied in the complex domain.
‘DOP853’: Explicit Runge-Kutta method of order 8 [13]_. Python implementation of the “DOP853” algorithm originally written in Fortran [14]_. A 7-th order interpolation polynomial accurate to 7-th order is used for the dense output. Can be applied in the complex domain.
‘Radau’: Implicit Runge-Kutta method of the Radau IIA family of order 5 [4]. The error is controlled with a third-order accurate embedded formula. A cubic polynomial which satisfies the collocation conditions is used for the dense output.
‘BDF’: Implicit multi-step variable-order (1 to 5) method based on a backward differentiation formula for the derivative approximation [5]. The implementation follows the one described in [6]. A quasi-constant step scheme is used and accuracy is enhanced using the NDF modification. Can be applied in the complex domain.
‘LSODA’: Adams/BDF method with automatic stiffness detection and switching [7], [8]. This is a wrapper of the Fortran solver from ODEPACK.
- **kwargs
Arbitrary keyword arguments are passed along to
scipy.integrate.solve_ivp.
- stimulus{
Notes
The ODEs are solved numerically using the function
scipy.integrate.solve_ivp.If
stimulusis passed as an array, it and the time array, defined byTanddt, will be used to create an interpolation function viascipy.interpolate.interp1d.solve_ivpis an ODE solver with adaptive step size. If the keyword argumentfirst_stepis not specified, the solver will empirically select an initial step size with the functionselect_initial_step(found here https://github.com/scipy/scipy/blob/master/scipy/integrate/_ivp/common.py#L64).This function calculates two proposals and returns the smallest. It first calculates an intermediate proposal,
h0, that is based on the initial condition (y0) and the ODE’s RHS evaluated for the initial condition (f0). For the standard Hodgkin-Huxley model, however, this estimated step size will be very large due to unfortunate circumstances (becausenorm(y0) > 0whilenorm(f0) ~= 0). Sinceh0only is an intermediate calculation, it is not used or returned by the solver. However, it is used to calculate the next proposal,h1, by calling the RHS. Normally, this procedure poses no problem, but can fail if an object with a limited interval is present in the RHS, such as aninterp1dobject.In the case of the standard Hodgkin-Huxley model, one might be tempted to pass the stimulus as an array to the solver. In order for
solve_ivpto be able to evaluate the stimulus, it must be passed as a callable or constant. Thus, if an array is passed to the solver, an interpolation function must be created, in this implementation done withinterp1d, forsolve_ivpto be able to evaluate it. For the reasons explained above, the program will hence terminate unless thefirst_stepkeyword is specified and is set to a sufficiently small value. In this implementation,first_step=dtis already set insolve_ivp.The
solve_ivpkeywordmax_stepshould be considered to be specified for stimuli over short time spans, in order to ensure that the solver does not step over them.Note that
first_stepstill needs to specified even ifmax_stepis.select_initial_stepwill be called regardless iffirst_stepis not specified, and the calls for calculatingh1will be done before checking whetherh0is larger than than the max allowed step size or not. Thus will only specifyingmax_stepstill result in program termination ifstimulusis passed as an array. (Will not be a problem in this implementation sincefirst_stepis already specified.)References
- 1
J. R. Dormand, P. J. Prince, “A family of embedded Runge-Kutta formulae”, Journal of Computational and Applied Mathematics, Vol. 6, No. 1, pp. 19-26, 1980.
- 2
L. W. Shampine, “Some Practical Runge-Kutta Formulas”, Mathematics of Computation,, Vol. 46, No. 173, pp. 135-150, 1986.
- 3
P. Bogacki, L.F. Shampine, “A 3(2) Pair of Runge-Kutta Formulas”, Appl. Math. Lett. Vol. 2, No. 4. pp. 321-325, 1989.
- 4
E. Hairer, G. Wanner, “Solving Ordinary Differential Equations II: Stiff and Differential-Algebraic Problems”, Sec. IV.8.
- 5
Backward Differentiation Formula on Wikipedia.
- 6
L. F. Shampine, M. W. Reichelt, “THE MATLAB ODE SUITE”, SIAM J. SCI. COMPUTE., Vol. 18, No. 1, pp. 1-22, January 1997.
- 7
A. C. Hindmarsh, “ODEPACK, A Systematized Collection of ODE Solvers,” IMACS Transactions on Scientific Computation, Vol 1., pp. 55-64, 1983.
- 8
L. Petzold, “Automatic selection of methods for solving stiff and nonstiff systems of ordinary differential equations”, SIAM Journal on Scientific and Statistical Computing, Vol. 4, No. 1, pp. 136-148, 1983.