Question about Unwrap trajectories

Dear developers,
I want to unwarp a trajectory. However, I found some atoms move over half of box between two near frames. Fox example, x coordinate of atom 0 moves from 17.3101 (frame 10) to 10.9027 (frame 11), the box length is 12.795. Is it a bug?
For reproducing the result, the trajectory has been uploaded. (404.3 KB)

It looks like simulation cell dimensions are changing at each frame, following the minimum/maximum extent of particle positions. Box length on frame 11 is 12.795, but on frame 10 it is 12.8796. I am not sure about how UnwrapTrajectories works, I can only guess that it is using the box dimensions of frame 10 to perform the calculation of displacement.

Actually, performing the calculation “by hand” seems to verify my suspicion. Maybe someone who knows the inner workings of this modifier could give a definitive answer.

For atom index 5, the x-coordinate changes from 4.78421 (frame 12) to 11.2496 (frame 13), resulting in a difference of 12.930779999999999. This difference exceeds the box length of frame 12 (12.7934) and frame 13 (12.9117), which is unexpected.

Unwrapping trajectories from simulations with changing box sizes is not a trivial task and comes with some caveats. Please refer to

Bullerjahn JT, von Bülow S, Heidari M, Hénin J, Hummer G. Unwrapping NPT Simulations to Calculate Diffusion Coefficients. J Chem Theory Comput. 2023 Jun 13;19(11):3406-3417. doi: 10.1021/acs.jctc.3c00308. Epub 2023 May 31. PMID: 37257090; PMCID: PMC10269326.

for further details.

I have implemented the 2 alternate unwrapping schemes suggested by the authors (Toroidal-View-Preserving (TOR) Scheme and Modern Lattice-View (LAT) Scheme) as OVITO python modifiers. Maybe they work better for your dataset. Note that this script is not thoroughly tested and might produce incorrect results. (2.5 KB)

Note that if a particle has moved a distance larger than half of the simulation cell in between two subsequent frames, there’s no guarantee that the unwrapping works correctly.

If particle Periodic image flags are not present in the input data, OVITO first processes all frames by calculating delta vectors, which are derived from comparing reduced coordinates in consecutive frames, i.e., all cells are rescaled to a common reference size for distance calculations. If any component of a delta vector is greater than or equal to 0.5, a PBC crossing is recorded as a shift vector, where each entry can be 0 or 1. This shift vector is then subsequently used to unwrap the particle positions in each frame, utilizing the current simulation cell.

In the Ovito unwrapped trajectory, I observed a particle that traveled a distance greater than half the size of the simulation cell between two consecutive frames, which struck me as unusual.

Thanks for you reply, I will try the script. :grin:

Please review your trajectory file again, as there are many instances where atoms move more than half a box length between two frames. Due to this, it is not possible to unwrap the coordinates using OVITO’s Unwrap Trajectory modifier.

I understand now. Thank you very much.