MDTraj Utils

MDTraj contains a number of tools to help with development. These are located in mdtraj.utils.


import_(module) Import a module, and issue a nice message to stderr if the module isn’t installed.
in_units_of(quantity, units_in, units_out[, …]) Convert a numerical quantity between unit systems.
ilen(iterable) Length of an iterator.
timing([name]) A timing context manager


ensure_type(val, dtype, ndim, name[, …]) Typecheck the size, shape and dtype of a numpy array, with optional casting.
check_random_state(seed) Turn seed into a np.random.RandomState instance

Unit cell and Periodic Boundary Conditions

lengths_and_angles_to_box_vectors(a_length, …) Convert from the lengths/angles of the unit cell to the box vectors (Bravais vectors).
box_vectors_to_lengths_and_angles(a, b, c) Convert box vectors into the lengths and angles defining the box.


rotation_matrix_from_quaternion(q) Compute a 3x3 rotation matrix from a given quaternion (4-vector).
uniform_quaternion([size, random_state]) Generate uniform normalized quaternion 4-vectors