sbmlmath¶
Conversion of CellML maths to libsbml ASTs.
The libcellml analyser gives every equation as a binary tree of
AnalyserEquationAst nodes with the variables resolved. ast_to_sbml walks
such a tree into a libsbml.ASTNode; the variable of integration becomes the
SBML time symbol, variables get their SBML id. mathml_to_sbml reads the
MathML of a reset with libsbml and remaps the ci names the same way.
The analyser AST has the values of the numbers but not their units.
NumberUnits reads them from the MathML of the components and finds the
equation of an analyser AST by its variables and numbers.
MathConversionError
¶
Bases: ValueError
A CellML expression cannot be converted to SBML.
NumberUnits
¶
Units of the numbers of the equations of a CellML model.
The equations are read from the MathML of the components. An analyser AST is matched with the equation which has the same variables and numbers in the same order; the analyser may have rearranged an equation, which is then found by its variables and numbers in any order and gives the units by the value of the numbers. An equation is handed out once, so equations which only differ in their units stay apart.
Read the numbers of all equations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Model
|
the (flattened) CellML model. |
required |
ids
|
VariableIds
|
SBML ids of the model. |
required |
unit_id
|
Callable[[str], str]
|
SBML unit id of a CellML units name. |
required |
units_of
¶
Units of the numbers of an equation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ast
|
Any
|
root of the analyser AST of the equation. |
required |
Returns:
| Type | Description |
|---|---|
_Units
|
The units of its numbers from the left to the right, for |
_Units
|
|
_Units
|
equation is not found (logged). |
variable_node
¶
AST node referencing a CellML variable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variable
|
Any
|
libcellml variable. |
required |
ids
|
VariableIds
|
SBML ids of the model. |
required |
Returns:
| Type | Description |
|---|---|
ASTNode
|
The |
ASTNode
|
with the SBML id. |
count_numbers
¶
Number of cn nodes of an analyser AST.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Any
|
|
required |
Returns:
| Type | Description |
|---|---|
int
|
How many units of |
ast_to_sbml
¶
Convert an analyser AST into a libsbml AST.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Any
|
|
required |
ids
|
VariableIds
|
SBML ids of the model. |
required |
units
|
_Units
|
SBML units of the numbers below |
None
|
Returns:
| Type | Description |
|---|---|
ASTNode
|
The libsbml AST. |
Raises:
| Type | Description |
|---|---|
MathConversionError
|
for a node type without SBML counterpart, e.g.
|
mathml_to_sbml
¶
Read CellML MathML with libsbml and remap the variable names.
Used for the maths of resets, which the analyser does not cover. Units on
numbers (cellml:units) become sbml:units.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mathml
|
str
|
complete |
required |
component_name
|
str
|
component the MathML belongs to, resolves the names. |
required |
ids
|
VariableIds
|
SBML ids of the model. |
required |
unit_id
|
Callable[[str], str] | None
|
SBML unit id of a CellML units name, the name itself when
|
None
|
Returns:
| Type | Description |
|---|---|
ASTNode
|
The libsbml AST. |
Raises:
| Type | Description |
|---|---|
MathConversionError
|
if the MathML does not parse or a name is unknown. |