Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions example/msd_nojump_demo.py
Comment thread
orbeckst marked this conversation as resolved.
Outdated
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# mypy: ignore-errors
import MDAnalysis as mda
from MDAnalysis.analysis.msd import EinsteinMSD
from MDAnalysis.tests.datafiles import RANDOM_WALK, RANDOM_WALK_TOPO
from MDAnalysis.transformations import NoJump
import matplotlib.pyplot as plt

print("Using input files:")
print("Topology:", RANDOM_WALK_TOPO)
print("Trajectory:", RANDOM_WALK)

u = mda.Universe(RANDOM_WALK_TOPO, RANDOM_WALK)

# --- FIX: define box dimensions BEFORE NoJump runs ---
box = [100.0, 100.0, 100.0, 90.0, 90.0, 90.0]


def set_box(ts):
ts.dimensions = box
return ts


# Apply transformations in correct order
u.trajectory.add_transformations(
set_box, # must come first
NoJump(u), # requires PBC
)

# Compute MSD
msd = EinsteinMSD(u, select="all", msd_type="xyz", fft=False)
msd.run()

lagtimes = msd.results.delta_t_values
msd_values = msd.results.timeseries

plt.figure(figsize=(6, 4))
plt.plot(lagtimes, msd_values, label="Computed MSD")
plt.plot(lagtimes, 6 * lagtimes, "--", label="Theoretical 3D MSD (6τ)")
plt.xlabel("Lag time (τ)")
plt.ylabel("MSD")
plt.legend()
plt.title("Mean Squared Displacement with NoJump")

plt.savefig("example/msd_nojump.png", dpi=150, bbox_inches="tight")

plt.close()

print("Saved plot to msd_nojump.png")
1 change: 1 addition & 0 deletions package/AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ Chronological list of authors
- Raúl Lois-Cuns
- Pranay Pelapkar
- Shreejan Dolai
- Tanisha Dubey

External code
-------------
Expand Down
29 changes: 27 additions & 2 deletions package/MDAnalysis/analysis/msd.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,33 @@
back into the primary simulation cell.

In MDAnalysis you can use the
:class:`~MDAnalysis.transformations.nojump.NoJump`
transformation.
:class:`~MDAnalysis.transformations.nojump.NoJump`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indentation looks off. Please correct.

transformation.
transformation to unwrap coordinates on-the-fly.

A minimal example:

.. code-block:: python

import MDAnalysis as mda
from MDAnalysis.transformations import NoJump

u = mda.Universe(TOP, TRAJ)

# Apply NoJump transformation to unwrap coordinates
nojump = NoJump(u)
u.trajectory.add_transformations(nojump)
Comment thread
tani-dubey marked this conversation as resolved.
Outdated

# Now the trajectory is unwrapped and MSD can be computed normally:
from MDAnalysis.analysis.msd import EinsteinMSD
MSD = EinsteinMSD(u, select="all", msd_type="xyz")
MSD.run()

This example assumes that the trajectory contains periodic box
dimensions. If no periodic boundary information is present, box
dimensions must be defined before applying ``NoJump``.
Comment thread
tani-dubey marked this conversation as resolved.
Outdated

This replaces the need to preprocess trajectories externally.

In GROMACS, for example, this can be done using `gmx trjconv`_ with the
``-pbc nojump`` flag.
Expand Down
Loading