Reading CellML¶
To start using cellmlmanip, load a model using
- cellmlmanip.load_model(path, unit_store=None)[source]¶
Parses a CellML file and returns a
cellmlmanip.model.Model.- Parameters:
unit_store – Optional
cellmlmanip.units.UnitStoreinstance; if given the model will share the underlying registry so that conversions between model units and those from the provided store work.
This uses the cellmlmanip.parser.Parser class.
Most users won’t need to worry about this, but its documentation is included below for completeness.
This cellmlmanip.parser module contains the CellML parser and related classes. It reads a CellML model and
stores model information in the cellmlmanip.model.Model class. MathML equations are translated to Sympy. RDF
is handled by RDFLib.
- cellmlmanip.parser.with_ns(ns_enum, name)[source]¶
Returns an ElementTree-friendly name with namespace in brackets
- class cellmlmanip.parser.Parser(filepath)[source]¶
Bases:
objectHandles parsing of CellML files
- parse(unit_store=None)[source]¶
The main method that reads the XML file and extracts the relevant parts of the CellML model definition.
- Parameters:
unit_store – Optional
cellmlmanip.units.UnitStoreinstance; if given the model will share the underlying registry so that conversions between model units and those from the provided store work.- Returns:
a
Modelholding CellML model definition, reading for manipulation.
- transform_constants()[source]¶
Standardise handling of ‘constants’.
Once this has been called, the only variables with an initial_value attribute will be state variables, and the initial value will do what it implies - hold the value the state variable should take at t=0.
Non state variables with an initial value are treated as constants. For consistent processing later on we add equations defining them, and remove the initial_value attribute.
- class cellmlmanip.parser.Transpiler(symbol_generator=None, number_generator=None)[source]¶
Bases:
objectHandles conversion of MathmL to Sympy exprerssions.
- Parameters:
symbol_generator – An optional method to create expressions for symbols. Must have signature
f(name) -> sympy.Basic.number_generator – An optional method to create expressions for numbers with units. Must have signature
f(value, unit) -> sympy.Basic.
- static set_mathml_handler(mathml_operator, operator_class)[source]¶
Change how the transpiler handles a given mathml_operator.
- Parameters:
mathml_operator – The name of a MathML operator e.g. ‘exp’, ‘true’ etc.
operator_class – A class that can handle the given operator e.g.
sympy.exp, or a function that creates and returns a sympy object given the operands as arguments.
- parse_string(xml_string)[source]¶
Reads MathML content from a string and returns equivalent SymPy expressions. :return: A list of SymPy expressions.