How lammps compute MSD of the molecules

Dear all,
I have a basic question while calculating MSD of molecules in the sytem. A molecule goes out of the box and due to PBC it comes back again fron the opposite side. So when this happens MSD reduces as it again recenter to the same position where it was initially. How we can compute MSD then, when there should not be an image recentering of the molecules.
Please help!

If you are using LAMMPS’s compute msd it will automatically take care of this.

If you are not, but have the image flags and positions, you can use those in combination with the box geometry to calculate the actual position and use that.

If you have neither, but you have frames of the simulation for which the atoms have not moved a lot between the frames, you can guess the image flags by checking if the atoms move more than half the box size in between frames. If you have just the frames and positions but no atom positions, then there is not much you can do.