mdtraj.utils.in_units_of¶
-
mdtraj.utils.
in_units_of
(quantity, units_in, units_out, inplace=False)¶ Convert a numerical quantity between unit systems.
Parameters: quantity : {number, np.ndarray, simtk.unit.Quantity}
quantity can either be a unitted quantity – i.e. instance of simtk.unit.Quantity, or just a bare number or numpy array
units_in : str
If you supply a quantity that’s not a simtk.unit.Quantity, you should tell me what units it is in. If you don’t, i’m just going to echo you back your quantity without doing any unit checking.
units_out : str
A string description of the units you want out. This should look like “nanometers/picosecond” or “nanometers**3” or whatever
inplace : bool
Attempt to do the transformation inplace, by mutating the quantity argument and avoiding a copy. This is only possible if quantity is a writable numpy array.
Returns: rquantity : {number, np.ndarray}
The resulting quantity, in the new unit system. If the function was called with inplace=True and quantity was a writable numpy array, rquantity will alias the same memory as the input quantity, which will have been changed inplace. Otherwise, if a copy was required, rquantity will point to new memory.
Examples
>>> in_units_of(1, 'meter**2/second', 'nanometers**2/picosecond') 1000000.0