Skip to main content

A Pythonic, object-oriented, monkey patch for NEURON

Project description

Build Status codecov

*No ducks were punched during the construction of this monkey patch.

Installation

pip install nrn-patch

Inline replacement

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.

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 PythonHocObjects 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__().

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__())

Known unpatched holes

  • When inserting point processes the returned object is unwrapped. This can be resolved using Glia, or by using this syntax:

    point_process = p.PointProcess(p.MyMechanismName, *args, **kwargs)

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

nrn_patch-1.0.0-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file nrn_patch-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: nrn_patch-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.7.6

File hashes

Hashes for nrn_patch-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bbc8ca21127c0eabf3ff1c4bbd77dd575e0c9238d8f442689069952b70d67a49
MD5 2f73119b52a7c557e7d7c9ecd2629ca7
BLAKE2b-256 dbffec73cfcadac93ed0980fc24786d53c8cb57d7aaaca2122f16ae79949e46f

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