diff --git a/benchmarks/benchmarks/analysis/contacts.py b/benchmarks/benchmarks/analysis/contacts.py new file mode 100644 index 0000000000..a91742fca0 --- /dev/null +++ b/benchmarks/benchmarks/analysis/contacts.py @@ -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() diff --git a/package/AUTHORS b/package/AUTHORS index 887210c0ae..32eca18004 100644 --- a/package/AUTHORS +++ b/package/AUTHORS @@ -276,6 +276,7 @@ Chronological list of authors - Kunj Sinha - Ayush Agarwal - Parth Uppal + - Amarendra Mohan External code ------------- diff --git a/package/CHANGELOG b/package/CHANGELOG index d17748755b..1f10c41924 100644 --- a/package/CHANGELOG +++ b/package/CHANGELOG @@ -42,6 +42,7 @@ Fixes DSSP by porting upstream PyDSSP 0.9.1 fix (Issue #4913) Enhancements + * Added ASV benchmark for `MDAnalysis.analysis.contacts` (PR #5291) * MOL2Parser now reads unit cell dimensions from @CRYSIN records (Issue #3341) * Reduces duplication of code in _apply() function (Issue #5247, PR #5294) * Added new top-level `MDAnalysis.fetch` module (PR #4943)