Welcome to
The modular and extandable simulation toolkit for neurophysiology
Installation β’ Documentation β’ Examples β’ How to Cite
Overview#
MyoGen is a modular and extensible neuromuscular simulation framework for generating physiologically grounded motor-unit activity, muscle force, and surface EMG signals.
It supports end-to-end modeling of the neuromuscular pathway, from descending neural drive and spinal motor neuron dynamics to muscle activation and bioelectric signal formation at the electrode level. MyoGen is designed for algorithm validation, hypothesis-driven research, and education, providing configurable building blocks that can be independently combined and extended.
Highlights#
𧬠Biophysically inspired neuron models β NEURON-based motor neurons with validated calcium dynamics and membrane properties
π― Everything is inspectable β Complete access to every motor unit, spike time, fiber location etc. for rigorous algorithm testing
β‘οΈ Vectorized & parallel β Multi-core CPU processing with NumPy/Numba vectorization for fast computation
π¬ End-to-end simulation β From motor unit recruitment to high-density surface EMG in a single framework
π Reproducible science β Deterministic random seeds and standardized Neo Block outputs for exact replication
π§° Comprehensive toolkit β Surface EMG, intramuscular EMG, force generation, and spinal network modeling
Installation#
Requires Python 3.12+ β Check your version with
python --version
System Requirements#
Platform |
Before Installing MyoGen |
|---|---|
Windows |
NEURON 8.2.6 - Download, run installer, select βAdd to PATHβ |
Linux |
|
macOS |
|
[!CAUTION]
Windows Users: Prerequisites
You MUST install the following before installing MyoGen on Windows:
1. Visual C++ Build Tools
Download and install Visual C++ Build Tools.
During installation, select these components:
MSVC Build Tools for x64/x86 (Latest)
MSVC v143 β VS 2022 C++ x64/x86 build tools
Windows 11 SDK (latest)
C++ core desktop features
2. NEURON Simulator
Download: NEURON 8.2.6 Installer
Run the installer and select βAdd to PATHβ when prompted
Restart your terminal (close and reopen)
Then continue with the installation below
Step 1: Install uv (Package Manager)#
We use uv - a fast Python package manager. Install it first:
Windows (open PowerShell):
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
Linux/macOS:
curl -LsSf https://astral.sh/uv/install.sh | sh
After installing, restart your terminal (close and reopen it).
Step 2: Create a New Project#
Open a terminal and navigate to where you want your project:
# Create a new folder for your project
mkdir my_emg_project
cd my_emg_project
# Initialize a Python project
uv init
# Add MyoGen to your project
uv add myogen
Thatβs it! MyoGen is now installed and ready to use.
Step 3: Verify Installation#
Create a test file to make sure everything works:
# Create a test script
uv run python -c "from myogen import simulator; print('MyoGen installed successfully!')"
If you see MyoGen installed successfully! - youβre all set!
Alternative: pip install#
If you prefer pip over uv:
pip install myogen
For Developers (From Source)#
git clone https://github.com/NsquaredLab/MyoGen.git
cd MyoGen
uv sync
uv run poe setup_myogen
Optional: GPU Acceleration#
For 5-10Γ faster convolutions (requires NVIDIA GPU):
uv add cupy-cuda12x
Quick Start#
Generate motor unit action potentials (MUAPs):
from myogen import simulator
import quantities as pq
# 1. Generate recruitment thresholds (100 motor units)
thresholds, _ = simulator.RecruitmentThresholds(
N=100,
recruitment_range__ratio=50,
mode="fuglevand"
)
# 2. Create muscle model with fiber distribution
muscle = simulator.Muscle(
recruitment_thresholds=thresholds,
radius_bone__mm=1.0 * pq.mm,
fiber_density__fibers_per_mm2=400 * pq.mm**-2,
fat_thickness__mm=10 * pq.mm,
autorun=True
)
# 3. Set up surface electrode array
electrode_array = simulator.SurfaceElectrodeArray(
num_rows=5,
num_cols=5,
inter_electrode_distances__mm=5 * pq.mm,
electrode_radius__mm=5 * pq.mm,
bending_radius__mm=muscle.radius__mm + muscle.skin_thickness__mm + muscle.fat_thickness__mm,
)
# 4. Create surface EMG simulator
surface_emg = simulator.SurfaceEMG(
muscle_model=muscle,
electrode_arrays=[electrode_array],
sampling_frequency__Hz=2048.0,
MUs_to_simulate=[0, 1, 2, 3, 4] # First 5 motor units
)
# 5. Simulate MUAPs (parallel processing)
muaps = surface_emg.simulate_muaps(n_jobs=-2)
Access MUAP data:
import numpy as np
# Get MUAP from motor unit 0
muap_signal = muaps.groups[0].segments[0].analogsignals[0]
print(f"MUAP shape: {muap_signal.shape}") # (time, rows, cols)
# Extract from specific electrode (row 2, col 2)
electrode_muap = muap_signal[:, 2, 2]
peak_amplitude = np.max(np.abs(electrode_muap.magnitude))
print(f"Peak amplitude: {peak_amplitude:.3f} {electrode_muap.units}")
For full EMG simulation with spike trains, see examples
Documentation#
π Read the full documentation
User Guide β Working with simulation outputs
API Reference β Complete class documentation
Examples β Step-by-step tutorials from recruitment to EMG
How to Cite#
If you use MyoGen in your research, please cite:
TBD
Contributing#
Contributions welcome! See issues if you want to add a feature or fix a bug.
License#
MyoGen is AGPL licensed. See LICENSE for details.
Package Structure#
MyoGen/
βββ myogen/ # Main package source code
β βββ simulator/ # Core simulation functionality
β β βββ core/ # Core simulation components
β β β βββ emg/ # EMG signal generation
β β β βββ muscle/ # Muscle modeling
β β β βββ spike_train/ # Motor neuron simulation
β β βββ ...
β βββ utils/ # Utility functions and tools
β β βββ plotting/ # Visualization utilities
β β βββ currents.py # Current generation
β β βββ nmodl.py # NMODL file handling
β βββ ...
βββ examples/ # Example scripts and tutorials
βββ docs/ # Documentation source
βββ pyproject.toml # Project metadata and dependencies
βββ uv.lock # Pinned versions of dependencies