sciml.formula¶
The math of SBML as sympy expressions for the network compiler and hybridization.
formula_expression, formula_symbols and evaluate_formula read a formula
with libsbml and sbmlmath, which make a symbol of every identifier, also of
beta, gamma, lambda, S or I, which sympify would read as the
functions and constants of sympy. expression_to_astnode and
expression_to_formula are the way back, from a sympy expression to the math
of SBML.
formula_expression
¶
Parse an L3 formula of SBML into a sympy expression.
Every identifier of the formula is a symbol of its name, also the
identifiers which are functions or constants of sympy (beta, gamma,
lambda, S, I). The time of the model is the symbol time. The
constant avogadro stays the csymbol of SBML, which is not an
identifier: formula_symbols does not list it and evaluate_formula
gives it its value. A logarithm with a base is a quotient of natural
logarithms, rem and quotient truncate as they do in SBML.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
formula
|
str
|
the formula, e.g. |
required |
Returns:
| Type | Description |
|---|---|
Basic
|
The expression. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the formula is empty, is not valid math (units of a number are not) or uses a function which is not a function of the MathML of SBML. |
formula_symbols
¶
Get the identifiers a formula uses.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
formula
|
str
|
the formula, an L3 formula of SBML. |
required |
Returns:
| Type | Description |
|---|---|
set[str]
|
The names of the symbols of the formula, |
set[str]
|
model. Constants like |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the formula is not valid math, see
|
evaluate_formula
¶
Evaluate an L3 formula of SBML on the values of its identifiers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
formula
|
str
|
the formula. |
required |
variables
|
Mapping[str, Any]
|
the value of every identifier of the formula, a number or an array. The values of identifiers the formula does not use are not used, but give the shape of the result. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The value of the formula: a float if all values are numbers, else an |
Any
|
array of the shape the values broadcast to, with |
Any
|
formula is not defined. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the formula is not valid math, see
|
expression_to_astnode
¶
Convert a sympy expression into the math of SBML.
The numbers of the expression carry no units, so the math is valid in
every level of SBML. The symbol time is the time of the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expression
|
Basic
|
the expression. |
required |
Returns:
| Type | Description |
|---|---|
ASTNode
|
The syntax tree of the MathML of the expression. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the expression uses a function the MathML of SBML does not have, e.g. the error function. |
expression_to_formula
¶
Write a sympy expression as an L3 formula of SBML.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expression
|
Basic
|
the expression. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The formula, which |
str
|
natural logarithm is |
str
|
formula of SBML. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the expression has no MathML of SBML, see
|