Quantity

class openff.units.Quantity(value: MagnitudeT, units: UnitLike | None = None)
class openff.units.Quantity(value: str, units: UnitLike | None = None)
class openff.units.Quantity(value: Sequence[ScalarT], units: UnitLike | None = None)
class openff.units.Quantity(value: PlainQuantity[Any], units: UnitLike | None = None)

Bases: Quantity

Methods

check

Return true if the quantity's dimension matches passed dimension.

clip

compare

compatible_units

compute

Compute the Dask array wrapped by pint.PlainQuantity.

dot

Dot product of two arrays.

fill

format_babel

from_list

Transforms a list of Quantities into an numpy.array quantity.

from_sequence

Transforms a sequence of Quantities into an numpy.array quantity.

from_tuple

is_compatible_with

check if the other object is compatible

ito

Inplace rescale to different units.

ito_base_units

Return PlainQuantity rescaled to plain units.

ito_preferred

Return Quantity converted to a unit composed of the preferred units.

ito_reduced_units

Return PlainQuantity scaled in place to reduced units, i.e. one unit per dimension.

ito_root_units

Return PlainQuantity rescaled to root units.

m_as

PlainQuantity's magnitude expressed in particular units.

persist

Persist the Dask Array wrapped by pint.PlainQuantity.

plus_minus

prod

Return the product of quantity elements over a given axis

put

searchsorted

to

Return PlainQuantity rescaled to different units.

to_base_units

Return PlainQuantity rescaled to plain units.

to_compact

"Return PlainQuantity rescaled to compact, human-readable units.

to_openmm

Convert the quantity to an openmm.unit.Quantity.

to_preferred

Return Quantity converted to a unit composed of the preferred units.

to_reduced_units

Return PlainQuantity scaled in place to reduced units, i.e. one unit per dimension.

to_root_units

Return PlainQuantity rescaled to root units.

to_timedelta

to_tuple

tolist

unit_items

A view of the unit items.

visualize

Produce a visual representation of the Dask graph.

Attributes

T

UnitsContainer

dimensionality

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

dimensionless

dtype

flat

force_ndarray

force_ndarray_like

imag

m

PlainQuantity's magnitude.

magnitude

PlainQuantity's magnitude.

ndim

real

shape

u

PlainQuantity's units.

unitless

units

PlainQuantity's units.

property T
property UnitsContainer: Callable[..., UnitsContainerT]
check(dimension: UnitLike) bool

Return true if the quantity’s dimension matches passed dimension.

clip(min=None, max=None, out=None, **kwargs)
compare(*args, **kwargs)
compatible_units(*contexts)
compute(**kwargs)

Compute the Dask array wrapped by pint.PlainQuantity.

Parameters

**kwargs (dict) – Any keyword arguments to pass to dask.compute.

Returns

pint.PlainQuantity – A pint.PlainQuantity wrapped numpy array.

default_format: str
property dimensionality: UnitsContainerT

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

property dimensionless: bool
dot(b)

Dot product of two arrays.

Wraps np.dot().

property dtype
fill(value) None
property flat
property force_ndarray: bool
property force_ndarray_like: bool
format_babel(spec: str = '', **kwspec: Any) str
classmethod from_list(quant_list: list[PlainQuantity[MagnitudeT]], units=None) PlainQuantity[MagnitudeT]

Transforms a list of Quantities into an numpy.array quantity. If no units are specified, the unit of the first element will be used. Same as from_sequence.

If units is not specified and list is empty, the unit cannot be determined and a ValueError is raised.

Parameters
  • quant_list (list of pint.PlainQuantity) – list of pint.PlainQuantity

  • units (UnitsContainer, str or pint.PlainQuantity) – units of the physical quantity to be created (Default value = None)

Returns

pint.PlainQuantity

classmethod from_sequence(seq: Sequence[PlainQuantity[MagnitudeT]], units=None) PlainQuantity[MagnitudeT]

Transforms a sequence of Quantities into an numpy.array quantity. If no units are specified, the unit of the first element will be used.

If units is not specified and sequence is empty, the unit cannot be determined and a ValueError is raised.

Parameters
  • seq (sequence of pint.PlainQuantity) – sequence of pint.PlainQuantity

  • units (UnitsContainer, str or pint.PlainQuantity) – units of the physical quantity to be created (Default value = None)

Returns

pint.PlainQuantity

