amici.sbml_utils

SBML Utilities

This module provides helper functions for working with SBML.

Functions

add_assignment_rule(model, variable_id, formula)

Helper for adding an assignment rule to a SBML model.

add_compartment(model, compartment_id, *[, size])

Helper for adding a compartment to a SBML model.

add_inflow(model, species_id, rate, *[, ...])

rtype

libsbml.Reaction

add_parameter(model, parameter_id, *[, ...])

Helper for adding a parameter to a SBML model.

add_rate_rule(model, variable_id, formula[, ...])

Helper for adding a rate rule to a SBML model.

add_species(model, species_id, *[, ...])

Helper for adding a species to a SBML model.

create_sbml_model(model_id[, level, version])

Helper for creating an empty SBML model.

get_sbml_units(model, x)

Try to get the units for expression x.

mathml2sympy(mathml, *[, evaluate, locals, ...])

rtype

sympy.core.basic.Basic

pretty_xml(ugly_xml)

Prettifies an XML document (given as a string).

sbml_math_ast(expr, **kwargs)

Convert a SymPy expression to SBML math AST.

sbml_mathml(expr, *[, replace_time, pretty])

Prints a SymPy expression to a MathML expression parsable by libSBML.

set_sbml_math(obj, expr, **kwargs)

Set the math attribute of a SBML node using a SymPy expression.

Classes

MathMLSbmlPrinter([settings])

Prints a SymPy expression to a MathML expression parsable by libSBML.

Exceptions

SbmlAnnotationError

SbmlDuplicateComponentIdError

SbmlInvalidIdSyntax

SbmlMathError

SbmlMissingComponentIdError

class amici.sbml_utils.MathMLSbmlPrinter(settings=None)[source]

Prints a SymPy expression to a MathML expression parsable by libSBML.

Differences from sympy.MathMLContentPrinter: 1. underscores in symbol names are not converted to subscripts 2. symbols with name ‘time’ are converted to the SBML time symbol

__init__(settings=None)
apply_patch()
doprint(expr, *, pretty=False)[source]

Prints the expression as MathML.

Return type

str

emptyPrinter(expr)
mathml_tag(e)

Returns the MathML tag for an expression.

property order
printmethod: str = '_mathml_content'
restore_patch()
classmethod set_global_settings(**settings)

Set system-wide printing settings.

exception amici.sbml_utils.SbmlAnnotationError[source]
__init__(*args, **kwargs)
args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception amici.sbml_utils.SbmlDuplicateComponentIdError[source]
__init__(*args, **kwargs)
args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception amici.sbml_utils.SbmlInvalidIdSyntax[source]
__init__(*args, **kwargs)
args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception amici.sbml_utils.SbmlMathError[source]
__init__(*args, **kwargs)
args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception amici.sbml_utils.SbmlMissingComponentIdError[source]
__init__(*args, **kwargs)
args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

amici.sbml_utils.add_assignment_rule(model, variable_id, formula, rule_id=None)[source]

Helper for adding an assignment rule to a SBML model.

Parameters
  • model (libsbml.Model) – SBML model to which the assignment rule is to be added.

  • variable_id (typing.Union[str, sympy.core.symbol.Symbol]) – SBML ID of the quantity for which the assignment rule is to be added.

  • formula – Formula for the assignment rule (it will be sympified).

  • rule_id (typing.Optional[str]) – SBML ID of the new assignment rule. Defaults to ‘assignment_’ + variableId.

Return type

libsbml.AssignmentRule

Returns

The assignment rule as a libsbml.AssignmentRule object.

amici.sbml_utils.add_compartment(model, compartment_id, *, size=1.0)[source]

Helper for adding a compartment to a SBML model.

Parameters
  • model (libsbml.Model) – SBML model to which the compartment is to be added.

  • compartment_id (typing.Union[str, sympy.core.symbol.Symbol]) – SBML ID of the new compartment.

  • size (float) – Size of the new compartment. Defaults to 1.0.

