Skip to main content

Modeling stimulation of peripheral nerve fibers

Project description

PyFibers

PyFibers paper citation will be available soon.

DOI Contributors Python PyPI PyPI - Downloads

Development Status Code Style Pre-commit Documentation Issues Pull Requests CI

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 import 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 import of high-resolution potentials from finite element simulations
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
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:

  • It is normal to see the following message during compilation: NEURON mechanisms not found in <path>. Check the NEURON output that follows for a message that the mechanisms were compiled successfully (e.g., for Windows: nrnmech.dll was built successfully.) In the future 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 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 using 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
)

Running a Simulation

The fiber object can be run in simulations using our provided ScaledStim class; alternatively, users can create their own custom simulation setup (See Custom Simulations). Once you have a fiber object, you can create a ScaledStim instance, which is a set of instructions for stimulating model fibers.

# Add extracellular potentials to the fiber.
fiber.potentials = potential_values

# 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.

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

  • Developed at Duke University by Daniel Marshall, Elie Farrah, and Eric Musselman
  • Please see: <Paper REF Forthcoming>

License

See LICENSE

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyfibers-0.7.0.tar.gz (78.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyfibers-0.7.0-py3-none-any.whl (113.9 kB view details)

Uploaded Python 3

File details

Details for the file pyfibers-0.7.0.tar.gz.

File metadata

  • Download URL: pyfibers-0.7.0.tar.gz
  • Upload date:
  • Size: 78.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for pyfibers-0.7.0.tar.gz
Algorithm Hash digest
SHA256 aaf52d7c7c1d058c1c8aa78b169781f5c7c63466e9af171f994beec27b70ef24
MD5 6557fed39c993bb8d2655736945f5ea3
BLAKE2b-256 ca1fd4ee7747b1e7f481174099e9e926327015fe2e59938756b53271021125eb

See more details on using hashes here.

File details

Details for the file pyfibers-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: pyfibers-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 113.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for pyfibers-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ba665d80271f67b999c040b5638a907c4eabdc813d9fee7149d04637e6efc015
MD5 e12748589fded38958c4e147054dc33d
BLAKE2b-256 1c9e1aebfd2cc28d8a5044f45242996f6e7970db202188db79256e93e3a4ed0d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page