Package: nrn-patch
*No ducks were punched during the construction of this monkey patch.Installationpip install nrn-patchMinimal requirementsPython 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 theh.Section,h.NetStimandh.NetConfunctions. Feel free to open an issue or fork this
project and open a pull request for missing or broken parts of the interface.PhilosophyPython 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 abugin NEURON where every
exception results in NEURON callingMPI_Abortand shutting down the
simulation. If this leads to confusing failure modes please post an issue with
your Patch code to the GitHub repo!Basic usageUse 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 interpreterp, thePythonHocInterpreterwhich wraps the
standard HOC interpreterhprovided by NEURON. Any objects returned will either bePythonHocObject'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 withobj.__neuron__().frompatchimportpimportgliaasgsection=p.Section()point_process=g.insert(section,"AMPA")stim=p.NetStim()stim.start=10stim.number=5stim.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__fromneuronimporthnrn_section=h.Section()nrn_section.connect(section.__neuron__())Magic methods__neuron__Get the object's NEURON pointerWhenever 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 pointerWhenever 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 justp.NetCon(section, synapse)