patch package

patch.core module

patch.core.assert_connectable(obj, label=None)[source]

Assert whether an object could be used as a Connectable.

Parameters:

label (str) – Optional label to display to describe the object if the assertion fails.

patch.core.is_density_mechanism(obj: str | neuron.hoc.HocObject)[source]

Check if obj is a (name of a) DensityMechanism on the HocInterpreter.

Parameters:

obj – HocObject or name of the DensityMechanism to look for. Needs to be a known attribute of neuron.h.

Return type:

bool

patch.core.is_nrn_scalar(obj)[source]
patch.core.is_point_process(obj: str | neuron.hoc.HocObject)[source]

Check if obj is a (name of a) PointProcess on the HocInterpreter.

Parameters:

obj – HocObject or name of the PointProcess to look for. Needs to be a known attribute of neuron.h.

Return type:

bool

patch.core.is_section(obj)[source]

Check if an object is a section.

patch.core.is_segment(obj)[source]

Check if an object is a segment.

patch.core.transform(obj)[source]

Transform an object to its NEURON representation, if the __neuron__ magic method is present.

patch.core.transform_arc(obj, *args, **kwargs)[source]

Get an arclength object on a NEURON object.

Calls the __arc__ magic method on the callable object if present, otherwise returns the transformed object.

patch.core.transform_netcon(obj)[source]

Transform an object into the pointer that should be connected, if the __netcon__ magic method is present.

patch.core.transform_record(obj)[source]

Transform an object into the pointer that should be recorded, if the __record__ magic method is present.

patch.interpreter module

class patch.interpreter.ParallelContext(*args, **kwargs)[source]

Bases: PythonHocObject

broadcast(data, root=0)[source]

Broadcast either a Vector or arbitrary picklable data. If data is a Vector, the Vectors are resized and filled with the data from the Vector in the root node. If data is not a Vector, it is pickled, transmitted and returned from this function to all nodes.

Parameters:
  • data (Vector or any picklable object.) – The data to broadcast to the nodes.

  • root (int) – The id of the node that is broadcasting the data.

Returns:

None (Vectors filled) or the transmitted data

Raises:

BroadcastError if neuron.hoc.HocObjects that aren’t Vectors are transmitted

cell(gid, nc)[source]
gid_connect(gid, target)[source]
psolve(tstop, v_init=None)[source]
set_gid2node(gid, id=None)[source]
setup_transfer(*args, **kwargs)
source_var(*args, **kwargs)
spike_record(gids=-1, time_vector=None, gid_vector=None, /)[source]
target_var(*args, **kwargs)
class patch.interpreter.PythonHocInterpreter[source]

Bases: object

IClamp(x=0.5, sec=None)[source]
NetCon(source, target, *args, **kwargs)[source]
NetStim(interpreter: PythonHocInterpreter, ptr)
ParallelCon(a, b, output=True, *args, **kwargs)[source]
ParallelContext()[source]
PointProcess(interpreter: PythonHocInterpreter, ptr)
SEClamp(sec, x=0.5)[source]
Section(interpreter: PythonHocInterpreter, ptr)
SectionRef(*args, sec=None)[source]
Segment(interpreter, ptr, section, **kwargs)
TimeSingleton(interpreter: PythonHocInterpreter, ptr)
VecStim(*args, pattern=None, **kwargs)[source]
Vector(interpreter: PythonHocInterpreter, ptr)
cas()[source]
continuerun(duration, v_init=None)[source]
finitialize(initial=None)[source]
nrn_load_dll(path)[source]
property parallel: ParallelContext
record(target)[source]
classmethod register_hoc_object(hoc_object_class)[source]
run(duration, v_init=None, reset=True)[source]
property time
class patch.interpreter.TimeSingleton(interpreter: PythonHocInterpreter, ptr)[source]

Bases: Vector

patch.objects module

class patch.objects.Connectable(*args, **kwargs)[source]

Bases: object

class patch.objects.IClamp(*args, **kwargs)[source]

Bases: PythonHocObject

property amplitude: float

Get the amplitude during current injection.

property duration: float

Get the duration of the current injection.

class patch.objects.NetCon(*args, **kwargs)[source]

Bases: PythonHocObject

record(vector=None)[source]
property threshold
class patch.objects.NetStim(interpreter: PythonHocInterpreter, ptr)[source]

Bases: PythonHocObject, Connectable

class patch.objects.PointProcess(interpreter: PythonHocInterpreter, ptr)[source]

Bases: PythonHocObject, Connectable, WrapsPointers

Wrapper for all point processes (membrane and synapse mechanisms).

stimulate(pattern=None, weight=0.04, delay=0.0, **kwargs)[source]

Stimulate a point process.

Parameters:
  • pattern (list[float]) – Specific stimulus event times to play into the point process.

  • kwargs – All keyword arguments will be passed set on the NetStim

class patch.objects.PointerWrapper(attr)[source]

Bases: object

class patch.objects.PythonHocObject(interpreter: PythonHocInterpreter, ptr)[source]

Bases: object

__deref__(obj)[source]

Magic method that is called when a strong reference needs to be removed from the object.

__neuron__()[source]

Magic method that is called when this object is passed to NEURON.

__ref__(obj)[source]

Magic method that is called when a strong reference needs to be stored on the object.

class patch.objects.SEClamp(*args, **kwargs)[source]

Bases: PythonHocObject

property after

Get the duration of the period after clamping during which the holding potential is clamped.

property delay

Get the delay period from 0ms to delay ms during which the holding potential is clamped.

property duration

Get the duration of the command potential clamping period.

property holding

Get the holding potential that is active before and after the step period.

property voltage
class patch.objects.Section(interpreter: PythonHocInterpreter, ptr)[source]

Bases: PythonHocObject, Connectable, WrapsPointers

add_3d(points, diameters=None)[source]

Add new 3D points to this section xyz data.

Parameters:
  • points – A 2D array of xyz points.

  • diameters (float | list[float]) – A scalar or array of diameters corresponding to the points. Default value is the section diameter.

connect(target, *args, **kwargs)[source]

Connect this section to another one as child section.

connect_synapse(target, **kwargs)[source]

Connect a Segment of this Section to a target.

Usually used to connect the membrane potential to a point process.

iclamp(amplitude: float = 1, *, x: float = 0.5, delay: float = 0, duration: float = 100) IClamp[source]

Create a current clamp on the section.

Parameters:
  • x (float) – Location along the segment from 0 to 1.

  • delay (float) – Duration of the pre-step holding interval, from 0 to delay ms.

  • duration (float) – Duration of the step interval, from delay to delay + duration ms.

  • amplitude (float | list[float]) – Can be a single value to define the current during the step (delay to delay + duration ms), or a sequence to play after delay ms. This will play 1 value of the sequence into the clamp per timestep.

Returns:

The current clamp placed in the section.

Return type:

objects.SEClamp

insert(*args, **kwargs)[source]

Insert a mechanism into the Section.

property parent

Returns the parent of the Section, or None

property points

Return the 3d point information associated to this section.

pop()[source]

Pop this section off the section stack.

push()[source]

Return a context manager that pushes this Section onto the section stack and takes it off when the context is exited.

record(x=None)[source]

Record the Section at a certain point.

Parameters:

x (float) – Arcpoint, defaults to __arc__ if omitted.

set_dimensions(length, diameter)[source]

Set the length and diameter of the piece of cable this Section will represent in the simulation.

set_segments(segments)[source]

Set the number of discrete points where equations are solved during simulation.

synapse(factory, *args, store=False, attributes=None, **kwargs)[source]

Insert a synapse into the Section.

Parameters:
  • factory (Callable) – Callable that creates a point process, is given the Section as first argument and passes on all other args.

  • store (bool) – Store the synapse on the Section in a synapses attribute.

vclamp(voltage: float = -70, *, x: float = 0.5, before: float = 0, duration: float = 100, after: float = 0, holding=-70) SEClamp[source]

Create a voltage clamp on the section.

Parameters:
  • x (float) – Location along the segment from 0 to 1.

  • before (float) – Duration of the pre-step holding interval, from 0 to delay ms.

  • duration (float) – Duration of the step interval, from delay to delay + duration ms.

  • after (float) – Duration of the post-step holding interval, from delay + duration to delay + duration + after ms.

  • voltage (float | list[float]) – Can be a single value to define the voltage during the step (delay to delay + duration ms), or 3 values to define the pre-step, step and post-step voltages altogether.

  • holding (float) – If voltage is a single value, holding is used for the pre-step and post-step voltages.

Returns:

The single electrode voltage clamp placed in the section.

Return type:

objects.SEClamp

wholetree()[source]

Return the whole tree of child Sections.

Return type:

List[patch.objects.Section]

class patch.objects.SectionRef(interpreter: PythonHocInterpreter, ptr)[source]

Bases: PythonHocObject

property child
class patch.objects.Segment(interpreter, ptr, section, **kwargs)[source]

Bases: PythonHocObject, Connectable, WrapsPointers

class patch.objects.VecStim(interpreter: PythonHocInterpreter, ptr)[source]

Bases: PythonHocObject, Connectable

property pattern
property vector
class patch.objects.Vector(interpreter: PythonHocInterpreter, ptr)[source]

Bases: PythonHocObject

record(target, *args, **kwargs)[source]
class patch.objects.WrapsPointers(*args, **kwargs)[source]

Bases: object

Module contents

Quality of life patch for the NEURON simulator.

patch.connection(source, target, strict=True)[source]
patch.h: PythonHocInterpreter = <patch.interpreter.PythonHocInterpreter object>
patch.is_density_mechanism(obj: str | neuron.hoc.HocObject)[source]

Check if obj is a (name of a) DensityMechanism on the HocInterpreter.

Parameters:

obj – HocObject or name of the DensityMechanism to look for. Needs to be a known attribute of neuron.h.

Return type:

bool

patch.is_nrn_scalar(obj)[source]
patch.is_point_process(obj: str | neuron.hoc.HocObject)[source]

Check if obj is a (name of a) PointProcess on the HocInterpreter.

Parameters:

obj – HocObject or name of the PointProcess to look for. Needs to be a known attribute of neuron.h.

Return type:

bool

patch.is_section(obj)[source]

Check if an object is a section.

patch.is_segment(obj)[source]

Check if an object is a segment.

patch.p: PythonHocInterpreter = <patch.interpreter.PythonHocInterpreter object>
patch.transform_arc(obj, *args, **kwargs)[source]

Get an arclength object on a NEURON object.

Calls the __arc__ magic method on the callable object if present, otherwise returns the transformed object.

patch.transform_netcon(obj)[source]

Transform an object into the pointer that should be connected, if the __netcon__ magic method is present.

patch.transform_record(obj)[source]

Transform an object into the pointer that should be recorded, if the __record__ magic method is present.