Skip to content

rust

The reader and the converter in rust (crates/, issue #68).

The rust crates convert a CellML document to SBML and an SBML document to CellML without libcellml and without libsbml, which the module sbml2cellml._rust (crates/python, built into the wheel by maturin) makes available in the process. It is the default engine of cellml2sbml.convert_cellml2sbml and of sbml2cellml.convert_sbml2cellml: the conversion is faster than the one through libcellml by two orders of magnitude, and it is the code which runs in a browser next to sbmlsim-core.

What the rust converter does not do is left to libcellml and libsbml by the caller: the imports of a CellML document (has_imports, which cellml2sbml flattens with libcellml before it hands the document over), the submodels of a hierarchical SBML model (which sbml2cellml flattens with libsbml) and the hierarchical conversion to the comp package of SBML. The metadata of the elements is written and applied for both engines: a conversion gives the SBML element of every CellML element which stands for one (Origin, Mapping), which the python package turns into the RDF of the CellML model and back onto the elements of the SBML model.

RustError

Bases: ValueError

The rust reader or the rust converter refused a document.

convert_cellml_to_sbml

convert_cellml_to_sbml(text)

Convert a CellML document to SBML level 3 version 2.

Parameters:

Name Type Description Default
text str

the CellML document, with its imports resolved.

required

Returns:

Type Description
str

The SBML document, the warnings of the conversion and the SBML

list[str]

element of every CellML element with an id (Mapping), which the

list[Mapping]

metadata of the conversion needs.

Raises:

Type Description
RustError

if the document cannot be read or converted.

convert_sbml_to_cellml

convert_sbml_to_cellml(text, name)

Convert an SBML document to CellML 2.0.

Parameters:

Name Type Description Default
text str

the SBML document of any level and version, with the submodels of a hierarchical model flattened.

required
name str

the name of the CellML model when the SBML model has no id.

required

Returns:

Type Description
str

The CellML document, the warnings of the conversion and the SBML

list[str]

element of every element of the CellML model which stands for one

list[Origin]

(Origin), which the metadata of the conversion needs.

Raises:

Type Description
RustError

if the document cannot be read or converted.

cellml_version

cellml_version(text)

The version of CellML a document is written in.

Parameters:

Name Type Description Default
text str

the CellML document.

required

Returns:

Type Description
str

"2.0", "1.1" or "1.0".

Raises:

Type Description
RustError

if the document is no CellML model.

has_imports

has_imports(text)

Whether a document imports a component or units.

Parameters:

Name Type Description Default
text str

the CellML document.

required

Returns:

Type Description
bool

True if the document has an import, which the conversion needs

bool

resolved.

Raises:

Type Description
RustError

if the document is no CellML model.