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()
Empty file.
19 changes: 19 additions & 0 deletions benchmarks/benchmarks/lib/dihedrals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import numpy as np
from MDAnalysis.lib.distances import calc_dihedrals


class DihedralBench:

params = [100, 500, 1000, 10000]
param_names = ["n_dihedrals"]

def setup(self, n_dihedrals):
self.coords = np.random.random((n_dihedrals, 4, 3))

def time_calc_dihedrals(self, n_dihedrals):
calc_dihedrals(
self.coords[:,0],
self.coords[:,1],
self.coords[:,2],
self.coords[:,3]
)
26 changes: 26 additions & 0 deletions benchmarks/benchmarks/lib/distances.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import numpy as np
from MDAnalysis.lib.distances import distance_array, self_distance_array


class DistanceArrayBench:

params = [100, 500, 1000, 10000]
param_names = ["n_atoms"]

def setup(self, n_atoms):
self.coords1 = np.random.random((n_atoms, 3))
self.coords2 = np.random.random((n_atoms, 3))

def time_distance_array(self, n_atoms):
distance_array(self.coords1, self.coords2)

class SelfDistanceArrayBench:

params = [100, 500, 1000, 10000]
param_names = ["n_atoms"]

def setup(self, n_atoms):
self.coords = np.random.random((n_atoms, 3))

def time_self_distance_array(self, n_atoms):
self_distance_array(self.coords)
16 changes: 16 additions & 0 deletions benchmarks/benchmarks/lib/fastns.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import numpy as np
from MDAnalysis.lib.nsgrid import FastNS


class FastNSBench:

params = [100, 500, 1000, 10000]
param_names = ["n_atoms"]

def setup(self, n_atoms):
self.coords = np.random.random((n_atoms, 3)).astype(np.float32)
self.box = np.array([10, 10, 10, 90, 90, 90], dtype=np.float32)

def time_fastns(self, n_atoms):
ns = FastNS(5.0, self.coords, self.box)
ns.self_search()
15 changes: 15 additions & 0 deletions benchmarks/benchmarks/lib/neighborsearch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import numpy as np
from MDAnalysis.lib.NeighborSearch import AtomNeighborSearch
import MDAnalysis as mda
from MDAnalysisTests.datafiles import PSF, DCD


class NeighborSearchBench:

def setup(self):
self.u = mda.Universe(PSF, DCD)
self.atoms = self.u.select_atoms("protein")
self.ns = AtomNeighborSearch(self.atoms)

def time_neighbor_search(self):
self.ns.search(self.atoms, 5.0)
1 change: 1 addition & 0 deletions package/AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ Chronological list of authors
- Harshit Gajjela
- Kunj Sinha
- Ayush Agarwal
- Amarendra Mohan
Comment thread
Amarendra22 marked this conversation as resolved.
Outdated
- Parth Uppal

External code
Expand Down
1 change: 1 addition & 0 deletions package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Enhancements
* Adds support for parsing `.tpr` files produced by GROMACS 2026.0
* Enables parallelization for analysis.diffusionmap.DistanceMatrix
(Issue #4679, PR #4745)
* Added ASV benchmark for `MDAnalysis.analysis.contacts` (PR #5291)
Comment thread
Amarendra22 marked this conversation as resolved.
Outdated

Changes
* The msd.py inside analysis is changed, and ProgressBar is implemented inside
Expand Down
Loading