-
Notifications
You must be signed in to change notification settings - Fork 764
Added NoJump on-the-fly example to MSD documentation (Issue #4169) #5165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello there first time contributor! Welcome to the MDAnalysis community! We ask that all contributors abide by our Code of Conduct and that first time contributors introduce themselves on GitHub Discussions so we can get to know you. You can learn more about participating here. Please also add yourself to package/AUTHORS as part of this PR.
IAlibay
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not reviewing the code but enforcing license - please don't change the license.
|
Thank you for pointing this out! I’ve updated the file to restore the correct license header ( |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #5165 +/- ##
===========================================
+ Coverage 92.72% 92.73% +0.01%
===========================================
Files 180 180
Lines 22473 22475 +2
Branches 3189 3190 +1
===========================================
+ Hits 20838 20843 +5
+ Misses 1177 1175 -2
+ Partials 458 457 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
orbeckst
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please demonstrate to yourself and your reviewers that your doc update is correct.
package/MDAnalysis/analysis/msd.py
Outdated
| .. 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) | ||
| # 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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please run code and post images of the output graph. Demonstrate to the reviewers that the example does what you say it is doing.
When you run code, show us the code that you're running, including the input files.
89d9658 to
b81e783
Compare
orbeckst
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is RANDOM_WALK a good example, namely, did you check that it was actually generated with periodic boundary conditions?
In order to demonstrate that the example is working, I'd expect to see a comparison between omitting and using NoJump.
package/MDAnalysis/analysis/msd.py
Outdated
| In MDAnalysis you can use the | ||
| :class:`~MDAnalysis.transformations.nojump.NoJump` | ||
| transformation. | ||
| :class:`~MDAnalysis.transformations.nojump.NoJump` |
There was a problem hiding this comment.
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.
Thanks for the clarification, After checking more carefully, I realized that:-
Instead of assuming wrapping is present in the input data, I will construct a deterministic test where a periodic box is defined and an artificial jump across the boundary is introduced between consecutive frames. This allows us to verify the intended behavior directly. |
|
@orbeckst the code i used to demonstrate this -- |
orbeckst
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for testing explicitly. This looks good.
I added a note on setdimensions (see comments). Could you please check that this works as intended (post code and results). Thank you!
Co-authored-by: Oliver Beckstein <orbeckst@gmail.com>
Co-authored-by: Oliver Beckstein <orbeckst@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for checking that set_dimensions, NoJump is working in a simple example without MSD.
You haven't demonstrated yet that it works with MSD but you should now know enough about transformations and PBC to create a proper test case.
My recommendation would be to take the existing RANDOM_WALK trajectory and wrap it in a small box (figure out reasonable dimensions by analyzing the random walk) using wrap and write it to a new file. Then use this file as input for MSD (1) with NoJump, (2) without NoJump and compare as before.
|
Got it, I used Code- import numpy as np
import matplotlib.pyplot as plt
import MDAnalysis as mda
from MDAnalysis.tests.datafiles import RANDOM_WALK, RANDOM_WALK_TOPO
from MDAnalysis.transformations import NoJump, wrap
from MDAnalysis.transformations.boxdimensions import set_dimensions
from MDAnalysis.analysis.msd import EinsteinMSD
from MDAnalysis.coordinates.XTC import XTCWriter
# ----------------------------
# create a input file
# ----------------------------
box = [20.0, 20.0, 20.0, 90.0, 90.0, 90.0]
u = mda.Universe(RANDOM_WALK_TOPO, RANDOM_WALK)
u.trajectory.add_transformations(
set_dimensions(box),
wrap(u.atoms),
)
with XTCWriter("random_walk_wrapped.xtc",u.atoms.n_atoms) as W:
for ts in u.trajectory:
W.write(u.atoms)
# # ----------------------------
# # 1. MSD WITHOUT NoJump
# # ----------------------------
u= mda.Universe(RANDOM_WALK_TOPO,"random_walk_wrapped.xtc")
msd_wrapped = EinsteinMSD(
u,
select="all",
msd_type="xyz",
fft=False,
)
msd_wrapped.run()
t = msd_wrapped.results.delta_t_values
msd_nojump = msd_wrapped.results.timeseries.copy()
# # ----------------------------
# # 2. MSD WITH NoJump
# # ----------------------------
# # Reload universe to avoid transformation stacking
u = mda.Universe(RANDOM_WALK_TOPO, "random_walk_wrapped.xtc")
u.trajectory.add_transformations(
NoJump(u),
)
msd_unwrapped = EinsteinMSD(
u,
select="all",
msd_type="xyz",
fft=False,
)
msd_unwrapped.run()
msd_with_nojump = msd_unwrapped.results.timeseries
# # ----------------------------
# # 3. Plot comparison
# # ----------------------------
plt.figure(figsize=(6, 4))
plt.plot(t, msd_nojump, label="Wrapped (no NoJump)")
plt.plot(t, msd_with_nojump, label="Unwrapped (with NoJump)")
plt.xlabel("Lag time")
plt.ylabel("MSD")
plt.legend()
plt.title("Effect of NoJump on MSD for RANDOM_WALK")
plt.tight_layout()
plt.show() |
orbeckst
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for checking. This looks good!
I'll fix an indentation problem and then will merge.
|
@IAlibay do you want to have a look here or can I just dismiss your review as stale? There are no changes to the license in the PR. |
|
@tanii1125 is your name already in the AUTHORS file? If not, please add it. |
|
Please discard my review, thanks! |
|
@orbeckst, yes my name is in AUTHORS file |
concern addressed, reviewer ok with dismissal
|
Thank you for your contribution @tanii1125 ! |




This PR updates the MSD documentation inside
MDAnalysis.analysis.msdto show users how to correctly apply the NoJump transformation using on-the-fly trajectory transformations.Issue #4169 noted that although NoJump exists, there was no example showing how to use it directly in MDAnalysis.
This PR adds:
Fixes: #4169
I would appreciate any feedback or suggestions for improvement.
Reviews are very welcome, and I’m happy to revise the PR based on your guidance.
📚 Documentation preview 📚: https://mdanalysis--5165.org.readthedocs.build/en/5165/