chemistry_tools.units

Functions for handling SI units.

Data:

SI_base_registry

Mapping of SI measurements to their units.

cm3

Square cenimetre

dimension_codes

Mapping of dimension names to symbols.

dm

Decimetre

dm3

Square decimetre

kilogray

Kilogray

kilojoule

Kilojoule

m3

Square metre

m_math_space

A medium mathematical space, `` ` / ``\u205f.

micromole

Micromole

molal

Molal (moles per kilogram)

nanomolar

Nanomolar

nanomole

Nanomole

per100eV

Per 100 electronVolts.

perMolar_perSecond

Per Molar per second.

umol_per_J

Micro mole per joule.

Functions:

allclose(a, b[, rtol, atol])

Analogous to numpy.allclose().

as_latex(quant)

Returns the LaTeX reperesentation of the unit of a quantity.

compare_equality(a, b)

Returns True if two arguments are equal.

format_si_units(value, *units)

Returns the given value, followed by the given units, and separated by a medium mathematical space.

format_string(value[, precision, tex])

Formats a scalar with unit as two strings.

SI_base_registry = {'amount': UnitSubstance('mole', 'mol'), 'current': UnitCurrent('ampere', 'A'), 'length': UnitLength('meter', 'm'), 'luminous_intensity': UnitLuminousIntensity('candela', 'cd'), 'mass': UnitMass('kilogram', 'kg'), 'temperature': UnitTemperature('Kelvin', 'K'), 'time': UnitTime('second', 's')}

Type:    dict

Mapping of SI measurements to their units.

allclose(a, b, rtol=1e-08, atol=None)[source]

Analogous to numpy.allclose().

Parameters
  • a

  • b

  • rtol – The relative tolerance. Default 1e-08.

  • atol – The absolute tolerance. Default None.

Return type

bool

as_latex(quant)[source]

Returns the LaTeX reperesentation of the unit of a quantity.

Example:

>>> print(as_latex(1/quantities.kelvin))
\mathrm{\frac{1}{K}}
Return type

str

cm3 = array(1.) * cm**3

Type:    Quantity

Square cenimetre

compare_equality(a, b)[source]

Returns True if two arguments are equal.

Both arguments need to have the same dimensionality.

Examples:

>>> km, m = quantities.kilometre, quantities.metre
>>> compare_equality(3*km, 3)
False
>>> compare_equality(3*km, 3000*m)
True
Parameters
Return type

bool

dimension_codes = {'amount': 'N', 'current': 'I', 'length': 'L', 'mass': 'M', 'temperature': 'Θ', 'time': 'T'}

Type:    dict

Mapping of dimension names to symbols.

dm = UnitQuantity('decimetre', 0.1 * m)

Type:    UnitQuantity

Decimetre

dm3 = array(1.) * decimetre**3

Type:    Quantity

Square decimetre

format_si_units(value, *units)[source]

Returns the given value, followed by the given units, and separated by a medium mathematical space.

Parameters

New in version 0.4.0.

Return type

str

format_string(value, precision='%.5g', tex=False)[source]

Formats a scalar with unit as two strings.

Examples:

>>> print(' '.join(format_string(0.42*quantities.mol/decimetre**3)))
0.42 mol/decimetre**3
>>> print(' '.join(format_string(2/quantities.s, tex=True)))
2 \mathrm{\frac{1}{s}}
Parameters
  • value (Quantity) – Value with unit

  • precision (str) – Default '%.5g'.

  • tex (bool) – Whether the string should be formatted for LaTeX. Default False.

Return type

Tuple[str, str]

kilogray = UnitQuantity('kilogray', 1000.0 * Gy)

Type:    UnitQuantity

Kilogray

kilojoule = UnitQuantity('kilojoule', 1000.0 * J)

Type:    UnitQuantity

Kilojoule

m3 = array(1.) * m**3

Type:    Quantity

Square metre

m_math_space = '\u205f'

Type:    str

A medium mathematical space, `` ` / ``\u205f.

New in version 0.4.0.

micromole = UnitQuantity('micromole', 1e-06 * mol)

Type:    UnitQuantity

Micromole

molal = UnitQuantity('molal', 1.0 * mol/kg)

Type:    UnitQuantity

Molal (moles per kilogram)

nanomolar = UnitQuantity('nM', 1e-06 * mol/m**3)

Type:    UnitQuantity

Nanomolar

nanomole = UnitQuantity('nanomole', 1e-09 * mol)

Type:    UnitQuantity

Nanomole

per100eV = UnitQuantity('per_100_eV', 0.01 * 1/(N_A*eV))

Type:    UnitQuantity

Per 100 electronVolts.

perMolar_perSecond = array(1.) * 1/(s*M)

Type:    Quantity

Per Molar per second.

umol_per_J = array(1.) * umol/J

Type:    Quantity

Micro mole per joule.