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
Return true if the quantity's dimension matches passed dimension.
Compute the Dask array wrapped by pint.PlainQuantity.
Dot product of two arrays.
Transforms a list of Quantities into an numpy.array quantity.
Transforms a sequence of Quantities into an numpy.array quantity.
check if the other object is compatible
Inplace rescale to different units.
Return PlainQuantity rescaled to plain units.
Return Quantity converted to a unit composed of the preferred units.
Return PlainQuantity scaled in place to reduced units, i.e. one unit per dimension.
Return PlainQuantity rescaled to root units.
PlainQuantity's magnitude expressed in particular units.
Persist the Dask Array wrapped by pint.PlainQuantity.
Return the product of quantity elements over a given axis
Return PlainQuantity rescaled to different units.
Return PlainQuantity rescaled to plain units.
"Return PlainQuantity rescaled to compact, human-readable units.
Convert the quantity to an
openmm.unit.Quantity
.Return Quantity converted to a unit composed of the preferred units.
Return PlainQuantity scaled in place to reduced units, i.e. one unit per dimension.
Return PlainQuantity rescaled to root units.
A view of the unit items.
Produce a visual representation of the Dask graph.
Attributes
returns:
dict
-- Dimensionality of the PlainQuantity, e.g.PlainQuantity's magnitude.
PlainQuantity's magnitude.
PlainQuantity's units.
PlainQuantity's units.
- check(dimension: UnitLike) bool
Return true if the quantity’s dimension matches passed dimension.
- compute(**kwargs)
Compute the Dask array wrapped by pint.PlainQuantity.
- Parameters
**kwargs (
dict
) – Any keyword arguments to pass todask.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
- fill(value) None
- property force_ndarray: bool
- property force_ndarray_like: bool
- 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
ofpint.PlainQuantity
) – list of pint.PlainQuantityunits (
UnitsContainer
,str
orpint.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
ofpint.PlainQuantity
) – sequence of pint.PlainQuantityunits (
UnitsContainer
,str
orpint.PlainQuantity
) – units of the physical quantity to be created (Default value = None)
- Returns
pint.PlainQuantity
- 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
orpint.Context
) – Contexts to use in the transformation.**ctx_kwargs – Values for the Context/s
- Returns
- ito(other: QuantityOrUnitLike | None = None, *contexts, **ctx_kwargs) None
Inplace rescale to different units.
- Parameters
other (
pint.PlainQuantity
,str
ordict
) – Destination units. (Default value = None)*contexts (
str
orpint.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
- 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 todask.persist
.- Returns
pint.PlainQuantity
– A pint.PlainQuantity wrapped Dask array.
- 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
- to(other: QuantityOrUnitLike | None = None, *contexts, **ctx_kwargs) PlainQuantity
Return PlainQuantity rescaled to different units.
- Parameters
other (
pint.PlainQuantity
,str
ordict
) – destination units. (Default value = None)*contexts (
str
orpint.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
- property u: Unit
PlainQuantity’s units. Short form for units
- 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 todask.visualize
.