Repository navigation
Speed up Compound.add and Compound.remove on large compounds - #1388
Merged
chrisjonesBSU merged 5 commits intoNov 20, 2026
Merged
Conversation
Compound.add composed the root bond graph with nx.compose, which copies the whole root graph on every add; merging the child's graph in place with Graph.update gives the same graph without the copy. _prune_ghost_ports tested port anchors for membership in a list of all particles; a set makes each test O(1). Together these cut glycan placement on the BG505 trimer (56k atoms, 63 attaches) by about 12%.
…e bond graph Compound._remove copied the whole root bond graph to iterate one part's neighbors while deleting its bonds; listing the neighbors first is enough. On a 56k-atom protein each copy cost ~0.1 s, paid on every remove.
…emove Adding compounds one at a time or as a list keeps every bond and its order in the root bond graph, and removing one bonded particle drops only that particle's bond.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #1388 +/- ##
===========================================
+ Coverage 82.71% 82.74% +0.03%
===========================================
Files 72 72
Lines 8794 8794
===========================================
+ Hits 7274 7277 +3
+ Misses 1520 1517 -3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
chrisjonesBSU
approved these changes
Nov 20, 2026
chrisjonesBSU
approved these changes
Nov 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Summary:
Three small changes in
Compoundthat remove a copy of the whole bond graph fromaddandremove. None of them change end behavior.Compound.addmerged the child's bond graph into the root's withnx.compose, which builds a new graph containing every node and edge of the root on each call.BondGraphis annx.Graph, soself.root.bond_graph.update(child_graph)gives the same graph in place. This is changed in both the single-compound and the list branch ofadd._removeiterated a removed particle's neighbors overself.root.bond_graph.copy()so it could delete bonds during the loop. Listing the neighbors first,list(graph.neighbors(part)), is enough._prune_ghost_portschecked each port's anchor against a list of all particles. It now uses a set.Timings on
develop(a862a5a) and on this branch, building a compound from ethanes added one at a time and then removing one hydrogen per ethane one at a time:Benchmark script
I ran into this while building large proteins with many attached groups (#1355), where each
addorremovescaled with the size of the whole structure.Two tests are added. One checks that adding compounds, either one at a time or as a list, keeps every bond and its order in the root bond graph. The other checks that removing one bonded particle removes only that particle's bond.
PR Checklist