Crate hodgkin_huxley

Crate hodgkin_huxley 

Source
Expand description

§Hodgkin-Huxley Neuron Library

A production-ready implementation of the Hodgkin-Huxley neuron model with exact biophysical equations from the seminal 1952 paper.

§Overview

This library provides a complete implementation of the Hodgkin-Huxley equations for modeling action potentials in neurons. It includes:

  • Accurate biophysics: Exact equations from Hodgkin & Huxley (1952)
  • Multiple neuron types: Regular spiking, fast spiking, intrinsically bursting, etc.
  • Numerical solvers: RK4 and exponential Euler integrators
  • Temperature effects: Q10 scaling for realistic temperature dependence
  • Ion channels: Na⁺, K⁺, Ca²⁺-activated K⁺, and leak channels

§Mathematical Model

The membrane voltage is governed by:

C_m * dV/dt = -I_Na - I_K - I_K(Ca) - I_leak + I_ext

Where:

  • I_Na = g_Na * m³ * h * (V - E_Na) - Fast sodium current
  • I_K = g_K * n⁴ * (V - E_K) - Delayed rectifier potassium current
  • I_K(Ca) = g_K(Ca) * a * b * (V - E_K) - Calcium-activated potassium current
  • I_leak = g_leak * (V - E_leak) - Leak current

Gating variables evolve according to:

dm/dt = α_m(V) * (1 - m) - β_m(V) * m
dh/dt = α_h(V) * (1 - h) - β_h(V) * h
dn/dt = α_n(V) * (1 - n) - β_n(V) * n
da/dt = α_a(V) * (1 - a) - β_a(V) * a
db/dt = α_b(V) * (1 - b) - β_b(V) * b

§Quick Start

use hodgkin_huxley::{HodgkinHuxleyNeuron, neuron_types::NeuronConfig};
use nalgebra::DVector;

// Create a regular spiking cortical neuron
let config = NeuronConfig::regular_spiking();
let mut neuron = HodgkinHuxleyNeuron::new(config).unwrap();

// Initialize at resting state
neuron.initialize_rest();

// Apply a current pulse and simulate
let i_ext = 10.0; // µA/cm²
let dt = 0.01;    // ms
let duration = 50.0; // ms

for _ in 0..(duration / dt) as usize {
    neuron.step(dt, i_ext).unwrap();
}

// Check if neuron spiked
let spikes = neuron.detect_spikes(-20.0);
println!("Number of spikes: {}", spikes.len());

§Examples

§Simulate different neuron types

use hodgkin_huxley::{HodgkinHuxleyNeuron, neuron_types::NeuronConfig};

// Fast spiking interneuron
let fs_neuron = HodgkinHuxleyNeuron::new(NeuronConfig::fast_spiking()).unwrap();

// Intrinsically bursting neuron
let ib_neuron = HodgkinHuxleyNeuron::new(NeuronConfig::intrinsically_bursting()).unwrap();

// Classical squid axon
let squid_neuron = HodgkinHuxleyNeuron::new(NeuronConfig::squid_axon()).unwrap();

§Record voltage trace

use hodgkin_huxley::{HodgkinHuxleyNeuron, neuron_types::NeuronConfig};

let mut neuron = HodgkinHuxleyNeuron::new(NeuronConfig::regular_spiking()).unwrap();
neuron.initialize_rest();

let mut voltage_trace = Vec::new();
let dt = 0.01;

for t in 0..5000 {
    let current = if t > 1000 && t < 4000 { 10.0 } else { 0.0 };
    neuron.step(dt, current).unwrap();
    voltage_trace.push((t as f64 * dt, neuron.voltage()));
}

Modules§

channels
Ion channel implementations for the Hodgkin-Huxley model.
constants
Physical and biological constants for the Hodgkin-Huxley model.
error
Error types for the Hodgkin-Huxley neuron library.
neuron_types
Predefined neuron type configurations.
solvers
Numerical integration methods for solving differential equations.

Structs§

HodgkinHuxleyNeuron
Complete Hodgkin-Huxley neuron model with 6 state variables.