strip_unit¶
- mdhelper.algorithm.unit.strip_unit(value: Number | Quantity | Quantity, unit_: str | Unit | Unit = None) tuple[Number, None | Unit | Unit] [source]¶
Strips the unit from an
openmm.unit.Quantity
orpint.Quantity
object.- Parameters:
- valuenumbers.Number, openmm.unit.Quantity, or pint.Quantity
Physical quantity for which to get the magnitude of in the unit specified in unit_.
- unit_str, openmm.unit.Unit, or pint.Unit, optional
Unit to convert to. If not specified, the original unit is used.
- Returns:
- valuenumbers.Number
Magnitude of the physical quantity in the specified unit.
- unit_openmm.unit.Unit or pint.Unit
Unit of the physical quantity.
Examples
For any quantity other than a
openmm.unit.Quantity
orpint.Quantity
object, the raw quantity and user-specified unit are returned.>>> strip_unit(90.0, "deg") (90.0, 'deg') >>> strip_unit(90.0, ureg.degree) (90.0, <Unit('degree')>)
If no target unit is specified, the magnitude and original unit of the quantity are returned.
>>> strip_unit(1.380649e-23 * ureg.joule * ureg.kelvin ** -1) (1.380649e-23, <Unit('joule / kelvin')>)
If a target unit using the same module as the quantity is specified, the quantity is first converted to the target unit, if necessary, before its magnitude and unit are returned.
>>> g = 9.80665 * ureg.meter / ureg.second ** 2 >>> strip_unit(g, "meter/second**2") (9.80665, <Unit('meter / second ** 2')>) >>> strip_unit(g, ureg.foot / ureg.second ** 2) (32.17404855643044, <Unit('foot / second ** 2')>)
If a target unit using a different module than the quantity is specified, the quantity is converted to the specified target unit in the new module, if necessary, before its magnitude and unit are returned.
>>> strip_unit(8.205736608095969e-05 * unit.meter ** 3 * unit.atmosphere ... / (unit.kelvin * unit.mole), ... ureg.joule / (ureg.kelvin * ureg.mole)) (8.31446261815324, <Unit('joule / kelvin / mole')>) >>> strip_unit(8.205736608095969e-05 * ureg.meter ** 3 * ureg.atmosphere ... / (ureg.kelvin * ureg.mole), ... unit.joule / (unit.kelvin * unit.mole)) (8.31446261815324, Unit({BaseUnit(..., name="kelvin", ...): -1.0, ...}))