pydantic_units
#
Support for OpenMM units as pydantic fields
Modules:
Classes:
-
OpenMMQuantity
–A pydantic safe OpenMM quantity type that validates unit compatibility.
Functions:
-
quantity_serializer
–Serialize a Quantity to a string
-
quantity_validator
–Validate a string or quantity as a quantity with expected units
OpenMMQuantity
#
Bases: Quantity
A pydantic safe OpenMM quantity type that validates unit compatibility.
quantity_serializer
#
Serialize a Quantity to a string
Parameters:
-
value
(Quantity
) –The quantity to serialize
Returns:
-
str
–The serialized string
Source code in pydantic_units/_common.py
quantity_validator
#
Validate a string or quantity as a quantity with expected units
Parameters:
-
value
(str | Quantity
) –The value to validate
-
expected_units
(Unit
) –The expected units
Raises:
-
ValueError
–If the value is not a valid quantity or has the wrong units
Returns:
-
Quantity
–The validated quantity.