3. MOOSE builtins

This document describes classes and functions specific to the MOOSE Python module. This is an API reference.

3.1. How to use the documentation

MOOSE documentation is split into Python documentation and builtin documentation. The functions and classes that are only part of the Python interface can be viewed via Python’s builtin help function:

>>> help(moose.connect)

The documentation built into main C++ code of MOOSE can be accessed via the module function doc:

>>> moose.doc('Neutral')

To get documentation about a particular field:

>>> moose.doc('Neutral.childMsg')

3.2. Builtin functions and classes in moose module (Python only)

class moose.DestField

Bases: moose.Field

DestField is a method field, i.e. it can be called like a function. Use moose.doc(‘classname.fieldname’) to display builtin documentation for field in class classname.

Methods

__call__(...) <==> x(...)
class moose.ElementField

Bases: moose.Field

ElementField represents fields that are themselves elements. For example, synapse in an IntFire neuron. Element fields can be traversed like a sequence. Additionally, you can set the number of entries by setting the num attribute to a desired value.

Attributes

dataIndex dataIndex of the field element
name Name of the field element.
num Number of entries in the field.
owner Reference to owner element of the field element.
path Path of the field element.
vec Id of the field element.
dataIndex

dataIndex of the field element

name

Name of the field element.

num

Number of entries in the field.

owner

Reference to owner element of the field element.

path

Path of the field element.

vec

Id of the field element.

class moose.LookupField

Bases: moose.Field

LookupField is dictionary-like fields that map keys to values. The keys need not be fixed, as in case of interpolation tables, keys can be any number and the corresponding value is dynamically computed by the method of interpolation. Use moose.doc(‘classname.fieldname’) to display builtin documentation for field in class classname.

moose.ce()

Set the current working element. ‘ce’ is an alias of this function

moose.connect(src, src_field, dest, dest_field, message_type) → bool

Create a message between src_field on src object to dest_field on dest object.

Parameters:

src : element/vec/string

the source object (or its path)

src_field : str

the source field name. Fields listed under srcFinfo and sharedFinfo qualify for this.

dest : element/vec/string

the destination object.

dest_field : str

the destination field name. Fields listed under destFinfo and sharedFinfo qualify for this.

message_type : str (optional)

Type of the message. Can be Single, OneToOne, OneToAll. If not specified, it defaults to Single.

Returns:

msgmanager: melement

message-manager for the newly created message.

Examples

Connect the output of a pulse generator to the input of a spike generator:

>>> pulsegen = moose.PulseGen('pulsegen')
>>> spikegen = moose.SpikeGen('spikegen')
>>> moose.connect(pulsegen, 'output', spikegen, 'Vm')
moose.copy(src, dest, name, n, toGlobal, copyExtMsg) → bool

Make copies of a moose object.

Parameters:

src : vec, element or str

source object.

dest : vec, element or str

Destination object to copy into.

name : str

Name of the new object. If omitted, name of the original will be used.

n : int

Number of copies to make.

toGlobal : int

Relevant for parallel environments only. If false, the copies will reside on local node, otherwise all nodes get the copies.

copyExtMsg : int

If true, messages to/from external objects are also copied.

Returns:

vec

newly copied vec

moose.delete(obj) → None

Delete the underlying moose object. This does not delete any of the Python objects referring to this vec but does invalidate them. Any attempt to access them will raise a ValueError.

Parameters:

id : vec

vec of the object to be deleted.

Returns:

None

moose.doc(arg, inherited=True, paged=True)

Display the documentation for class or field in a class.

Parameters:

arg : str/class/melement/vec

A string specifying a moose class name and a field name separated by a dot. e.g., ‘Neutral.name’. Prepending moose. is allowed. Thus moose.doc(‘moose.Neutral.name’) is equivalent to the above. It can also be string specifying just a moose class name or a moose class or a moose object (instance of melement or vec or there subclasses). In that case, the builtin documentation for the corresponding moose class is displayed.

paged: bool

Whether to display the docs via builtin pager or print and exit. If not specified, it defaults to False and moose.doc(xyz) will print help on xyz and return control to command line.

Returns:

None

Raises:

NameError

If class or field does not exist.

moose.element(arg) → moose object

Convert a path or an object to the appropriate builtin moose class instance

Parameters:

arg : str/vec/moose object

path of the moose element to be converted or another element (possibly available as a superclass instance).

Returns:

melement

MOOSE element (object) corresponding to the arg converted to write subclass.

moose.exists()

True if there is an object with specified path.

moose.getCwe()

Get the current working element. ‘pwe’ is an alias of this function.

moose.getField()

getField(element, field, fieldtype) – Get specified field of specified type from object vec.

moose.getFieldDict(className, finfoType) → dict

Get dictionary of field names and types for specified class.

Parameters:

className : str

MOOSE class to find the fields of.

finfoType : str (optional)

Finfo type of the fields to find. If empty or not specified, all fields will be retrieved.

Returns:

dict

field names and their types.

Notes

This behaviour is different from getFieldNames where only valueFinfo`s are returned when `finfoType remains unspecified.

Examples

List all the source fields on class Neutral:

>>> moose.getFieldDict('Neutral', 'srcFinfo')

{‘childMsg’: ‘int’}

moose.getFieldNames(className, finfoType='valueFinfo') → tuple

Get a tuple containing the name of all the fields of finfoType kind.

Parameters:

className : string

Name of the class to look up.

finfoType : string

The kind of field (valueFinfo, srcFinfo, destFinfo, lookupFinfo, fieldElementFinfo.).

Returns:

tuple

Names of the fields of type finfoType in class className.

moose.isRunning()

True if the simulation is currently running.

moose.le(el=None)

List elements under el or current element if no argument specified.

Parameters:

el : str/melement/vec/None

The element or the path under which to look. If None, children

of current working element are displayed.

Returns:

None

moose.loadModel(filename, modelpath, solverclass) → vec

Load model from a file to a specified path.

Parameters:

filename : str

model description file.

modelpath : str

moose path for the top level element of the model to be created.

solverclass : str, optional

solver type to be used for simulating the model.

Returns:

vec

loaded model container vec.

class moose.melement

Bases: object

Individual moose element contained in an array-type object (vec).

Each element has a unique path, possibly with its index in the vec. These are identified by three components: vec, dndex and findex. vec is the containing vec, which is identified by a unique number (field value). dindex is the index of the current item in the containing vec. dindex is 0 for single elements. findex is field index, specifying the index of elements which exist as fields of another moose element.

Parameters:

path : str

path of the element to be created.

n : positive int, optional

defaults to 1. If greater, then a vec of that size is created and this element is a reference to the first entry of the vec.

g : int, optional

if 1, this is a global element, else if 0 (default), the element is local to the current node.

dtype : str

name of the class of the element. If creating any concrete subclass, this is automatically taken from the class name and should not be specified explicitly.

Notes

Users need not create melement directly. Instead use the named moose class for creating new elements. To get a reference to an existing element, use the moose.element function.

Examples

>>> a = Neutral('alpha') # Creates element named `alpha` under current working element
>>> b = Neutral('alpha/beta') # Creates the element named `beta` under `alpha`
>>> c = moose.melement(b)

Attributes

vec Return the vec this element belongs to.
dindex (int) index of this element in the container vec
findex: int if this is a tertiary object, i.e. acts as a field in another element (like synapse[0] in IntFire[1]), then the index of this field in the containing element.

Methods

