Skip to content
62 changes: 62 additions & 0 deletions benchmarks/benchmarks/analysis/contacts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import MDAnalysis as mda
from MDAnalysis.analysis import contacts
from MDAnalysisTests.datafiles import PSF, DCD


class ContactsBench(object):
"""
Benchmarks for MDAnalysis.analysis.contacts.Contacts
"""

# Parameter combinations tested in the benchmark.
# radius : cutoff distance used to define a contact
# method : algorithm used to compute contacts
# pbc : whether periodic boundary conditions are applied
params = [
[4.5, 6.0],
["hard_cut", "soft_cut", "radius_cut"],
[True, False],
]

# Names corresponding to the parameters above
param_names = ["radius", "method", "pbc"]

def setup(self, radius, method, pbc):
"""
Prepare the Universe and contact analysis object
for benchmarking.
"""

# Load test trajectory
self.u = mda.Universe(PSF, DCD)

# Define atom selections
self.sel1 = "protein"
self.sel2 = "name CA"

# Create atom groups from the selections
g1 = self.u.select_atoms(self.sel1)
g2 = self.u.select_atoms(self.sel2)

# Initialize the Contacts analysis
# select : atom selection strings
# refgroup : reference atom groups used for contacts
# radius : contact cutoff distance
# method : contact calculation method
# pbc : periodic boundary conditions flag
self.analysis = contacts.Contacts(
self.u,
select=(self.sel1, self.sel2),
refgroup=(g1, g2),
radius=radius,
method=method,
pbc=pbc,
)

def time_contacts_run(self, radius, method, pbc):
"""
Benchmark execution of Contacts.run()
over the full trajectory.
"""

self.analysis.run()
1 change: 1 addition & 0 deletions package/AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ Chronological list of authors
- Ayush Agarwal
- Parth Uppal
- Olivier Languin--Cattoën
- Amarendra Mohan

External code
-------------
Expand Down
3 changes: 2 additions & 1 deletion package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ The rules for this file:
??/??/?? IAlibay, orbeckst, marinegor, tylerjereddy, ljwoods2, marinegor,
spyke7, talagayev, tanii1125, BradyAJohnston, hejamu, jeremyleung521,
harshitgajjela-droid, kunjsinha, aygarwal, jauy123, Dreamstick9,
ollyfutur
ollyfutur, Amarendra22

* 2.11.0

Expand Down Expand Up @@ -46,6 +46,7 @@ Fixes
DSSP by porting upstream PyDSSP 0.9.1 fix (Issue #4913)

Enhancements
* Added ASV benchmark for `MDAnalysis.analysis.contacts` (PR #5291)
* Improved performance of inverse index mapping in AtomGroup using an optimized
Cython implementation in lib._cutils.inverse_int_index()
(Issue #3387, PR #5252)
Expand Down
Loading