Question about MSD calculations and Unwrapped Coordinates using Images

344 views
Skip to first unread message

Kevin Modica

unread,
Feb 16, 2021, 3:36:22 PM2/16/21
to freud-users
Hi all, I have a little bit of trouble understanding how the "images" section works for Freud MSD, especially if I use Hoomd to get that image.

For example, when I normally do MSD code by hand, I check to see if a particle coordinate has changed by a distance of more than L/2 between two consecutive trajectory dump readouts, if it has I will instead subtract out a distance of L to make the coordinates "unwrapped"

When using Freud and the box.get_Images, is that what it is doing? Or is there some hidden way Hoomd keeps track of when a particle crosses a boundary behind the hood.

A lot of this stems from the fact that I would like to take fewer trajectory readouts (say every 1e5 timesteps instead of every 1e3), but if I do that I run into the unlikely scenario that a particle has actually traversed more than L/2 distance without going around the boundary and I just missed it.



##### MSD Code I found for Freud, where snapshots are Hoomd Snapshots read by gsd ####


box1 = t0snapshot.configuration.box
positions = np.zeros((NumSnaps, NumParticles ,3))
msdclassxyz = freud.msd.MSD(box1,'window')

boxF = msdclass.box
t0_tstep = t0snapshot.configuration.step
time_list = np.zeros(NumSnaps)

for snapind in range(NumSnaps):
    currentsnap = snapshot_list[snapind]
    current_tstep = currentsnap.configuration.step
    time_list[snapind] = (current_tstep - t0_tstep)*(1e-3)
    curr_raj = currentsnap.particles.position
    positions[snapind, : , : ] = curr_traj

### Get MSD
last_frame = positions[0]
cumulative_img = 0
wrapped_pos = [ ]
images = [ ]
for frame in positions:
    delta = frame - last_frame
    images.append(cumulative_img - boxF.get_images(delta))
    wrapped_pos.append(frame)
    last_frame = frame
    cumulative_img = images[-1]
msdclassxyz.compute(wrapped_pos,images)


Joshua Anderson

unread,
Feb 16, 2021, 4:17:28 PM2/16/21
to Kevin Modica, freud-users
Kevin,

HOOMD checks on every time step whether a particle crossed a box boundary. When it does, HOOMD adds the appropriate value to the image and you can store images in GSD files.

You can reconstruct this in post processing as you suggest, but you will miss cases where particles move more than one box image between two frames of a trajectory file.

I'm not familiar with this freud example, but it does appear to be post processing to compute the images instead of accessing currentsnap.particles.image to get the images computed by HOOMD.
------
Joshua A. Anderson, Ph.D.
Research Area Specialist, Chemical Engineering, University of Michigan
> --
> You received this message because you are subscribed to the Google Groups "freud-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to freud-users...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/freud-users/028a8a3d-3e40-4c5d-9489-ed8a46c2a153n%40googlegroups.com.

Kevin Modica

unread,
Feb 16, 2021, 6:43:46 PM2/16/21
to freud-users
Hi Dr. Anderson,

Thank you! So you would recommend I use something like:

unwrapped_trajectory = currentsnap.particles.position*currentsnap.particles.image

Where an image would be the number of times each particle position component crosses the boundary?

Best,
Kevin

Kevin Modica

unread,
Feb 16, 2021, 8:38:56 PM2/16/21
to freud-users
Oh I see it would be this.

box1 = t0snapshot.configuration.box
msd = freud.msd.MSD(box, mode='window')

for step in range(NumSnaps):
     snapshot = snapshot_list[step]
     positionsarray[step, : ,  : ] = snapshot.particles.position
     imagesarray[step, : , :] = snapshot.particles.images

msd.compute(positions=positionsarray, images=imagesarray, reset=True)

Kevin Modica

unread,
Feb 16, 2021, 10:24:44 PM2/16/21
to freud-users
Sorry to keep replying to myself, but it does not seem like that works. The snapshot.particles.image remains constant across the simulation snapshots as an array of zeros.

Is that a known issue with snapshot.particles.image?

Joshua Anderson

unread,
Feb 17, 2021, 6:53:30 AM2/17/21
to Kevin Modica, freud-users
Kevin,

HOOMD writes only particle positions and orientations to GSD files by default to keep files small. You need to opt-in to writing particle images with the setting dynamic=['momentum']
https://hoomd-blue.readthedocs.io/en/latest/module-hoomd-write.html#hoomd.write.GSD
------
Joshua A. Anderson, Ph.D.
Research Area Specialist, Chemical Engineering, University of Michigan

> To view this discussion on the web visit https://groups.google.com/d/msgid/freud-users/42dda934-3c4a-4c04-8c29-1f27c8bbb94an%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages