[![Build Status](https://travis-ci.org/Helveg/patch.svg?branch=master)](https://travis-ci.org/Helveg/patch)
[![codecov](https://codecov.io/gh/Helveg/patch/branch/master/graph/badge.svg)](https://codecov.io/gh/Helveg/patch)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Documentation Status](https://readthedocs.org/projects/patch/badge/?version=latest)](https://patch.readthedocs.io/en/latest/?badge=latest)
_*No ducks were punched during the construction of this monkey patch._
# Installation
```
pip install nrn-patch
```
## Minimal requirements
* Python 3.8+
* NEURON 8.0+
Be aware that the interface is currently incomplete, this means that most parts are still
"just" NEURON. I've only patched holes I frequently encounter myself when using the
`h.Section`, `h.NetStim` and `h.NetCon` functions. Feel free to open an issue or fork this
project and open a pull request for missing or broken parts of the interface.
# Philosophy
Python interfaces should be Pythonic, this wrapper offers just that:
- Full Python objects: each wonky C-like NEURON object is wrapped in a
full fledged Python object, easily handled and extended through
inheritance.
- Duck typed interface: take a look at the magic methods I use and any
object you create with those methods present will work just fine
with Patch.
- Correct garbage collection, objects connected to eachother don't
dissapear: Objects that rely on eachother store a reference to
eachother. As is the basis for any sane object oriented interface.
- Explicit exceptions: I catch silent failures and gotchas and raise
semantic errors with a class hierarchy instead for granular
exception handling.
**Warning:** When running MPI simulations errors cannot be caught due to a
[bug](https://github.com/neuronsimulator/nrn/issues/1112) in NEURON where every
exception results in NEURON calling `MPI_Abort` and shutting down the
simulation. If this leads to confusing failure modes please post an issue with
your Patch code to the GitHub repo!
# Basic usage
Use it like you would use NEURON. The wrapper doesn't make any changes to the interface,
it just patches up some of the more frequent and ridiculous gotchas.
Patch supplies a new HOC interpreter `p`, the `PythonHocInterpreter` which wraps the
standard HOC interpreter `h` provided by NEURON. Any objects returned will either be
`PythonHocObject`'s wrapping their corresponding NEURON object, or whatever NEURON
returns.
When using just Patch the difference between NEURON and Patch objects is handled
transparently, but if you wish to mix interpreters you can transform all Patch objects
back to NEURON objects with `obj.__neuron__()`.
``` python
from patch import p
import glia as g
section = p.Section()
point_process = g.insert(section, "AMPA")
stim = p.NetStim()
stim.start = 10
stim.number = 5
stim.interval = 10
# And here comes the magic! This explicitly defined connection
# isn't immediatly garbage collected! What a crazy world we live in.
# Has science gone too far?
p.NetCon(stim, point_process)
# It's fully compatible using __neuron__
from neuron import h
nrn_section = h.Section()
nrn_section.connect(section.__neuron__())
```
# Magic methods
## \_\_neuron\_\_
_Get the object's NEURON pointer_
Whenever an object with this method present is sent to the NEURON HOC interpreter, the
result of this method is passed instead. This allows Python methods to encapsulate NEURON
pointers transparently
## \_\_netcon\_\_
_Get the object's NetCon pointer_
Whenever an object with this method present is used in a NetCon call, the result of this
method is passed instead. The connection is stored on the original object. This allows to
simplify the calls to NetCon, or to add more elegant default behavior, like inserting the
connection on a random segment of a section and being able to use just ``p.NetCon(section,
synapse)``
Raw data
{
"_id": null,
"home_page": "https://github.com/helveg/patch",
"name": "nrn-patch",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": "",
"keywords": "",
"author": "Robin De Schepper",
"author_email": "robingilbert.deschepper@unipv.it",
"download_url": "https://files.pythonhosted.org/packages/af/e2/05aeeb04bd707eceeb154da1057600a00fc480a79f50f00aa8c86045f92b/nrn-patch-3.0.1.tar.gz",
"platform": "",
"description": "[![Build Status](https://travis-ci.org/Helveg/patch.svg?branch=master)](https://travis-ci.org/Helveg/patch)\n[![codecov](https://codecov.io/gh/Helveg/patch/branch/master/graph/badge.svg)](https://codecov.io/gh/Helveg/patch)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n[![Documentation Status](https://readthedocs.org/projects/patch/badge/?version=latest)](https://patch.readthedocs.io/en/latest/?badge=latest)\n\n_*No ducks were punched during the construction of this monkey patch._\n\n# Installation\n\n```\npip install nrn-patch\n```\n\n## Minimal requirements\n\n* Python 3.8+\n* NEURON 8.0+\n\nBe aware that the interface is currently incomplete, this means that most parts are still\n\"just\" NEURON. I've only patched holes I frequently encounter myself when using the\n`h.Section`, `h.NetStim` and `h.NetCon` functions. Feel free to open an issue or fork this\nproject and open a pull request for missing or broken parts of the interface.\n\n# Philosophy\n\nPython interfaces should be Pythonic, this wrapper offers just that:\n\n - Full Python objects: each wonky C-like NEURON object is wrapped in a\n full fledged Python object, easily handled and extended through\n inheritance.\n - Duck typed interface: take a look at the magic methods I use and any\n object you create with those methods present will work just fine\n with Patch.\n - Correct garbage collection, objects connected to eachother don't\n dissapear: Objects that rely on eachother store a reference to\n eachother. As is the basis for any sane object oriented interface.\n - Explicit exceptions: I catch silent failures and gotchas and raise\n semantic errors with a class hierarchy instead for granular\n exception handling.\n\n**Warning:** When running MPI simulations errors cannot be caught due to a\n[bug](https://github.com/neuronsimulator/nrn/issues/1112) in NEURON where every\nexception results in NEURON calling `MPI_Abort` and shutting down the\nsimulation. If this leads to confusing failure modes please post an issue with\nyour Patch code to the GitHub repo!\n\n# Basic usage\n\nUse it like you would use NEURON. The wrapper doesn't make any changes to the interface,\nit just patches up some of the more frequent and ridiculous gotchas.\n\nPatch supplies a new HOC interpreter `p`, the `PythonHocInterpreter` which wraps the\nstandard HOC interpreter `h` provided by NEURON. Any objects returned will either be\n`PythonHocObject`'s wrapping their corresponding NEURON object, or whatever NEURON\nreturns.\n\nWhen using just Patch the difference between NEURON and Patch objects is handled\ntransparently, but if you wish to mix interpreters you can transform all Patch objects\nback to NEURON objects with `obj.__neuron__()`.\n\n``` python\nfrom patch import p\nimport glia as g\n\nsection = p.Section()\npoint_process = g.insert(section, \"AMPA\")\nstim = p.NetStim()\nstim.start = 10\nstim.number = 5\nstim.interval = 10\n\n# And here comes the magic! This explicitly defined connection\n# isn't immediatly garbage collected! What a crazy world we live in.\n# Has science gone too far?\np.NetCon(stim, point_process)\n\n# It's fully compatible using __neuron__\nfrom neuron import h\nnrn_section = h.Section()\nnrn_section.connect(section.__neuron__())\n```\n\n# Magic methods\n\n## \\_\\_neuron\\_\\_\n\n_Get the object's NEURON pointer_\n\nWhenever an object with this method present is sent to the NEURON HOC interpreter, the\nresult of this method is passed instead. This allows Python methods to encapsulate NEURON\npointers transparently\n\n## \\_\\_netcon\\_\\_\n\n_Get the object's NetCon pointer_\n\nWhenever an object with this method present is used in a NetCon call, the result of this\nmethod is passed instead. The connection is stored on the original object. This allows to\nsimplify the calls to NetCon, or to add more elegant default behavior, like inserting the\nconnection on a random segment of a section and being able to use just ``p.NetCon(section,\nsynapse)``\n\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A Pythonic, object-oriented, monkey patch for NEURON",
"version": "3.0.1",
"project_urls": {
"Homepage": "https://github.com/helveg/patch"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f7df7b5b85d33553e2e90c7fddab576a733f0eb46f75a22b9558c786afd2959c",
"md5": "a3d14e5d7d646c39b52f1d8e18990ff6",
"sha256": "50af16d676e3760e75542b60d77d0a5d3f3e2f4c6d732e25843c6901d9adc1ad"
},
"downloads": -1,
"filename": "nrn_patch-3.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "a3d14e5d7d646c39b52f1d8e18990ff6",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 19737,
"upload_time": "2021-11-17T16:08:32",
"upload_time_iso_8601": "2021-11-17T16:08:32.368932Z",
"url": "https://files.pythonhosted.org/packages/f7/df/7b5b85d33553e2e90c7fddab576a733f0eb46f75a22b9558c786afd2959c/nrn_patch-3.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "afe205aeeb04bd707eceeb154da1057600a00fc480a79f50f00aa8c86045f92b",
"md5": "4bc4324584a0d81d24e1f239c359b865",
"sha256": "1e55c8d7ccee0622543b2de5a1bd567f954d951b2fe9313c674e2036bda9df88"
},
"downloads": -1,
"filename": "nrn-patch-3.0.1.tar.gz",
"has_sig": false,
"md5_digest": "4bc4324584a0d81d24e1f239c359b865",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 18038,
"upload_time": "2021-11-17T16:08:34",
"upload_time_iso_8601": "2021-11-17T16:08:34.635655Z",
"url": "https://files.pythonhosted.org/packages/af/e2/05aeeb04bd707eceeb154da1057600a00fc480a79f50f00aa8c86045f92b/nrn-patch-3.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2021-11-17 16:08:34",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "helveg",
"github_project": "patch",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "nmodl-glia",
"specs": [
[
"==",
"4.0.0b3"
]
]
},
{
"name": "errr",
"specs": [
[
"==",
"1.2.0"
]
]
},
{
"name": "mpi4py",
"specs": [
[
"==",
"3.1.5"
]
]
},
{
"name": "coverage",
"specs": [
[
"==",
"5.5"
]
]
}
],
"lcname": "nrn-patch"
}