An interface for importing CellML 1.0 and up is provided, as well as an export to CellML 1.0.


Myokit can import most models listed in the CellML electrophysiology repository.

However, most CellML models contain a hard-coded stimulus current which will cause problems for the solver. These must rewritten manually to use Myokit’s pacing system.

In the following example we show how to import the Beeler-Reuter model from the CellML database.

  1. Find and download the model file (beeler_reuter_1977.cellml).
  2. Open the GUI and select Convert > Import model from CellML.
  3. Have a look at the imported code. Apart from the messy representation of the meta-data, everything should be in order.
  4. Run the embedded script or explorer. You should see something like this:
  1. To fix this, scroll down to the stimulus section. It should look like this:

    Istim = piecewise(engine.time >= IstimStart and engine.time <= ...
        in [A/m^2]
    IstimStart = 10 [ms]
    IstimEnd = 50000 [ms]
    IstimAmplitude = 0.5 [A/m^2]
    IstimPeriod = 1000 [ms]
    IstimPulseDuration = 1 [ms]

    Replace the piecewise statement with a formulation using the external pace variable:

    IstimAmplitude = 0.5 [A/m^2]
    level = 0 bind pace
    Istim = level * IstimAmplitude [A/m^2]

    Next, use the information from IstimStart, IStimPeriod and IStimPulseDuration to update the pacing protocol on the next tab:

    # Level  Start    Length   Period   Multiplier
    1.0      10.0     1.0      1000.0   0
  2. Validate the model and try again. Now that the simulation engine knows where the discontinuities are, you should get the expected result:


The same procedure can be followed for any other valid model in the database.

Model quality

Please keep in mind that the quality of available CellML models may vary. Some models are incomplete, contain errors or are not written in valid CellML. In addition, some models contain experimental features such as random variation or partial differential equations. These are not currently part of the CellML standard and are not supported by Myokit.


CellML is built with a larger scope in mind than Myokit and includes a few oddities such as <arccsch>, which were included ” because they are reasonably straightforward to translate to computer code” (CellML 1.0 specification). Below is a list of the CellML features Myokit does not support.

CellML 1.0

Differential algebraic equations (DAEs)
Myokit has no support for DAEs, so model that contain them cannot be imported. However, these models can manually be rewritten to a form supported by Myokit.
The factorial operation is not common in cell models or in programming math libraries (C for example, does not include it). In addition, note that 13! > 2^32 and 21! > 2^64 so that there is only a very small subset of factorials that we can easily compute. At the time of writing, July 2015, none of the cardiac models in the CellML electrophysiology repository use this feature.
The <reaction> element and its children are used to specify biochemical pathways without an explicit mathematical form. Since there are plenty of tools for pathways already, Myokit does not support them. At the time of writing, July 2015, none of the models in the CellML electrophysiology repository use this feature.
The <semantics> element and its children can be used to specify both a meaningful set of equations and a pretty set of equations. Since Myokit has only one way of displaying equations, this is not supported. At the time of writing, July 2015, none of the models in the CellML electrophysiology repository use this feature.

CellML 1.1

The import element introduced in CellML 1.1 is currently not supported, but this may change in the future.

Optional features

Unit conversion
Myokit’s CellML import does not perform automatic unit conversion, but it will warn if inconsistent units are found.
CellML scripting is not supported by Myokit.


Myokit provides an export to CellML 1.0. Since Myokit separates the model from the pacing protocol, but most CellML based tools do not expect this, Myokit has an option to embed a hardcoded stimulus protocol in exported CellML files. This is enabled by default but can be disabled when exporting models via the API (see CellMLExporter).

Note that the protocol has a default duration of 2ms, making it suitable for most older models but not the more modern ones. For models that require shorter stimulus currents, adapt the CellML model by searching for a component named “stimulus” (or “stimulus_2” if that name was already taken) and changing the “duration” variable.


A few notes about OpenCOR:

  1. The OpenCOR manual states that, “a model that requires a stimulus protocol should have the maximum step value of the CVODE solver set to the length of the stimulus”. Since most models have a stimulus protocol you’ll usually have to set the maximum step size on the “simulation” tab for models to work in OpenCOR.
  2. OpenCOR has been known to complain about nested piecewise functions. If these are present it seems to run anyway.


The standard interfaces for importing and exporting are provided:


Tests if the given name is a valid CellML 1 identifier.


Returns a dict of all importers available in this module.

class myokit.formats.cellml.CellMLImporter(verbose=False)

This:class:Importer <myokit.formats.Importer> imports a model definition from CellML.

component(path, model)

Imports a component from the given path and adds it to the given model.

The importer may pose restraints on the used model. For example, the model may be required to contain a variable labelled “membrane_potential”. For details, check the documentation of the individual importers.

The created myokit.Component is returned. A myokit.ImportError will be raised if any errors occur.


Returns a string containing information about this importer.


Returns this exporter’s TextLogger.


Reads a CellML file and returns a:class:myokit.Model.


Imports a protocol from the given path.

The created myokit.Protocol is returned. A myokit.ImportError will be raised if any errors occur.


Returns a bool indicating if component import is supported.


Returns True.


Returns a bool indicating if protocol import is supported.


Returns a dict of all exporters available in this module.

class myokit.formats.cellml.CellMLExporter

This:class:Exporter <myokit.formats.Exporter> creates a CellML model.


Creates an almost readable name for a custom Myokit unit.


Returns a string containing information about this exporter.

This should be implemented by each subclass.


Returns this exporter’s TextLogger.

model(path, model, protocol=None, add_hardcoded_pacing=True, pretty_xml=True)

Writes a CellML model to the given filename.


The path/filename to write the generated code too.
The model to export
This argument will be ignored: protocols are not supported by CellML.
Set this to True to add a hardcoded pacing signal to the model file. This requires the model to have a variable bound to pace.
Set this to True to write the output in formatted “pretty” xml.

Notes about CellML export:

  • CellML expects a unit for every number present in the model. Since Myokit allows but does not enforce this, the resulting CellML file may only validate with unit checking disabled.
  • Files downloaded from the CellML repository typically have a pacing stimulus embedded in them, while Myokit views models and pacing protocols as separate things. To generate a model file with a simple embbeded protocol, add the optional argument add_hardcoded_pacing=True.
  • Variables annotated with an oxmeta property will be annotated using the oxmeta namespace in the created CellML. For example, a variable with the meta-data oxmeta: time will be annotated as https://chaste.comlab.ox.ac.uk/cellml/ns/oxford-metadata#time in the CellML file.
runnable(path, model, protocol=None, *args)

Exports a myokit.Model and optionally a myokit.Protocol to something that can be run or compiled.

The output will be stored in the directory path. A myokit.ExportError will be raised if any errors occur.


Returns True.


Returns True if this exporter supports export of a model and optional protocol to a runnable piece of code.


Returns a dict of all expression writers available in this module.

class myokit.formats.cellml.CellMLExpressionWriter(units=None)

Writes equations for variables using CellML’s version of MathML.

Differences from normal MathML:

  1. Only content MathML is supported
  2. Variable names are always written as unames.
  3. Every number defines an attribute cellml:units

The expression writer requires a single argument units. This should be a mapping of Myokit units to string unit names.

eq(eq, element=None)

Converts an equation to a string.

The optional argument element can be used to pass in an ElementTree element. If given, this element will be updated with the generated xml and nothing will be returned.

ex(e, element=None)

Converts an expression to a string.

The optional argument element can be used to pass in an ElementTree element. If given, this element will be updated with the generated xml and nothing will be returned.


By default this ExpressionWriter uses the xml.etree.cElementTree module. This method can be used to change this behaviour by passing in a reference to a different implementation.


This expression writer always uses unames, setting an LHS function is not supported.


This expression writer only supports content MathML.


Sets the time variable to use for this expression writer’s derivatives.

class myokit.formats.cellml.CellMLError(message)

Raised when a fatal error occurs when importing CellML