43 views

### Tianming Qu

Jun 29, 2022, 10:52:01 AM6/29/22
to MDnalysis discussion
Hi all,

I am recently trying to use the MSD module of MDanalysis. In the tutorial there is something says that the time_step has to be the actual time between frames. Does anyone know what is the unit for the timestep specified here?

Also, I would like to calculate the MSD only for side chain H, is there anyway I can select that?

### Hugo Macdermott-Opeskin

Jul 22, 2022, 11:41:28 PM7/22/22
to MDnalysis discussion
Hi,

If you are talking about constructing the graph as is done in the example with:

import matplotlib.pyplot as plt
nframes = MSD.n_frames
timestep = 1 # this needs to be the actual time between frames
lagtimes = np.arange(nframes)*timestep# make the lag-time axis
fig = plt.figure() ax = plt.axes() # plot the actual MSD
ax.plot(lagtimes, msd, lc="black", ls="-", label=r'3D random walk')
exact = lagtimes*6
# plot the exact result
ax.plot(lagtimes, exact, lc="black", ls="--", label=r'$y=2 D\tau$')
plt.show()


This simply means that the msd plot does not actually make use of the time units of your trajectory and that you need to reconstruct this information your self.
This is because in many cases the trajectory does not actually provide a timestamp for each frame. In this case the msd comes out looking something like this as an array:

[0,0.5,1,2,3 ...]

And does not contain the right "x axis" time information. This means that you need to use the code snippet above to get the right x axis for your MSD.
For example if there was 150 nanoseconds between each frame of your trajectory and you wanted the MSD in time units of nanoseconds:

nframes = MSD.n_frames
timestep = 150 # now in units of ns
lagtimes = np.arange(nframes)*timestep# make the lag-time axis

If you wanted the same thing but in units of ps you could adjust the units accordingly.

To select a portion of the system, use the select="..." keyword to the MSD function. eg  MSD(u, select="residue 1 to 10 and name H") to select hydrogens from residue 1 to 10.
You will have to figure out the correct selection syntax for your system.

Hope this helps

Cheers

Hugo