mdtraj.utils.in_units_of(quantity, units_in, units_out, inplace=False)

Convert a numerical quantity between unit systems.

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


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.


A string description of the units you want out. This should look like “nanometers/picosecond” or “nanometers**3” or whatever


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.

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.


>>> in_units_of(1, 'meter**2/second', 'nanometers**2/picosecond')