Neuroinformatics Original Research Article Neuron and Python

The NEURON simulation program now allows Python to be used, alone or in combination with NEURON's traditional Hoc interpreter. Adding Python to NEURON has the immediate benefi t of making available a very extensive suite of analysis tools written for engineering and science. It also catalyzes NEURON software development by offering users a modern programming tool that is recognized for its fl exibility and power to create and maintain complex programs. At the same time, nothing is lost because all existing models written in Hoc, including graphical user interface tools, continue to work without change and are also available within the Python context. An example of the benefi ts of Python availability is the use of the xml module in implementing NEURON's Import3D and CellBuild tools to read MorphML and NeuroML model specifi cations. for the purely numerical issue of how many compartments are used to represent each of the cable sections. In the early 90's, Hoc syntax was again extended to provide some limited support for classes and objects, that is, data encapsulation and polymorphism, but not inheritance. Though Hoc has served well, continuing development and maintenance of a general programming language steals signifi cant time and effort from neurobiology domain-specifi c improvements. Furthermore, Hoc has turned out to be an orphan language limited to NEURON users. What is desirable is a modern programming language such as Python, which provides expressive syntax, powerful debugging capabilities, and support for modularity, facilitating the construction and maintenance of complex programs. Python has proved its utility by giving rise to a large and diverse community of software developers who are making reusable tools that are easy to plug-in to the user's code, the so-called " batteries included " (Dubois, 2007). In the domain of scientifi c computing, some examples include Numpy (Oliphant, 2007) and Scipy (Jones et al., 2001) for core scientifi c functionality, Matplotlib (Hunter, 2007) for 2-D plotting, and IPython (Prez and Granger, 2007) for a convenient interactive environment. There are three distinct ways to use NEURON with Python. One is to run the NEURON program with Python as the interpreter accepting interactive commands in the terminal window. Another is to run NEURON with Hoc as the interactive interpreter and access Python functionality through Hoc objects and function calls. These fi rst two cases we will refer to as embedded Python. The third way is to dynamically import NEURON in a …

for the purely numerical issue of how many compartments are used to represent each of the cable sections.In the early 90's, Hoc syntax was again extended to provide some limited support for classes and objects, that is, data encapsulation and polymorphism, but not inheritance.
Though Hoc has served well, continuing development and maintenance of a general programming language steals signifi cant time and effort from neurobiology domain-specifi c improvements.Furthermore, Hoc has turned out to be an orphan language limited to NEURON users.What is desirable is a modern programming language such as Python, which provides expressive syntax, powerful debugging capabilities, and support for modularity, facilitating the construction and maintenance of complex programs.Python has proved its utility by giving rise to a large and diverse community of software developers who are making reusable tools that are easy to plug-in to the user's code, the so-called "batteries included" (Dubois, 2007).In the domain of scientifi c computing, some examples include Numpy (Oliphant, 2007) and Scipy (Jones et al., 2001) for core scientifi c functionality, Matplotlib (Hunter, 2007) for 2-D plotting, and IPython (Prez and Granger, 2007) for a convenient interactive environment.
There are three distinct ways to use NEURON with Python.One is to run the NEURON program with Python as the interpreter accepting interactive commands in the terminal window.Another is to run NEURON with Hoc as the interactive interpreter and access Python functionality through Hoc objects and function calls.These fi rst two cases we will refer to as embedded Python.The third way is to dynamically import NEURON in a running Python or IPython instance, which we will refer to as using NEURON as an extension module for Python.
In the sections to follow, we describe the steps required to use NEURON with Python, from a user's point of view, and the techniques employed to enable NEURON and Python to work together, from a developer's point of view.We begin in Section "Getting

