Unit

class openff.units.Unit(*args, **kwargs)

Bases: Unit

Methods

compare

compatible_units

format_babel

from_

Converts a numerical value or quantity to this unit

is_compatible_with

check if the other object is compatible

m_from

Converts a numerical value or quantity to this unit, then returns the magnitude of the converted value

Attributes

default_format

Default formatting string.

dimensionality

returns: dict -- Dimensionality of the PlainUnit, e.g.

dimensionless

Return True if the PlainUnit is dimensionless; False otherwise.

systems

compare(other, op) bool
compatible_units(*contexts)
default_format: str = ''

Default formatting string.

property dimensionality: UnitsContainer

returns: dict – Dimensionality of the PlainUnit, e.g. {length: 1, time: -1}

property dimensionless: bool

Return True if the PlainUnit is dimensionless; False otherwise.

format_babel(spec='', locale=None, **kwspec: Any) str
from_(value, strict=True, name='value')

Converts a numerical value or quantity to this unit

Parameters
  • value – a Quantity (or numerical value if strict=False) to convert

  • strict – boolean to indicate that only quantities are accepted (Default value = True)

  • name – descriptive name to use if an exception occurs (Default value = “value”)

Returns

type – The converted value as this unit

is_compatible_with(other: Any, *contexts: Union[str, Context], **ctx_kwargs: Any) bool

check if the other object is compatible

Parameters
  • other – The object to check. Treated as dimensionless if not a Quantity, PlainUnit or str.

  • *contexts (str or pint.Context) – Contexts to use in the transformation.

  • **ctx_kwargs – Values for the Context/s

Returns

bool

m_from(value, strict=True, name='value')

Converts a numerical value or quantity to this unit, then returns the magnitude of the converted value

Parameters
  • value – a Quantity (or numerical value if strict=False) to convert

  • strict – boolean to indicate that only quantities are accepted (Default value = True)

  • name – descriptive name to use if an exception occurs (Default value = “value”)

Returns

type – The magnitude of the converted value

property systems