To be able to have an opinion about the applicability of rust as a language to use for building biophysical models I
have tried to implement and benchmark the Hodgkin-Huxley neuron model. As I haven't found any implementation of that
model in the language I thought I'd try as an excercise.
The neuron model in question consists of a set of of differential equations for updating some gating variables, and
one for updating the membrane voltage of a neuron's membrane. We can store those in a State struct
struct State {
n: f64,
m: f64,
h: f64,
V: f64,
}
The gating variables get updated depending on some voltage rate contants:
$$\dot{n} = \alpha_n(V_m)(1-n) = \beta_n(V_m)n$$ $$\dot{m} = \alpha_m(V_m)(1-m) = \beta_m(V_m)m$$ $$\dot{h} = \alpha_h(V_m)(1-h) = \beta_h(V_m)h$$
Where $\alpha_x$ and $\beta_x$ are rate constants for the respective channels, which are for $x = (n, m, h)$:
$$\alpha_x(V_m) = \frac{x_\infty(V_m)}{\tau_x}$$ $$\beta_x(V_m) = \frac{1 - x_\infty(V_m)}{\tau_x}$$
These gating variables can then be used to compute the total current over the membrane:
$$ I = C_m \dot{V_m} + g_Kn^4(V_m - V_K) + g_{Na}m^3h(V_m - V_{Na}) + g_l(V_m - V_l) $$
The exact interpretation of the parameters is not of interest for the article. But this is just to show that we have a reasonably complicated model with enough decision points when it comes to optimizing an implementation. The ion gates , membrane voltage, alpha and beta rates and the input current $I$ have to computed per time step, while we can for now treat the others as constants. The naive implementation could look something like this: