-
Notifications
You must be signed in to change notification settings - Fork 652
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
Allow bonds etc to be additively guessed when present #4761
Conversation
Hello @lilyminium! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:
Comment last updated at 2024-11-11 08:38:31 UTC |
(Current status of PR: tests are failing due to #4762, assuming they pass after that's resolved, this should be ready for review.) |
@yuxuanzhuang if you have time to look at this, it'd be great if you could see if this resolves the original issue in #4759! |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## develop #4761 +/- ##
===========================================
+ Coverage 93.59% 93.64% +0.04%
===========================================
Files 177 189 +12
Lines 21710 22808 +1098
Branches 3052 3055 +3
===========================================
+ Hits 20320 21358 +1038
- Misses 943 1003 +60
Partials 447 447 ☔ View full report in Codecov by Sentry. |
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.
First half of a review - blocking over the NoDataError check, but also some suggestions for some code comments to help future devs / reviewers.
@@ -1640,23 +1649,32 @@ def guess_TopologyAttrs( | |||
fg = attr in force_guess | |||
try: | |||
values = guesser.guess_attr(attr, fg) | |||
except ValueError as e: | |||
except NoDataError as e: |
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.
Do we really want to do this? There are a couple of cases in guess_bonds
where we can encounter a ValueError instead of a NoDataError.
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.
Also what should happen when you encounter a KeyError? (i.e. the unrecognised topologyattr check you added)
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.
Yup for this exact case -- I didn't want to change existing behaviour too much in case downstream packages were relying on it, and this is an existing test for vdwradii that wasn't introduced with guessers. The NoDataError is meant to catch cases where (e.g.) masses can't be guessed since there aren't types, not if the vdwradii is incomplete, so you can turn it off with error_if_missing
. Same with the KeyError.
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'm sorry, I just don't follow what you mean here.
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.
Oops. I hallucinated that you linked a test instead of a spot in the code, sorry about that. Basically IIRC there's two tests that test for this ValueError. One is definitely
mdanalysis/testsuite/MDAnalysisTests/core/test_universe.py
Lines 464 to 467 in e776f12
def test_universe_guess_bonds_no_vdwradii(self): | |
"""Make a Universe that has atoms with unknown vdwradii.""" | |
with pytest.raises(ValueError): | |
mda.Universe(two_water_gro_nonames, guess_bonds=True) |
These passed in the initial guesser PR because that was pre #4754.
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.
Yes, keeping the original behavior makes sense to me (and I confirm it is the original behavior).
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 NoDataError is meant to catch cases where (e.g.) masses can't be guessed since there aren't types, not if the vdwradii is incomplete, so you can turn it off with error_if_missing. Same with the KeyError.
I'm not sure I understand what you mean by "same with the KeyError" - i.e. there is nothing here that catches the KeyError as far as I can tell.
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.
For the sake of not stalling things more I'm going to go with it (i.e. the KeyError shouldn't happen under normal circumstances), but I would like to know what you meant here @lilyminium - it's unclear if you meant that the KeyError should behave like the NoDataError, in which case this except should include the KeyError too?
Thanks for the work here @lilyminium - overall this looks good, but I'm blocking on a bit more discussion for the NoDataError and the "duplicate old bonds" test. |
I don't know the topology/guessers well enough to give informed input here, sorry. |
Co-authored-by: Irfan Alibay <IAlibay@users.noreply.github.com>
Co-authored-by: Irfan Alibay <IAlibay@users.noreply.github.com>
Co-authored-by: Irfan Alibay <IAlibay@users.noreply.github.com>
Co-authored-by: Irfan Alibay <IAlibay@users.noreply.github.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.
After testing a few corner cases and comparing it with the previous behavior, I think it looks good to me!
@@ -1640,23 +1649,32 @@ def guess_TopologyAttrs( | |||
fg = attr in force_guess | |||
try: | |||
values = guesser.guess_attr(attr, fg) | |||
except ValueError as e: | |||
except NoDataError as e: |
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.
Yes, keeping the original behavior makes sense to me (and I confirm it is the original behavior).
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 have one follow-up question that I'm going to punt to later, and one formatting thing that I'll self merge. Otherwise lgtm.
@@ -1640,23 +1649,32 @@ def guess_TopologyAttrs( | |||
fg = attr in force_guess | |||
try: | |||
values = guesser.guess_attr(attr, fg) | |||
except ValueError as e: | |||
except NoDataError as e: |
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 NoDataError is meant to catch cases where (e.g.) masses can't be guessed since there aren't types, not if the vdwradii is incomplete, so you can turn it off with error_if_missing. Same with the KeyError.
I'm not sure I understand what you mean by "same with the KeyError" - i.e. there is nothing here that catches the KeyError as far as I can tell.
@@ -1640,23 +1649,32 @@ def guess_TopologyAttrs( | |||
fg = attr in force_guess | |||
try: | |||
values = guesser.guess_attr(attr, fg) | |||
except ValueError as e: | |||
except NoDataError as e: |
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.
For the sake of not stalling things more I'm going to go with it (i.e. the KeyError shouldn't happen under normal circumstances), but I would like to know what you meant here @lilyminium - it's unclear if you meant that the KeyError should behave like the NoDataError, in which case this except should include the KeyError too?
Fixes #4759
Changes made in this Pull Request:
PR Checklist
Developers certificate of origin
📚 Documentation preview 📚: https://mdanalysis--4761.org.readthedocs.build/en/4761/