INTRODUCTION
The NEURON simulation environment has become widely used in the fi eld of computational neuroscience, with more than 700 papers reporting work employing it as of April, 2008.In large part this is because of its fl exibility and the fact that it is continually being extended to meet the evolving research needs of its user community.Experience shows that most of these needs have a software solution that has already been implemented elsewhere in the domain of scientifi c computing.The problem is one of interfacing an existing package with NEURON's interpreter.Some cases demand intimate knowledge of NEURON's internals and considerable effort; examples include network parallelization with MPI, and adoption of Sundials for adaptive integration.There are many more cases in which existing packages could potentially be employed by NEURON users.Few people, however, have the specialized expertise required to manually interface an existing software package and the creation of such interfaces is tedious.Instead of laborious piecemeal adoption of individual packages that requires intervention by a handful of experts, a better approach is to offer Python as an alternative interpreter so that a huge number of resources becomes available at the cost of only minimal interface code that most users can write for themselves.
Since 1984, the NEURON simulation environment has used the Hoc interpreter (Kernighan and Pike, 1984) for setup and control of neural simulations.Hoc has a syntax for expressions and control fl ow vaguely similar to the C language.Hoc is not exactly an interpreted language since, analogous to Pascal, Java, or Python, Hoc statements are fi rst dynamically compiled to an internal stack machine representation using a yacc parser and then the stack machine statements are executed.A fundamental extension to Hoc syntax was made in the late 80's in order to represent the notion of continuous cables, called sections.Sections are connected to form a tree shaped structure and their principle purpose is to allow the user to specify the physical properties of a neuron without regard Started Using NEURON with Python" by describing how to install and run NEURON with Python.We then demonstrate how modelling is carried out using Python by comparing it side-by-side with Hoc syntax in Section "Writing NEURON Models in Python".In Section "Using Python Code from Hoc", we describe how Python can be accessed from the Hoc interpreter.In Section "Technical Aspects", we discuss some technical aspects of the implementation of the Python-NEURON interaction.Finally, in Section "Importing MorphML Files -A Practical Example" we give a detailed, practical example, from the current NEURON distribution, of combining Python and Hoc.
The code listings in Figures 1-3 are available for public download from the ModelDB model repository of the Senselab database, http://senselab.med.yale.edu(accession number 116491).

INSTALLATION
NEURON works with Python on Windows, Mac OS X, Linux, andmany other platforms such as the IBM Blue Gene/L/P and Cray XT3 supercomputers.Detailed installation information can be found at http://www.neuron.yale.edu by following the "Download and Install" link.
Binary installers are available for Windows, OS X and RPM-based Linux systems.The Windows installer contains a large portion of Cygwin Python 2.5.On OS X and Linux, the latest version of Python 2.3-2.5 previously or subsequently installed is dynamically loaded when NEURON is launched.The binary installers provide Python embedded in NEURON, but do not support using NEURON as an extension module for Python or IPython.
If you would like to use NEURON as an extension module for Python or IPython, if no installer for your platform exists, or if you need to customize the installation (e.g.enable parallel/ MPI support, or change the location of binaries), you should instead get the source code for the standard distribution, also available from the above "Download and Install" link, and compile it for your machine.Further instructions for this are given in the Appendix.

BASIC USE
NEURON may be started without the graphical user interface (GUI) using nrniv or with the GUI using nrngui.To use Python as the interpreter, rather than Hoc, use the -python option:

>>> from neuron import h
If there are any NEURON NMODL extension mechanisms (Hines and Carnevale, 2000) in the working directory, and they have been compiled with nrnivmodl, they will be loaded automatically.
Alternatively, you may wish to use NEURON as an extension to the normal Python interpreter, or to IPython (Prez and Granger, 2007), a more interactive variant.To do so, you must build NEURON from source and install the NEURON shared library for Python, as described in the Appendix.In Python (or IPython) then, NEURON is started (and any NMODL mechanisms loaded) when you import neuron:

