-
Notifications
You must be signed in to change notification settings - Fork 667
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
DCD reader copies timestep while other readers update it. #3889
Comments
I don’t remember if this was intentional or not. Did you run git blame to see who added the line? It might have been an attempt to make the behavior of ts more intuitive (namely for the case of pulling a list of ts). But I’m with you: this should be consistent and the performance is important, especially as the DCD reader became a lot slower when we switched to cython (but it was necessary for maintainability). |
Changing this behavior counts as a “fix” for me—I don’t think it was ever promised to behave in the current way. |
I'll add proposed changes to #3888 |
Now that there is an issue for adding a deprecation warning #3923 this can be the main issue to actually deprecate the behaviour pinned to 3.0. |
* Fixes #3882 and #3923 * Improves the cython in the DCD reader to be more compiled. * add annotate_cython setup.cfg option * add types and fix is_periodic * make int cast explicit * change whence dict * move DCD reader to no copy API and update tests accordingly * add temporary buffer to DCD reader * add module level directives * pxdify libdcd: add new lib/formats/libdcd.pxd * Add deprecation warning for `timestep` copying in DCDReader (Issue #3889) * add DCD to public libmdanalysis API * update tests * update CHANGELOG
If the finding in #4008 is true that DCDReader effectively ignores transformations then we need to fix this here asap and not just do a deprecation and change in 3.0. |
I think the problem is with all ChainReader instances?
On Tue, 14 Feb 2023 at 5:01 am, Oliver Beckstein ***@***.***> wrote:
If the finding in #4008
<#4008> is true that
DCDReader effectively *ignores* transformations then we need to fix this
here asap and not just do a deprecation and change in 3.0.
—
Reply to this email directly, view it on GitHub
<#3889 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AF3RHC77AXA45LAACQGMNBTWXJZIJANCNFSM6AAAAAARQQ4NUY>
.
You are receiving this because you were assigned.Message ID:
***@***.***>
--
Hugo MacDermott-Opeskin
|
You got a warning
and now you are wondering what this is all about. Read on. Does the upcoming change in DCD reading behavior affect you?Possibly YES if
In MDAnalysis 1.x and 2.x, the following works (for DCD only!) in the sense that you can pull out a list of coordinates from a trajectory: import MDAnalysis as mda
from MDAnalysis.tests import datafiles as data
import numpy as np
u = mda.Universe(data.PSF, data.DCD) # load a DCD file
### ONLY WORKS AS INTENDED IN MDAnalysis < 3.0
all_coordinates = [ts.positions for ts in u.trajectory] # store ALL coordinates
all_coordinates = np.array(all_coordinates) # make numpy array Check that all coordinates are identical, frame by frame for i, ts in enumerate(u.trajectory):
match = np.allclose(ts.positions, all_coordinates[i])
if not match:
print(f"Coordinate mismatch at frame {i}")
print("done") With MDAnalysis < 3.0 the above will NOT find any mismatches.
However, with MDAnalysis >= 3.0 you will get mismatches beyond frame 0:
What to do?If your code relies on the behavior of the DCDReader to make a copy of Timestep then you must change your code or it will produce WRONG results. The easiest change is to make a copy of any data yourself. This means for the positions array (and other arrays/data structures of Timestep) to use the appropriate copy methods. For example, for ts.positions to ts.positions.copy() ( The code from above would then be written as all_coordinates = [ts.positions.copy() for ts in u.trajectory] # store ALL coordinates See alsoFor the specific application of pulling coordinates out of a trajectory, all trajectory readers have the timeseries() method that you can use instead of writing an explicit loop over the trajectory. Using |
@orbeckst thanks for the clarification, much better than my developer speak. |
Hello, I've run into this warning (so thank you for placing it). Please could you confirm if I have understood the above messages correctly and now configured my code to avoid this issue once version 3.0 is released? I've tried to provide a minimal example so hopefully that is okay to just glance over. For what it is worth, different trajectory file types work fine with this process.
Thanks! |
Did you change the lines res1_atoms.positions.copy(),
res2_atoms.positions.copy() from originally res1_atoms.positions,
res2_atoms.positions ? If this is the case, then there are two reasons why the original lines can remain (no copy() needed):
|
Thanks for the quick response! Yes it went exactly as you described, originally I didn't have the .copy() but after seeing the warning I thought it might be safer to place it just in case. And thanks for the explanation, it's good to know that I can remove the .copy() and safely ignore this warning. |
Checked and validated the warning is not relevant for this code, see: MDAnalysis/mdanalysis#3889
@yingyingwukim the error that you see probably has nothing to do with this issue, so in order to keep this issue focused on the original problem I am going to ask you to take your question elsewhere: Could you please ask for help either in the Discussions forum or in the MDAnalysis Discord server? If you have any indication that the error is a bug in MDAnalysis then please raise a new issue. |
@yingyingwukim can I re-iterate Oliver's point above, please either open up a discussion or a new issue, as far as we can tell your comment has nothing to do DCD reader timestep issues. |
Hi @yingyingwukim, please avoid replying to old message chains related to specific GitHub issues. The messages are tied to specific issues on GitHub, therefore they appear in the wrong place. Please use Discussions forum on GitHub (via the web interface) or in the MDAnalysis Discord server; there is no mailing list for MDAnalysis anymore. Thank you for your understanding. |
If you got a warning
and now you are wondering what this is all about, please see explanation below.
Expected behavior
The readers should all have the same behaviour with respect to iterating through the trajectory and changing the base values in the
position
attribute.Actual behavior
The DCD reader creates a new copy of the current timestep which allows the coordinates in each frame to vary independently. This is best illustrated in the below code snippet.
Copying the timestep incurs a ~30% performance penalty.
Code to reproduce the behavior
A number of tests seem to rely on this behaviour (test_atomgroup_write) and some of the LAMMPSDumpDCD tests
Current version of MDAnalysis
python -c "import MDAnalysis as mda; print(mda.__version__)"
) 2.4.0-dev0The text was updated successfully, but these errors were encountered: