Repository navigation
Speed up find_stacking_interactions() and find_pi_cation_interactions() - #1019
Conversation
e6be6d9 to
e405352
Compare
Merging this PR will regress 2 benchmarks
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance ChangesTip Investigate this regression by commenting Comparing Footnotes
|
…ons()` by vectorizing ring geometry
e405352 to
e27f830
Compare
Both functions computed the centroid and plane normal of each aromatic ring in a Python loop (
mean()+np.cross()per ring). The per-ring NumPy call overhead dominated the runtime for structures with many rings.Fix: compute all centroids and normals at once in a new
_get_ring_geometry()helper (replaces_get_ring_normal()): centroids vianp.add.at()on the concatenated ring coordinates, normals via a singlenp.cross()on the first three atoms of each ring.np.add.at()was chosen overnp.add.reduceat(), as the latter is not bitwise identical tomean().Centroids and normals are bitwise identical to the previous implementation for all rings in
tests/structure/data/pdb/*.bcif; the returned interactions are identical for these structures (also with all nitrogen atoms artificially charged to exercise the pi-cation path).find_stacking_interactionsfind_stacking_interactionsfind_stacking_interactionsfind_pi_cation_interactionsTests run:
tests/structure/test_rings.py,tests/test_doctest.py::test_doctest[biotite.structure].Authored by Claude