$ ipython […]
In [1] >>> stim = h.IClamp(0.5,sec=h.soma)Note that the soma section created through the Hoc interpreter appears in Python as a Section object.We can also create Sections directly in Python, e.g.
>>> dend = h.Section() These two section objects are entirely equivalent, the only difference being that the name "dend" is not accessible within the Hoc interpreter.In addition to the HocObject class (and through it, any class defi ned in Hoc) and the Section class, the Python neuron module also provides the Segment, Mechanism and RangeVariable classes.More in-depth examples of using NEURON from Python are given in Section "Writing NEURON Models in Python", while using Python code from Hoc is introduced in Section "Using Python Code from Hoc".

WRITING NEURON MODELS IN PYTHON
To show how a model neuron is implemented using Python, we repeat the example described in Chapter 6 of the NEURON Book (Carnevale and Hines, 2006), but using Python rather than Hoc.The code listing is given in Figures 1 and 2, and has Python code on the left and the equivalent Hoc code on the right.
There are only a few syntax and conceptual differences between the Python and Hoc versions, and we expect that Hoc users will have little diffi culty transitioning to Python, should they wish to do so (Hoc will continue to be supported, of course).We now comment on the most signifi cant differences.
First are the import statements, absent from the Hoc listing, although Hoc does have the xopen() function that has similar functionality.Since NEURON is now only one of potentially many modules living within the Python interpreter, it must live in its own namespace, so that the names of NEURON-specifi c classes and variables do not interfere with those from other modules.Of particular importance is the object h, which is the top-level Hoc interpreter, and gives access to Hoc classes, functions and variables.
While sections are created using the create keyword in Hoc, in Python we instantiate a Section object.Hence the important distinction in Hoc between sections and objects is removed: Everything in Python is an object.Similarly, the connect keyword in Hoc is replaced by a method call of the child section object in Python.
In NEURON, each cable section is made up one or more segments, and the diameter is a property of each segment.Hoc's shorthand, allowing the diam attribute to be set on all segments by setting it on the section is also available in Python.Inhomogeneous values for range variables such as diam can also be set on the specifi c Segment object, returned by calling the Section object as a function.
The forall keyword in Hoc, which iterates over all sections, is replaced by the allsec() method of the top-level Hoc interpreter object h.Here again we see, in setting the membrane capacitance cm, the Hoc and Python shorthands to set the value for all segments at once, without having to explicitly iterate over all Segments.
In instrumenting the model, we see that Python and Hoc objects have very similar behaviours.In general, all Hoc classes (Vector, List, NetCon, etc) are accessible within Python via the h object.Hoc object references must be declared using the objref keyword, and objects created using new, but once created, attribute access and method calls have near-identical syntax in Python and Hoc.
There are three major exceptions to this rule.First, many functions and methods act in the context of the 'currently-accessed section' .To support this in Python, these functions take a keyword argument sec.Second, certain method calls take Hoc expressions as arguments, so, for example, in adding the membrane potential of the soma section to the list of variables to plot, in Hoc we use g.addvar("soma.v(0.5)"),but in the Python version the variable soma does not exist on the Hoc side, and so we have to pass the soma Section object as the sec keyword argument so that the Hoc expression is evaluated in the context of that section.Third, a number of functions/methods take Hoc variable references (indicated by preceding the variable name with the '&' character) as arguments, the most important being Vector.record(&var)and NetCon(&var, target).The equivalent syntax in Python is to precede the variable name with _ref_, e.g.: Vector.record(_ref_var).For example, given 'pre' and 'post' Section objects and a dictionary of Hoc Vector objects addressed by a mnemonic string, recording the voltage at the centres of those sections is activated by the statements: # record the membrane potentials and # synaptic currents vec ['v_pre'].record(pre(0.5)._ref_v) vec ['v_post'].record(post(0.5)._ref_v) vec ['i_syn'].record(syn._ref_i)vec ['t'].record(h._ref_t) Figure 3 shows the complete listing with the above fragment in context and also illustrates the ease with which NEURON code can be mixed with third-party code such as the powerful Pylab/Matplotlib plotting package (http://matplotlib.sourceforge.net/):NEURON Vector objects work just as well as Python lists or arrays as arguments to the plot() function.

