Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of Parallelization to analysis.bat #4693

Merged
merged 14 commits into from
Sep 14, 2024
1 change: 1 addition & 0 deletions package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ Enhancements
(Issue #4158, PR #4304)
* Enables parallelization for analysis.gnm.GNMAnalysis (Issue #4672)
* explicitly mark `analysis.pca.PCA` as not parallelizable (Issue #4680)
* enables parallelization for analysis.bat.BAT (Issue #4663)
* Improve error message for `AtomGroup.unwrap()` when bonds are not present.(Issue #4436, PR #4642)
* Add `analysis.DSSP` module for protein secondary structure assignment, based on [pydssp](https://github.com/ShintaroMinami/PyDSSP)
* Added a tqdm progress bar for `MDAnalysis.analysis.pca.PCA.transform()`
Expand Down
29 changes: 25 additions & 4 deletions package/MDAnalysis/analysis/bat.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class to calculate dihedral angles for a given set of atoms or residues
import copy

import MDAnalysis as mda
from .base import AnalysisBase
from .base import AnalysisBase, ResultsGroup

from MDAnalysis.lib.distances import calc_bonds, calc_angles, calc_dihedrals
from MDAnalysis.lib.mdamath import make_whole
Expand Down Expand Up @@ -253,10 +253,28 @@ class BAT(AnalysisBase):
Bond-Angle-Torsions (BAT) internal coordinates will be computed for
the group of atoms and all frame in the trajectory belonging to `ag`.

.. versionchanged:: 2.8.0
Enabled **parallel execution** with the ``multiprocessing`` and ``dask``
backends; use the new method :meth:`get_supported_backends` to see all
supported backends.

"""
@due.dcite(Doi("10.1002/jcc.26036"),
description="Bond-Angle-Torsions Coordinate Transformation",
path="MDAnalysis.analysis.bat.BAT")
_analysis_algorithm_is_parallelizable = True

@classmethod
def get_supported_backends(cls):
return (
"serial",
"multiprocessing",
"dask",
)

@due.dcite(
Doi("10.1002/jcc.26036"),
description="Bond-Angle-Torsions Coordinate Transformation",
path="MDAnalysis.analysis.bat.BAT",
)

def __init__(self, ag, initial_atom=None, filename=None, **kwargs):
r"""Parameters
----------
Expand Down Expand Up @@ -558,3 +576,6 @@ def Cartesian(self, bat_frame):
def atoms(self):
"""The atomgroup for which BAT are computed (read-only property)"""
return self._ag

def _get_aggregator(self):
return ResultsGroup(lookup={'bat': ResultsGroup.ndarray_vstack})
6 changes: 6 additions & 0 deletions testsuite/MDAnalysisTests/analysis/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
OldAPIAnalysis,
)
from MDAnalysis.analysis.rms import RMSD, RMSF
from MDAnalysis.analysis.bat import BAT
from MDAnalysis.lib.util import is_installed
from MDAnalysis.analysis.gnm import GNMAnalysis

Expand Down Expand Up @@ -93,3 +94,8 @@ def client_RMSF(request):
@pytest.fixture(scope='module', params=params_for_cls(GNMAnalysis))
def client_GNMAnalysis(request):
return request.param


@pytest.fixture(scope='module', params=params_for_cls(BAT))
def client_BAT(request):
return request.param
12 changes: 6 additions & 6 deletions testsuite/MDAnalysisTests/analysis/test_bat.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ def selected_residues(self):
return ag

@pytest.fixture()
def bat(self, selected_residues):
def bat(self, selected_residues, client_BAT):
R = BAT(selected_residues)
R.run()
R.run(**client_BAT)
return R.results.bat

@pytest.fixture
def bat_npz(self, tmpdir, selected_residues):
def bat_npz(self, tmpdir, selected_residues, client_BAT):
filename = str(tmpdir / 'test_bat_IO.npy')
R = BAT(selected_residues)
R.run()
R.run(**client_BAT)
R.save(filename)
return filename

Expand All @@ -73,8 +73,8 @@ def test_bat_coordinates(self, bat):
atol=1.5e-5,
err_msg="error: BAT coordinates should match test values")

def test_bat_coordinates_single_frame(self, selected_residues):
bat = BAT(selected_residues).run(start=1, stop=2).results.bat
def test_bat_coordinates_single_frame(self, selected_residues, client_BAT):
bat = BAT(selected_residues).run(start=1, stop=2, **client_BAT).results.bat
test_bat = [np.load(BATArray)[1]]
assert_allclose(
bat,
Expand Down
Loading