AA. VV. libNeuroML and PyLEMS. Using Python To Combine Procedural and Declarative Modeling Approaches in Computational Neuroscience PDF
AA. VV. libNeuroML and PyLEMS. Using Python To Combine Procedural and Declarative Modeling Approaches in Computational Neuroscience PDF
Edited by: NeuroML is an XML-based model description language, which provides a powerful
Eilif Benjamin Muller, Ecole common data format for defining and exchanging models of neurons and neuronal
Polytechnique Fédérale de
Lausanne, Switzerland
networks. In the latest version of NeuroML, the structure and behavior of ion
channel, synapse, cell, and network model descriptions are based on underlying
Reviewed by:
Jochen Martin Eppler, Research definitions provided in LEMS, a domain-independent language for expressing hierarchical
Center Jülich, Germany mathematical models of physical entities. While declarative approaches for describing
Marcel Stimberg, École Normale models have led to greater exchange of model elements among software tools in
Supérieure, France
computational neuroscience, a frequent criticism of XML-based languages is that they are
*Correspondence:
difficult to work with directly. Here we describe two Application Programming Interfaces
Michael Vella, Department of
Physiology, Development and (APIs) written in Python (http://www.python.org), which simplify the process of developing
Neuroscience, University of and modifying models expressed in NeuroML and LEMS. The libNeuroML API provides
Cambridge, Downing Street, a Python object model with a direct mapping to all NeuroML concepts defined by the
Cambridge CB2 3EG, UK
e-mail: [email protected];
NeuroML Schema, which facilitates reading and writing the XML equivalents. In addition, it
Padraig Gleeson, Department of offers a memory-efficient, array-based internal representation, which is useful for handling
Neuroscience, Physiology and large-scale connectomics data. The libNeuroML API also includes support for performing
Pharmacology, University College common operations that are required when working with NeuroML documents. Access
London, Gower Street, London,
WC1E 6BT, UK
to the LEMS data model is provided by the PyLEMS API, which provides a Python
e-mail: [email protected] implementation of the LEMS language, including the ability to simulate most models
expressed in LEMS. Together, libNeuroML and PyLEMS provide a comprehensive solution
for interacting with NeuroML models in a Python environment.
Keywords: NeuroML, LEMS, model specification, standardization, API, modeling, Python, SWC
were not considered during the design of the description lan- The elements in NeuroML v2 have corresponding structural and
guage or when constructing large, repetitive models, which can mathematical definitions described in LEMS.
be expressed more tersely in a procedural language by means of The LEMS language is used to formally describe the compo-
recursions or loops. Here we describe libNeuroML and PyLEMS, nents of models of physical systems, which may contain hier-
which address these issues for the NeuroML and LEMS lan- archical relationships. These components can have parameters,
guages, respectively. A wide range of models, from point neu- which are fixed, and state variables, which vary according to
rons to morphologically detailed, conductance based cell and defined relationships. In LEMS, and hence also in NeuroML, all
network models, can be created, parsed, and saved using the parameters and state variables are dimensional quantities rather
libNeuroML API. PyLEMS is a Python API for creating and work- than relying on an implicit set of units. Whenever a quantity is
ing with models and model components specified directly in expressed in a model, dimensionally correct units must be pro-
LEMS. vided. It is the responsibility of the implementation to check
While there are a number of Python applications for reading, the units and convert to a consistent internal set of units for
modifying and writing XML such as lxml (http://lxml.de)—the calculations. Another important concept in LEMS is that of con-
advantage of libNeuroML and PyLEMS over these more generic tainment of components, encoding the concept that one model
tools is that they contain sub-tools and optimizations specific to element is part of another (e.g., a population of cells is part of a
the modeling of neural systems. Here we present a brief overview network, a gate is part of an ion channel). Another key LEMS con-
of the current state of NeuroML and LEMS, describe the motiva- cept is the ability to declare a prototype ComponentType, which
tion for developing procedural APIs for these languages, outline defines the generic structure and dynamics for a broad class of
the design considerations for libNeuroML and PyLEMS, and models. Models can then be instantiated as Components by pro-
provide a number of examples of the usage of these libraries. viding a set of parameters for a specific instance. An example
libNeuroML and PyLEMS allow a user to enjoy the benefits pro- of the ComponentType concept is shown in Figure 2Bi for the
vided by the domain-specificity and rigor of NeuroML and LEMS, spiking cell model of Izhikevich (2003), a widely-used model in
while facilitating the use of the Python programming language for computational neuroscience, which exhibits a diverse range of
procedural model descriptions. physiologically-realistic spiking behaviors by changing a small set
of parameters in the model. Instances of the model (Components),
OVERVIEW OF NeuroML AND LEMS such as the cell defined on the left in Figure 2Bi, are specified by
The current scope of NeuroML covers abstract, point neuron providing specific values for the parameters. NeuroML and LEMS
models [e.g., leaky integrate and fire models or two-variable use Fortran-like “gt” and “lt” inequality operator symbols instead
spiking neuron models (Izhikevich, 2003; Brette and Gerstner, of “>” and “<.” This is done because in XML the symbols “>”
2005)], conductance based neuron models, morphologically and “<” are used in the declaration of XML tags.
detailed, multicompartmental neuron models, voltage, and cal- While any modeler is free to describe a model in LEMS,
cium dependent ion channel models, both fixed and plastic the NeuroML initiative has developed a set of curated LEMS
synapse models, and models for networks of neurons posi- definitions (e.g., Cells.xml and Synapses.xml in Figure 2B) for
tioned in 3D with synaptic connections among populations of commonly used models, which form the basis for NeuroML
cells. Figure 1A gives an overview of the elements allowed in a v2. Similar classes of model types can be linked together by
NeuroML file, and Figure 1B shows an example of a NeuroML using the type extension mechanism of LEMS. For example, any
serialization of a model. NeuroML is being developed by an object which produces a current extends the type basePointCur-
international consortium of contributors, where the formal spec- rent, while all synaptic models extend baseSynapse. This approach
ification for the latest version is being developed by the NeuroML also provides for user defined extensions to the core NeuroML
Editorial Board (http://www.neuroml.org/editors.php). language.
NeuroML v1.x (Gleeson et al., 2010) focused on LEMS provides complete, machine readable model defini-
conductance-based cell models, often with a corresponding tions for a broad range of cell, ion channel and synapse mod-
multicompartmental representation of neuronal morphology. els in NeuroML v2 (though not yet for multicompartmental
For these earlier versions, the mathematical descriptions of model cell models, see Discussion). Each NeuroML release includes a
components, such as ion channel models based on the Hodgkin- W3C XML Schema Document (XSD, http://www.w3.org/XML/
Huxley formalism (Hodgkin and Huxley, 1952), are specified in Schema), which can be used to validate NeuroML documents,
user documentation (see supplementary information of Gleeson i.e., check whether all required elements and attributes are
et al., 2010). Modelers or application developers wishing to utilize present. Simulators and other applications that aim to support
or support a feature of NeuroML were required to familiarize the language can choose to base their import/export functions
themselves with the relevant documentation for that component on the structure of the language specified by the Schema and
and ensure compliance for any model description or software associated documentation, as was the case in NeuroML v1.x.
application (Figure 2A). A disadvantage of this approach is the However, any simulator utilizing NeuroML should be designed
possibility for ambiguity in the documentation. NeuroML v2 was to ensure that simulated behavior complies with LEMS defini-
designed in conjunction with a new XML-based language called tions in order for that application to be NeuroML-compliant.
Low Entropy Model Specification language (LEMS), which can The LEMS ComponentType definitions are also defined in XML
be used for creating fully machine-readable definitions of the format, and a LEMS-specific Schema document exists for the
structure and behavior of the model components (Figure 2B). purpose of validation.
FIGURE 1 | Structure of NeuroML v2. (A) Overall structure of NeuroML v2. to cells include square pulse and sine waves. Networks contain populations
The top-level element of NeuroML, neuroml, contains a number of child of cells, with projections between them and lists of inputs. Lines ending in
elements of various types. A morphology element contains lists of segment diamonds show containment of elements. Filled diamonds indicate that
and segmentGroup elements defining the structure of the neuronal multiple child elements of that type are permitted, unfilled diamonds indicate
morphology. Various cell types are allowed including point neurons such as only one child of that type is permitted. Not all elements in NeuroML v2 are
izhikevichCell, but also cell elements which can have detailed morphologies shown. A full description of all elements in NeuroML v2 is available at
and biophysicalProperties for ion channel densities etc. Ion channels of two http://www.neuroml.org/NeuroML2CoreTypes. (B) A partial example of a
main types can be specified, based on either the Hodgkin-Huxley formalism NeuroML v2 file in XML. This model contains a cell with a morphology, an
or using a kinetic scheme-based description. Allowed synapse models include ion channel mechanism and a synapse as well as a network with a population
single and double exponential conductance waveform models. Current inputs of the cells and a projection for synaptic connections between them.
DECLARATIVE AND PROCEDURAL MODEL DESCRIPTIONS IN nature of the problem being solved rather than the details of the
COMPUTATIONAL NEUROSCIENCE specific sequence of operations used to solve that problem. A
Procedural programming languages require a description of the neuroscientist with a background in biophysics and a minimal
sequence of steps to be executed (or control flow) in a computer amount of programming experience can read, understand and
program in terms of sequential commands. On the other hand, modify a NeuroML model with relative ease. However, this may
declarative languages provide the information needed for compu- not be true for an equivalent model written in a general-purpose
tation without directly expressing the control flow. In this section procedural language such as Python or C. Moreover, declarative
the comparative advantages and disadvantages of these paradigms formats like XML also allow for an easier transformation into
are described in the context of modeling in neuroscience. more readable presentations such as HTML websites.
Declarative languages for computational modeling such as
ADVANTAGES OF DECLARATIVE MODEL DESCRIPTIONS NeuroML provide a good interchange format for different soft-
Declarative specification of models can be of benefit in ware tools by ensuring model completeness and facilitating
three principal respects: model readability, model interoperabil- machine-parsing of the models. The domain-specificity of a par-
ity/validation, and the avoidance of fragmentation. ticular declarative language means that relationships between
Domain-specific declarative languages are generally easier to model elements can be formalized (e.g., in an XML Schema),
read and understand because they shift focus onto describing the providing a fixed framework for defining models. This facilitates
FIGURE 2 | Relationship between NeuroML v2 and LEMS. (A) Model using OnConditions. This example of izhikevichCell has been simplified to
definitions in NeuroML v1.x are specified as textual descriptions in remove scaling factors for unit correctness. Shortened examples of a
human-readable documentation. (B) In NeuroML v2, components have a synapse (ii) and an ion channel model (iii) are also shown. Instances of LEMS
corresponding structural and mathematical definition in LEMS. A number of ComponentTypes can be created by specifying the values for each of the
examples of ComponentTypes in LEMS are shown. A ComponentType parameters. These instances are represented in NeuroML files. The full
izhikevichCell is defined in LEMS (i), and its parameters are specified as a, b, NeuroML v2 ComponentType definitions are contained in XML files (including
c, d, and thresh. The Dynamics of the ComponentType defines the state Cells.xml, Synapses.xml, Channels.xml as shown here), which have been
variables v and U. LEMS specifies how these vary with time. Conditions such developed by the NeuroML project and are available at
as when the membrane potential crosses firing threshold are also defined http://www.neuroml.org/NeuroML2CoreTypes.
model validation and typically makes it simpler to diagnose and LEMS and the Python code that can be used to create
errors, although it should be noted that this form of validation the equivalent entities. More detailed overviews of the APIs for
indicates little about the scientific veracity of the model (Crook libNeuroML and PyLEMS are shown in Figures 4, 5, respectively.
et al., 2013). A core aim of libNeuroML and PyLEMS is to provide production-
As a consequence of improved readability and software quality, easy-to-use utilities for the manipulation of NeuroML
interoperability, efforts such as NeuroML also reduce the frag- and LEMS, using tools and standards familiar to Python pro-
mentation in a scientific discipline. The development of com- grammers that are also easy to use for those less experienced with
mon formats for specification of models accelerates progress by Python. With this core aim in mind, libNeuroML and PyLEMS
encouraging model sharing and reuse, as can be seen with SBML have been implemented with the design goals described below.
(the Systems Biology Markup Language Hucka et al., 2003 and
MathML Miner, 2005). DESIGN GOALS SHARED BY BOTH libNeuroML AND PyLEMS
Python naming conventions and adherence to Python PEP8 style
ADVANTAGES OF PROCEDURAL MODEL DESCRIPTIONS guide
Despite the advantages of writing models in a declarative man- libNeuroML and PyLEMS strongly adhere to naming conven-
ner, procedural specification of models does have two important tions that are widely used in the Python community and cod-
benefits. First, procedural languages are generally more practi- ified in the PEP8 Style Guide for Python Code (http://www.
cal for describing models when there are aspects of the model python.org/dev/peps/pep-0008/). In the case of libNeuroML,
that can not be described with the base components of a declar- this adherence to convention is enforced by automated con-
ative modeling language. When the boundaries and concepts for version from NeuroML to Python naming conventions, which
model design are not clear, a procedural language often will pro- occurs during the automatic generation of the libNeuroML
vide a needed degree of flexibility. As an example, if one were object model from the corresponding NeuroML Schema (see
designing a multicompartmental model where a particular mem- below). NeuroML elements have their names modified in the
brane conductance was only present on dendrites more distal libNeuroML object model to use standard Python naming con-
than the second branch point from the soma, it would proba- ventions; for instance, izhikevichCell (element) and q10Settings
bly be easier to describe this concisely using a general-purpose (attribute) in NeuroML become IzhikevichCell (class) and
language like Python or C, since NeuroML does not natively sup- q10_settings (field), respectively in libNeuroML.
port defining regions of the cell in this way. A second advantage of
Automated XML validation
developing libraries to allow procedural model description devel-
opment is that it is easier to integrate with other libraries such libNeuroML provides a validation utility to ensure that NeuroML
as those providing visualization utilities or analysis routines. The documents are well-formed (following the basic syntactic rules of
libSBML API (Bornstein et al., 2008) for the SBML language has XML) and valid (following the structure defined in the NeuroML
been an important factor in the widespread support for that lan- Schema). A similar utility exists in PyLEMS for validating against
guage among systems biology applications (Sauro and Bergmann, the LEMS Schema. Note that while the NeuroML ComponentType
2008). definitions as well as XML generated by PyLEMS are valid accord-
Thus, both procedural and declarative paradigms play an ing to this Schema, PyLEMS is flexible enough to parse invalid
important role in computational neuroscience. When working LEMS files (e.g., with reordered elements) as long as they follow
within a widely used modeling formalism, such as Hodgkin- the correct containment rules for LEMS elements.
Huxley type conductance based models, having the ability to Ease of installation
easily export it to a declarative format is useful and important. libNeuroML and PyLEMS utilize the standard distutils (http://
In such a situation, declarative modeling allows for ease of devel- docs.python.org/2/library/distutils.html) tool for packaging
opment, model interchange among software tools, and model Python programs, making installation standard and simple.
reproducibility. When working with novel modeling approaches Both APIs require the lxml (http://lxml.de) Python package.
or when integrating with scientific or visualization libraries, it is Additionally, libNeuroML requires numpy (http://www.numpy.
useful to use a procedural approach. org), jsonpickle (https://pypi.python.org/pypi/jsonpickle),
mongodb (http://docs.mongodb.org/ecosystem/drivers/python),
libNeuroML AND PyLEMS and PyTables (http://www.pytables.org) packages. Both APIs
To facilitate procedural model description development for the are currently tested and stable for Python versions 2.6 and
NeuroML and LEMS languages we have developed libNeuroML 2.7. All of these packages can be obtained from the Python
and PyLEMS. These Python modules can be imported into a Package Index (https://pypi.python.org/pypi). The full source
Python script to allow loading of XML files in their respective code for the libraries can be obtained from https://github.com/
formats, parsing and editing of the models using APIs which NeuralEnsemble/libNeuroML and https://github.com/LEMS/
closely follow the structure of the XML languages, and saving in pylems.
valid XML. libNeuroML, which parses and saves NeuroML v2,
has added functionality to use optimized representations of large ADDITIONAL DESIGN GOALS FOR libNeuroML
models, both internally and as serialization formats. PyLEMS Auto-generation from NeuroML Schema
has the additional ability to simulate the dynamical behavior of In libNeuroML every element (such as cell, network or pulseGen-
LEMS models. Figure 3 shows examples of XML from NeuroML erator, see Figure 1A) in the NeuroML Schema corresponds to
FIGURE 3 | Examples of NeuroML and LEMS models specified in XML automatically by the Python code on the right. The NeuroML example
and equivalent models specified with Python using the libNeuroML and describes a soma segment as a 3D cylinder. The LEMS example illustrates
PyLEMS APIs, respectively. The XML code on the left is generated how a simple integrate and fire cell can be defined.
a concrete class and therefore can be instantiated as an object implementation or architecture. This allows libNeuroML to
by calling neuroml.<NameOfClass>(). This is is possi- be a core part of the regular NeuroML release process. New
ble because the libNeuroML core object model is auto-generated versions of the NeuroML Schema will always be released
from a NeuroML Schema file via the generateDS tool (https:// along with a libNeuroML version which reflects those Schema
bitbucket.org/dkuhlman/generateds), where the generated object changes.
model defines all necessary type interfaces. Therefore, libNeu- 2. Backward—support. This feature allows users to create a
roML provides a complete and direct mapping between the Python API for handling NeuroML even if they are work-
NeuroML Schema and its internal Python object model with ing with older versions of the NeuroML representation for-
several advantages: mat, including versions that existed before libNeuroML.
However, the user must auto-generate this libNeuroML ver-
1. Maintainability. libNeuroML can be rapidly updated to reflect sion via the generateDS tool as described in libNeuroML
the latest NeuroML Schema with little or no knowledge of documentation.
FIGURE 4 | An overview of the structure of the libNeuroML API. The API number of broad classifications (right) based on the types of models they
is divided into four main modules (left), the largest of which (neuroml) represent. Examples of Python code using the classes is also shown on the
consists of Python classes generated from the NeuroML XML Schema right. Extra modules have been created to facilitate loading or writing
Document. There is roughly a one to one correspondence between the NeuroML (in XML or other serialization formats) and for validating NeuroML
NeuroML elements and Python classes. These classes can be split into a files.
3. Flexibility. It is possible for a user to modify the NeuroML 4. Saving to valid NeuroML. A key feature of generateDS and, by
Schema in order to develop new components or change exist- extension, libNeuroML is the ability to save XML files which
ing ones. A custom copy of libNeuroML can then be generated are valid against the Schema used to generate the API.
for further testing. Such modifications can then be proposed 5. Automatic conversion of names to Python format. While the
for inclusion in the language through discussions on the convention in NeuroML is to use “camel case” for naming
NeuroML mailing list. elements and their attributes, the generated Python class and
FIGURE 5 | An overview of the structure of the PyLEMS API. Classes can export this to an XML file. Generated or other LEMS files can also
are present for each of the main elements of the LEMS language (left). be validated through the API. More information about the LEMS
Examples of using these in a Python script are shown on the right. The elements on which the classes above are based can be found here:
Model class is a container which can be used to hold the model and http://lems.github.io/LEMS/elements.
method names automatically are converted to Python naming the case of SWC however, the format is only suited to serializing a
conventions. small subset of morphological data and is intrinsically unable to
serialize complex models, due to the nature of the SWC format as
One notable disadvantage of an auto-generated API is that it described below.
contains syntax which is less usable than it might be for a In addition to file-based serialization, libNeuroML pro-
“hand-written” API. However, we have contributed updates to the vides the ability to store data in a MongoDB (http://www.
generateDS tool to increase usability and readability of the API, mongodb.org) database via an intermediate JSON document. All
and these will continue to be improved. serialization and deserialization operations, including database
operations, are carried out through the neuroml.writers
Serialization and database support and neuroml.loaders modules of libNeuroML, respectively
This section describes the different serialization formats provided (Figure 4).
by libNeuroML. In this section the term NeuroML specifically
refers to the XML-based file format rather than NeuroML as a NeuroML (XML). The de-facto libNeuroML serialization out-
model description language. libNeuroML supports serialization put is the standard XML-based format in which NeuroML
of models into four different storage formats: NeuroML (XML), models are written. Small to medium-sized NeuroML mod-
JavaScript Object Notation (JSON) (http://www.json.org), HDF5 els generally should be written in this format, as these docu-
(http://www.hdfgroup.org/HDF5), and SWC (Cannon et al., ments can be edited with standard text editors and validated
1999). Of these four serialization formats, two (NeuroML and against the NeuroML Schema independently of libNeuroML.
JSON) are lossless, which is to say that they preserve all of the The XML serialization is the format most widely supported
NeuroML model data, and the other two (HDF5 and SWC) are by NeuroML compliant software tools (http://www.neuroml.org/
lossy and are only able to serialize a subset of the data, namely the tool_support.php). It is recommended that unless there is
morphological structure of detailed neuronal reconstructions. In a clear reason to do otherwise, users should use XML
serialization until they encounter performance bottlenecks. is compatible with NeuroML’s arraymorph module, large
NeuroML serialization, though the slowest and least concise, models can be stored in a MongoDB database at a fraction of
permits the use of NeuroML-compliant tools (such as morphol- the disk requirements for equivalent NeuroML documents. One
ogy viewers) and the ability to easily track changes across file MongoDB limitation is that JSON files exceeding 16 MB can not
versions. be stored; large documents (more than 100,000 segments) should
therefore be stored as individual files.
JSON. JSON is an open, text-based format for human-readable
data interchange. Any file serialized by libNeuroML to JSON Serialization file sizes. For reconstructed morphologies, the file
format can be loaded by libNeuroML without any loss of sizes of the different serialization formats vary linearly with the
information and thus can be re-serialized as NeuroML. The number of segments in the morphology with NeuroML requir-
jsonpickle (https://github.com/jsonpickle/jsonpickle) mod- ing 316 B/segment, JSON requiring 62 B/segment, and HDF5
ule is used to serialize NeuroML documents in JSON format. requiring 41 B/segment. For a typical reconstructed morphology
There are three primary advantages of JSON serialization: of 2000 segments, a NeuroML (XML) file would require 617 KB,
and the corresponding JSON and HDF5 files would require 80
1. Some users report that JSON is easier to read and understand and 41 KB, respectively.
than XML.
2. Many tools exist to facilitate the use of JSON in situations OPTIMIZED INTERNAL REPRESENTATION (ARRAYMORPH)
where data is transmitted over networks. This is particularly The arraymorph module of libNeuroML provides highly
true for web-based applications since a number of such tools optimized representations of neuronal morphologies to
and frameworks are optimized for working with JSON. increase read/write speed and reduce memory footprint.
3. When used in conjunction with the libNeuroML Neuronal morphologies are instantiated as a non-NeuroML
arraymorph module, large-scale morphological recon- ArrayMorphology type, which inherits from the standard
structions require substantially less space on disk when stored NeuroML Morphology type but uses Numpy (http://www.
as JSON-serialized documents. numpy.org/) arrays to represent morphologies in a way that
is transparent to the user and is highly-influenced by the
SWC. SWC is a tree-based representation used for storing mor- SWC format. With the arraymorph module, it remains
phological reconstructions of neurons, and it is the data stor- possible to manipulate NeuroML segment objects, and all
age format of the NeuroMorpho.org database of reconstructed helper methods and properties continue to work as with the
neurons (Ascoli et al., 2007). In SWC, each node contains standard NeuroML Morphology type. However, low-level
diameter and position information, and the conical frustum access to the arrays is also possible, although the user must
between two nodes is treated as a segment of morphology. This understand the internal details of implementation. The rationale
allows, for instance, reconstructions of dendritic arborizations of for development of this module stems from several draw-
theoretically-unlimited complexity. libNeuroML can import the backs of both Python and XML that can be summarized as
Morphology component of a cell in SWC format. However, any follows:
other NeuroML component data such as information about the
distribution of channels or synapses with regard to the morphol- • Python requires a relatively large memory footprint when
ogy would be lost when serializing in this format. instantiating objects. Representing every component in a
NeuroML file in-memory by an instantiated object can
HDF5. HDF5 (Hierarchical Data Format 5, http://www. demand an unfeasibly-large amount of memory. A typical
hdfgroup.org/HDF5) is a set of file formats and tools for stor- reconstructed morphology of 1600 segments requires 6.9 MB
ing and organizing large amounts of numerical and hierar- in memory; a network of over 1000 cells would therefore
chical data. HDF5 serialization is provided by libNeuroML, require over 1 GB of memory.
although presently the level of serialization support which is • XML serialization results in performance bottlenecks when
provided only extends to morphological reconstructions of neu- read/write operations are conducted on large XML files
rons. The main advantage of HDF5 support is the relatively because NeuroML is a relatively verbose format, and the whole
low memory footprint and support for rapid read/write opera- file must be loaded for even one element to be accessed.
tions, which is demonstrated in the benchmarks section of this • Because many NeuroML documents are mainly morphological
article. reconstructions with a very small amount of metadata, a SWC-
like format can store most of the same data with a much smaller
MongoDB. MongoDB (http://www.mongodb.org/) is a performance overhead.
document-oriented “NoSQL” database which departs from • Recent projects in the field of computational neuroscience
the traditional table-based relational database paradigm toward such as the Blue Brain Project (Markram, 2006) and the
JSON-like documents with dynamic schemas. Its document- Brain Activity Map Project (Alivisatos et al., 2012) require
oriented approach is particularly suitable for storing NeuroML increasingly large amounts of morphological reconstruction
documents. The MongoDB support provided by libNeuroML is data.
particularly useful for users wishing to store large amounts of • Some mathematical analysis methods and transformations
data on a server, such as for use with a website. Since MongoDB that can be performed on reconstructed morphologies,
USAGE EXAMPLES system of this worm contains only 302 neurons, making it a
EXAMPLES USING libNeuroML very interesting model organism in experimental and computa-
Network example tional neuroscience. The morphology of each of these neurons
libNeuroML can simplify the process of describing a model of (as well as all other cells of the adult hermaphrodite) has been
a spiking neural network in NeuroML. All of the cell, synapse reconstructed in 3D at the VirtualWorm project (http://caltech.
and channel models in NeuroML are available for use in net- wormbase.org/virtualworm) and released into the public domain
works, and the structure of a network can be generated in a in Blender (http://www.blender.org) format, which is used for
procedural way, using all the capabilities of Python to encode the creation of 3D applications. These have been converted to
the connectivity. Figure 7 shows a network of two randomly con- NeuroML format for the OpenWorm project and made avail-
nected populations of integrate and fire neurons, one of which able at https://github.com/openworm/CElegansNeuroML. Data
receives current injections of random magnitude. The structure on the connectivity between individual cells is available in a
of the network can be saved in XML format (or JSON format spreadsheet (CElegansNeuronTables.xls) in that repository and
as outlined previously), but an important point is that many includes the numbers of known chemical or electrical connec-
of the diverse network connectivity options available can not tions between neurons of a particular type.
be described efficiently in NeuroML, and a Python script using We have developed a libNeuroML-based Python script to ana-
libNeuroML provides a compact, cross-platform encoding of the lyze the integrity of this data that loads each neuron morphology,
network. While the XML in the example in Figure 7 is roughly generates connections based the connectivity data, and saves the
the same length as the associated Python script, generally this network file to NeuroML. When generating connections for each
will not be the case for larger networks. Also, the XML repre- pair of cells where there exist N connections, the script chooses a
sents only one instance of a network that can be generated by variable number (100–5000 depending on number of segments in
the script. Modifying the script to specify the random seed will the cells) of random points on the presynaptic and postsynaptic
ensure reproducibility of the network connectivity, and so the lib- cells and chooses the N closest pairs of points for the connections.
NeuroML version of the network can be distributed instead of the The generated network file can be loaded into neuroConstruct
potentially very large XML or JSON serialization. (Gleeson et al., 2007), which can import NeuroML cells and net-
PyNN (Davison et al., 2009) is an API in Python that also works for visualization (Figure 8). Due to the fact that all neurites
offers the advantage of compact, procedural network descrip- are reconstructed, it should be possible to find points separated by
tions. Currently, the cell models that can be defined in PyNN a short distance on any connected pair of presynaptic and post-
scripts are limited to a set of commonly-used point neuron synaptic cells. The long connections between some neurons in
models on simulators with PyNN backends. As outlined in the Figure 8B (which could not be removed by increasing the number
Discussion section of this article, we are actively working toward of random connections tested) highlights that these are unlikely
greater compatibility between PyNN and network descriptions in to be real anatomical connections.
libNeuroML.
PyLEMS EXAMPLE
Multicompartmental cells The NeuroML v2 ComponentType definitions specified in LEMS
Aside from the ability to load and parse NeuroML docu- for multiple commonly-used cell, synapse and ion channel types
ments containing morphological reconstructions of neurons, (Figure 2) can be loaded by PyLEMS. Another important feature
libNeuroML allows for the modification and analysis of these of using LEMS as the basis for NeuroML v2 model types is that a
morphologies, as well as the generation of completely synthetic modeler can define a new model type in LEMS if that model is not
morphologies. Listing 1 shows an example of a script in lib- already present in the core definitions, significantly increasing the
NeuroML which loads a morphology file from an XML rep- extensibility of the NeuroML language. PyLEMS allows these new
resentation, extracts the morphology and calculates the total models to be created using Python and saved in a valid, standard
volume and area of the segments in the cell. In this listing, format. Figure 9 shows the code required to define a Hindmarsh
volume and area methods do not have trailing parentheses and Rose spiking cell model (Hindmarsh and Rose, 1984) and
because they are Python getter methods modified by the Python the behavior of one state variable when simulated with PyLEMS.
@property decorator. This demonstrates how helper meth- More details on the implementation of this model can be found
ods can be used for operations that will commonly be required on the Open Source Brain website (http://www.opensourcebrain.
on those classes (e.g., getting the surface area or volume of org/projects/hindmarshrose1984).
the conical frustum). For details on how such helper meth-
ods can be added to libNeuroML the reader is referred to the DISCUSSION
libNeuroML developer documentation (http://libneuromldev. SUMMARY OF ADVANTAGES
readthedocs.org/en/latest/#developer-documentation). NeuroML is a model description language which can represent
biological concepts such as cells, ion channels and networks in
OpenWorm and neuroConstruct a declarative format, while the corresponding mathematical and
The OpenWorm project (http://www.openworm.org) is an inter- structural definitions of these elements can be defined in LEMS.
national collaboration with the aim of creating a physically- and The libraries described here, libNeuroML and PyLEMS, together
biologically-detailed computer model of a behaving multicellu- provide a flexible toolkit for utilizing and extending the NeuroML
lar organism, the nematode Caenorhabditis elegans. The nervous language with Python. They complement the declarative model
specification benefits of the XML forms of these languages by representation for morphological neuron reconstructions and
offering APIs which can be used for procedural model devel- allows export of NeuroML models into different formats. lib-
opment. While the libNeuroML API provides a Python object NeuroML also provides a range of helper methods that provide
model which has a type interface defined by the NeuroML several common operations required when interacting with mod-
Schema, it also offers a memory-efficient array-based internal els expressed in NeuroML. In the same way that libNeuroML
FIGURE 7 | Example of creation of a network of integrate-and-fire parameters, along with a prototype synapse based on expTwoSynapse. A
neurons using libNeuroML (right) and the equivalent XML projection is created between the two populations and for each cell in the
representation (left). The network consists of two populations of five cells presynaptic population, an input current is applied, and connections are made
each. The cell type is a simple integrate-and-fire cell using the NeuroML to the postsynaptic cells with probability 0.3. The XML on the left is an
element iafCell. A prototype component is created for this setting all of the example of one network instance which can be generated from this script.
Figure 9 | The Hindmarsh and Rose spiking neuron model. A LEMS with a particular set of parameters is created. This Python script
ComponentType for this model is built adding the three state variables produces valid LEMS XML which can be used by any LEMS-compliant
(x, y, z) and the eight fixed parameters required for instances of the simulator to simulate the model. The inset shows the behavior of the
model. Time derivatives for the state variables are specified using state variable x (corresponding to the model neuron’s membrane
derived variables to shorten the required expressions. One Component potential) when the model is executed in PyLEMS.
SpineML conversion is a feature of the Java based jNeuroML representation, and scripts developed in this way are portable
tool (see below), which will assist interoperability between these across simulators.
languages. This approach of using libNeuroML as a library could be used
for other applications which only use a subset of the elements
libNeuroML AS AN OBJECT-MODEL FOR THIRD-PARTY APPLICATIONS of NeuroML, such as an application for visualizing or editing
One potential use of libNeuroML is to provide an object model neuronal morphologies or an application for analyzing channel
for third-party applications such as visualization, modeling, and kinetics.
simulation libraries. This is the route taken by the in-development
Pyramidal project (http://pyramidal.readthedocs.org), which JAVA LIBRARIES FOR NeuroML AND LEMS
seeks to create an API for running multicompartmental simu- In addition to the Python APIs described here for working with
lations across different simulators. In contrast to libNeuroML, NeuroML and LEMS, there are corresponding libraries in the Java
which loads the model elements into an internal object tree language for reading, editing, writing, and validating NeuroML
for manipulation, Pyramidal interacts with the underlying sim- (https://github.com/NeuroML/org.neuroml.model) and LEMS
ulator to store the model in that application’s native format. (https://github.com/LEMS/jLEMS) documents. jLEMS is a more
The advantages are that the modeler only deals with model ele- mature package than PyLEMS and is the reference simula-
ments defined in NeuroML and interacts with them through tor implementation of the LEMS language. These libraries
libNeuroML, while the simulator uses its own efficient, internal are complemented by other Java packages for importing and
Raikov, I., Cannon, R., Clewley, R., Cornelis, H., Davison, A. P., De Schutter, E., Received: 01 October 2013; accepted: 25 March 2014; published online: 23 April 2014.
et al. (2011). NineML: the network interchange for neuroscience modeling lan- Citation: Vella M, Cannon RC, Crook S, Davison AP, Ganapathy G, Robinson HPC,
guage. BMC Neurosci. 12(Suppl. 1):P330. doi: 10.1186/1471-2202-12-S1-P330 Silver RA and Gleeson P (2014) libNeuroML and PyLEMS: using Python to com-
Richmond, P., Cope, A., Gurney, K., and Allerton, D. (2013). From model speci- bine procedural and declarative modeling approaches in computational neuroscience.
fication to simulation of biologically constrained networks of spiking neurons. Front. Neuroinform. 8:38. doi: 10.3389/fninf.2014.00038
Neuroinformatics 1–17. doi: 10.1007/s12021-013-9208-z. [Epub ahead of print]. This article was submitted to the journal Frontiers in Neuroinformatics.
Sauro, H. M., and Bergmann, F. T. (2008). Standards and ontologies in com- Copyright © 2014 Vella, Cannon, Crook, Davison, Ganapathy, Robinson, Silver and
putational systems biology. Essays Biochem. 45, 211–222. doi: 10.1042/ Gleeson. This is an open-access article distributed under the terms of the Creative
BSE0450211 Commons Attribution License (CC BY). The use, distribution or reproduction in other
forums is permitted, provided the original author(s) or licensor are credited and that
Conflict of Interest Statement: The authors declare that the research was con- the original publication in this journal is cited, in accordance with accepted academic
ducted in the absence of any commercial or financial relationships that could be practice. No use, distribution or reproduction is permitted which does not comply with
construed as a potential conflict of interest. these terms.