petab.v1.models.sbml_model

Functions for handling SBML models

Functions

antimony2sbml(ant_model)

Convert Antimony model to SBML.

sympify_sbml(sbml_obj)

Convert SBML math expression to sympy expression.

Classes

SbmlModel([sbml_model, sbml_reader, ...])

PEtab wrapper for SBML models

class petab.v1.models.sbml_model.SbmlModel(sbml_model: Model = None, sbml_reader: SBMLReader = None, sbml_document: SBMLDocument = None, model_id: str = None, rel_path: Path | str | None = None, base_path: str | Path | None = None)[source]

Bases: Model

PEtab wrapper for SBML models

static from_antimony(ant_model: str | Path, **kwargs) SbmlModel[source]

Create SBML model from an Antimony model.

Requires the antimony package (https://github.com/sys-bio/antimony).

Parameters:
  • ant_model – Antimony model as string or path to file. Strings are interpreted as Antimony model strings.

  • kwargs – Additional keyword arguments passed to SbmlModel.from_string().

static from_file(filepath_or_buffer, model_id: str = None, base_path: str | Path = None) SbmlModel[source]

Load the model from the given path/URL

Parameters:
  • filepath_or_buffer – Absolute or relative path/URL to the model file. If relative, it is interpreted relative to base_path, if given.

  • base_path – Base path for relative paths in the model file.

  • model_id – Model ID

Returns:

A Model instance holding the given model

static from_string(sbml_string, model_id: str = None) SbmlModel[source]

Create SBML model from an SBML string.

Parameters:
  • sbml_string – SBML model as string.

  • model_id – Model ID. Defaults to the SBML model ID.

get_free_parameter_ids_with_values() Iterable[tuple[str, float]][source]

Get free model parameters along with their values

Returns:

Iterator over tuples of (parameter_id, parameter_value)

get_parameter_ids() Iterable[str][source]

Get all parameter IDs from this model

Returns:

Iterator over model parameter IDs

get_parameter_ids_with_values() Iterable[tuple[str, float]][source]
get_parameter_value(id_: str) float[source]

Get a parameter value

Parameters:

id – ID of the parameter whose value is to be returned

Raises:

ValueError – If no parameter with the given ID exists

Returns:

The value of the given parameter as specified in the model

get_valid_ids_for_condition_table() Iterable[str][source]

Get IDs of all model entities that are allowed to occur as columns in the PEtab conditions table.

Returns:

Iterator over model entity IDs

get_valid_parameters_for_parameter_table() Iterable[str][source]

Get IDs of all parameters that are allowed to occur in the PEtab parameters table

Returns:

Iterator over parameter IDs

has_entity_with_id(entity_id) bool[source]

Check if there is a model entity with the given ID

Parameters:

entity_id – ID to check for

Returns:

True, if there is an entity with the given ID, False otherwise

is_state_variable(id_: str) bool[source]

Check whether the given ID corresponds to a model state variable

is_valid() bool[source]

Validate this model

Returns:

True if the model is valid, False if there are errors in this model

property model_id
symbol_allowed_in_observable_formula(id_: str) bool[source]

Check if the given ID is allowed to be used in observable and noise formulas

Returns:

True, if allowed, False otherwise

to_antimony() str[source]

Convert the SBML model to an Antimony string.

to_file(filename: str | Path | None = None) None[source]

Save the model to the given file

Parameters:

filename – Destination filename

to_sbml_str() str[source]

Convert the SBML model to an SBML/XML string.

type_id = 'sbml'