| Crates.io | hodgkin-huxley |
| lib.rs | hodgkin-huxley |
| version | 0.1.0 |
| created_at | 2025-11-10 21:21:56.090639+00 |
| updated_at | 2025-11-10 21:21:56.090639+00 |
| description | High-performance Hodgkin-Huxley neuron models with exact biophysical equations for computational neuroscience |
| homepage | |
| repository | https://github.com/Yatrogenesis/cortexia-workspace |
| max_upload_size | |
| id | 1926208 |
| size | 113,167 |
A production-ready Rust implementation of the Hodgkin-Huxley neuron model with exact biophysical equations from the seminal 1952 paper.
thiserrorThe 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 currentI_K = g_K * n⁴ * (V - E_K) - Delayed rectifier potassium currentI_K(Ca) = g_K(Ca) * a * b * (V - E_K) - Calcium-activated potassium currentI_leak = g_leak * (V - E_leak) - Leak currentGating 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
Add this to your Cargo.toml:
[dependencies]
hodgkin-huxley = "0.1.0"
use hodgkin_huxley::{HodgkinHuxleyNeuron, neuron_types::NeuronConfig};
fn main() {
// 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());
}
use hodgkin_huxley::HodgkinHuxleyNeuron;
// Fast spiking interneuron
let fs_neuron = HodgkinHuxleyNeuron::fast_spiking().unwrap();
// Intrinsically bursting neuron
let ib_neuron = HodgkinHuxleyNeuron::intrinsically_bursting().unwrap();
// Classical squid axon
let squid_neuron = HodgkinHuxleyNeuron::squid_axon().unwrap();
use hodgkin_huxley::HodgkinHuxleyNeuron;
let mut neuron = HodgkinHuxleyNeuron::regular_spiking().unwrap();
neuron.initialize_rest();
let trace = neuron.simulate(100.0, 0.01, 10.0).unwrap();
// trace is a Vec<(f64, f64)> of (time, voltage) pairs
for (time, voltage) in trace.iter().take(10) {
println!("t = {:.2} ms, V = {:.2} mV", time, voltage);
}
use hodgkin_huxley::HodgkinHuxleyNeuron;
let mut neuron = HodgkinHuxleyNeuron::squid_axon().unwrap();
neuron.initialize_rest();
neuron.simulate(100.0, 0.01, 15.0).unwrap();
// Detect spikes
let spikes = neuron.detect_spikes(-20.0);
// Calculate firing rate
let rate = HodgkinHuxleyNeuron::firing_rate(&spikes);
println!("Firing rate: {:.2} Hz", rate);
// Calculate interspike intervals
let isis = HodgkinHuxleyNeuron::interspike_intervals(&spikes);
println!("Mean ISI: {:.2} ms", isis.iter().sum::<f64>() / isis.len() as f64);
The library includes several examples demonstrating its capabilities:
# Simulate an action potential
cargo run --example action_potential --release
# Compare different neuron types
cargo run --example neuron_comparison --release
The library includes realistic physical constants and ion concentrations:
Two integration methods are provided:
Default time step: 0.01 ms (10 µs)
All quantities use standard electrophysiological units:
Run the test suite:
# Run all tests
cargo test
# Run only unit tests
cargo test --lib
# Run documentation tests
cargo test --doc
# Run with verbose output
cargo test -- --nocapture
Generate and view the full documentation:
cargo doc --open
The library is optimized for production use:
nalgebraRun benchmarks:
cargo bench
Hodgkin, A. L., & Huxley, A. F. (1952). A quantitative description of membrane current and its application to conduction and excitation in nerve. The Journal of Physiology, 117(4), 500-544.
Connor, J. A., & Stevens, C. F. (1971). Prediction of repetitive firing behaviour from voltage clamp data on an isolated neurone soma. The Journal of Physiology, 213(1), 31-53.
Traub, R. D., & Miles, R. (1991). Neuronal Networks of the Hippocampus. Cambridge University Press.
Licensed under either of:
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
If you use this library in your research, please cite:
@software{hodgkin_huxley_rust,
title = {hodgkin-huxley: A Rust implementation of the Hodgkin-Huxley neuron model},
author = {Your Name},
year = {2024},
url = {https://github.com/cortexia/hodgkin-huxley}
}