Skip to content

units

Conversion of CellML units to SBML unit definitions.

The standard units of CellML (second, metre, kilogram, gram, mole, litre, dimensionless, ampere, kelvin, ...) are all unit kinds of SBML level 3 and are used by name. A custom Units becomes a UnitDefinition whose units reference base kinds only: a reference to another custom Units is expanded recursively.

UnitsConversionError

Bases: ValueError

CellML units cannot be converted to SBML.

BaseUnit dataclass

BaseUnit(kind, exponent, scale, multiplier)

One unit of an SBML unit definition: (multiplier * 10^scale * kind)^exponent.

prefix_scale

prefix_scale(prefix)

Scale of a CellML unit prefix.

Parameters:

Name Type Description Default
prefix str

SI prefix name (milli), an integer string (-3) or empty.

required

Returns:

Type Description
int

The power of ten.

Raises:

Type Description
UnitsConversionError

if the prefix is unknown.

expand_units

expand_units(units, model)

Expand CellML units into SBML base units.

A CellML unit stands for multiplier * (10^prefix * reference)^exponent, an SBML unit for (multiplier * 10^scale * kind)^exponent: the prefix becomes the scale and the multiplier its root multiplier^(1/exponent). A unit referencing custom units is expanded recursively, every resulting exponent multiplied by the outer exponent and the outer factor multiplier * 10^(prefix * exponent) folded into the first resulting unit. A factor which is left, e.g. of a unit with the exponent 0, becomes a dimensionless unit with that multiplier.

New base units (custom units without any unit) have no SBML counterpart and are dropped with a warning, except for item.

Parameters:

Name Type Description Default
units Any

libcellml units.

required
model Model

model the units belong to, resolves references to custom units.

required

Returns:

Type Description
list[BaseUnit]

The base units, empty for units without any unit (dimensionless).

Raises:

Type Description
UnitsConversionError

for an unknown reference or prefix.

add_units

add_units(model_cellml, model_sbml)

Add a unit definition for every custom units of a CellML model.

Parameters:

Name Type Description Default
model_cellml Model

CellML model.

required
model_sbml Model

SBML model the definitions are added to.

required

Returns:

Type Description
dict[str, str]

The SBML unit id by CellML units name, for unit_id.

unit_id

unit_id(units_name, unit_ids)

SBML unit id of a CellML units name.

Parameters:

Name Type Description Default
units_name str

name of the units of a variable.

required
unit_ids dict[str, str]

result of add_units.

required

Returns:

Type Description
str

The unit definition id for custom units, the name itself for standard units.