Multi-model functions

The module myokit.lib.multi contains functions for working with multiple Myokit models.

myokit.lib.multi.binding(model, binding)

Returns the variable bound to binding from the given myokit.Model model.

The method will raise a myokit.IncompatibleModelError if no such variable is found.

myokit.lib.multi.iterdir(path)

Iterates over a directory yielding tuples (name, model, protocol) where name is the name of a model, model is a myokit.Model and protocol is a myokit.Protocol.

Depending on the contents of the found files, some entries in the model or protocol lists may be None. The results will be yielded ordered by filename. Model names are determined by inspecting the models for a meta-data entry “name”, if no such entry is found the filename is used (without the extension). The method does not descend into child directories.

Names that do not specify a name will be given their filename as name. This ensures every model read by this method has a name meta-property.

myokit.lib.multi.label(model, label)

Returns the variable labelled label from the given myokit.Model model.

The method will raise a myokit.IncompatibleModelError if no such variable is found.

myokit.lib.multi.scandir(path)

Scans a directory using iterdir() and returns a list of myokit.Model objects and a list of myokit.Protocol objects. The models (and corresponding protocols) will be ordered by model name.

myokit.lib.multi.time(model)

Returns the time variable from the given myokit.Model model.

The method will raise a myokit.IncompatibleModelError if no time variable is found.

myokit.lib.multi.unit(variable, unit)

Checks if the given variable’s unit can be converted into units unit and, if so, returns the appropriate conversion factor. If not, a myokit.IncompatibleModelError is raised.

Example:

>>> import myokit
>>> import myokit.lib.multi as multi
>>> m,p,x = myokit.load('example')
>>> print(multi.unit(m.label('membrane_potential'), myokit.units.V))
0.001

(Because a millivolt can be converted to a volt by multiplying by 0.001)