Myokit can import most models listed in the CellML electrophysiology
repository.
(Although take care, some of the CellML versions of models are known to
have issues. This is usually mentioned in their documentation).
Most CellML models contain a hard-coded stimulus current.
Myokit will try to detect these stimulus currents and replace them by an
appropriate myokit.Protocol.
However, if this fails, the stimulus will need to be converted by hand, which
is described below.
In the following example we show how to import the Beeler-Reuter model from
the CellML database.
Find and download the model file (beeler_reuter_1977.cellml).
Open the GUI and select Convert>ImportmodelfromCellML.
Have a look at the imported code. You should find a stimulus current
implemented as pace*IstimAmplitude. This has automatically been
added when you imported the model.
If you run the code, you should see an action potential!
Now let’s import the model in code, without automatic conversion:
In a script, load the Myokit formats module (importmyokit.formats)
and create a CellMLImporter: i=myokit.formats.importer('cellml').
Import the model, using i.model('beeler_reuter_1977.cellml').
Have a look at the generated code. You should see the hardcoded stimulus
that was present in the CellML file.
Run the embedded script or explorer. You should see something like this:
To fix this, scroll down to the stimulus section. It should look like
this:
Next, use the information from IstimStart, IStimPeriod and
IStimPulseDuration to update the pacing protocol on the next tab:
# Level Start Length Period Multiplier1.010.01.01000.00
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.
An automated version of this procedure is implemented as
myokit.lib.guess.remove_embedded_protocol().
Myokit provides an export to CellML 1.0, 1.1, and 2.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 can be done by passing a myokit Protocol to the exporter along with
the model to export.
If given, an attempt will be made to convert the protocol to an
expression and insert it into the model before exporting. See
myokit.lib.guess.add_embedded_protocol() for details.
If given, an attempt will be made to convert the protocol to an
expression and insert it into the model before exporting. See
myokit.lib.guess.add_embedded_protocol() for details.
If given, an attempt will be made to convert the protocol to an
expression and insert it into the model before exporting. See
myokit.lib.guess.add_embedded_protocol() for details.
Writes equations for variables using CellML’s version of MathML.
To use, create an expression writer, then pass in a method to set good
variable names with set_lhs_function(), and a method to look up
unit names with set_unit_function().
The optional argument element can be used to pass in an
lxml.etree.ElementTree element. If given, this element will be
updated with the generated xml and nothing will be returned.
The optional argument element can be used to pass in an
lxml.etree.ElementTree element. If given, this element will be
updated with the generated xml and nothing will be returned.