Skip to main content

PyFibers

PyFibers Paper: Marshall DP, Farah ES, Musselman ED, Pelot NA, Grill WM (2025) PyFibers: An open-source NEURON-Python package to simulate responses of model nerve fibers to electrical stimulation. PLoS Comput Biol 21(12): e1013764. https://doi.org/10.1371/journal.pcbi.1013764

Publication Citations GitHub Documentation DOI Stars CI codecov PyPI PyPI Downloads PyPI Downloads PyPI - Python Version

This package implements biophysical models of axons in the NEURON simulation environment using Python. With our package, you can model the responses of axons to electrical stimulation (e.g., find the minimum current amplitude required to activate or block an action potential). You can add your own fiber models and simulations protocols. You can use analytical tools for extracellular potentials, or use outputs from finite element models (FEM) such as COMSOL, ANSYS, or FEniCS.

Feature Description
Flexible stimulation Support for custom waveforms and extracellular potential distributions
FEM integration Easy usage of high-resolution potentials from finite element simulations (COMSOL, ANSYS, or other FEM software)
Resampling tools Automatically interpolate potentials to match your fiber geometry
1D and 3D fibers Support for both straight and curved fiber geometries
Advanced analysis Built-in threshold search, conduction velocity measurement, and comprehensive data recording
Multi-source support Combine potentials from multiple electrodes with different waveforms
Extensible Add your own fiber models and simulation protocols
Simulate recording Simple tools to calculate single fiber action potentials
Library of built-in fiber models MRG (Myelinated): MRG-discrete, MRG-interpolation, Peña (Small MRG-interpolation)
Sweeney (Myelinated)
Thio (Unmyelinated): Autonomic, Cutaneous
Sundt (Unmyelinated)
Tigerholm (Unmyelinated)
Rattay (Unmyelinated)
Schild (Unmyelinated): Schild 1994, Schild 1997

Installation

Note that these installation instructions are for users. Developer instructions are available in contributing.md.

It is recommended (But not required) you create a new virtual environment for PyFibers. For example, using Anaconda/Miniconda:

conda create -n pyfibers
conda activate pyfibers
  1. Install NEURON and add to PATH (https://nrn.readthedocs.io/en/latest/)
    • Make sure your NEURON and Python versions are compatible (https://nrn.readthedocs.io/en/latest/changelog.html)
    • Check your installation by running the following command: python -c "import neuron; neuron.test(); quit()". If successful, test outputs along with "OK" should be printed to the terminal.
  2. Install PyFibers from PyPI and compile the .mod files.
    pip install pyfibers
    pyfibers_compile
    

Some notes for pyfibers_compile:

  • Check the NEURON output that follows for a message that the mechanisms were compiled successfully (e.g., for Windows: nrnmech.dll was built successfully.) While using PyFibers, if you see the NEURON mechanisms not found in <path>. message, this is cause for concern, as this means PyFibers cannot find the compiled mechanisms. Failed compiles will commonly cause the error message Argument not a density mechanism name to appear when trying to create fibers.
  • Careful! Make sure that the correct NEURON installation is in your path, as the first found installation will be used for compilation. The version used for compilation must be the same version used to run PyFibers code.
  • If you receive a message that the pyfibers_compile command is not found, find the executable for this command in the Scripts path of your python directory (e.g. C:\Users\<username>\Anaconda3\envs\pyfibers\Scripts) and run the executable (e.g., pyfibers_compile.exe).

Usage

📖 Documentation: For detailed information on usage, see our documentation:

The basic steps for running a PyFibers simulation are as follows:

Creating a model fiber

Use the build_fiber function to create a fiber object. The fiber object consists of NEURON sections with ion channel mechanisms inserted for the fiber model chosen when the object is initialized. Users can add custom fiber models as well as use our provided models (see Custom Fiber Models).

from pyfibers import build_fiber

fiber = build_fiber(
    fiber_model=FiberModel.MRG_DISCRETE,
    diameter=10,  # um
    n_nodes=25,  # um
    temperature=37,  # C
)

Adding extracellular potentials

PyFibers supports both analytical calculations and using electrical potentials exported from solvers such as COMSOL or Ansys (see Extracellular Potentials documentation):

# Add extracellular potentials using point source approximation
fiber.potentials = fiber.point_source_potentials(0, 100, fiber.length / 2, 1, 0.3)

Running a simulation

To run a simulation with extracellular stimulation, use the ScaledStim class; users can also create custom simulation setups (See Custom Simulations) or use IntraStim for intracellular stimulation.

# Create instance of ScaledStim class
stimulation = ScaledStim(waveform=waveform, dt=time_step, tstop=time_stop)

# Run threshold search
amp, _ = stimulation.find_threshold(fiber)
print(f"Threshold for 5.7 micron fiber: {amp} (mA)")

For more examples, see the documentation.

Logging

PyFibers provides helpful logging messages during simulations. By default, logging is disabled to avoid interfering with your application's logging configuration.

To enable logging:

import pyfibers

pyfibers.enable_logging()  # Enable INFO level logging

For detailed logging configuration options, see the API documentation.

Contributing

If you develop additional functionality that would be generally useful to our users, please open a Pull Request for us to review. For detailed contribution guidelines, see our contributing guide.

Authors and acknowledgment

License

See LICENSE

Metadata

Release files for pyfibers 0.10.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyfibers 0.10.3
File Size Uploaded
pyfibers-0.10.3.tar.gz 84.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyfibers 0.10.3
File Interpreter ABI Platform
pyfibers-0.10.3-py3-none-any.whl Python 3 none any Details

Total release size: 205.9 kB

Release files / pyfibers-0.10.3.tar.gz

Download URL pyfibers-0.10.3.tar.gz
Size 84.9 kB
Tags Source
SHA-256 checksum
How to use checksums
a5fb8d5cb6169ab0baad975351f98b0e1afb775b481b3dd1d545c5cedc26ac41
BLAKE2b-256 checksum
How to use checksums
930d1ebaa7c07f9a7e852c1d831a937134d4513dcae6d11d823f2c9814ec7fe7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Release files / pyfibers-0.10.3-py3-none-any.whl

Download URL pyfibers-0.10.3-py3-none-any.whl
Size 121.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c7fbf0ad1913902327712e1111476877a4148e9f0f09fc2cdffa3af5e2087588
BLAKE2b-256 checksum
How to use checksums
c856e881f31fbfffd969b9930674a8e6e5b3d41df1b282b28ede78b1e5bb00e1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Release history Release notifications | RSS feed

0.11.0

2 release files

0.10.4

2 release files

This release

0.10.3 This release

2 release files

0.10.2

2 release files

0.10.1

2 release files

0.10.0

2 release files

0.9.2

2 release files

0.9.1

2 release files

0.9.0

2 release files

0.8.5

2 release files

0.8.4

2 release files

0.8.3

2 release files

0.8.2

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page