n_restarts

mdtools.dynamics.n_restarts(n_frames, restart)[source]

Get the number of restarting points for each lag time.

Useful to normalize quantities that depend on a lag time and should be averaged over all possible restarting times. The most prominent example for such a quantity is the Mean Square Displacement (MSD), another example is autocorrelation functions.

Parameters:
  • n_frames (int) – Number of frames in the trajectory. Must be greater than zero.

  • restart (int) – Number of frames between restarting points. Must be greater than zero and should be less than n_frames.

Returns:

n_restarts (numpy.ndarray) – Array of shape (n_frames,) and dtype numpy.uint32 containing the number of restarting points for each lag time.

Examples

>>> n_frames = 5
>>> for restart in range(1, n_frames+1):
...     mdt.dyn.n_restarts(n_frames, restart)
array([5, 4, 3, 2, 1], dtype=uint32)
array([3, 2, 2, 1, 1], dtype=uint32)
array([2, 2, 1, 1, 1], dtype=uint32)
array([2, 1, 1, 1, 1], dtype=uint32)
array([1, 1, 1, 1, 1], dtype=uint32)
>>> #  0  1  2  3  4  Corresponding lag times [in trajectory frames]

mdtools.dynamics.n_restarts() is equivalent to but faster than the following nested loops

>>> n_frames, restart = 5, 2
>>> n_restarts = np.zeros(n_frames, dtype=np.uint32)
>>> for t0 in range(0, n_frames, restart):
...     for lag in range(n_frames-t0):
...         n_restarts[lag] += 1
>>> n_restarts
array([3, 2, 2, 1, 1], dtype=uint32)
>>> np.array_equal(n_restarts, mdt.dyn.n_restarts(n_frames, restart))
True

The nested loop from above can also be reduced to a single loop. But still, mdtools.dynamics.n_restarts() is faster.

>>> n_frames, restart = 5, 2
>>> n_restarts = np.zeros(n_frames, dtype=np.uint32)
>>> for t0 in range(0, n_frames, restart):
...     n_restarts[:n_frames-t0] += 1
>>> n_restarts
array([3, 2, 2, 1, 1], dtype=uint32)
>>> np.array_equal(n_restarts, mdt.dyn.n_restarts(n_frames, restart))
True