Skip to content

cellml2sbml

Conversion of CellML 2.0 models to SBML level 3 version 2.

The libcellml analyser classifies the variables and equations of the model and resolves the connections between components; the converter renders its model as SBML: every variable is a parameter, states get rate rules, algebraic variables assignment rules, computed constants initial assignments, and the resets of the components become events. CellML units become unit definitions. There are no compartments, species or reactions.

The metadata of an SBML model which sbml2cellml wrote next to the CellML file (sbml2cellml.metadata) comes back on the parameters, the unit definitions and the model.

CellML2SBMLConversionError

Bases: ValueError

The CellML model cannot be converted.

convert_cellml2sbml

convert_cellml2sbml(
    cellml_path,
    sbml_path=None,
    validate=True,
    metadata=True,
)

Convert a CellML file to an SBML document.

Parameters:

Name Type Description Default
cellml_path Path

path of the CellML file; imports are resolved relative to it.

required
sbml_path Path | None

path the SBML is written to, not written if None.

None
validate bool

check the consistency of the document with libsbml and raise if it has errors.

True
metadata bool

read the metadata from the RDF file next to the CellML file (<stem>.rdf, see sbml2cellml.metadata) when it exists.

True

Returns:

Type Description
SBMLDocument

The SBML document.

Raises:

Type Description
CellML2SBMLConversionError

if the file does not exist, the imports cannot be resolved, the analyser reports errors, the model is not an ODE or algebraic model, or a construct is not supported.

CellMLValidationError

if the file cannot be parsed.

SBMLValidationError

if validate is set and the document has errors.

build_document

build_document(model, analyser_model, records=None)

Build the SBML document of an analysed CellML model.

Parameters:

Name Type Description Default
model Model

the (flattened) CellML model.

required
analyser_model Any

its analyser model without errors.

required
records dict[str, Record] | None

metadata by the id of a CellML element (sbml2cellml.metadata.read_metadata), none when None.

None

Returns:

Type Description
SBMLDocument

The SBML document, not validated.

Raises:

Type Description
MathConversionError

for a construct which cannot be converted; convert_cellml2sbml wraps it.

UnitsConversionError

for units which cannot be converted; convert_cellml2sbml wraps it.