Skip to content

sbml_math

The math of SBML as sympy expressions and numpy functions.

The MathML of SBML is read with sbmlmath into sympy expressions, with the meaning SBML gives it (MathMLParser): rem and quotient truncate, a number in e-notation is the double of its text, and a logarithm with a base is a quotient of natural logarithms (log_quotient). sbmlsim.sciml.formula reads the formulas of the networks with it.

compile_math compiles the math of the events of a model, which the executor evaluates when a change of a simulation makes the trigger of an event true (sbmlsim.model.symbols.EventSymbols, sbmlsim.simulator.executor): every function of the MathML of SBML (#299), the function definitions of the model are expanded when its symbols are read. rateOf and delay have no value at a single time, a math with them is no math compile_math compiles. The values are doubles as roadrunner computes them: a division by zero is infinite, the root of a negative number is not a number, and every number of the math is the double of its text.

MathMLParser

Bases: SBMLMathMLParser

The MathML parser of sbmlmath with the meaning SBML gives the math.

sbmlmath reads rem and quotient with the modulo of sympy, which rounds towards negative infinity. The rem of SBML is the remainder of the truncated division, rem(-7, 3) is -1, and the quotient is the truncated quotient, quotient(-7, 3) is -2. A number in e-notation, 1.1 <sep/> -5, is the double of 1.1e-5, which sbmlmath computes as 1.1 * 10**-5, a different double.

handle_apply

handle_apply(element)

Parse an apply, rem and quotient truncate.

Parameters:

Name Type Description Default
element Any

the apply element.

required

Returns:

Type Description
Expr

The expression.

handle_cn

handle_cn(element)

Parse a number, one in e-notation as the double of its text.

Parameters:

Name Type Description Default
element Any

the cn element.

required

Returns:

Type Description
Expr

The number.

log_quotient

log_quotient(expression)

Write the logarithms with a base as quotients of natural logarithms.

sbmlmath reads log(x), log10(x) and log(b, x) as log(x, b), which neither the printer of MathML nor lambdify at full precision handle.

Parameters:

Name Type Description Default
expression Basic

the expression.

required

Returns:

Type Description
Basic

The expression, in which log(x, b) is log(x) / log(b).

log10_of_quotient

log10_of_quotient(expression)

Write a quotient with the logarithm of 10 as log10.

log(1000) / log(10) is 2.9999999999999996, log10(1000) is 3.

Parameters:

Name Type Description Default
expression Basic

the expression, in which a base is a quotient of logarithms, see log_quotient.

required

Returns:

Type Description
Basic

The expression, in which log(x) / log(10) is log10(x), which a

Basic

function of lambdify evaluates with numpy.log10.

math_formula

math_formula(mathml)

Write the MathML of SBML as an L3 formula, e.g. for a message.

Parameters:

Name Type Description Default
mathml str

the MathML.

required

Returns:

Type Description
str

The formula, the MathML itself if libsbml does not read it.

math_function cached

math_function(mathml)

Get the numpy function of the MathML of SBML and the names of its arguments.

The function computes the operations of the math as they are written, q / 3 and not (1/3) * q, and every number is the double of its text. It computes on the values it is given: on numbers python raises for a complex value, an overflow or a division by zero, on arrays numpy gives nan and inf; compile_math gives doubles, as roadrunner computes them.

Parameters:

Name Type Description Default
mathml str

the MathML; the csymbol of the time is time, the Avogadro constant AVOGADRO. The units of its numbers are ignored.

required

Returns:

Type Description
tuple[str, ...]

The names of the identifiers, sorted, and the function of their

Callable[..., Any]

values, in this order.

Raises:

Type Description
ValueError

if the math is not read or uses a function which has no value at a time: rateOf, delay or a function the MathML of SBML does not have.

compile_math cached

compile_math(mathml)

Compile the MathML of SBML whose identifiers are selections, see the module.

Parameters:

Name Type Description Default
mathml str

the MathML, its identifiers selections of roadrunner, e.g. [S] for the concentration of a species, see math_function.

required

Returns:

Type Description
CompiledFormula

The compiled math, its formula the L3 formula of the math. Its

CompiledFormula

values are doubles, also where numpy would warn or python raise.

Raises:

Type Description
ValueError

if the math is not read or uses a function which has no value at a time, see math_function.