USING USER-DEFINED MECHANISMS
One of NEURON's most powerful features is the ability to write new mechanisms using the NMODL language, and then compile these mechanisms into the executable or into dynamic libraries (DLLs).The standard behaviour of NEURON is to load any mechanisms that have been compiled in the working directory.It is also possible to load DLLs from elsewhere in the fi lesystem using the Hoc function nrn_load_dll().This has the disadvantage that the full path to the shared library fi le must be provided, which can be hard to determine, since the fi le is within a hidden folder which itself is within a folder with a platform-specifi c name.To simplify this, the neuron Python module adds a function load_mechanisms(), which takes as an argument the path to the directory containing the NMODL source fi les, and searches for shared library fi les below this directory.Furthermore, in analogy to the PYTHONPATH environment variable which contains a list of paths to search for importable Python modules, if you have defi ned a NRN_NMODL_PATH environment variable, NEURON will search these paths for shared libraries and load them at import time.

USING USER-DEFINED CLASSES
One of the principal advantages of writing NEURON programs in Python rather than Hoc, especially for large, complex programs, is that Python is a fully object-oriented language, supporting encapsulation, polymorphism and inheritance, whereas Hoc supports only encapsulation and a limited form of polymorphism.
Just as with built-in Hoc classes, access to attributes and methods of user-defi ned Hoc classes (using the begintemplate/ endtemplate keywords) uses the same syntax in Python as in Hoc.For example, if we have the following user-defi ned Hoc class in the fi le string.hoc:

NUMERICAL DATA TRANSFER BETWEEN HOC AND PYTHON
The Hoc Vector object provides NEURON with a convenient and effi cient container for storing and manipulating collections of numerical values, such as membrane potential traces or spike-times.
In Python, Hoc Vector objects expose iterator and indexing methods, such that they can be used in most cases where Numpy (Oliphant, 2007), Scipy (Jones et al., 2001), and Matplotlib (Hunter, 2007), the most important scientifi c modules, accept lists.
To benefi t from the elegant and expressive notation of Numpy for N-dimensional array manipulation, and from results computed using the large and growing repertoire of scientifi c packages available for Python, which largely return Numpy arrays, several optimized methods are available for the conversion of Hoc Vectors to and from Numpy arrays.
Transferring one-dimensional Numpy arrays and non-nested lists with fl oat or integer items to Hoc Vectors is straightforward, as the Hoc Vector constructor accepts an array or list as an argument: Transferring a Hoc Vector to an array or list is equally straight forward:

USING PYTHON CODE FROM HOC
For interacting with Python, Hoc provides the nrnpython() function and the PythonObject class.nrnpython() takes as its one argument a string that can be any Python statement, e.g.: oc> nrnpython("a = 3.14159") oc> nrnpython("print a") 3.14159 PythonObject has two main uses.Creating an instance using new returns an object that encapsulates the top-level Python interpreter, e.g.For objects (such as lists and tuples) that take integer indices or are callable as functions, there is a special method named '_' (underscore): oc> objref lst oc> nrnpython("c = [7, 8.0, 'nine']") oc> lst = py.coc> for i = 0, lst.__len__() -1 { print lst._[i] } 7.0 8.0 nine The only other trap for the unwary is that both single and double quotes are valid for string defi nitions in Python, but only double quotes are accepted by Hoc!A detailed example of using Python from Hoc, and of the value of being able to access its large standard library, is given in Section "Importing MorphML Files -A Practical Example" for the case of importing 3D morphology from a MorphML fi le.

