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

Unit

Manage units via this implementation of the SBML Unit specifications.

UnitDefinition

Manage units via implementation of SBML UnitDefinition specifications.

Functions

print_defined_unit_values([value])

Print the pre-defined unit quantities in the units submodule.

Attributes

SBML_BASE_UNIT_KINDS_DICT

Contains SBML base units and their int values.

SI_PREFIXES_DICT

Contains SI unit prefixes and scale values.

PREDEFINED_UNITS_DICT

Contains pre-built Units.

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 scale[source]

Return the scale of the Unit.

Parameters

scale (int or str) – An integer representing the scale of the unit, or a string from the pre-defined SI prefixes. Not case sensitive.

property multiplier[source]

Get or set the multiplier of the Unit.

Parameters

multiplier (float) – A numerical value representing a multiplier for the unit.

__str__()[source]

Override of default str implementation.

Warning

This method is intended for internal use only.

__repr__()[source]

Override of default repr() implementation.

Warning

This method is intended for internal use only.

mass.core.units.PREDEFINED_UNITS_DICT[source]

Contains pre-built Units.

Type

DictWithID

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
  • id (str) – The identifier to associate with the unit definition

  • name (str) – A human readable name for the unit definition.

list_of_units

A list containing Units that are needed to define the UnitDefinition, or a string that corresponds with the pre-defined units. Invalid units are ignored.

Type

list

create_unit(kind, exponent=1, scale=0, multiplier=1)[source]

Create a Unit and add it to the UnitDefinition.

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 Units to the list_of_units.

Parameters

new_units (list) – A list of Units and the string identifiers of pre-built units to add to the list_of_units

remove_units(units_to_remove)[source]

Remove Units from the list_of_units.

Parameters

units_to_remove (list) – A list of Units and/or the string corresponding to the unit Unit.kind to remove from the list_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.

__repr__()[source]

Override of default repr() implementation.

Warning

This method is intended for internal use only.

__iter__()[source]

Override of default iter() implementation.

Warning

This method is intended for internal use only.

mass.core.units.print_defined_unit_values(value='Units')[source]

Print the pre-defined unit quantities in the units submodule.

Parameters

value (str) –

A string representing which pre-defined values to display. Must be one of the following:

  • "Scales"

  • "BaseUnitKinds"

  • "Units"

  • "all"

Default is "Units" to display all pre-defined Units.