connect((srcfield, destobj, destfield, ...) Connect another object via a message.
getDataIndex(() -> int) Get the dataIndex of this object.
getField(fieldname) Get the value of the field fieldname.
getFieldIndex Get the index of this object as a field.
getFieldNames((fieldType=) -> tuple of str) Get the names of fields on this element.
getFieldType(fieldname) Get the string representation of the type of the field fieldname.
getId(() -> vec) Get the vec of this object
getLookupField((fieldname, key) -> value type) Lookup entry for key in fieldName
getNeighbors((fieldName) -> tuple of vecs) Get the objects connected to this element on specified field.
setDestField(arg0, arg1, ...) Set a destination field.
setField(fieldname, value) Set the value of specified field.
setLookupField(fieldname, key, value) Set a lookup field entry.
vec Return the vec this element belongs to.
connect(srcfield, destobj, destfield, msgtype) → bool

Connect another object via a message.

Parameters:

srcfield : str

source field on self.

destobj : element

Destination object to connect to.

destfield : str

field to connect to on destobj.

msgtype : str

type of the message. Can be Single, OneToAll, AllToOne,

OneToOne, Reduce, Sparse. Default: Single.

Returns:

msgmanager: melement

message-manager for the newly created message.

See also

moose.connect

Examples

Connect the output of a pulse generator to the input of a spike generator:

>>> pulsegen = moose.PulseGen('pulsegen')
>>> spikegen = moose.SpikeGen('spikegen')
>>> pulsegen.connect('output', spikegen, 'Vm')
getDataIndex() → int

Get the dataIndex of this object.

getField(fieldname)

Get the value of the field fieldname.

Parameters:

fieldname : string

Name of the field.

getFieldIndex()

Get the index of this object as a field.

getFieldNames(fieldType='') → tuple of str

Get the names of fields on this element.

Parameters:

fieldType : str

Field type to retrieve. Can be valueFinfo, srcFinfo,

destFinfo, lookupFinfo, etc. If an empty string is specified,

names of all avaialable fields are returned.

Returns:

names : tuple of strings.

names of the fields of the specified type.

Examples

List names of all the source fields in PulseGen class:

>>> moose.getFieldNames('PulseGen', 'srcFinfo')
('childMsg', 'output')
getFieldType(fieldname)

Get the string representation of the type of the field fieldname.

Parameters:

fieldname : string

Name of the field to be queried.

getId() → vec

Get the vec of this object

getLookupField(fieldname, key) → value type

Lookup entry for key in fieldName

Parameters:

fieldname : string

Name of the lookupfield.

key : appropriate type for key of the lookupfield (as in the dict getFieldDict).

Key for the look-up.

getNeighbors(fieldName) → tuple of vecs

Get the objects connected to this element on specified field.

Parameters:

fieldName : str

name of the connection field (a destFinfo/srcFinfo/sharedFinfo)

Returns:

neighbors: tuple of vecs.

tuple containing the ids of the neighbour vecs.

setDestField(arg0, arg1, ...)

Set a destination field. This is for advanced uses. destFields can (and should) be directly called like functions as element.fieldname(arg0, ...)

Parameters:

The number and type of paramateres depend on the destFinfo to be

set. Use moose.doc(‘{classname}.{fieldname}’) to get builtin

documentation on the destFinfo `fieldname`

setField(fieldname, value)

Set the value of specified field.

Parameters:

fieldname : string

Field to be assigned value to.

value : python datatype compatible with the type of the field

The value to be assigned to the field.

setLookupField(fieldname, key, value)

Set a lookup field entry.

Parameters:

fieldname : str

name of the field to be set

key : key type

key in the lookup field for which the value is to be set.

value : value type

value to be set for key in the lookup field.

vec()

Return the vec this element belongs to. This is overridden by the attribute of the same name for quick access.

moose.move()

Move a vec object to a destination.

moose.pwe()

Print present working element. Convenience function for GENESIS users. If you want to retrieve the element in stead of printing the path, use moose.getCwe()

moose.quit()

Finalize MOOSE threads and quit MOOSE. This is made available for debugging purpose only. It will automatically get called when moose module is unloaded. End user should not use this function.

moose.rand() -> [0, 1)
Returns:float in [0, 1) real interval generated by MT19937.

See also

moose.seed

Notes

MOOSE does not automatically seed the random number generator. You must explicitly call moose.seed() to create a new sequence of random numbers each time.

moose.readSBML()

Import SBML model to Moose.

moose.reinit() → None

Reinitialize simulation.

This function (re)initializes moose simulation. It must be called before you start the simulation (see moose.start). If you want to continue simulation after you have called moose.reinit() and moose.start(), you must NOT call moose.reinit() again. Calling moose.reinit() again will take the system back to initial setting (like clear out all data recording tables, set state variables to their initial values, etc.

moose.saveModel(source, filename) → None

Save model rooted at source to file filename.

Parameters:

source : vec/element/str

root of the model tree

filename : str

destination file to save the model in.

Returns:

None

moose.seed(seedvalue) → None

Reseed MOOSE random number generator.

Parameters:

seed : int

Optional value to use for seeding. If 0, a random seed is automatically created using the current system time and other information. If not specified, it defaults to 0.

default: 0

Returns:

None

See also

moose.rand, 1

moose.setClock(tick, dt)

set the ticking interval of tick to dt.

A tick with interval dt will call the functions scheduled on that tick every dt timestep.

Parameters:

tick : int

tick number

dt : double

ticking interval

moose.setCwe()

Set the current working element. ‘ce’ is an alias of this function

moose.showfield(el, field='*', showtype=False)

Show the fields of the element el, their data types and values in human readable format. Convenience function for GENESIS users.

Parameters:

el : melement/str

Element or path of an existing element.

field : str

Field to be displayed. If ‘*’ (default), all fields are displayed.

showtype : bool

If True show the data type of each field. False by default.

Returns:

None

moose.showmsg(el)

Print the incoming and outgoing messages of el.

Parameters:

el : melement/vec/str

Object whose messages are to be displayed.

Returns:

None

moose.start(time) → None

Run simulation for t time. Advances the simulator clock by t time.

After setting up a simulation, YOU MUST CALL MOOSE.REINIT() before CALLING MOOSE.START() TO EXECUTE THE SIMULATION. Otherwise, the simulator behaviour will be undefined. Once moose.reinit() has been called, you can call moose.start(t) as many time as you like. This will continue the simulation from the last state for t time.

Parameters:

t : float

duration of simulation.

Returns:

None

See also

moose.reinit
(Re)initialize simulation
moose.stop()

Stop simulation

moose.useClock(tick, path, fn)

schedule fn function of every object that matches path on tick no. tick.

Most commonly the function is ‘process’. NOTE: unlike earlier versions, now autoschedule is not available. You have to call useClock for every element that should be updated during the simulation.

The sequence of clockticks with the same dt is according to their number. This is utilized for controlling the order of updates in various objects where it matters. The following convention should be observed when assigning clockticks to various components of a model:

Clock ticks 0-3 are for electrical (biophysical) components, 4 and 5 are for chemical kinetics, 6 and 7 are for lookup tables and stimulus, 8 and 9 are for recording tables.

Generally, process is the method to be assigned a clock tick. Notable exception is init method of Compartment class which is assigned tick 0.

  • 0 : Compartment: init
  • 1 : Compartment: process
  • 2 : HHChannel and other channels: process
  • 3 : CaConc : process
  • 4,5 : Elements for chemical kinetics : process
  • 6,7 : Lookup (tables), stimulus : process
  • 8,9 : Tables for plotting : process
Parameters:

tick : int

tick number on which the targets should be scheduled.

path : str

path of the target element(s). This can be a wildcard also.

fn : str

name of the function to be called on each tick. Commonly process.

Examples

In multi-compartmental neuron model a compartment’s membrane potential (Vm) is dependent on its neighbours’ membrane potential. Thus it must get the neighbour’s present Vm before computing its own Vm in next time step. This ordering is achieved by scheduling the init function, which communicates membrane potential, on tick 0 and process function on tick 1.

>>> moose.useClock(0, '/model/compartment_1', 'init')
>>> moose.useClock(1, '/model/compartment_1', 'process')
class moose.vec

Bases: object

An object uniquely identifying a moose array-element.

array-elements are narray-like objects which can have one or more single-elements within them. vec can be traversed like a Python sequence and is item is an element identifying single-objects contained in the array element.

you can create multiple references to the same MOOSE object in Python, but as long as they have the same path/id value, they all point to the same entity in MOOSE.

Field access to ematrices are vectorized. For example, vec.name returns a tuple containing the names of all the single-elements in this vec. There are a few special fields that are unique for vec and are not vectorized. These are path, value, shape and className. There are two ways an vec can be initialized, (1) create a new array element or (2) create a reference to an existing object.

vec(self, path=path, n=size, g=isGlobal, dtype=className)
Parameters:

path : str/vec/int

Path of an existing array element or for creating a new one. This has the same format as unix file path: /{element1}/{element2} ... If there is no object with the specified path, moose attempts to create a new array element. For that to succeed everything until the last / character must exist or an error is raised

Alternatively, path can be vec or integer value of the id of an existing vec object. The new object will be another reference to the existing object.

n : positive int

This is a positive integers specifying the size of the array element to be created. Thus n=2 will create an vec with 2 elements.

g : int

Specify if this is a global or local element. Global elements are shared between nodes in a computing cluster.

dtype: string

The vector will be of this moose-class.

Examples

>>> iaf = moose.vec('/iaf', n=10, dtype='IntFire')
>>> iaf.Vm = range(10)
>>> print iaf[5].Vm
5.0
>>> print iaf.Vm
array([ 0.,  1.,  2.,  3.,  4.,  5.,  6.,  7.,  8.,  9.])

Methods

delete(() -> None) Delete the underlying moose object.
getPath Return the path of this vec object.
getShape Get the shape of the vec object as a tuple.
getValue Return integer representation of the id of the element.
setField((fieldname, value_vector) -> None) Set the value of fieldname in all elements under this vec.
delete() → None

Delete the underlying moose object. This will invalidate all references to this object and any attempt to access it will raise a ValueError.

getPath()

Return the path of this vec object.

getShape()

Get the shape of the vec object as a tuple.

getValue()

Return integer representation of the id of the element.

setField(fieldname, value_vector) → None

Set the value of fieldname in all elements under this vec.

Parameters:

fieldname: str

field to be set.

value: sequence of values

sequence of values corresponding to individual elements under this vec.

Notes

This is an interface to SetGet::setVec

moose.wildcardFind(expression) → tuple of melements.

Find an object by wildcard.

Parameters:

expression : str

MOOSE allows wildcard expressions of the form:

{PATH}/{WILDCARD}[{CONDITION}]

where {PATH} is valid path in the element tree. {WILDCARD} can be # or ##.

# causes the search to be restricted to the children of the element specified by {PATH}.

## makes the search to recursively go through all the descendants of the {PATH} element. {CONDITION} can be:

TYPE={CLASSNAME} : an element satisfies this condition if it is of
class {CLASSNAME}.
ISA={CLASSNAME} : alias for TYPE={CLASSNAME}
CLASS={CLASSNAME} : alias for TYPE={CLASSNAME}
FIELD({FIELDNAME}){OPERATOR}{VALUE} : compare field {FIELDNAME} with
{VALUE} by {OPERATOR} where {OPERATOR} is a comparison operator (=,
!=, >, <, >=, <=).

For example, /mymodel/##[FIELD(Vm)>=-65] will return a list of all the objects under /mymodel whose Vm field is >= -65.

Returns:

tuple

all elements that match the wildcard.

moose.writeSBML()

Export biochemical model to an SBML file.

Table Of Contents

This Page