mass.core.units
Unit and UnitDefinition implementation based on SBML specifications.
The units
module contains the Unit
and
UnitDefinition
classes based on the implementation of units in
SBML.
Note that mass
does not support automatic unit tracking to ensure
unit consistency. Therefore, it is incumbent upon the user to maintain unit
consistency as they use the various mass
modules and functions.
To view valid units, use the print_defined_unit_values()
function.
Please send a PR if you want to add something to the pre-built
Unit
s.
Module Contents
Classes
Manage units via this implementation of the SBML Unit specifications. |
|
Manage units via implementation of SBML UnitDefinition specifications. |
Functions
|
Print the pre-defined unit quantities in the |
Attributes
Contains SBML base units and their |
|
Contains SI unit prefixes and scale values. |
|
Contains pre-built |
- mass.core.units.SBML_BASE_UNIT_KINDS_DICT[source]
Contains SBML base units and their
int
values.- Type
DictWithID
- mass.core.units.SI_PREFIXES_DICT[source]
Contains SI unit prefixes and scale values.
- Type
DictWithID
- class mass.core.units.Unit(kind, exponent, scale, multiplier)[source]
Manage units via this implementation of the SBML Unit specifications.
- Parameters
kind (str or int) – A string representing the SBML Level 3 recognized base unit or its corresponding SBML integer value as defined in
SBML_BASE_UNIT_KINDS_DICT
.exponent (int) – The unit exponent.
scale (int or str) – An integer representing the scale of the unit, or a string for one of the pre-defined SI scales in
SI_PREFIXES_DICT
.multiplier (float) – A number used to multiply the unit by a real-numbered factor, enabling units that are not necessarily a power-of-ten multiple.
- property kind[source]
Return the unit kind of the
Unit
.- Parameters
kind (str) – An SBML recognized unit kind as a string.
- property exponent[source]
Return the exponent of the
Unit
.- Parameters
exponent (int) – The exponent of the unit as an integer.
- property multiplier[source]
Get or set the multiplier of the
Unit
.- Parameters
multiplier (float) – A numerical value representing a multiplier for the unit.
- class mass.core.units.UnitDefinition(id=None, name='', list_of_units=None)[source]
Bases:
cobra.core.object.Object
Manage units via implementation of SBML UnitDefinition specifications.
- Parameters
- list_of_units
A list containing
Unit
s that are needed to define theUnitDefinition
, or a string that corresponds with the pre-defined units. Invalid units are ignored.- Type
- create_unit(kind, exponent=1, scale=0, multiplier=1)[source]
Create a
Unit
and add it to theUnitDefinition
.- Parameters
kind (str) – A string representing the SBML Level 3 recognized base unit.
exponent (int) – The exponent on the unit. Default is
1
.scale (int or str) – An integer representing the scale of the unit, or a string for one of the pre-defined scales. Default is
0.
multiplier (float) – A number used to multiply the unit by a real-numbered factor, enabling units that are not necessarily a power-of-ten multiple. Default is
1.
- add_units(new_units)[source]
Add
Unit
s to thelist_of_units
.- Parameters
new_units (list) – A list of
Unit
s and the string identifiers of pre-built units to add to thelist_of_units
- remove_units(units_to_remove)[source]
Remove
Unit
s from thelist_of_units
.- Parameters
units_to_remove (list) – A list of
Unit
s and/or the string corresponding to the unitUnit.kind
to remove from thelist_of_units
.
- _units_to_alter(units)[source]
Create a set of units to alter in the unit definition.
Warning
This method is intended for internal use only.