TECHNICAL ASPECTS
Tools for building Python extensions, such as BOOST.Python (Abrahams and Grosse-Kunstleve, 2003) or SWIG (Beazley, 1996) might have been useful in more expert hands.However, the ability of users to declare variables, objects, and classes in Hoc, the fact that many existing C++ classes and class methods were not generally meant to be directly visible to the user except through the intermediation of Hoc syntax, and the fact that the Hoc connection to the internal NEURON code was already reasonably uniform, of reasonable size, and understood by us in depth, suggested to us that a Python interface written using the Python C-API (http:// docs.python.org/c-api/) that reused as much as possible the existing Hoc connection to internal data and functions would give us the general control we needed, and allow us to accomplish the project in reasonable time.It should be emphasized that this design decision to reuse a few of the C functions that manipulate the Hoc runtime stack neither hinders nor assists any future work on development of APIs for major NEURON components, such as the numerical solvers, which may be useful to other simulators.However, our interface implementation does provide a compact example of how an application can communicate with NEURON within a shared address space and therefore makes the the process of dynamically linking NEURON into a user application much simpler.
Since double precision variables, arrays, constant strings, functions, and objects have very similar syntax and semantics in Hoc and Python, a single PyTypeObject structure called HocObjectType associated with a PyHocObject structure for a Python object instance containing Hoc Symbol and Object fi elds was suffi cient to allow Python access to all these Hoc data-types.When a name is given to an attribute method of the HocObjectType (the refl exive self PyHocObject is also an argument to the method), the name is looked up in Hoc's symbol table for the PyHocObject Hoc Object fi eld, and the symbol along with the Hoc object calls the same function that the Hoc interpreter would call to resolve the attribute at runtime.The attribute, which is typically a number, string, or HocObject, is then wrapped in a Python object of the proper type and returned.Function calls from Python into Hoc consist of pushing the function arguments onto the Hoc runtime stack and, again, calling the same function the Hoc interpreter would call at runtime.Thus, Python statements involving PyHocObject objects end up generating and executing the same Hoc stack machine code at runtime that would be accomplished by the corresponding Hoc statement.It should be noted that a great deal of interpreter effi ciency can be gained in loop body statements by factoring out as much as possible the precursor objects.For example: can be optimized by avoiding the repeated search for the attribute x: The former takes 1.3 s on a 3 GHz machine, while the latter takes 1.0 s.
A critical requirement was to have as natural a correspondence as possible in Python for the special Hoc syntax for Sections, position along a Section, membrane mechanisms, and Range Variables.This was achieved through the C++ defi nition of corresponding types in Python to create instances for: NPySecObj, NPySegObj, NPyMechObj, and NPyRangeVar.For example, the NPySegObj segment (compartment) object points to the NPySecObj of which it is a part, specifi es its location, x, and also contains a fi eld to help in iterating over the mechanisms that exist at that location.An NPyRangeVar has, in practice, required only a pointer to the compartment (NPySegObj) where it exists and a pointer to its Hoc Symbol.A Section represents a continuous cable and evaluation of or assignment to a variable associated with a particular location always involves specifying both which Section and the relative arc length location (0 ≤ x ≤1) along the Section.Internally, NEURON employs a Section stack to determine the working Section and Hoc syntax provided three ways to specify the top of the Section stack.The Hoc Section.variable(x)syntax has a direct correspondence to the Python Section(x).variable syntax and the latter perhaps has more clarity.The Hoc Section { Hoc statements } syntax is unique to NEURON and for the Python side we were reduced to explicit management of the Section stack with Section.push() with an explicit h.pop_section() as the fi nal statement.This gets tedious for single function calls and so in Python we allow the keyword argument, sec=Section, to push and pop the Section during the scope of the Hoc function call.The Hoc access Section statement does not require a Python counterpart.However, the Python statement, sec = h.cas(),returns the top of the Section stack.
There were several cases of syntax mismatch which could only be overcome by the addition of new idioms.Hoc syntax does not allow an object to be treated as a function, so in Hoc we use po._( …).Python does not allow call by reference arguments.Therefore, when a Hoc function called from Python requires a reference argument, the variable name must be prefi xed by '_ref_'.Of course, such variables can only be Hoc variables but that is not a diffi culty in practice since either the need is to pass a Hoc RangeVariable or the Python program can construct a Hoc variable for use in these cases.Since all numbers in Hoc are double precision, type errors are raised when Python expects an integer.For the case of array arguments, the Hoc-to-Python interface converts the doubles to integers automatically.Unfortunately, one cannot in general call the __getitem__(int) method explicitly but must use the [expr] Hoc syntax.If this becomes a problem in practice, it will be necessary to supply a set of cast functions that can be explicitly invoked by the user.
We have encountered only one problem with freeing object memory that has proved resistant to a solution.In some cases there is an ambiguity in regard to whether the Hoc or the Python side owns a reference to an object.When this situation occurs, a reference to the object is kept in a list for a deferred call to Py_DECREF when it is guaranteed that it is safe to do so.
Assignment of a constant value to a range variable in a Section is far more common than assignment of different values within the segments of a Section and Hoc provides a simple syntax for that case which avoids writing an explicit loop.The latest extension of the NEURON Python interface mimics that behavior in Python by interpreting Section.RangeVariableName in that fashion instead of raising an "AttributeError".We are also considering extending the implicit iteration idea to SectionLists and Cells to allow not only assignment of constants but also application of inhomogeneous functions.
A list of the principal differences in syntax between Hoc and Python is given in Table 1.

IMPORTING MORPHML FILES -A PRACTICAL EXAMPLE
Our fi rst serious use of the NEURON Python interface was to extend the Import3D GUI tool to read MorphML specifi cation fi les.Import3D is structured around a graphical view of a list of Import3d_Section objects defi ned in Hoc.Among many method and fi eld attributes, the principle data fi eld of the Import3d_Section object is the raw x, y, z, diam information along an unbranched cable and a list index indicating the parent Import3d_Section.The list of Import3d_Section objects is constructed by various fi le reader objects that understand a specifi c fi le format such as Eutectic, SWC, or NeuroLucida versions 1 or 3. Since MorphML is an XML format, it was opportune to employ the XML reader module in the standard Python distribution.
The problem of parsing and analyzing the MorphML format is similar in diffi culty to that for NeuroLucida V3 fi les.We divided the problem into Hoc and Python code portions.In contrast to a fi le size of 1180 lines for the NeuroLucida V3 fi le reader, the read_morphml.hocfi le size is 78 lines and the Python portion of the problem is carried out by rdxml.pywith a fi le size of 370 lines.Since these fi les are located in the NEURON package default search path -…/nrn/lib/hoc for the read_morphml.hocfi le and …/nrn/lib/python for the rdxml.pyfi le -the MorphML reader extension works wherever the NEURON Python interface is installed.
The read_morphml.hocfi le defi nes an Import3d_MorphML Hoc template (class) which interacts with Import3d_GUI in exactly the same manner as the other format readers.
When an Import3d_MorphML instance is created, the Python helper module we wrote to parse the input fi le is imported with nrnpython("import rdxml") and p = new PythonObject() is defi ned in order to allow access to Python functions.
The proc input() {…} procedure defi nes a sections list and populates it with Import3dSection objects indirectly via p.rdxml.rdxml($s1, this) which passes the fi lename selected earlier by the user along with a reference to the Import3dMorphML instance to allow callback from the Python code.(Crook et al., 2007) and NeuroML (Goddard et al., 2001) model specifi cations.The Hoc portion of the xml readers makes heavy use of Python maps and lists.
With the release of NEURON version 7.0, the Python interface has largely stabilized, and is ready for general use.We recommend that new users of NEURON and those already familiar with Python should use Python rather than Hoc to develop new models.Those with considerable expertise in Hoc but without Python knowledge are likely to be more productive by continuing to develop models with Hoc, but accessing Python's powerful data structures, large standard library and external numerical/plotting packages through nrnpython() and the PythonObject class.There is no need to rewrite legacy code in Python, as it will continue to work using the Hoc interpreter or mixed in with new Python code and accessed via the h object.
Users are encouraged to submit bug reports and feature requests at the NEURON forum (http://www.neuron.yale.edu/phpBB) in the "NEURON+Python" sub-section, so that we can continue to improve the Python interface in response to users' experiences.

APPENDIX
Here we give detailed instructions for building and installing NEURON as a Python extension.Note that, as mentioned earlier, to use NEURON with Python embedded you can use one of the binary installers.
The following assumes a standard GNU build environment, and a bash shell.You will need both NEURON (nrn-VERSION.tar.gz) and InterViews (iv-VERSION.tar.gz)sources, available through the "Download and Install" link at http://www.neuron.yale.edu.
First, build and install Interviews: $ N= 'pwd ' $ tar xzf iv-17.tar.gz$ cd iv-17 $ ./configure--prefix= 'pwd ' $ make $ make install Then build and install NEURON: $ cd.. $ tar xzf nrn-7.0.tar.gz$ cd nrn-7.0$ ./configure--prefix= 'pwd '\ --with-iv=$N/iv-17 --with-nrnpython $ make $ make install Here, the "\" at the end of the fourth line, indicates it is continued on the fi fth.If you want to run parallel NEURON (Hines et al., 2008;Migliore et al., 2006), add --with-paranrn to the configure options.This requires a version of MPI to be installed, for example MPICH2 (Gropp, 2002) or openMPI (Gabriel et al., 2004).Now add the NEURON bin directory to your PATH: $ export PATH=$N/nrn-7.0/i686/bin:$PATH (Here i686 will be different for different CPU architectures).Now build and install the NEURON shared library for Python: $ cd src/nrnpython # python setup.pyinstall This command installs the neuron package to the Python sitepackages directory, which usually requires root access.If you don't have root access, you can install it locally using --prefix to specify a location under your home directory: $ python setup.pyinstall\ --prefix=$HOME/local This will install the neuron package to $HOME/local/lib/ python/site-packages under your home directory.You will then have to add this directory to the PYTHONPATH environment variable: $ export PYTHONPATH=$PYTHONPATH:\ $HOME/local/lib/python/site-packages http://www.neuron.yale.edu/credits.html

FIGURE 1 |
FIGURE 1 | Code listing for a simple model neuron: building the neuron.The Python code is on the left and the equivalent Hoc code on the right.

FIGURE 2 |
FIGURE 2 | Code listing for a simple model neuron (continued from Figure 1): instrumenting and running the model.The Python code is on the left and the equivalent Hoc code on the right.

FIGURE 3 | Code listing demonstrating the use of ref and plotting.
vec ['t '], vec['v_post ']) pylab .subplot (2 ,1 ,2) pylab .plot ( vec ['t '], vec['i_syn ']) It is also possible to subclass both built-in and user-defi ned Hoc classes in Python, although with the restriction that multiple inheritance from Hoc-derived classes is not possible.Subclassing requires the use of the hclass class factory: The reference to the Import3d_MorphML instance is stored by the initializer for later use at the end of parsing.During fi le reading there is no interaction between Hoc and Python, so let it suffi ce that the xml parsing style is, at the beginning and end of every xml element, to call the MyContentHandler methods interpreter, all Python objects are accessible via the PythonObject.Binary installation remains straightforward for the usage case of launching NEURON with Python embedded: The MS Windows installer contains a large subset of the 2.5 version of Python, and the Linux RPM and Mac OS X dmg installations will use the latest version of Python, if any, that is already present or subsequently installed.The usage case of launching Python, e.g. using IPython, and dynamically importing NEURON also works but presently requires the extra installation steps described in the Appendix.Numpy is not a prerequisite but, if present, copying of vectors between Numpy and NEURON is very effi cient.The Python xml module is used in the present standard distribution to extend NEURON's Import3D and CellBuild tools to allow reading of MorphML