This document describes classes and functions specific to the MOOSE Python module. This is an API reference.
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')
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(...) |
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 of the field element
Name of the field element.
Number of entries in the field.
Reference to owner element of the field element.
Path of the field element.
Id of the field element.
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.
Set the current working element. ‘ce’ is an alias of this function
Create a message between src_field on src object to dest_field on dest object.
Parameters: | src : element/vec/string
src_field : str
dest : element/vec/string
dest_field : str
message_type : str (optional)
|
---|---|
Returns: | msgmanager: melement
|
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')
Make copies of a moose object.
Parameters: | src : vec, element or str
dest : vec, element or str
name : str
n : int
toGlobal : int
copyExtMsg : int
|
---|---|
Returns: | vec
|
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
|
---|---|
Returns: | None |
Display the documentation for class or field in a class.
Parameters: | arg : str/class/melement/vec
paged: bool
|
---|---|
Returns: | None |
Raises: | NameError
|
Convert a path or an object to the appropriate builtin moose class instance
Parameters: | arg : str/vec/moose object
|
---|---|
Returns: | melement
|
True if there is an object with specified path.
Get the current working element. ‘pwe’ is an alias of this function.
getField(element, field, fieldtype) – Get specified field of specified type from object vec.
Get dictionary of field names and types for specified class.
Parameters: | className : str
finfoType : str (optional)
|
---|---|
Returns: | dict
|
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’}
Get a tuple containing the name of all the fields of finfoType kind.
Parameters: | className : string
finfoType : string
|
---|---|
Returns: | tuple
|
True if the simulation is currently running.
List elements under el or current element if no argument specified.
Parameters: | el : str/melement/vec/None
|
---|---|
Returns: | None |
Load model from a file to a specified path.
Parameters: | filename : str
modelpath : str
solverclass : str, optional
|
---|---|
Returns: | vec
|
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
n : positive int, optional
g : int, optional
dtype : str
|
---|
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 another object via a message.
Parameters: | srcfield : str
destobj : element
destfield : str
msgtype : str
|
---|---|
Returns: | msgmanager: melement
|
See also
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')
Get the dataIndex of this object.
Get the value of the field fieldname.
Parameters: | fieldname : string
|
---|
Get the index of this object as a field.
Get the names of fields on this element.
Parameters: | fieldType : str
|
---|---|
Returns: | names : tuple of strings.
|
Examples
List names of all the source fields in PulseGen class:
>>> moose.getFieldNames('PulseGen', 'srcFinfo')
('childMsg', 'output')
Get the string representation of the type of the field fieldname.
Parameters: | fieldname : string
|
---|
Get the vec of this object
Lookup entry for key in fieldName
Parameters: | fieldname : string
key : appropriate type for key of the lookupfield (as in the dict getFieldDict).
|
---|
Get the objects connected to this element on specified field.
Parameters: | fieldName : str
|
---|---|
Returns: | neighbors: tuple of vecs.
|
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` |
---|
Set the value of specified field.
Parameters: | fieldname : string
value : python datatype compatible with the type of the field
|
---|
Set a lookup field entry.
Parameters: | fieldname : str
key : key type
value : value type
|
---|
Return the vec this element belongs to. This is overridden by the attribute of the same name for quick access.
Move a vec object to a destination.
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()
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.
Returns: | float in [0, 1) real interval generated by MT19937. |
---|
See also
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.
Import SBML model to Moose.
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.
Save model rooted at source to file filename.
Parameters: | source : vec/element/str
filename : str
|
---|---|
Returns: | None |
Reseed MOOSE random number generator.
Parameters: | seed : int
|
---|---|
Returns: | None |
See also
moose.rand, 1
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
|
---|
Set the current working element. ‘ce’ is an alias of this function
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
field : str
showtype : bool
|
---|---|
Returns: | None |
Print the incoming and outgoing messages of el.
Parameters: | el : melement/vec/str
|
---|---|
Returns: | 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
|
---|---|
Returns: | None |
See also
Stop simulation
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
path : str
fn : str
|
---|
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')
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
|
---|
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 the underlying moose object. This will invalidate all references to this object and any attempt to access it will raise a ValueError.
Return the path of this vec object.
Get the shape of the vec object as a tuple.
Return integer representation of the id of the element.
Set the value of fieldname in all elements under this vec.
Parameters: | fieldname: str
value: sequence of values
|
---|
Notes
This is an interface to SetGet::setVec
Find an object by wildcard.
Parameters: | expression : str
|
---|---|
Returns: | tuple
|
Export biochemical model to an SBML file.