From 81d14789fd73e9aae2cd50725690eb4bace59cb7 Mon Sep 17 00:00:00 2001 From: Egor Marin Date: Tue, 21 Mar 2023 19:52:48 +0300 Subject: [PATCH 1/8] Add progress bar keywords --- package/MDAnalysis/analysis/base.py | 10 ++++++++-- testsuite/MDAnalysisTests/analysis/test_base.py | 8 +++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/package/MDAnalysis/analysis/base.py b/package/MDAnalysis/analysis/base.py index 266ae68a02e..84f94a2be4a 100644 --- a/package/MDAnalysis/analysis/base.py +++ b/package/MDAnalysis/analysis/base.py @@ -390,7 +390,7 @@ def _conclude(self): pass # pylint: disable=unnecessary-pass def run(self, start=None, stop=None, step=None, frames=None, - verbose=None): + verbose=None, *, pbar_kwargs={}): """Perform the calculation Parameters @@ -411,6 +411,10 @@ def run(self, start=None, stop=None, step=None, frames=None, verbose : bool, optional Turn on verbosity + + pbar_kwargs : dict, optional + ProgressBar keywords with custom parameters regarding progress bar position, etc; + see :class:`MDAnalysis.lib.log.ProgressBar` for full list. .. versionchanged:: 2.2.0 @@ -429,9 +433,11 @@ def run(self, start=None, stop=None, step=None, frames=None, self._prepare() logger.info("Starting analysis loop over %d trajectory frames", self.n_frames) + for i, ts in enumerate(ProgressBar( self._sliced_trajectory, - verbose=verbose)): + verbose=verbose, + **pbar_kwargs)): self._frame_index = i self._ts = ts self.frames[i] = ts.frame diff --git a/testsuite/MDAnalysisTests/analysis/test_base.py b/testsuite/MDAnalysisTests/analysis/test_base.py index 09b7b158f0a..b7217217f83 100644 --- a/testsuite/MDAnalysisTests/analysis/test_base.py +++ b/testsuite/MDAnalysisTests/analysis/test_base.py @@ -30,7 +30,7 @@ from numpy.testing import assert_equal, assert_almost_equal import MDAnalysis as mda -from MDAnalysis.analysis import base +from MDAnalysis.analysis import base, rms from MDAnalysisTests.datafiles import PSF, DCD, TPR, XTC from MDAnalysisTests.util import no_deprecated_call @@ -274,6 +274,12 @@ def test_verbose_progressbar_run(u, capsys): actual = err.strip().split('\r')[-1] assert actual[:24] == expected[:24] +def test_verbose_progressbar_run_with_kwargs(u, capsys): + an = FrameAnalysis(u.trajectory).run(verbose=True, pbar_kwargs={'desc':'custom'}) + out, err = capsys.readouterr() + expected = u'custom: 100%|██████████| 98/98 [00:00<00:00, 8799.49it/s]' + actual = err.strip().split('\r')[-1] + assert actual[:24] == expected[:24] def test_incomplete_defined_analysis(u): with pytest.raises(NotImplementedError): From e38c01127b6c40c4383e9c651e0b38246fc02134 Mon Sep 17 00:00:00 2001 From: Egor Marin Date: Tue, 21 Mar 2023 21:06:53 +0300 Subject: [PATCH 2/8] Update authors list for first isssue #4085 --- package/AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/package/AUTHORS b/package/AUTHORS index 01b535d69fe..e0624de9f4b 100644 --- a/package/AUTHORS +++ b/package/AUTHORS @@ -209,6 +209,7 @@ Chronological list of authors - Vishal Parmar - Moritz Schaeffler - Xu Hong Chen + - Egor Marin External code ------------- From 5874f5e3f150245a6732a0c93ca421f41e228afd Mon Sep 17 00:00:00 2001 From: Egor Marin Date: Sun, 26 Mar 2023 20:15:17 +0300 Subject: [PATCH 3/8] Rename `pbar_kwargs` to `progressbar_kwargs` --- package/MDAnalysis/analysis/base.py | 6 +++--- testsuite/MDAnalysisTests/analysis/test_base.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package/MDAnalysis/analysis/base.py b/package/MDAnalysis/analysis/base.py index 84f94a2be4a..838f7e1f3d2 100644 --- a/package/MDAnalysis/analysis/base.py +++ b/package/MDAnalysis/analysis/base.py @@ -390,7 +390,7 @@ def _conclude(self): pass # pylint: disable=unnecessary-pass def run(self, start=None, stop=None, step=None, frames=None, - verbose=None, *, pbar_kwargs={}): + verbose=None, *, progressbar_kwargs={}): """Perform the calculation Parameters @@ -412,7 +412,7 @@ def run(self, start=None, stop=None, step=None, frames=None, verbose : bool, optional Turn on verbosity - pbar_kwargs : dict, optional + progressbar_kwargs : dict, optional ProgressBar keywords with custom parameters regarding progress bar position, etc; see :class:`MDAnalysis.lib.log.ProgressBar` for full list. @@ -437,7 +437,7 @@ def run(self, start=None, stop=None, step=None, frames=None, for i, ts in enumerate(ProgressBar( self._sliced_trajectory, verbose=verbose, - **pbar_kwargs)): + **progressbar_kwargs)): self._frame_index = i self._ts = ts self.frames[i] = ts.frame diff --git a/testsuite/MDAnalysisTests/analysis/test_base.py b/testsuite/MDAnalysisTests/analysis/test_base.py index b7217217f83..b45c83cf2e8 100644 --- a/testsuite/MDAnalysisTests/analysis/test_base.py +++ b/testsuite/MDAnalysisTests/analysis/test_base.py @@ -275,7 +275,7 @@ def test_verbose_progressbar_run(u, capsys): assert actual[:24] == expected[:24] def test_verbose_progressbar_run_with_kwargs(u, capsys): - an = FrameAnalysis(u.trajectory).run(verbose=True, pbar_kwargs={'desc':'custom'}) + an = FrameAnalysis(u.trajectory).run(verbose=True, progressbar_kwargs={'desc':'custom'}) out, err = capsys.readouterr() expected = u'custom: 100%|██████████| 98/98 [00:00<00:00, 8799.49it/s]' actual = err.strip().split('\r')[-1] From aa0adf77908e8963bcf9b9100a760c20ac706a35 Mon Sep 17 00:00:00 2001 From: Egor Marin Date: Sun, 26 Mar 2023 20:30:19 +0300 Subject: [PATCH 4/8] Update changelog for PR #4085 --- package/CHANGELOG | 1 + package/MDAnalysis/analysis/base.py | 3 +++ 2 files changed, 4 insertions(+) diff --git a/package/CHANGELOG b/package/CHANGELOG index fb72be82d6e..c5db55edb2c 100644 --- a/package/CHANGELOG +++ b/package/CHANGELOG @@ -44,6 +44,7 @@ Enhancements * AuxReaders are now pickle-able and copy-able (Issue #1785, PR #3887) * Add pickling support for Atom, Residue, Segment, ResidueGroup and SegmentGroup. (PR #3953) + * Add `progressbar_kwargs` parameter to `AnalysisBase.run` method, allowing to modify description, position etc of tqdm progressbars. Changes * As per NEP29 the minimum supported NumPy version has been raised to 1.21 diff --git a/package/MDAnalysis/analysis/base.py b/package/MDAnalysis/analysis/base.py index 838f7e1f3d2..4e3638cc18c 100644 --- a/package/MDAnalysis/analysis/base.py +++ b/package/MDAnalysis/analysis/base.py @@ -421,6 +421,9 @@ def run(self, start=None, stop=None, step=None, frames=None, Added ability to analyze arbitrary frames by passing a list of frame indices in the `frames` keyword argument. + .. versionchanged:: 2.5.0 + Add `progressbar_kwargs` parameter, + allowing to modify description, position etc of tqdm progressbars """ logger.info("Choosing frames to analyze") # if verbose unchanged, use class default From 4a7c40c3e1dc35b3657080b01603d91fd6f01f78 Mon Sep 17 00:00:00 2001 From: Egor Marin Date: Sun, 26 Mar 2023 20:31:26 +0300 Subject: [PATCH 5/8] Remove unnecessary use of `rms` --- testsuite/MDAnalysisTests/analysis/test_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testsuite/MDAnalysisTests/analysis/test_base.py b/testsuite/MDAnalysisTests/analysis/test_base.py index b45c83cf2e8..72d0e51dfdc 100644 --- a/testsuite/MDAnalysisTests/analysis/test_base.py +++ b/testsuite/MDAnalysisTests/analysis/test_base.py @@ -30,7 +30,7 @@ from numpy.testing import assert_equal, assert_almost_equal import MDAnalysis as mda -from MDAnalysis.analysis import base, rms +from MDAnalysis.analysis import base from MDAnalysisTests.datafiles import PSF, DCD, TPR, XTC from MDAnalysisTests.util import no_deprecated_call From 6b50556f864ea66b734c198f6d9f1a5353c628a6 Mon Sep 17 00:00:00 2001 From: Egor Marin Date: Sun, 26 Mar 2023 20:33:26 +0300 Subject: [PATCH 6/8] Update testcase to include number of iterations --- testsuite/MDAnalysisTests/analysis/test_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testsuite/MDAnalysisTests/analysis/test_base.py b/testsuite/MDAnalysisTests/analysis/test_base.py index 72d0e51dfdc..e26cee6912b 100644 --- a/testsuite/MDAnalysisTests/analysis/test_base.py +++ b/testsuite/MDAnalysisTests/analysis/test_base.py @@ -279,7 +279,7 @@ def test_verbose_progressbar_run_with_kwargs(u, capsys): out, err = capsys.readouterr() expected = u'custom: 100%|██████████| 98/98 [00:00<00:00, 8799.49it/s]' actual = err.strip().split('\r')[-1] - assert actual[:24] == expected[:24] + assert actual[:30] == expected[:30] def test_incomplete_defined_analysis(u): with pytest.raises(NotImplementedError): From e93053e06d160c7486506313a93b2b43cad019bd Mon Sep 17 00:00:00 2001 From: Hugo MacDermott-Opeskin Date: Wed, 29 Mar 2023 11:59:53 +1100 Subject: [PATCH 7/8] Update AUTHORS --- package/AUTHORS | 1 - 1 file changed, 1 deletion(-) diff --git a/package/AUTHORS b/package/AUTHORS index f75c0ad32d4..6ce8660ff99 100644 --- a/package/AUTHORS +++ b/package/AUTHORS @@ -215,7 +215,6 @@ Chronological list of authors - Josh Vermaas - Egor Marin - External code ------------- From cd26ce5d121b367c83d500c517ca57237a4a2cbf Mon Sep 17 00:00:00 2001 From: Hugo MacDermott-Opeskin Date: Wed, 29 Mar 2023 13:47:46 +1100 Subject: [PATCH 8/8] Update CHANGELOG to make newest first --- package/CHANGELOG | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/CHANGELOG b/package/CHANGELOG index cd163bb9c34..4e073688b81 100644 --- a/package/CHANGELOG +++ b/package/CHANGELOG @@ -37,6 +37,7 @@ Fixes (Issue #3336) Enhancements + * Add `progressbar_kwargs` parameter to `AnalysisBase.run` method, allowing to modify description, position etc of tqdm progressbars. * Add a nojump transformation, which unwraps trajectories so that particle paths are continuous. (Issue #3703, PR #4031) * Added AtomGroup TopologyAttr to calculate gyration moments (Issue #3904, @@ -47,7 +48,6 @@ Enhancements * AuxReaders are now pickle-able and copy-able (Issue #1785, PR #3887) * Add pickling support for Atom, Residue, Segment, ResidueGroup and SegmentGroup. (PR #3953) - * Add `progressbar_kwargs` parameter to `AnalysisBase.run` method, allowing to modify description, position etc of tqdm progressbars. Changes * Add progress bars to track the progress of _conclude() functions