Component¶
- class myokit.Component(model, name)¶
A model component, containing several
variables.Components should not be created directly, but only via
Model.add_component().Variables can be accessed using the
comp['var_name']syntax or through the iterator methods.Meta-data properties can be accessed via the property
meta, for examplemodel.meta['key']= 'value'.- add_alias(name, variable)¶
Adds an alias to this component: the alias
namewill be refer to theVariableobject given asvariable.Aliases can only be created for variables of other components.
- add_variable(name, unit=None, rhs=None, label=None, binding=None, initial_value=None)¶
Adds a child variable with the given
nameto thisVarOwner.Returns the newly created
myokit.Variableobject.If given, the
unit,rhs, and alabelorbindingwill also be set.If an
initial_valueis given the variable will be promoted to a state and its initial value will be set.
- add_variable_allow_renaming(name)¶
Attempts to add a child variable with the given name to this
VarOwner, but uses a different name if this causes any conflicts.The new variable’s name will be modified by appending _1, _2, etc. until the conflict is resolved.
This method can be used when symbolically manipulating a model in situations where the exact names are unimportant.
Returns the newly created
myokit.Variableobject.
- alias_for(variable)¶
Returns an alias for the
Variablevariable.Raises a
KeyErrorif no such alias is found.
- can_add_variable(name, variable_whitelist=None)¶
Returns
Trueif a variable can be added to thisVarOwnerunder the givenname.This method is automatically called by
add_variable()and move_variable(), there is no need to call it before using these methods.To ignore clashes with known variables, a list
variable_whitelistcan be passed in.
- code()¶
Returns this object in
mmtsyntax.
- count_equations(const=None, inter=None, state=None, bound=None, deep=False)¶
Returns the number of equations matching the given criteria. See
equations()for an explanation of the arguments.
- count_variables(const=None, inter=None, state=None, bound=None, deep=False)¶
Returns the number of variables matching the given criteria. See
variables()for an explanation of the arguments.
- equations(const=None, inter=None, state=None, bound=None, deep=False)¶
Creates and returns a filtered iterator over the equations of this object’s variables.
The returned values can be filtered using the following arguments:
const=True|False|NoneSet to
Trueto return only constants’ equations.Falseto exclude all constants and any other value to ignore this check.For a definition of “constant variable” see
variables().inter=True|False|NoneSet to
Trueto return only intermediary variables’ equations,Falseto exclude all intermediary variables and any other value to ignore this check.For a definition of “intermediary variable” see
variables().state=True|False|NoneSet to
Trueto return only state variables’ equations,Falseto exclude all state variables and any other value to ignore this check.bound=True|False|NoneSet to
Trueto return only bound variables’ equations,Falseto exclude all bound variables and any other value to ignore this check.deep=True|False(by default it’sFalse)Set to
Trueto include the equations of nested variables meeting all other criteria.
- get(name, class_filter=None)¶
Searches for a variable with the given
qnameand returns it.To return only objects of a certain class, pass it in as
class_filter.The qnames are specified relative to the
VarOwner. For example, in a model with a componentinaand a variableina.hwe expect the following results>>> import myokit >>> m = myokit.load_model('example') >>> c = m.get('ina') # Retrieves the component <ina> >>> h = c.get('h') # Retrieves the variable <ina.h> >>> x = c.get('ina.h') # Searches for <ina.ina.h>: KeyError! Traceback (most recent call last): File "<stdin>", line 1, in <module> KeyError: 'ina'
- has_equations(const=None, inter=None, state=None, bound=None, deep=False)¶
Returns True if there are any equations that can be returned by calling :meth:
equationswith the same arguments.
- has_variable(name)¶
Returns True if the given name corresponds to a variable in this object. Accepts both single names
xand qualified namesx.yas input.This function performs the same search as
variable, so in most cases it will be more efficient to callvariable()in a try-catch block rather than checking for existence explicitly.
- has_variables(const=None, inter=None, state=None, bound=None, deep=False)¶
Returns True if there are any variables that can be returned by calling :meth:
variableswith the same arguments.
- is_ancestor(obj)¶
Returns
Trueif this object is an ancestor of the givenModelPart`object.
- model()¶
Returns the
myokit.Modelthis object belongs to (if set).
- move_variable(variable, new_parent, new_name=None)¶
Moves the given variable to another
VarOwnernew_parent. In addition, this method can be used to rename variables (either with or without moving them).
- name()¶
Returns this object’s name.
- parent(kind=None)¶
Returns this object’s parent.
If the optional variable
kindis set, the method will scan until an instance of the requested type is found.
- qname(hide=None)¶
Returns this component’s
qname.A component’s
qnameis simply its name. No model name is prefixed.
- remove_variable(variable, recursive=False)¶
Removes the given variable from this
VarOwnerand from the model.If
recursiveisTrue, any child variables will be deleted as well.A
myokit.IntegrityErrorwill be raised if the variable cannot be removed because other variables depend on it. (Although dependencies from child variables will be ignored ifrecursiveis set toTrue).
- uname()¶
Returns a globally unique name for this object.
- validate()¶
Attempts to check component validity, raises errors if it isn’t.
- var(name)¶
Searches for the given variable and returns it if found. Accepts both single names
xand qualified namesx.yas input.
- variables(const=None, inter=None, state=None, bound=None, deep=False, sort=False)¶
Creates and returns a filtered iterator over the contained variables.
The returned values can be filtered using the following arguments:
const=True|False|NoneConstants are defined as variables that do not depend on state variables or derivatives. In other words, any variable whose value can be determined before starting an ODE solving routine.
Set to
Trueto return only constants,Falseto exclude all constants and any other value to ignore this check.inter=True|False|NoneIntermediary variables are those variables that are not constant but are not part of the state. In other words, intermediary variables are the variables that need to be calculated at every step of an ODE solving routine before calculating the ODE derivatives and updating the state.
Set to
Trueto return only intermediary variables,Falseto exclude all intermediary variables and any other value to ignore this check.state=True|False|NoneSet to True to return only state variables, False to exclude all state variables and any other value to ignore this check.
bound=True|False|NoneSet to True to return only variables bound to an external value, False to exclude all bound variables and any other value to forgo this check.
deep=True|False(by default it’sFalse)Set to True to return nested variables meeting all other criteria.
sort=True|False(by default it’sFalse)Set to True to return the variables in a consistent order. (Note that this does _not_ mean alphabetical sorting of all variables, just that the order is consistent between calls!)