MSD from the center of mass

307 views
Skip to first unread message

Tojo RASOANARIVO

unread,
Apr 19, 2022, 8:33:47 AM4/19/22
to MDnalysis discussion
Hello,

I am currently working on a system of 2 types of molecules and I would like to get the MSD for one of them. As long as the molecules are able to rotate, I think about getting the MSD through the center of mass. Is there any way to do it ?

I took a look on the source code of MDAnalysis.analysis.msd and this function calls the positions of each atoms which satisfy the 'select' condition in order to compute the MSD.

Thank you for your help,
Tojo

Oliver Beckstein

unread,
Apr 22, 2022, 12:48:42 PM4/22/22
to mdnalysis-discussion
Hi Tojo,
There’s currently no straightforward option to “calculate the MSD of the center of mass of a selection”. You might get a reasonable approximation of the center of mass by selecting a heavy atom closest to your computed center of mass. 

Alternatively, you could create your own MSD class where you override the single_frame method: (Note, I didn’t test this but it *might* work):

class MSDCom(MDAnalysis.analysis.msd.MSD):
  def __init__(self, *args, **kwargs):
        super(MSDCom, self).__init__(*args, **kwargs)
        self.n_particles = 1   # just one center of mass

  def _single_frame(self):
        r""" Constructs array of positions for MSD calculation.
        Use the Center of Mass of ALL atoms as the only entry in the array.
        """
        # shape of position array set here, use span in last dimension
        # from this point on
        self._position_array[self._frame_index] = (self.ag.center_of_mass[self._dim])

Compare to the original code https://docs.mdanalysis.org/stable/_modules/MDAnalysis/analysis/msd.html#EinsteinMSD . As I said, I am not sure that it will work out of the box, but you get the idea.

Oliver


Thank you for your help,
Tojo


--
Oliver Beckstein (he/his/him)

GitHub: @orbeckst

MDAnalysis – a NumFOCUS fiscally sponsored project





Tojo RASOANARIVO

unread,
Apr 25, 2022, 4:22:43 AM4/25/22
to MDnalysis discussion
Hi Oliver,

First of all, thank you for your answer !

Because one of my molecules is a ring, I cannot really use a heavy atom as an approximation of the center of mass.

I modified a copy of the MSD code according to your suggestion and it seems to work as expected ! From now on, I might be able to find out how to compute the average MSD from a bunch of molecules and I'll be pleased to share it here.

Cheers,
Tojo
Reply all
Reply to author
Forward
0 new messages