classmethod from_tuple(tup)
property imag: pint.facets.numpy.quantity.NumpyQuantity
is_compatible_with(other: Any, *contexts: 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 PlainQuantity, Unit or str.

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

  • **ctx_kwargs – Values for the Context/s

Returns

bool

ito(other: QuantityOrUnitLike | None = None, *contexts, **ctx_kwargs) None

Inplace rescale to different units.

Parameters
  • other (pint.PlainQuantity, str or dict) – Destination units. (Default value = None)

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

  • **ctx_kwargs – Values for the Context/s

ito_base_units() None

Return PlainQuantity rescaled to plain units.

ito_preferred(preferred_units: list[UnitLike] | None = None) PlainQuantity

Return Quantity converted to a unit composed of the preferred units.

Examples

>>> import pint
>>> ureg = pint.UnitRegistry()
>>> (1*ureg.acre).to_preferred([ureg.meters])
<Quantity(4046.87261, 'meter ** 2')>
>>> (1*(ureg.force_pound*ureg.m)).to_preferred([ureg.W])
<Quantity(4.44822162, 'watt * second')>
ito_reduced_units() None

Return PlainQuantity scaled in place to reduced units, i.e. one unit per dimension. This will not reduce compound units (e.g., ‘J/kg’ will not be reduced to m**2/s**2), nor can it make use of contexts at this time.

ito_root_units() None

Return PlainQuantity rescaled to root units.

property m: pint.facets.plain.quantity.MagnitudeT

PlainQuantity’s magnitude. Short form for magnitude

m_as(units) MagnitudeT

PlainQuantity’s magnitude expressed in particular units.

Parameters

units (pint.PlainQuantity, str or dict) – destination units

property magnitude: pint.facets.plain.quantity.MagnitudeT

PlainQuantity’s magnitude. Long form for m

property ndim: int
persist(**kwargs)

Persist the Dask Array wrapped by pint.PlainQuantity.

Parameters

**kwargs (dict) – Any keyword arguments to pass to dask.persist.

Returns

pint.PlainQuantity – A pint.PlainQuantity wrapped Dask array.

plus_minus(error, relative=False)
prod(axis=None, dtype=None, out=None, keepdims=np._NoValue, initial=np._NoValue, where=np._NoValue)

Return the product of quantity elements over a given axis

Wraps np.prod().

put(indices, values, mode='raise') None
property real: pint.facets.numpy.quantity.NumpyQuantity
searchsorted(v, side='left', sorter=None)
property shape: tuple[int, ...]
to(other: QuantityOrUnitLike | None = None, *contexts, **ctx_kwargs) PlainQuantity

Return PlainQuantity rescaled to different units.

Parameters
  • other (pint.PlainQuantity, str or dict) – destination units. (Default value = None)

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

  • **ctx_kwargs – Values for the Context/s

Returns

pint.PlainQuantity

to_base_units() PlainQuantity[MagnitudeT]

Return PlainQuantity rescaled to plain units.

to_compact(unit: UnitsContainer | None = None) PlainQuantity

“Return PlainQuantity rescaled to compact, human-readable units.

To get output in terms of a different unit, use the unit parameter.

Examples

>>> import pint
>>> ureg = pint.UnitRegistry()
>>> (200e-9*ureg.s).to_compact()
<Quantity(200.0, 'nanosecond')>
>>> (1e-2*ureg('kg m/s^2')).to_compact('N')
<Quantity(10.0, 'millinewton')>
to_openmm() openmm.unit.Quantity

Convert the quantity to an openmm.unit.Quantity.

Returns

openmm_quantity (openmm.unit.quantity.Quantity) – The OpenMM compatible quantity.

to_preferred(preferred_units: list[UnitLike] | None = None) PlainQuantity

Return Quantity converted to a unit composed of the preferred units.

Examples

>>> import pint
>>> ureg = pint.UnitRegistry()
>>> (1*ureg.acre).to_preferred([ureg.meters])
<Quantity(4046.87261, 'meter ** 2')>
>>> (1*(ureg.force_pound*ureg.m)).to_preferred([ureg.W])
<Quantity(4.44822162, 'watt * second')>
to_reduced_units() PlainQuantity

Return PlainQuantity scaled in place to reduced units, i.e. one unit per dimension. This will not reduce compound units (intentionally), nor can it make use of contexts at this time.

to_root_units() PlainQuantity[MagnitudeT]

Return PlainQuantity rescaled to root units.

to_timedelta() timedelta
to_tuple() tuple[MagnitudeT, tuple[tuple[str, ...]]]
tolist()
property u: Unit

PlainQuantity’s units. Short form for units

unit_items() Iterable[tuple[str, Union[float, int, Decimal, Fraction]]]

A view of the unit items.

property unitless: bool
property units: Unit

PlainQuantity’s units. Long form for u

visualize(**kwargs)

Produce a visual representation of the Dask graph.

The graphviz library is required.

Parameters

**kwargs (dict) – Any keyword arguments to pass to dask.visualize.