Return type

libsbml.Species

Returns

The new compartment as a libsbml.Compartment object.

amici.sbml_utils.add_inflow(model, species_id, rate, *, reaction_id=None, reversible=False)[source]
Return type

libsbml.Reaction

amici.sbml_utils.add_parameter(model, parameter_id, *, name=False, value=None, units=None, constant=None)[source]

Helper for adding a parameter to a SBML model.

Parameters
Return type

libsbml.Parameter

Returns

The new parameter as a libsbml.Parameter object.

amici.sbml_utils.add_rate_rule(model, variable_id, formula, rule_id=None)[source]

Helper for adding a rate rule to a SBML model.

Parameters
  • model (libsbml.Model) – SBML model to which the rate rule is to be added.

  • variable_id (typing.Union[str, sympy.core.symbol.Symbol]) – SBML ID of the quantity for which the rate rule is to be added.

  • formula – Formula for the rate rule (it will be sympified).

  • rule_id (typing.Optional[str]) – SBML ID of the new rate rule. Defaults to ‘rate_’ + variableId.

Return type

libsbml.RateRule

Returns

The new rate rule as a libsbml.RateRule object.

amici.sbml_utils.add_species(model, species_id, *, compartment_id=None, name=False, initial_amount=0.0, units=None)[source]

Helper for adding a species to a SBML model.

Parameters
  • model (libsbml.Model) – SBML model to which the species is to be added.

  • species_id (typing.Union[str, sympy.core.symbol.Symbol]) – SBML ID of the new species.

  • compartment_id (typing.Optional[str]) – Compartment ID for the new species. If there is only one compartment it can be auto-selected.

  • initial_amount (float) – Initial amount of the new species.

  • units (typing.Optional[str]) – Units attribute for the new species.

Return type

libsbml.Species

Returns

The new species as a libsbml.Species object.

amici.sbml_utils.create_sbml_model(model_id, level=2, version=5)[source]

Helper for creating an empty SBML model.

Parameters
  • model_id (str) – SBML ID of the new model.

  • level (int) – Level of the new SBML document.

  • version (int) – Version of the new SBML document.

Return type

typing.Tuple[libsbml.SBMLDocument, libsbml.Model]

Returns

A tuple containing the newly created libsbml.SBMLDocument and libsbml.Model.

amici.sbml_utils.get_sbml_units(model, x)[source]

Try to get the units for expression x.

Parameters
Return type

typing.Optional[str]

Returns

A string if the units could be determined, otherwise None.

amici.sbml_utils.mathml2sympy(mathml, *, evaluate=False, locals=None, expression_type='mathml2sympy')[source]
Return type

sympy.core.basic.Basic

amici.sbml_utils.pretty_xml(ugly_xml)[source]

Prettifies an XML document (given as a string).

Return type

str

amici.sbml_utils.sbml_math_ast(expr, **kwargs)[source]

Convert a SymPy expression to SBML math AST.

Parameters
  • expr – expression to be converted (will be sympified).

  • kwargs – extra options for MathML conversion.

Return type

libsbml.ASTNode

amici.sbml_utils.sbml_mathml(expr, *, replace_time=False, pretty=False, **settings)[source]

Prints a SymPy expression to a MathML expression parsable by libSBML.

Parameters
  • expr – expression to be converted to MathML (will be sympified).

  • replace_time (bool) – replace the AMICI time symbol with the SBML time symbol.

  • pretty (bool) – prettify the resulting MathML.

Return type

str

amici.sbml_utils.set_sbml_math(obj, expr, **kwargs)[source]

Set the math attribute of a SBML node using a SymPy expression.

Parameters
  • obj (libsbml.SBase) – SBML node supporting setMath method.

  • expr – expression to which the math attribute of obj should be se to (will be sympified).

  • kwargs – extra options for MathML conversion.

Return type

None