pyfibers


Namepyfibers JSON
Version 0.8.1 PyPI version JSON
download
home_pageNone
SummaryModeling stimulation of peripheral nerve fibers
upload_time2025-10-23 02:09:11
maintainerNone
docs_urlNone
authorDaniel Marshall, Elie Farah, Eric Musselman, Nicole Pelot, Warren Grill
requires_python>=3.10
licenseNone
keywords stimulation modeling computational fibers peripheral nerve
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # PyFibers
*PyFibers paper citation will be available soon.*


[![DOI](https://zenodo.org/badge/1010198505.svg)](https://doi.org/10.5281/zenodo.17068760)
[![Contributors](https://img.shields.io/github/contributors/wmglab-duke/pyfibers.svg)](https://github.com/wmglab-duke/pyfibers/graphs/contributors)
[![Python](https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12-blue.svg)](https://www.python.org/downloads/)
[![PyPI](https://img.shields.io/pypi/v/pyfibers.svg)](https://pypi.org/project/pyfibers/)
[![PyPI - Downloads](https://img.shields.io/pypi/dm/pyfibers.svg)](https://pypi.org/project/pyfibers/)
<!-- [![PyPI - License](https://img.shields.io/pypi/l/pyfibers.svg)](https://pypi.org/project/pyfibers/) -->
[![Development Status](https://img.shields.io/badge/development%20status-beta-yellow.svg)](https://pypi.org/classifiers/)
[![Code Style](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://pre-commit.com/)
[![Documentation](https://img.shields.io/badge/docs-github%20pages-blue.svg)](https://wmglab-duke.github.io/pyfibers/)
[![Issues](https://img.shields.io/github/issues/wmglab-duke/pyfibers.svg)](https://github.com/wmglab-duke/pyfibers/issues)
[![Pull Requests](https://img.shields.io/github/issues-pr/wmglab-duke/pyfibers.svg)](https://github.com/wmglab-duke/pyfibers/pulls)
[![CI](https://github.com/wmglab-duke/pyfibers/workflows/CI/badge.svg)](https://github.com/wmglab-duke/pyfibers/actions)

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)<br>**Sweeney** (Myelinated)<br>**Thio** (Unmyelinated): Autonomic, Cutaneous<br>**Sundt** (Unmyelinated)<br>**Tigerholm** (Unmyelinated)<br>**Rattay** (Unmyelinated)<br>**Schild** (Unmyelinated): Schild 1994, Schild 1997 |

## Installation

Note that these installation instructions are for users. Developer instructions are available in [contributing.md](https://github.com/wmglab-duke/pyfibers/blob/main/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.
   ```bash
   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](https://wmglab-duke.github.io/pyfibers/).

- [Tutorials](https://wmglab-duke.github.io/pyfibers/tutorials/index.html) on various operations.
- [API Documentation](https://wmglab-duke.github.io/pyfibers/autodoc/index.html) on function/class arguments and outputs.

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](https://wmglab-duke.github.io/pyfibers/custom_fiber.html))

```python
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](https://wmglab-duke.github.io/pyfibers/custom_stim.html)). Once you have a fiber object, you can create a `ScaledStim` instance, which is a set of instructions for stimulating model fibers.

```python
# 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](https://wmglab-duke.github.io/pyfibers/).

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

```python
import pyfibers

pyfibers.enable_logging()  # Enable INFO level logging
```

For detailed logging configuration options, see the [API documentation](https://wmglab-duke.github.io/pyfibers/autodoc/index.html).

## 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](https://github.com/wmglab-duke/pyfibers/blob/main/contributing.md).

## Authors and acknowledgment
   - Developed at Duke University by Daniel Marshall, Elie Farah, and Eric Musselman
   - Please see: \<Paper REF Forthcoming>

## License
See LICENSE


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "pyfibers",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "stimulation, modeling, computational, fibers, peripheral nerve",
    "author": "Daniel Marshall, Elie Farah, Eric Musselman, Nicole Pelot, Warren Grill",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/63/a0/bd77952e7dcaedeb876f2d1dc95566693754c7aa2aae9e38074ce47e2be9/pyfibers-0.8.1.tar.gz",
    "platform": null,
    "description": "# PyFibers\n*PyFibers paper citation will be available soon.*\n\n\n[![DOI](https://zenodo.org/badge/1010198505.svg)](https://doi.org/10.5281/zenodo.17068760)\n[![Contributors](https://img.shields.io/github/contributors/wmglab-duke/pyfibers.svg)](https://github.com/wmglab-duke/pyfibers/graphs/contributors)\n[![Python](https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12-blue.svg)](https://www.python.org/downloads/)\n[![PyPI](https://img.shields.io/pypi/v/pyfibers.svg)](https://pypi.org/project/pyfibers/)\n[![PyPI - Downloads](https://img.shields.io/pypi/dm/pyfibers.svg)](https://pypi.org/project/pyfibers/)\n<!-- [![PyPI - License](https://img.shields.io/pypi/l/pyfibers.svg)](https://pypi.org/project/pyfibers/) -->\n[![Development Status](https://img.shields.io/badge/development%20status-beta-yellow.svg)](https://pypi.org/classifiers/)\n[![Code Style](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n[![Pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://pre-commit.com/)\n[![Documentation](https://img.shields.io/badge/docs-github%20pages-blue.svg)](https://wmglab-duke.github.io/pyfibers/)\n[![Issues](https://img.shields.io/github/issues/wmglab-duke/pyfibers.svg)](https://github.com/wmglab-duke/pyfibers/issues)\n[![Pull Requests](https://img.shields.io/github/issues-pr/wmglab-duke/pyfibers.svg)](https://github.com/wmglab-duke/pyfibers/pulls)\n[![CI](https://github.com/wmglab-duke/pyfibers/workflows/CI/badge.svg)](https://github.com/wmglab-duke/pyfibers/actions)\n\nThis package implements biophysical models of axons in the NEURON simulation environment using Python.\nWith 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).\nYou can add your own fiber models and simulations protocols.\nYou can use analytical tools for extracellular potentials, or import from finite element models (FEM) such as COMSOL, ANSYS, or FEniCS.\n\n| Feature | Description |\n|---------|-------------|\n| **Flexible stimulation** | Support for custom waveforms and extracellular potential distributions |\n| **FEM integration** | Easy import of high-resolution potentials from finite element simulations |\n| **1D and 3D fibers** | Support for both straight and curved fiber geometries |\n| **Advanced analysis** | Built-in threshold search, conduction velocity measurement, and comprehensive data recording |\n| **Extensible** | Add your own fiber models and simulation protocols |\n| **Simulate recording** | Simple tools to calculate single fiber action potentials |\n| **Library of built-in fiber models** | **MRG** (Myelinated): MRG-discrete, MRG-interpolation, Pe\u00f1a (Small MRG-interpolation)<br>**Sweeney** (Myelinated)<br>**Thio** (Unmyelinated): Autonomic, Cutaneous<br>**Sundt** (Unmyelinated)<br>**Tigerholm** (Unmyelinated)<br>**Rattay** (Unmyelinated)<br>**Schild** (Unmyelinated): Schild 1994, Schild 1997 |\n\n## Installation\n\nNote that these installation instructions are for users. Developer instructions are available in [contributing.md](https://github.com/wmglab-duke/pyfibers/blob/main/contributing.md).\n\nIt is recommended (But not required) you create a new virtual environment for PyFibers. For example, using Anaconda/Miniconda:\n  - `conda create -n pyfibers`\n  - `conda activate pyfibers`\n1. Install NEURON and add to PATH (https://nrn.readthedocs.io/en/latest/)\n   - Make sure your NEURON and Python versions are compatible (https://nrn.readthedocs.io/en/latest/changelog.html)\n   - 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.\n2. Install PyFibers from PyPI and compile the `.mod` files.\n   ```bash\n   pip install pyfibers\n   pyfibers_compile\n   ```\n\nSome notes for `pyfibers_compile`:\n- 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.\n- 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.\n- 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`).\n\n\n## Usage\n\ud83d\udcd6 **Documentation**: For detailed information on usage, see our [documentation](https://wmglab-duke.github.io/pyfibers/).\n\n- [Tutorials](https://wmglab-duke.github.io/pyfibers/tutorials/index.html) on various operations.\n- [API Documentation](https://wmglab-duke.github.io/pyfibers/autodoc/index.html) on function/class arguments and outputs.\n\nThe basic steps for running a PyFibers simulation are as follows:\n### Creating a model fiber\nUse 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](https://wmglab-duke.github.io/pyfibers/custom_fiber.html))\n\n```python\nfrom pyfibers import build_fiber\n\nfiber = build_fiber(\n    fiber_model=FiberModel.MRG_DISCRETE,\n    diameter=10,  # um\n    n_nodes=25,  # um\n    temperature=37,  # C\n)\n```\n### Running a Simulation\nThe fiber object can be run in simulations using our provided `ScaledStim` class; alternatively, users can create their own custom simulation setup (See [Custom Simulations](https://wmglab-duke.github.io/pyfibers/custom_stim.html)). Once you have a fiber object, you can create a `ScaledStim` instance, which is a set of instructions for stimulating model fibers.\n\n```python\n# Add extracellular potentials to the fiber.\nfiber.potentials = potential_values\n\n# Create instance of ScaledStim class\nstimulation = ScaledStim(waveform=waveform, dt=time_step, tstop=time_stop)\n\n# run threshold search\namp, _ = stimulation.find_threshold(fiber)\nprint(f\"Threshold for 5.7 micron fiber: {amp} (mA)\")\n```\nFor more examples, see the [documentation](https://wmglab-duke.github.io/pyfibers/).\n\n## Logging\n\nPyFibers provides helpful logging messages during simulations. By default, logging is disabled to avoid interfering with your application's logging configuration.\n\nTo enable logging:\n\n```python\nimport pyfibers\n\npyfibers.enable_logging()  # Enable INFO level logging\n```\n\nFor detailed logging configuration options, see the [API documentation](https://wmglab-duke.github.io/pyfibers/autodoc/index.html).\n\n## Contributing\nIf 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](https://github.com/wmglab-duke/pyfibers/blob/main/contributing.md).\n\n## Authors and acknowledgment\n   - Developed at Duke University by Daniel Marshall, Elie Farah, and Eric Musselman\n   - Please see: \\<Paper REF Forthcoming>\n\n## License\nSee LICENSE\n\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Modeling stimulation of peripheral nerve fibers",
    "version": "0.8.1",
    "project_urls": {
        "Changelog": "https://github.com/wmglab-duke/pyfibers/blob/main/CHANGELOG.md",
        "Documentation": "https://wmglab-duke.github.io/pyfibers/",
        "Homepage": "https://github.com/wmglab-duke/pyfibers",
        "Issues": "https://github.com/wmglab-duke/pyfibers/issues",
        "Repository": "https://github.com/wmglab-duke/pyfibers"
    },
    "split_keywords": [
        "stimulation",
        " modeling",
        " computational",
        " fibers",
        " peripheral nerve"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "f02e0969147c5837ca4993a40b866376aead1d8af50439110f945ea2836d3082",
                "md5": "870724915e22c40b0e6f466b62ec3984",
                "sha256": "b7348231741396f3eb80ade8a748a7179f8f07e33a7398fe5c82e52cea636e1a"
            },
            "downloads": -1,
            "filename": "pyfibers-0.8.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "870724915e22c40b0e6f466b62ec3984",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 115050,
            "upload_time": "2025-10-23T02:09:10",
            "upload_time_iso_8601": "2025-10-23T02:09:10.410524Z",
            "url": "https://files.pythonhosted.org/packages/f0/2e/0969147c5837ca4993a40b866376aead1d8af50439110f945ea2836d3082/pyfibers-0.8.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "63a0bd77952e7dcaedeb876f2d1dc95566693754c7aa2aae9e38074ce47e2be9",
                "md5": "99c59c3b875d694e574dee63b0b4838f",
                "sha256": "97d267868404b352dc7187c8b5b8b9f3d2367282b95207760aefb5d6a9048cd0"
            },
            "downloads": -1,
            "filename": "pyfibers-0.8.1.tar.gz",
            "has_sig": false,
            "md5_digest": "99c59c3b875d694e574dee63b0b4838f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 79673,
            "upload_time": "2025-10-23T02:09:11",
            "upload_time_iso_8601": "2025-10-23T02:09:11.888633Z",
            "url": "https://files.pythonhosted.org/packages/63/a0/bd77952e7dcaedeb876f2d1dc95566693754c7aa2aae9e38074ce47e2be9/pyfibers-0.8.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-10-23 02:09:11",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "wmglab-duke",
    "github_project": "pyfibers",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "pyfibers"
}
        
Elapsed time: 1.35519s