From 3e8bcf6685398cdb96f0cdc363842915561c1ba7 Mon Sep 17 00:00:00 2001 From: Valerij Talagayev <82884038+talagayev@users.noreply.github.com> Date: Sat, 19 Oct 2024 23:02:24 +0200 Subject: [PATCH 01/12] Update diffusionmap.py added backends and aggregator for DistanceMatrix --- package/MDAnalysis/analysis/diffusionmap.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/package/MDAnalysis/analysis/diffusionmap.py b/package/MDAnalysis/analysis/diffusionmap.py index 1c63357a160..3477f5bf5d0 100644 --- a/package/MDAnalysis/analysis/diffusionmap.py +++ b/package/MDAnalysis/analysis/diffusionmap.py @@ -143,7 +143,7 @@ from MDAnalysis.core.universe import Universe from MDAnalysis.core.groups import AtomGroup, UpdatingAtomGroup from .rms import rmsd -from .base import AnalysisBase +from .base import AnalysisBase, ResultsGroup logger = logging.getLogger("MDAnalysis.analysis.diffusionmap") @@ -233,8 +233,18 @@ class DistanceMatrix(AnalysisBase): :class:`DistanceMatrix` now also accepts `AtomGroup`. .. versionchanged:: 2.8.0 :class:`DistanceMatrix` is now correctly works with `frames=...` - parameter (#4432) by iterating over `self._sliced_trajectory` + parameter (#4432) by iterating over `self._sliced_trajectory`. + Enabled **parallel execution** with the ``multiprocessing`` and ``dask`` + backends; use the new method :meth:`get_supported_backends` to see all + supported backends. """ + + _analysis_algorithm_is_parallelizable = True + + @classmethod + def get_supported_backends(cls): + return ('serial', 'multiprocessing', 'dask') + def __init__(self, universe, select='all', metric=rmsd, cutoff=1E0-5, weights=None, **kwargs): # remember that this must be called before referencing self.n_frames @@ -286,6 +296,12 @@ def dist_matrix(self): def _conclude(self): self._calculated = True + def _get_aggregator(self): + return ResultsGroup( + lookup={ + "dist_matrix": ResultsGroup.ndarray_vstack, + } + ) class DiffusionMap(object): """Non-linear dimension reduction method From a86327f3fbe64168023adb4e79886f4f59dbf11f Mon Sep 17 00:00:00 2001 From: Valerij Talagayev <82884038+talagayev@users.noreply.github.com> Date: Sat, 19 Oct 2024 23:06:45 +0200 Subject: [PATCH 02/12] Update conftest.py added client_DistanceMatrix --- testsuite/MDAnalysisTests/analysis/conftest.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/testsuite/MDAnalysisTests/analysis/conftest.py b/testsuite/MDAnalysisTests/analysis/conftest.py index fc3c8a480c7..a54462445a2 100644 --- a/testsuite/MDAnalysisTests/analysis/conftest.py +++ b/testsuite/MDAnalysisTests/analysis/conftest.py @@ -14,6 +14,7 @@ from MDAnalysis.analysis.hydrogenbonds.hbond_analysis import ( HydrogenBondAnalysis, ) +from MDAnalysis.analysis.diffusionmap import DistanceMatrix from MDAnalysis.lib.util import is_installed @@ -141,3 +142,10 @@ def client_DSSP(request): @pytest.fixture(scope='module', params=params_for_cls(HydrogenBondAnalysis)) def client_HydrogenBondAnalysis(request): return request.param + + +# MDAnalysis.analysis.hydrogenbonds + +@pytest.fixture(scope="module", params=params_for_cls(DistanceMatrix)) +def client_DistanceMatrix(request): + return request.param From 3002f68e309dddb48bb4ab2061116079b737272b Mon Sep 17 00:00:00 2001 From: Valerij Talagayev <82884038+talagayev@users.noreply.github.com> Date: Sun, 20 Oct 2024 00:03:18 +0200 Subject: [PATCH 03/12] Update test_diffusionmap.py added client_DistanceMatrix to tests --- .../analysis/test_diffusionmap.py | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/testsuite/MDAnalysisTests/analysis/test_diffusionmap.py b/testsuite/MDAnalysisTests/analysis/test_diffusionmap.py index be58365b0fa..f45a570fb7e 100644 --- a/testsuite/MDAnalysisTests/analysis/test_diffusionmap.py +++ b/testsuite/MDAnalysisTests/analysis/test_diffusionmap.py @@ -52,13 +52,13 @@ def test_eg(dist, dmap): # makes no sense to test values here, no physical meaning -def test_dist_weights(u): +def test_dist_weights(u, client_DistanceMatrix): backbone = u.select_atoms('backbone') weights_atoms = np.ones(len(backbone.atoms)) dist = diffusionmap.DistanceMatrix(u, select='backbone', weights=weights_atoms) - dist.run(step=3) + dist.run(**client_DistanceMatrix, step=3) dmap = diffusionmap.DiffusionMap(dist) dmap.run() assert_array_almost_equal(dmap.eigenvalues, [1, 1, 1, 1], 4) @@ -69,14 +69,14 @@ def test_dist_weights(u): [.707, -.707, 0, 0]]), 2) -def test_dist_weights_frames(u): +def test_dist_weights_frames(u, client_DistanceMatrix): backbone = u.select_atoms('backbone') weights_atoms = np.ones(len(backbone.atoms)) dist = diffusionmap.DistanceMatrix(u, select='backbone', weights=weights_atoms) frames = np.arange(len(u.trajectory)) - dist.run(frames=frames[::3]) + dist.run(**client_DistanceMatrix, frames=frames[::3]) dmap = diffusionmap.DiffusionMap(dist) dmap.run() assert_array_almost_equal(dmap.eigenvalues, [1, 1, 1, 1], 4) @@ -86,18 +86,18 @@ def test_dist_weights_frames(u): [-.707, -.707, 0, 0], [.707, -.707, 0, 0]]), 2) -def test_distvalues_ag_universe(u): - dist_universe = diffusionmap.DistanceMatrix(u, select='backbone').run() +def test_distvalues_ag_universe(u, client_DistanceMatrix): + dist_universe = diffusionmap.DistanceMatrix(u, select='backbone').run(**client_DistanceMatrix) ag = u.select_atoms('backbone') - dist_ag = diffusionmap.DistanceMatrix(ag).run() + dist_ag = diffusionmap.DistanceMatrix(ag).run(**client_DistanceMatrix) assert_allclose(dist_universe.results.dist_matrix, dist_ag.results.dist_matrix) -def test_distvalues_ag_select(u): - dist_universe = diffusionmap.DistanceMatrix(u, select='backbone').run() +def test_distvalues_ag_select(u, client_DistanceMatrix): + dist_universe = diffusionmap.DistanceMatrix(u, select='backbone').run(**client_DistanceMatrix) ag = u.select_atoms('protein') - dist_ag = diffusionmap.DistanceMatrix(ag, select='backbone').run() + dist_ag = diffusionmap.DistanceMatrix(ag, select='backbone').run(**client_DistanceMatrix) assert_allclose(dist_universe.results.dist_matrix, dist_ag.results.dist_matrix) From 7d5ff8645fd60c38af6b1a7f3afab490aeee4d15 Mon Sep 17 00:00:00 2001 From: Valerij Talagayev <82884038+talagayev@users.noreply.github.com> Date: Sun, 20 Oct 2024 00:16:50 +0200 Subject: [PATCH 04/12] Update diffusionmap.py pep fixes --- package/MDAnalysis/analysis/diffusionmap.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package/MDAnalysis/analysis/diffusionmap.py b/package/MDAnalysis/analysis/diffusionmap.py index 3477f5bf5d0..447399efe8c 100644 --- a/package/MDAnalysis/analysis/diffusionmap.py +++ b/package/MDAnalysis/analysis/diffusionmap.py @@ -234,9 +234,9 @@ class DistanceMatrix(AnalysisBase): .. versionchanged:: 2.8.0 :class:`DistanceMatrix` is now correctly works with `frames=...` parameter (#4432) by iterating over `self._sliced_trajectory`. - Enabled **parallel execution** with the ``multiprocessing`` and ``dask`` - backends; use the new method :meth:`get_supported_backends` to see all - supported backends. + Enabled **parallel execution** with the ``multiprocessing`` and + ``dask`` backends; use the new method :meth:`get_supported_backends` + to see all supported backends. """ _analysis_algorithm_is_parallelizable = True From b8a03ceaab9f11f8f54eb3e88e0134e29e4d10a2 Mon Sep 17 00:00:00 2001 From: Valerij Talagayev <82884038+talagayev@users.noreply.github.com> Date: Sun, 20 Oct 2024 00:17:12 +0200 Subject: [PATCH 05/12] Update diffusionmap.py --- package/MDAnalysis/analysis/diffusionmap.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/MDAnalysis/analysis/diffusionmap.py b/package/MDAnalysis/analysis/diffusionmap.py index 447399efe8c..031d3c406ee 100644 --- a/package/MDAnalysis/analysis/diffusionmap.py +++ b/package/MDAnalysis/analysis/diffusionmap.py @@ -234,7 +234,7 @@ class DistanceMatrix(AnalysisBase): .. versionchanged:: 2.8.0 :class:`DistanceMatrix` is now correctly works with `frames=...` parameter (#4432) by iterating over `self._sliced_trajectory`. - Enabled **parallel execution** with the ``multiprocessing`` and + Enabled **parallel execution** with the ``multiprocessing`` and ``dask`` backends; use the new method :meth:`get_supported_backends` to see all supported backends. """ From 5e74e053dc9bba1702159aef1963dc67ec83a792 Mon Sep 17 00:00:00 2001 From: Valerij Talagayev <82884038+talagayev@users.noreply.github.com> Date: Sun, 20 Oct 2024 00:18:19 +0200 Subject: [PATCH 06/12] Update test_diffusionmap.py pep fixes --- testsuite/MDAnalysisTests/analysis/test_diffusionmap.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/testsuite/MDAnalysisTests/analysis/test_diffusionmap.py b/testsuite/MDAnalysisTests/analysis/test_diffusionmap.py index f45a570fb7e..97086d6d773 100644 --- a/testsuite/MDAnalysisTests/analysis/test_diffusionmap.py +++ b/testsuite/MDAnalysisTests/analysis/test_diffusionmap.py @@ -87,7 +87,8 @@ def test_dist_weights_frames(u, client_DistanceMatrix): [.707, -.707, 0, 0]]), 2) def test_distvalues_ag_universe(u, client_DistanceMatrix): - dist_universe = diffusionmap.DistanceMatrix(u, select='backbone').run(**client_DistanceMatrix) + dist_universe = diffusionmap.DistanceMatrix(u, + select='backbone').run(**client_DistanceMatrix) ag = u.select_atoms('backbone') dist_ag = diffusionmap.DistanceMatrix(ag).run(**client_DistanceMatrix) assert_allclose(dist_universe.results.dist_matrix, @@ -95,9 +96,11 @@ def test_distvalues_ag_universe(u, client_DistanceMatrix): def test_distvalues_ag_select(u, client_DistanceMatrix): - dist_universe = diffusionmap.DistanceMatrix(u, select='backbone').run(**client_DistanceMatrix) + dist_universe = diffusionmap.DistanceMatrix(u, + select='backbone').run(**client_DistanceMatrix) ag = u.select_atoms('protein') - dist_ag = diffusionmap.DistanceMatrix(ag, select='backbone').run(**client_DistanceMatrix) + dist_ag = diffusionmap.DistanceMatrix(ag, + select='backbone').run(**client_DistanceMatrix) assert_allclose(dist_universe.results.dist_matrix, dist_ag.results.dist_matrix) From 539ad1621acabdf3d2bf41d6961cc9506b3eeaa3 Mon Sep 17 00:00:00 2001 From: Valerij Talagayev <82884038+talagayev@users.noreply.github.com> Date: Sun, 20 Oct 2024 00:20:30 +0200 Subject: [PATCH 07/12] Update test_diffusionmap.py pep --- .../analysis/test_diffusionmap.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/testsuite/MDAnalysisTests/analysis/test_diffusionmap.py b/testsuite/MDAnalysisTests/analysis/test_diffusionmap.py index 97086d6d773..bbe8cf0e3bc 100644 --- a/testsuite/MDAnalysisTests/analysis/test_diffusionmap.py +++ b/testsuite/MDAnalysisTests/analysis/test_diffusionmap.py @@ -86,9 +86,11 @@ def test_dist_weights_frames(u, client_DistanceMatrix): [-.707, -.707, 0, 0], [.707, -.707, 0, 0]]), 2) + def test_distvalues_ag_universe(u, client_DistanceMatrix): - dist_universe = diffusionmap.DistanceMatrix(u, - select='backbone').run(**client_DistanceMatrix) + dist_universe = diffusionmap.DistanceMatrix(u, select='backbone').run( + **client_DistanceMatrix + ) ag = u.select_atoms('backbone') dist_ag = diffusionmap.DistanceMatrix(ag).run(**client_DistanceMatrix) assert_allclose(dist_universe.results.dist_matrix, @@ -96,11 +98,13 @@ def test_distvalues_ag_universe(u, client_DistanceMatrix): def test_distvalues_ag_select(u, client_DistanceMatrix): - dist_universe = diffusionmap.DistanceMatrix(u, - select='backbone').run(**client_DistanceMatrix) + dist_universe = diffusionmap.DistanceMatrix(u, select='backbone').run( + **client_DistanceMatrix + ) ag = u.select_atoms('protein') - dist_ag = diffusionmap.DistanceMatrix(ag, - select='backbone').run(**client_DistanceMatrix) + dist_ag = diffusionmap.DistanceMatrix(ag, select='backbone').run( + **client_DistanceMatrix + ) assert_allclose(dist_universe.results.dist_matrix, dist_ag.results.dist_matrix) From 820c8156aca7c1b7ef8714b5dfa650f90e9dd218 Mon Sep 17 00:00:00 2001 From: Valerij Talagayev <82884038+talagayev@users.noreply.github.com> Date: Sun, 20 Oct 2024 01:04:57 +0200 Subject: [PATCH 08/12] Update diffusionmap.py testing ndarray_mean --- package/MDAnalysis/analysis/diffusionmap.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/MDAnalysis/analysis/diffusionmap.py b/package/MDAnalysis/analysis/diffusionmap.py index 031d3c406ee..a84279e46ba 100644 --- a/package/MDAnalysis/analysis/diffusionmap.py +++ b/package/MDAnalysis/analysis/diffusionmap.py @@ -299,7 +299,7 @@ def _conclude(self): def _get_aggregator(self): return ResultsGroup( lookup={ - "dist_matrix": ResultsGroup.ndarray_vstack, + "dist_matrix": ResultsGroup.ndarray_mean, } ) From 4cef414ccb1dbc2fbeee0110955477e5924cdfb6 Mon Sep 17 00:00:00 2001 From: Valerij Talagayev <82884038+talagayev@users.noreply.github.com> Date: Thu, 19 Dec 2024 01:57:32 +0100 Subject: [PATCH 09/12] Update diffusionmap.py change to ndarray_vstack --- package/MDAnalysis/analysis/diffusionmap.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/MDAnalysis/analysis/diffusionmap.py b/package/MDAnalysis/analysis/diffusionmap.py index a84279e46ba..031d3c406ee 100644 --- a/package/MDAnalysis/analysis/diffusionmap.py +++ b/package/MDAnalysis/analysis/diffusionmap.py @@ -299,7 +299,7 @@ def _conclude(self): def _get_aggregator(self): return ResultsGroup( lookup={ - "dist_matrix": ResultsGroup.ndarray_mean, + "dist_matrix": ResultsGroup.ndarray_vstack, } ) From 795f26f53efd472ceeb87a4f9ff922a0042a6dea Mon Sep 17 00:00:00 2001 From: Valerij Talagayev <82884038+talagayev@users.noreply.github.com> Date: Thu, 19 Dec 2024 02:08:12 +0100 Subject: [PATCH 10/12] Update CHANGELOG Added parallelization change --- package/CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/package/CHANGELOG b/package/CHANGELOG index 909020a8661..8260d6511cc 100644 --- a/package/CHANGELOG +++ b/package/CHANGELOG @@ -25,6 +25,7 @@ Fixes the function to prevent shared state. (Issue #4655) Enhancements + * Enables parallelization for analysis.diffusionmap.DistanceMatrix (Issue #4679, PR #4745) * Enables parallelization for analysis.density.DensityAnalysis (Issue #4677, PR #4729) * Enables parallelization for analysis.contacts.Contacts (Issue #4660) * Enable parallelization for analysis.nucleicacids.NucPairDist (Issue #4670) From d8687f595ea6d60382a0c1c13c3f84b79b16c3d9 Mon Sep 17 00:00:00 2001 From: Valerij Talagayev <82884038+talagayev@users.noreply.github.com> Date: Thu, 19 Dec 2024 02:10:46 +0100 Subject: [PATCH 11/12] Update diffusionmap.py added version change for docs --- package/MDAnalysis/analysis/diffusionmap.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/package/MDAnalysis/analysis/diffusionmap.py b/package/MDAnalysis/analysis/diffusionmap.py index 2001ff7d52d..ca6f29541f4 100644 --- a/package/MDAnalysis/analysis/diffusionmap.py +++ b/package/MDAnalysis/analysis/diffusionmap.py @@ -233,10 +233,11 @@ class DistanceMatrix(AnalysisBase): :class:`DistanceMatrix` now also accepts `AtomGroup`. .. versionchanged:: 2.8.0 :class:`DistanceMatrix` is now correctly works with `frames=...` - parameter (#4432) by iterating over `self._sliced_trajectory`. - Enabled **parallel execution** with the ``multiprocessing`` and - ``dask`` backends; use the new method :meth:`get_supported_backends` - to see all supported backends. + parameter (#4432) by iterating over `self._sliced_trajectory` + .. versionchanged:: 2.9.0 + Introduced :meth:`get_supported_backends` allowing + for parallel execution on :mod:`multiprocessing` + and :mod:`dask` backends. """ _analysis_algorithm_is_parallelizable = True From ce626936a2e6edd790651d5bb2388328815df226 Mon Sep 17 00:00:00 2001 From: Valerij Talagayev <82884038+talagayev@users.noreply.github.com> Date: Thu, 19 Dec 2024 02:33:16 +0100 Subject: [PATCH 12/12] Update diffusionmap.py move back ndarray_sum --- package/MDAnalysis/analysis/diffusionmap.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/MDAnalysis/analysis/diffusionmap.py b/package/MDAnalysis/analysis/diffusionmap.py index ca6f29541f4..da23db7c0b8 100644 --- a/package/MDAnalysis/analysis/diffusionmap.py +++ b/package/MDAnalysis/analysis/diffusionmap.py @@ -300,7 +300,7 @@ def _conclude(self): def _get_aggregator(self): return ResultsGroup( lookup={ - "dist_matrix": ResultsGroup.ndarray_vstack, + "dist_matrix": ResultsGroup.ndarray_sum, } )