Repository navigation
Add option to evaluate only reference contact pairs - #5515
Conversation
Documentation build overview
96 files changed ·
|
IAlibay
left a comment
There was a problem hiding this comment.
@carlosvega I'm blocking to PR to ask you to please open an issue to discuss the need for the code you're adding.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #5515 +/- ##
========================================
Coverage 93.93% 93.93%
========================================
Files 184 184
Lines 22662 22675 +13
Branches 3223 3227 +4
========================================
+ Hits 21287 21300 +13
Misses 915 915
Partials 460 460 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Thanks, I opened #5517 to discuss whether this is needed. |
orbeckst
left a comment
There was a problem hiding this comment.
Overall the PR makes sense to me. Please see my initial comments.
BradyAJohnston
left a comment
There was a problem hiding this comment.
This mostly looks good to me, just some minor nits.
Additionally:
-
Need to update PR description to ref
comput_pairs_onlyinstead ofpairs. -
The
__init__stil builds the fullNxMself.r0which is still kept for the full lifetime. The initial memory isn't saved currently. We could also drop the full matrix and just use include the pairs as well saving some more memory for larger systems.
|
Hi, good point regarding r0. Maybe we can open a separate PR for this. I am worried because dropping the full matrix would change behaviour for everyone regardless of compute_pairs_only=True |
Hi again @IAlibay I opened #5517 to discuss this as requested. Could you take another look ? |
|
Hello everyone, is there anything I can do to move this PR forward? Thank you all. |
orbeckst
left a comment
There was a problem hiding this comment.
Overall looks good to me. I like that the clean separation of the two code paths though private methods.
| def test_rerun_after_initial_contacts_edit( | ||
| self, universe, compute_pairs_only | ||
| ): | ||
| """initial_contacts is public: editing it between runs must be |
There was a problem hiding this comment.
initial_contacts is not actually documented so calling it public is a bit of a stretch. However, clever people may have (ab)used it so I am ok with leaving this test in.
|
@IAlibay are you ok with moving forward with merging the PR? The issue was raised and described the idea, both Brady and I are happy with the PR. |
Yeah sorry about that - I dismissed the review. |
|
@carlosvega congratulations on your first merged PR 🎉 |
|
Thanks! |
Fixes #5517
Changes made in this Pull Request:
Contactsbuilds the full distance matrix of the two selections on every frame and then keeps only the entries that were in contact in the reference. When the native contacts are a tiny fraction of all pairs (for example all protein heavy atoms), nearly all of that work gets thrown away.This PR adds an opt-in
compute_pairs_only=Falsekeyword. Withcompute_pairs_only=True, the contact indices and reference distances are worked out once per run, and each frame callscalc_bondson just those pairs, using the same box and the samemethod. The default code path is untouched, and the results match the default (compared atrtol=1e-12in the tests and in the benchmark below).In short, instead of computing every distance and discarding most, we remember once which pairs matter and compute only those.
Benchmark. 15 cases on 7 systems (macOS ARM64, serial,
OMP_NUM_THREADS=1, median of 3–5 alternating runs,Contacts.run()only). "Density" is the share of all N×N atom pairs that are reference contacts. "init+run" also counts building theContactsobject, whose dense reference setup is unchanged. "Memory" is the peak memory allocated duringrun()(tracemalloc).compute_pairs_only=Falsecompute_pairs_only=Truerun(), MiB (compute_pairs_only=False/True)GRO_MEMPROT)GRO_MEMPROT)So it helps a lot when the contacts are sparse and the selection is large, is neutral for small selections, and is slower when almost every pair is a contact. That is why it is opt-in rather than the default. The Asp/Glu–Arg/Lys case is also a small selection, so it doesn't gain much either.
Test:
pytest testsuite/MDAnalysisTests/analysis/test_contacts.py. The existing tests are parametrized overcompute_pairs_onlyand run with bothFalseandTruefor hard/soft/radius cut, with and without PBC (serial and multiprocessing backends), and with a custom method. New tests cover several overlapping references and rerunning after editing the mask.LLM / AI generated code disclosure
LLMs or other AI-powered tools (beyond simple IDE use cases) were used in this contribution: yes
patch was checked with LLMs for quality, tests done with LLM and benchmark script were drafted with an AI coding assistant.
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.