Quantity

class openff.units.Quantity(value: str, units: Optional[UnitLike] = None)[source]
class openff.units.Quantity(value: Sequence, units: Optional[UnitLike] = None)
class openff.units.Quantity(value: Quantity[Magnitude], units: Optional[UnitLike] = None)
class openff.units.Quantity(value: Magnitude, units: Optional[UnitLike] = None)

Bases: Quantity[_MagnitudeType]

A value with associated units.

Methods

check

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

clip

compare

compatible_units

compute

Compute the Dask array wrapped by pint.Quantity.

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 Quantity rescaled to base units.

ito_reduced_units

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

ito_root_units

Return Quantity rescaled to root units.

m_as

Quantity's magnitude expressed in particular units.

persist

Persist the Dask Array wrapped by pint.Quantity.

plus_minus

prod

Return the product of quantity elements over a given axis

put

searchsorted

to

Return Quantity rescaled to different units.

to_base_units

Return Quantity rescaled to base units.

to_compact

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

to_openmm

Convert the quantity to an openmm.unit.Quantity.

to_reduced_units

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

to_root_units

Return Quantity rescaled to root units.

to_timedelta

to_tuple

tolist

visualize

Produce a visual representation of the Dask graph.

Attributes

T

UnitsContainer

debug_used

default_format

Default formatting string.

dimensionality

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

dimensionless

flat

force_ndarray

force_ndarray_like

imag

m

Quantity's magnitude.

magnitude

Quantity's magnitude.

real

shape

u

Quantity's units.

unitless

units

Quantity's units.

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

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

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

Compute the Dask array wrapped by pint.Quantity.

Parameters

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

Returns

pint.Quantity – A pint.Quantity wrapped numpy array.

property debug_used
default_format: str = ''

Default formatting string.

property dimensionality: UnitsContainerT

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

property dimensionless: bool
dot(b)[source]

Dot product of two arrays.

Wraps np.dot().

fill(value) None[source]
property flat
property force_ndarray: bool
property force_ndarray_like: bool
format_babel(spec: str = '', **kwspec: Any) str[source]
classmethod from_list(quant_list: List[Quantity], units=None) Quantity[ndarray][source]

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
Returns

pint.Quantity

classmethod from_sequence(seq: Sequence[Quantity], units=None) Quantity[ndarray][source]

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
Returns

pint.Quantity

classmethod from_tuple(tup)[source]
property imag: Quantity[pint._typing._MagnitudeType]
is_compatible_with(other: Any, *contexts: Union[str, Context], **ctx_kwargs: Any) bool[source]

check if the other object is compatible

Parameters
  • other – The object to check. Treated as dimensionless if not a Quantity, 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=None, *contexts, **ctx_kwargs) None[source]

Inplace rescale to different units.

Parameters
  • other (pint.Quantity, 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[source]

Return Quantity rescaled to base units.

ito_reduced_units() None[source]

Return Quantity 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[source]

Return Quantity rescaled to root units.

property m: pint._typing._MagnitudeType

Quantity’s magnitude. Short form for magnitude

m_as(units) _MagnitudeType[source]

Quantity’s magnitude expressed in particular units.

Parameters

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

property magnitude: pint._typing._MagnitudeType

Quantity’s magnitude. Long form for m

persist(**kwargs)[source]

Persist the Dask Array wrapped by pint.Quantity.

Parameters

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

Returns

pint.Quantity – A pint.Quantity wrapped Dask array.

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

Return the product of quantity elements over a given axis

Wraps np.prod().

put(indices, values, mode='raise') None[source]
property real: Quantity[pint._typing._MagnitudeType]
searchsorted(v, side='left', sorter=None)[source]
property shape: Tuple[int, ...]
to(other=None, *contexts, **ctx_kwargs) Quantity[_MagnitudeType][source]

Return Quantity rescaled to different units.

Parameters
  • other (pint.Quantity, 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.Quantity

to_base_units() Quantity[_MagnitudeType][source]

Return Quantity rescaled to base units.

to_compact(unit=None) Quantity[_MagnitudeType][source]

“Return Quantity 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() OpenMMQuantity[source]

Convert the quantity to an openmm.unit.Quantity.

Returns

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

to_reduced_units() Quantity[_MagnitudeType][source]

Return Quantity 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() Quantity[_MagnitudeType][source]

Return Quantity rescaled to root units.

to_timedelta() timedelta[source]
to_tuple() Tuple[_MagnitudeType, Tuple[Tuple[str]]][source]
tolist()[source]
property u: Unit

Quantity’s units. Short form for units

property unitless: bool
property units: Unit

Quantity’s units. Long form for u

visualize(**kwargs)[source]

Produce a visual representation of the Dask graph.

The graphviz library is required.

Parameters

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