Production-grade implementation of personalized brain network modeling for epilepsy surgery planning.
This repository implements the Virtual Epileptic Patient (VEP) framework, a computational pipeline that simulates seizure propagation in individual patient brains. The VEP approach enables neurosurgeons to virtually test surgical interventions before performing irreversible resections.
This implementation is based on the following peer-reviewed publications:
| Paper | Authors | Journal | Key Contribution |
|---|---|---|---|
| The Virtual Epileptic Patient | Jirsa et al. | Lancet Neurology (2017) | Core VEP framework and clinical validation |
| Epileptor: A Phenomenological Model | Jirsa et al. | Brain (2014) | 6D neural mass model of seizure dynamics |
| Bayesian Inference of Epileptogenic Networks | Hashemi et al. | PLOS Computational Biology (2020) | Probabilistic parameter estimation |
| The Virtual Brain Platform | Sanz-Leon et al. | Frontiers in Neuroinformatics (2013) | TVB simulation infrastructure |
The Epileptor is a phenomenological neural mass model that captures the essential dynamics of seizure generation and termination. Each brain region is modeled as a 6-dimensional dynamical system:
State Variables: [xβ, yβ, z, xβ, yβ, g]
Population 1 (Fast oscillations - seizure spikes):
dxβ/dt = yβ - fβ(xβ) - z + I_ext1 + KΒ·Ξ£β±Ό wα΅’β±Ό(xββ±Ό(t-Οα΅’β±Ό) - xβα΅’)
dyβ/dt = 1 - 5xβΒ² - yβ
Slow permittivity variable (seizure termination):
dz/dt = r Β· (4(xβ - xβ) - z)
Population 2 (Spike-wave complexes):
dxβ/dt = -yβ + xβ - xβΒ³ + I_ext2 + 0.002g - 0.3(z - 3.5)
dyβ/dt = (-yβ + xββ΄) / Οβ
Low-pass filter:
dg/dt = -0.01(g - 0.1xβ)
| Parameter | Symbol | Default | Description |
|---|---|---|---|
| Excitability | xβ | -2.2 (healthy), -1.6 (EZ) | Controls seizure threshold |
| Time constant | r | 0.00035 | Slow variable dynamics |
| External input 1 | I_ext1 | 3.1 | Baseline excitation (Pop 1) |
| External input 2 | I_ext2 | 0.45 | Baseline excitation (Pop 2) |
| Tau | Οβ | 2857 | Spike-wave time scale |
| Coupling strength | K | 0.1 | Global network coupling |
| Conduction velocity | v | 3.0 mm/ms | Signal propagation speed |
The Epileptor exhibits a saddle-node bifurcation controlled by the excitability parameter xβ:
- xβ < -2.0 β Stable fixed point (interictal/healthy state)
- xβ > -2.0 β Limit cycle (ictal/seizure state)
The complete brain data is located locally at:
/Users/amar/Codes/brain-modeling-research/tvb_data/tvb_data/
This is an extended version of The Virtual Brain's standard dataset, containing multiple species, atlas resolutions, and sensor configurations.
Each .zip file contains the brain's wiring diagram derived from diffusion MRI tractography:
| File | Regions | Size | Contents |
|---|---|---|---|
connectivity_66.zip |
66 | 30 KB | Desikan-Killiany atlas |
connectivity_68.zip |
68 | 14 KB | FreeSurfer default |
connectivity_76.zip |
76 | 44 KB | AAL atlas (default) |
connectivity_80.zip |
80 | 37 KB | Extended AAL |
connectivity_96.zip |
96 | 53 KB | Fine-grained parcellation |
connectivity_192.zip |
192 | 61 KB | High-resolution |
connectivity_998.zip |
998 | 567 KB | Ultra high-resolution |
Inside each ZIP:
weights.txt # NΓN matrix of connection strengths (normalized 0-1)
tract_lengths.txt # NΓN matrix of fiber distances (mm)
centres.txt # NΓ4 table: [label, x, y, z] MNI coordinates
3D triangulated meshes of the cortical surface for visualization:
| File | Vertices | Triangles | Size | Description |
|---|---|---|---|---|
cortex_16384.zip |
16,384 | 32,760 | 638 KB | Standard resolution |
cortex_80k.zip |
81,924 | 163,840 | 2.7 MB | High resolution |
cortex_2x120k.zip |
240,000 | ~480,000 | 13.5 MB | Ultra high-res (both hemispheres) |
Inside each ZIP:
vertices.txt # VΓ3 matrix of [x, y, z] coordinates (mm)
triangles.txt # TΓ3 matrix of vertex indices forming each triangle
normals.txt # VΓ3 matrix of surface normal vectors
Maps each cortical mesh vertex to its corresponding brain region:
| File | Mesh | Atlas | Description |
|---|---|---|---|
regionMapping_16k_76.txt |
16k | 76 | Standard mapping |
regionMapping_16k_192.txt |
16k | 192 | High-res atlas on standard mesh |
regionMapping_80k_80.txt |
80k | 80 | High-res mesh mapping |
Format: Single column of integers (16,384 or 81,924 lines), one per vertex, indicating region index (0 to N-1).
Non-human primate data for translational neuroscience:
| File | Size | Description |
|---|---|---|
connectivity_84.zip |
355 KB | 84-region macaque structural connectivity |
surface_147k.zip |
21.7 MB | High-resolution macaque cortex mesh |
regionMapping_147k_84.txt |
3.7 MB | Vertex-to-region mapping |
volumeMap_inF99.nii.gz |
113 KB | Volumetric parcellation (NIfTI) |
Mouse brain atlases for small animal modeling:
mouse/
βββ allen_2mm/ # Allen Institute Mouse Brain Atlas
β βββ Connectivity.h5 # 226 KB - HDF5 connectivity matrix
β βββ ConnectivityAllen2mm.zip # 368 KB - Alternative format
β βββ RegionVolumeMapping.h5 # 14.5 MB - 3D volume labels
β βββ StructuralMRI.h5 # 9.7 MB - Reference MRI
β βββ Volume.h5 # 33 KB - Volume definition
β
βββ calabrese/ # Calabrese Mouse Atlas
βββ Connectivity_Calabrese.zip # 783 KB - Connectivity
βββ Structural_MRI.nii # 9.6 MB - NIfTI MRI
βββ Vol_Calabrese.nii # 9.6 MB - Volume
Sensor positions for EEG, MEG, and SEEG recordings:
| File | Sensors | Modality | Description |
|---|---|---|---|
eeg_63.txt |
63 | EEG | Standard 10-20 system |
eeg_brainstorm_65.txt |
65 | EEG | Brainstorm format |
meg_248.txt |
248 | MEG | 4D Neuroimaging system |
meg_brainstorm_276.txt |
276 | MEG | CTF MEG system |
seeg_588.txt |
588 | SEEG | Stereo-EEG depth electrodes |
seeg_brainstorm_960.txt |
960 | SEEG | High-density SEEG |
Format: Each line contains [label, x, y, z] in MNI space (mm).
Pre-computed forward models mapping brain sources to sensor measurements:
| File | Size | Description |
|---|---|---|
projection_eeg_62_surface_16k.mat |
7.8 MB | EEG 62-ch β 16k surface |
projection_eeg_65_surface_16k.npy |
8.5 MB | EEG 65-ch β 16k surface |
projection_meg_276_surface_16k.npy |
36.2 MB | MEG 276-ch β 16k surface |
projection_seeg_588_surface_16k.npy |
77.1 MB | SEEG 588-ch β 16k surface |
Original diffusion tensor imaging data and processing pipeline:
| File | Size | Description |
|---|---|---|
InputDTI_Toronto.zip |
5.6 MB | Raw DTI tensors (Toronto dataset) |
InputDTI_AnaSolodkin.zip |
43.5 MB | Extended DTI dataset |
output_ConnectionCapacityMatrix.csv |
50 KB | Derived connectivity weights |
output_ConnectionDistanceMatrix.csv |
50 KB | Derived tract lengths |
| Regions | Species | Atlas Name | Mesh | Use Case |
|---|---|---|---|---|
| 66 | Human | Desikan-Killiany | 16k | Fast prototyping |
| 68 | Human | FreeSurfer default | 16k | Standard analysis |
| 76 | Human | AAL (Automated Anatomical Labeling) | 16k | Clinical VEP (default) |
| 80 | Human | Extended AAL | 80k | High-resolution |
| 96 | Human | Fine-grained | 16k | Detailed regional analysis |
| 192 | Human | High-resolution | 16k | Research applications |
| 998 | Human | Schaefer/HCP | 80k | Maximum spatial detail |
| 84 | Macaque | CoCoMac/F99 | 147k | Translational primate research |
The connectivity data is derived from:
-
Diffusion MRI Tractography
- Probabilistic streamline tracking through white matter
- Connection weights = number of streamlines between regions
- Source: Human Connectome Project (HCP), Toronto DTI pipeline
-
Automated Anatomical Labeling (AAL) Atlas
- Tzourio-Mazoyer et al. (2002) NeuroImage
- 76 cortical and subcortical regions
- Standard parcellation for clinical epilepsy studies
-
MNI Coordinate System
- Montreal Neurological Institute standard space
- Region centers derived from atlas centroids
-
Allen Brain Atlas (Mouse data)
- Allen Institute for Brain Science
- 2mm resolution mouse connectivity
brain-modeling-research/
βββ tvb_data/ # π Extended brain data (local)
β βββ tvb_data/ # Connectivity, meshes, sensors
β
βββ vep/ # π§ Core simulation package
β βββ config.py # Simulation parameters
β βββ anatomy.py # Multi-atlas data loading
β βββ epileptor.py # Neural mass model (JIT)
β βββ simulator.py # Time integration with delays
β βββ visualizer.py # 3D brain + time series
β
βββ pipeline.py # π CLI entry point
βββ checkpoint.npz # Saved simulation state
βββ vep_report.html # Generated visualization
- Numba JIT Compilation: Epileptor equations compiled to LLVM machine code (~1000x speedup)
- Ring Buffer Delays: Circular buffer for transmission delays (O(1) memory access)
- Downsampled Storage: Save every 1ms to reduce memory (dt=0.05ms runtime)
Οα΅’β±Ό = Lα΅’β±Ό / v
where:
Lα΅’β±Ό = tract length between regions (mm)
v = conduction velocity (3.0 mm/ms)
Οα΅’β±Ό = delay (typically 0-50 ms)
# Create virtual environment
python -m venv tvb_env
source tvb_env/bin/activate
# Install dependencies
pip install numpy numba plotly tqdm tvb-library# List available atlases
python pipeline.py --list-atlases
# Standard 76-region human simulation
python pipeline.py --duration 4000 --output vep_report.html
# High-resolution 192-region simulation
python pipeline.py --atlas 192 --cortex 80k --duration 4000
# Ultra high-resolution 998-region (research)
python pipeline.py --atlas 998 --cortex 80k --duration 2000
# Macaque brain simulation
python pipeline.py --atlas 84 --duration 4000 --output macaque_report.html
# Fast prototyping (66 regions, 500ms)
python pipeline.py --atlas 66 --duration 500 --output quick_test.html
# Resume from checkpoint
python pipeline.py --checkpoint checkpoint.npz --output from_checkpoint.html| Argument | Default | Description |
|---|---|---|
--atlas |
76 | Brain atlas (66, 68, 76, 80, 96, 192, 998, 84) |
--cortex |
16k | Cortex resolution (16k, 80k, 120k) |
--duration |
4000 | Simulation time (ms) |
--output |
vep_report.html | Output HTML path |
--checkpoint |
None | Load saved simulation |
--save-checkpoint |
checkpoint.npz | Save simulation |
--list-atlases |
- | Show available atlases |
The pipeline generates an interactive HTML report with:
- Translucent cortical mesh (16k-80k vertices)
- Color-coded region nodes:
- π΄ Red: Epileptogenic Zone (EZ)
- π Orange: Propagation Zone (PZ)
- π΅ Blue: Healthy regions
- Hover tooltips with region details
- Play/Pause animation
- Neural activity (xβ) for EZ and top propagated regions
- Proper axis labels and non-overlapping legend
- Seizure onset markers
@article{jirsa2017virtual,
title={The Virtual Epileptic Patient: Individualized whole-brain models of epilepsy spread},
author={Jirsa, Viktor K and Proix, TimothΓ©e and Perdikis, Dionysios and others},
journal={Neuroimage},
volume={145},
pages={377--388},
year={2017},
publisher={Elsevier}
}
@article{jirsa2014epileptor,
title={On the nature of seizure dynamics},
author={Jirsa, Viktor K and Stacey, William C and Quilichini, Pascale P and others},
journal={Brain},
volume={137},
number={8},
pages={2210--2230},
year={2014},
publisher={Oxford University Press}
}
@article{sanzleon2013virtual,
title={The Virtual Brain: a simulator of primate brain network dynamics},
author={Sanz-Leon, Paula and Knock, Stuart A and Woodman, Marmaduke M and others},
journal={Frontiers in Neuroinformatics},
volume={7},
pages={10},
year={2013},
publisher={Frontiers}
}- The Virtual Brain Official Website
- TVB Documentation
- EBRAINS Platform
- Allen Brain Atlas (Mouse data)
This project is for research and educational purposes. TVB is distributed under GPL-3.0.
- Institut de Neurosciences des Systèmes (INS), Marseille, France
- The Virtual Brain Consortium
- Human Brain Project / EBRAINS
- Allen Institute for Brain Science (Mouse atlas data)