SBML API¶
In addition to the SBML importer, Myokit contains an API to represent SBML models, along with methods to read SBML documents. These methods are used under the hood by the importer.
In most cases, it’s easier to avoid these methods and use the SBML Importer instead.
SBML Model API¶
- class myokit.formats.sbml.Compartment(model, sid)¶
Represents a compartment in SBML; to create a compartment use
model.add_compartment().A compartment acts as a
Quantity, where the value represents the compartment’s size.Arguments:
modelThe
myokit.formats.sbml.Modelthis compartment is in.sidThis compartment’s SId.
- initial_value()¶
- Returns a
myokit.Expressionfor this quantity’s initial value, or
Noneif not set.
- Returns a
- is_rate()¶
Returns
Trueif this quantity’s value is defined through a rate, elseFalse.
- set_initial_value(value)¶
Sets a
myokit.Expressionfor this quantity’s initial value.
- set_size_units(units)¶
Sets the
myokit.Unitfor this compartment’s size.
- set_spatial_dimensions(dimensions)¶
Sets the dimensionality of this compartment’s size (usually 1, 2, or 3); this is used to determine the units for the compartment size in the case that they are not explicitly set.
- set_value(value, is_rate=False)¶
Sets a
myokit.Expressionfor this quantity’s value.Arguments:
valueAn expression. The values of any
myokit.Nameobjects in the expression must be either subclasses ofmyokit.formats.sbml.api.Quantityor ofmyokit.formats.sbml.api.CSymbolVariable.rateSet to
Trueif the expression gives the rate of change of this variable.
- sid()¶
Returns this compartment’s sid.
- size_units()¶
Returns the units of this compartment’s size.
If not set explicitly, the units will be retrieved from the model. If not set there either, units of dimensionless are returned.
- spatial_dimensions()¶
Returns this compartment’s spatial dimensions, or
Noneif not set.
- value()¶
Returns a
myokit.Expressionfor this quantity’s value, orNoneif not set.
- class myokit.formats.sbml.CSymbolVariable(definition_url)¶
Represents a CSymbol that can appear in SBML expressions, but which has a predetermind value and/or meaning, e.g. “time”.
- definition_url()¶
Returns the
definitionUrlfor thisCSymbolVariable.
- class myokit.formats.sbml.Model(name=None)¶
Represents a model in SBML.
Arguments:
nameA user-friendly name for this model.
- add_compartment(sid)¶
Adds a
myokit.formats.sbml.Compartmentto this model.
- add_parameter(sid, is_constant=True)¶
Adds a
myokit.formats.sbml.Parameterto this model.
- add_reaction(sid)¶
Adds a
myokit.formats.sbml.Reactionto this model.
- add_species(compartment, sid, is_amount=False, is_constant=False, is_boundary=False)¶
Adds a
myokit.formats.sbml.Speciesto this model (located in the givencompartment).
- add_unit(unitsid, unit)¶
Adds a user unit with the given
unitsidand myokitunit.
- add_unit_if_possible(unit)¶
Adds a unit to the model if it’s not already present or in the set of base units, and returns the unit’s name.
- area_units()¶
Returns the default compartment size units for 2-dimensional compartments, or dimensionless if not set.
- assignable(sid)¶
Returns the
Compartment,Species,SpeciesReference, orParameterreferenced by the given SId.
- assignable_or_csymbol(identifier)¶
Like
assignable(), but will also return aCSymbolVariableif the given identifier is a known CSymboldefinitionUrl.
- compartment(sid)¶
Returns the compartment with the given sid.
- compartments()¶
Returns a list of all compartments in this model.
- conversion_factor()¶
Returns the
Parameteracting as global species conversion factor, orNoneif not set, seeSpecies.conversion_factor().
- extent_units()¶
Returns the default extent units in this model, or dimensionless if not set.
- static from_myokit_model(model: Model) Model¶
Creates an SBML model from a
myokit.Model.
- has_units() bool¶
Returns
Trueif this model has any units defined.
- length_units()¶
Returns the default compartment size units for 1-dimensional compartments, or dimensionless if not set.
- myokit_model()¶
Converts this SBML model to a
myokit.Model.SBML IDs are used for naming components and variables. If an ID starts with an underscore, the myokit name will be converted to underscore<name>.
Compartments defined by the SBML file are mapped to Myokit Components.
- name()¶
Returns this model’s name.
- notes()¶
Returns a string of notes (if set), or
None.
- parameters()¶
Returns a list of all parameters in this model.
- reactions()¶
Returns a list of all reactions in this model.
- set_area_units(units)¶
Sets the default compartment size units for 2-dimensional compartments.
- set_conversion_factor(factor)¶
Sets a
Parameteras global conversion factor for species, seeSpecies.conversion_factor().
- set_extent_units(units)¶
Sets the default units for “reaction extent”, i.e. for the kinetic law equations in reactions.
- set_length_units(units)¶
Sets the default compartment size units for 1-dimensional compartments.
- set_notes(notes=None)¶
Sets an optional notes string for this model.
- set_substance_units(units)¶
Sets the default units for reaction amounts (not concentrations).
- set_time_units(units)¶
Sets the time units used throughout the model.
- set_volume_units(units)¶
Sets the default compartment size units for 3-dimensional compartments.
- species(sid)¶
Returns the species with the given id.
- species_list()¶
returns a list of all species in this model.
- substance_units()¶
Returns the default units for reaction amounts (not concentrations), or dimensionless if not set.
- time()¶
Returns the
CSymbolVariablerepresenting time in this model.
- time_units()¶
Returns the default units for time, or dimensionless if not set.
- unit(unitsid)¶
Returns a user-defined or predefined unit.
- volume_units()¶
Returns the default compartment size units for 3-dimensional compartments, or dimensionless if not set.
- class myokit.formats.sbml.ModifierSpeciesReference(species, sid=None)¶
Represents a reference to a modifier species in an SBML reaction.
- sid()¶
Returns this species reference’s SId, or
Noneif not set.
- species()¶
Returns the species this object refers to.
- class myokit.formats.sbml.Parameter(model, sid, is_constant=True)¶
Represents a parameter in SBML; to create a parameter use
model.add_parameter().Arguments:
modelThe model this parameter is in.
sidThis parameter’s SId.
- initial_value()¶
- Returns a
myokit.Expressionfor this quantity’s initial value, or
Noneif not set.
- Returns a
- is_constant()¶
Returns
Trueif this parameter is constant, elseFalse.
- is_literal()¶
Returns
Trueif this parameter is a literal value.
- is_rate()¶
Returns
Trueif this quantity’s value is defined through a rate, elseFalse.
- set_initial_value(value)¶
Sets a
myokit.Expressionfor this quantity’s initial value.
- set_units(units)¶
Sets this parameters units to the given
units.
- set_value(value, is_rate=False)¶
Sets a
myokit.Expressionfor this quantity’s value.Arguments:
valueAn expression. The values of any
myokit.Nameobjects in the expression must be either subclasses ofmyokit.formats.sbml.api.Quantityor ofmyokit.formats.sbml.api.CSymbolVariable.rateSet to
Trueif the expression gives the rate of change of this variable.
- sid()¶
Returns this parameter’s sid.
- units()¶
Returns the units this parameter is in, or
Noneif not set.
- value()¶
Returns a
myokit.Expressionfor this quantity’s value, orNoneif not set.
- class myokit.formats.sbml.Quantity¶
Base class for anything that has a numerical value in an SBML model, and can be set by rules, reactions, or initial assignments.
- initial_value()¶
- Returns a
myokit.Expressionfor this quantity’s initial value, or
Noneif not set.
- Returns a
- is_rate()¶
Returns
Trueif this quantity’s value is defined through a rate, elseFalse.
- set_initial_value(value)¶
Sets a
myokit.Expressionfor this quantity’s initial value.
- set_value(value, is_rate=False)¶
Sets a
myokit.Expressionfor this quantity’s value.Arguments:
valueAn expression. The values of any
myokit.Nameobjects in the expression must be either subclasses ofmyokit.formats.sbml.api.Quantityor ofmyokit.formats.sbml.api.CSymbolVariable.rateSet to
Trueif the expression gives the rate of change of this variable.
- value()¶
Returns a
myokit.Expressionfor this quantity’s value, orNoneif not set.
- class myokit.formats.sbml.Reaction(model, sid)¶
Represents an SBML reaction; to create a reaction use
Model.add_reaction().Arguments:
modelThe model this reaction is in.
sidThis reaction’s SId.
- add_modifier(species, sid=None)¶
Adds a modifier to this reaction and returns the created object.
- add_product(species, sid=None)¶
Adds a reaction product to this reaction and returns the created object.
- add_reactant(species, sid=None)¶
Adds a reactant to this reaction and returns the created object.
- kinetic_law()¶
Returns the kinetic law set for this reaction, or
Noneif not set.
- modifiers()¶
Returns the list of modifiers used by this reaction (as
SpeciesReferenceobjects).
- products()¶
Returns the list of products created by this reaction (as
SpeciesReferenceobjects).
- reactants()¶
Returns the list of reactions used by this reaction (as
SpeciesReferenceobjects).
- set_kinetic_law(expression)¶
Sets this reaction’s kinetic law (as a
myokit.Expression).
- sid()¶
Returns this reaction’s sid.
- class myokit.formats.sbml.SBMLError¶
Raised if something goes wrong when working with an SBML model.
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- class myokit.formats.sbml.Species(compartment, sid, is_amount, is_constant, is_boundary)¶
Represents an SBML species; to create a species use
Compartment.add_species().Arguments:
compartmentThe
Compartmentthat this species is in.sidThis species’s SId.
is_amountWhether this species value is represented as an amount (if false, it is represented as a concentration, which depends on the size of the compartment it is in).
is_constantWhether or not this species is constant.
is_boundaryWhether or not this species is at the boundary of a reaction.
- compartment()¶
Returns the
Compartmentthat this species is in.
- conversion_factor()¶
Returns the
Parameteracting as conversion factor for this species, or the model default if not set (andNoneif that isn’t set either).When calculating the rate of change of the species, multiplying by this factor converts from the species units to “number of reaction events”.
- initial_value()¶
Returns a
myokit.Expression(or None) for this species’ initial value, and a boolean indicating whether initial value is provided in amount (True) or in concentration (False).
- is_amount()¶
Returns
Trueonly if this species is defined as an amount (not a concentration).
- is_boundary()¶
Returns
Trueonly if this species is at a reaction boundary.
- is_constant()¶
Returns
Trueonly if this species is constant.
- is_rate()¶
Returns
Trueif this quantity’s value is defined through a rate, elseFalse.
- set_conversion_factor(factor)¶
Sets a
Parameteras conversion factor for this species, seeconversion_factor().
- set_initial_value(value, in_amount=None)¶
Sets a
myokit.Expressionfor this species’ initial value.in_amount is a boolean that indicates whether the initial value is measured in amount (True) or concentration (False). If set to None value is treated to have the same units as the species.
- set_substance_units(units)¶
Sets the units this species amount (not concentration) is in.
- set_value(value, is_rate=False)¶
Sets a
myokit.Expressionfor this quantity’s value.Arguments:
valueAn expression. The values of any
myokit.Nameobjects in the expression must be either subclasses ofmyokit.formats.sbml.api.Quantityor ofmyokit.formats.sbml.api.CSymbolVariable.rateSet to
Trueif the expression gives the rate of change of this variable.
- sid()¶
Returns this species’s sid.
- substance_units()¶
Returns the units an amount of this species (not a concentration) is in, or the model default if not set.
- value()¶
Returns a
myokit.Expressionfor this quantity’s value, orNoneif not set.
- class myokit.formats.sbml.SpeciesReference(species, sid=None)¶
Represents a reference to a reactant or product species in an SBML reaction.
A species reference acts as a
Quantity, where the value represents the species’ stoichiometry.- initial_value()¶
- Returns a
myokit.Expressionfor this quantity’s initial value, or
Noneif not set.
- Returns a
- is_rate()¶
Returns
Trueif this quantity’s value is defined through a rate, elseFalse.
- set_initial_value(value)¶
Sets a
myokit.Expressionfor this quantity’s initial value.
- set_value(value, is_rate=False)¶
Sets a
myokit.Expressionfor this quantity’s value.Arguments:
valueAn expression. The values of any
myokit.Nameobjects in the expression must be either subclasses ofmyokit.formats.sbml.api.Quantityor ofmyokit.formats.sbml.api.CSymbolVariable.rateSet to
Trueif the expression gives the rate of change of this variable.
- sid()¶
Returns this species reference’s SId, or
Noneif not set.
- species()¶
Returns the species this object refers to.
- value()¶
Returns a
myokit.Expressionfor this quantity’s value, orNoneif not set.
SBML Parsing¶
- class myokit.formats.sbml.SBMLParser¶
Parses SBML models, creating an SBML Model structure that can be converted to a
myokit.Modelobject.Support notes:
SBML older than Level 2 version 1 is unlikely to work.
Algebraic rules are not supported.
Constraints are not supported.
Events are not supported.
Function definitions are not supported.
Local parameters in reactions are not supported.
Units “celsius” are not supported.
Since SBML does not support units in equations, variable units will be set, but RHS units will not.
- parse(element)¶
Parses an SBML document rooted in the given
ElementTreeelement and returns amyokit.Model.
- parse_file(path)¶
Parses the SBML file at
pathand returns amyokit.Model.
- parse_string(text)¶
Parses the SBML XML in the string
textand returns amyokit.Model.
- class myokit.formats.sbml.SBMLParsingError(message, element=None)¶
Thrown if an error occurs when parsing SBML.
The argument
elementcan be used to pass in an element that caused the error.
SBML Writing¶
- myokit.formats.sbml.write_string(model: Model) str¶
Writes an SBML model to a string and returns it.
- class myokit.formats.sbml.SBMLWriter¶
Writes SBML documents