-
Couldn't load subscription status.
- Fork 734
Robust sort_backbone: detect disconnected selections and avoid infinite loops #5113
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
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #5113 +/- ##
===========================================
+ Coverage 93.86% 93.88% +0.02%
===========================================
Files 179 180 +1
Lines 22249 22421 +172
Branches 3161 3185 +24
===========================================
+ Hits 20885 21051 +166
Misses 902 902
- Partials 462 468 +6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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 your fix @DrDomenicoMarson ! Please address @tylerjereddy 's comments and my minor ones.
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 addressing the other comments. Todo:
- check formatting (black)
- improve test coverage of patch
| if len(sorted_backbone) != len(backbone): | ||
| raise ValueError( | ||
| "Backbone traversal did not visit all atoms. " | ||
| "Expected {} atoms, got {}.".format( | ||
| len(backbone), len(sorted_backbone) | ||
| ) | ||
| ) |
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 covered by tests – could you please add a test for it?
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 wrote this as a final sanity check, but when I tested the code, I realized that I can’t reach this part of the code without having the analysis fail earlier (which is what it should do, considering the situation). So, I decided to remove this “untestable and useless” part.
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.
LGTM, thank you!
Will get into release 2.10.0.
Fixes #5112
Problem:
sort_backbonecan hang indefinitely when the inputAtomGroupis disconnected (e.g., some backbone atoms were excluded by selection). Currently, the function only checksn_fragments, which is insufficient to catch all cases of disconnected backbones.Cause:
n_fragmentsalone does not reliably detect disconnected selections.whileloop insort_backboneiterates until the backbone is fully traversed, but if the selection is disconnected, the loop can never complete.Solution / Changes made:
Added robust validation before the traversal, checking:
Replaced the “dangerous” unbounded
whileloop with a bounded iteration over the backbone length.Tested with backbone selections missing internal atoms, that now raises a descriptive ValueError instead of hanging.
PR Checklist
package/CHANGELOGfile 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--5113.org.readthedocs.build/en/5113/