-
Notifications
You must be signed in to change notification settings - Fork 723
fix DCDWriter angle cosines #5071
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
- fix #5069 - DCDWriter is now writing unit cell angles as cos(angle) to the DCD file as written in the docs (NAMD >= 2.5 convention) - add test - update CHANGELOG
FYI: I tried out AI assisted coding with Cursor, using the default model:
I rewrote basically everything; the only key thing that survived was the idea to write the cosines as sin(90 - angle), which it picked up from reading the DCDReader code. For the tests, it did not properly use my suggestions from the issue report to use the DCDFrame that the underlying dcd reading code provides. Still, it was helpful as a starting point. It had a really hard time formatting the CHANGELOG entry, trying 5 different ways, finally writing a sed script to do it, ... poor thing. (It also tried to delete half of CHANGELOG in the process....) |
- Original test only passed at rtol=1e-4 due to some angles close to 0, which is where the sin(90-angle) storage is much less accurate. Changed the test range of angles to between 5 and 120 (from 0 to 80) to be more realistic and exclude very small angles where we would see precision issues - formatted with black
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #5071 +/- ##
========================================
Coverage 93.85% 93.85%
========================================
Files 178 178
Lines 22122 22123 +1
Branches 3129 3129
========================================
+ Hits 20763 20764 +1
Misses 902 902
Partials 457 457 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
@p-j-smith or @yuxuanzhuang would you be able to have a look at this fairly simple bug fix in the DCDWriter code. please? Alternatively, do you have other suggestions for reviewers? |
@@ -467,10 +467,14 @@ def _write_next_frame(self, ag): | |||
xyz = self.convert_pos_to_native(xyz, inplace=True) | |||
dimensions = self.convert_dimensions_to_unitcell(ts, inplace=True) | |||
|
|||
# we only support writing charmm format unit cell info |
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.
Reading this, it sounds to me like we are replacing one feature with another, not necessarily fixing a "bug".
I get that our docs were wrong, but I wonder how many folks downstream expected charmm format instead of named/vmd. Do we think maybe putting in a flag to choose between the two might be useful? Either way, some docs that can loudly say "this is a change" might be useful.
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 chiming in.
CHARMM has been using box vectors for a while, which is why we have this code :
mdanalysis/package/MDAnalysis/coordinates/DCD.py
Lines 248 to 252 in d412c9a
elif np.any(uc < 0.) or np.any(uc[3:] > 180.): | |
# might be new CHARMM: box matrix vectors | |
H = frame.unitcell.copy() | |
e1, e2, e3 = H[[0, 1, 3]], H[[1, 2, 4]], H[[3, 4, 5]] | |
uc = triclinic_box(e1, e2, e3) |
To my understanding, nobody should be writing the bare unit cell info any more because that creates just more format confusion.
I am happy to add a warning box to the docs although I'd rather not add more confusion by making it possible to switch between old and new NAMD conventions.
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.
I added docs warning.
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.
@IAlibay is the warning in the docs sufficient or do you just think we shouldn't be changing anything?
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.
I think it's ok since the reader should still work either way. It's not ideal but I can see how this could be a bugfix.
I ran black (v24.10.0) on DCD.py and it made more changes than in the code that I touched. I was a bit surprised because I assumed that this file had originally been reformatted a while ago already. Sorry for the noisy diff – I can undo if this is preferred. |
2f95972
to
e7efa35
Compare
@orbeckst did you run it directly on the file? The DCD file is one of the excluded ones mdanalysis/package/pyproject.toml Line 157 in b4ab7e5
The exclusion list was added to minimize the disturbance to open PRs, but probably it is time to update it. |
This reverts commit 0f7df5a. DCD.py is on the exclusion list. Blacken in a separate commit.
e7efa35
to
0c43efa
Compare
I reverted black – probably should be done separately. |
Fixes #5069
Changes made in this Pull Request:
PR Checklist
package/CHANGELOG
file updated?package/AUTHORS
? (If it is not, add it!)Developers Certificate of Origin
I certify that I can submit this code contribution as described in the Developer Certificate of Origin, under the MDAnalysis LICENSE.
📚 Documentation preview 📚: https://mdanalysis--5071.org.readthedocs.build/en/5071/