Skip to content

Latest commit

 

History

History
877 lines (563 loc) · 24.8 KB

python.rst

File metadata and controls

877 lines (563 loc) · 24.8 KB

Python Language

This document describes installation and basic use of NEURON's Python interface. For information on the modules in the neuron namespace, see:

maxdepth

1

neuronpython.rst

Installation

Syntax:

./configure --with-nrnpython ...

make

make install

Description:

Builds NEURON with Python embedded as an alternative interpreter to HOC. The python version used is that found from which python.

NEURON can be used as an extension to Python if, after building as above, one goes to the src/nrnpython directory containing the Makefile and types something analogous to

python setup.py install --home=$HOME 

Which on my machine installs in /home/hines/lib64/python/neuron and can be imported into NEURON with

ipython 
import sys 
sys.path.append("/home/hines/lib64/python") 
import neuron 

It is probably better to avoid the incessant import sys... and instead add to your shell environment something analogous to

export PYTHONPATH=$PYTHONPATH:/home/hines/lib64/python 

since when launching NEURON and embedding Python, the path is automatically defined so that import neuron does not require any prerequisites. If there is a @<host-cpu@>/.libs/libnrnmech.so file in your working directory, those nmodl mechanisms will be loaded as well. After this, you will probably want to:

h = neuron.h # neuron imports hoc and does a  h = hoc.HocObject() 

In the past we also recommended an "import nrn" but this is no longer necessary as everything in that module is also directly available from the "h" object. You can use the hoc function :hocnrn_load_dll to load mechanism files as well, e.g. if neurondemo was used earlier so the shared object exists,

h = hoc.HocObject() 
h('nrn_load_dll("$(NEURONHOME)/demo/release/x86_64/.libs/libnrnmech.so")') 

Python Accessing HOC

Syntax:

nrniv -python [file.hoc file.py -c "python_statement"]

nrngui -python ...

neurondemo -python ...

Description:

Launches NEURON with Python as the command line interpreter. File arguments with a .hoc suffix are interpreted using the Hoc interpreter. File arguments with the .py suffix are interpreted using the Python interpreter. The -c statement causes python to execute the statement. The import statements allow use of the following







Segment

Syntax:

seg = section(x)

Description:

A Segment object is obtained from a Section with the function notation where the argument is 0 <= x <= 1 an the segment is the compartment that contains the location x. The x value of the segment is seg.x and the section is seg.sec . From a Segment one can obtain a Mechanism.


Mechanism

Syntax:

mech = segment.mechname

Description:

A Mechanism object is obtained from a Segment. From a Mechanism one can obtain a range variable. The range variable can also be obtained from the segment by using the hoc range variable name that has the mechanism suffix.


HOC accessing Python

Syntax:

nrniv [file.hoc...]

Description:

The absence of a -python argument causes NEURON to launch with Hoc as the command line interpreter. At present, no file.py arguments are allowed as all named files are treated as hoc files. Nevertheless, from the hoc world any python statement can be executed and anything in the python world can be assigned or evaluated.