A somewhat biologically realistic implementation of multi-compartment neurons based on cable theory, featuring Hodgkin-Huxley dynamics and synaptic modeling. This project provides a basic framework for simulating neuronal networks with detailed morphological and electrophysiological properties.
- Biological Background
- Mathematical Foundations
- Architecture
- Installation and Usage
- Visualization
- GUI Wrapper
- References
Neurons are the fundamental computational units of the nervous system, responsible for processing and transmitting information through electrical and chemical signals. A typical neuron consists of:
- Soma (Cell Body): Contains the nucleus and most organelles, integrates incoming signals
- Dendrites: Branching extensions that receive synaptic inputs from other neurons
- Axon: Long projection that transmits action potentials ("outputs") to target neurons
- Synapses: Specialized junctions where neurons communicate via neurotransmitters
The electrical activity of neurons is governed by the movement of ions across the cell membrane. The membrane potential (voltage difference across the membrane) changes dynamically due to:
- Ion Channels: Proteins that allow specific ions to pass through the membrane
- Ion Pumps: Active transporters that maintain ion concentration gradients
- Membrane Capacitance: The membrane's ability to store electrical charge
Real (biological) neurons are not electrically uniform structures. Different parts of a neuron (soma, dendrites, axon) have different electrical properties and channel distributions. This allows for modeling multiple scales, as is illustrated by the following image taken from Dayan & Abbott (2001):
Multi-compartment models divide neurons into discrete segments, each with its own:
- Membrane capacitance and resistance
- Ion channel densities
- Morphological properties (length, diameter)
- Electrical coupling to neighboring compartments
This approach allows realistic modeling of:
- Dendritic Integration: How synaptic inputs from other neurons are processed in the dendrites
- Action Potential Propagation: How spikes travel along axons (if an axon is modeled consisting of multiple compartments)
- Spatial Summation: How inputs from different locations combine
- Temporal Dynamics: How signals change over time and space
Cable theory provides a mathematical foundation for understanding electrical signal propagation in neurons. An estimation is made by modeling dendrites and axons as cylinders ("cable") composed of segments. So it basically treats neuronal processes as electrical cables with:
-
Axial Resistance (
$R_a$ ): Resistance to current flow along the process -
Membrane Resistance (
$R_m$ ): Resistance to current flow across the membrane -
Membrane Capacitance (
$C_m$ ): Ability to store electrical charge
The cable equation describes how voltage changes propagate:
Where:
-
$c_m$ is membrane capacitance -
$V$ is membrane potential -
$a$ is cable radius -
$r_L$ is axial resistance (=longitudinal) -
$i_m$ is membrane current density -
$i_e$ is external current density -
$x$ is cable distance
Alan Hodgkin and Andrew Huxley introduced a mathematical framework for modeling ionic currents of excitable membranes that has become standard. It describes the ionic mechanisms underlying action potential generation. The Hodgkin-Huxley model is a system of four ordinary differential equations (ODEs):
Where:
-
$C$ is Membrane capacitance -
$I_{app}$ is applied current -
$I_{Na_V}$ is sodium current -
$I_{K_V}$ is potassium current -
$I_L$ is passive leak current
Sodium Current:
Potassium Current:
Leak Current:
Where:
-
$g_{Na}$ ,$g_K$ ,$g_L$ : Maximum conductances -
$E_{Na}$ ,$E_K$ ,$E_L$ : Reversal potentials -
$m$ ,$h$ ,$n$ : Gating variables ($0 \le m$ ,$h$ ,$n \le 1$ )
The transition of each subunit gate can be described by a kinetic scheme, in which the gating transition closed → open occurs at a voltage-dependent rate
So the gating variables follow first-order kinetics:
Where
Sodium activation (m):
Sodium inactivation (h):
Potassium activation (n):
A graphical visualization of the temporal evolution of the dynamic variables of the Hodgkin-HUxley model during a single action potential is shown below:
The upper-most trace is the membrane potential, the second is the membrane current produced by the sum of the Hodgkin-Huxley
- Implements Hodgkin-Huxley dynamics
- Manages ion channels and gating variables
- Handles synaptic inputs
- Manages multiple compartments (soma, axon, dendrites)
- Handles connections between the neurons' compartments
- Provides interface for neuron operations
- Manages multiple neurons
- Handles synaptic connections between neurons
- Coordinates network simulation
CompartmentParameters: Morphological and electrical propertiesNeuronParameters: Neuron settingsSynapticParameters: Synapse properties
- High sodium and potassium conductances
- Primary spike initiation site
- Standard Hodgkin-Huxley parameters
- Enhanced sodium conductance for reliable propagation
- Lower capacitance for faster dynamics
- Long length for signal transmission
- Additional ion channels
- Calcium dynamics for plasticity
- Variable lengths and diameters
src/- Main implementationneuron.py- Multi-compartment neuron classcompartment.py- Individual compartment with Hodgkin-Huxley dynamicsnetwork.py- Network of connected neuronsparameters.py- Model parameters and configdemo.py- Example simulation and visualization
- Python 3.7+
- NumPy
- Matplotlib
- Seaborn
- Networkx
pip install numpy matplotlib seaborn networkxcd src/
python demo.py# Create a single neuron
neuron = Neuron(neuron_id=0)
soma_id, axon_id, dendrite_ids = neuron.create_morphology(num_dendrites=2)
# Add external current
neuron.update({soma_id: 0.1}) # 0.1 nA current injection
# Create a simple network with 3 neurons
network = NeuronalNetwork(num_neurons=3)
network.connect_neurons(0, 1, weight=1.5, delay=1.0)
network.simulate(duration=100.0) # 100 ms simulationThe project includes comprehensive visualization tools:
- Graph representation of neuron connections
- Layer-based organization
- Connection weight visualization
- Spike timing across neurons
- Color-coded by neuron type
- Time-resolved activity patterns
- Per-neuron firing rates
- Statistical summaries
- Activity distribution
- Neuron parameter comparisons
- Threshold vs. refractory period plots
- Morphological property distributions
- Weight matrices
- Connection density analysis
- Network topology visualization
A graphical user interface (GUI) allows easier configuration and simulation.
-
Dayan & Abbott (2001). Theoretical Neuroscience: Computational and Mathematical Modeling of Neural Systems. MIT Press.
-
Smith (2019). Cellular Biophysics and Modeling: A Primer on the Computational Biology of Escitable Cells. Cambridge University Press.
-
Churchland & Sejnowski (1997) Grundlagen zur Neuroinformatik und Neurobiologie. Vieweg.
A song on the equations to get into the right mood: The Spark Within the Veil



