From 98d7e6ec4d2f497030336487b3db11b1cdf86bee Mon Sep 17 00:00:00 2001 From: Oliver Beckstein Date: Thu, 3 Jul 2025 12:34:20 -0700 Subject: [PATCH 1/3] fix AnalysisBase docs - fix #5075 - document attributes n_frames, start, stop, step --- package/MDAnalysis/analysis/base.py | 31 +++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/package/MDAnalysis/analysis/base.py b/package/MDAnalysis/analysis/base.py index 675c6d6967..95b20173d4 100644 --- a/package/MDAnalysis/analysis/base.py +++ b/package/MDAnalysis/analysis/base.py @@ -184,6 +184,11 @@ class AnalysisBase(object): All results should be stored as attributes of the :class:`MDAnalysis.analysis.results.Results` container. + .. Note:: + The instance attributes are populated during and on conclusion of + calling the :meth:`AnalysisBase.run` method. + + Parameters ---------- trajectory : MDAnalysis.coordinates.base.ReaderBase @@ -194,14 +199,28 @@ class AnalysisBase(object): Attributes ---------- times: numpy.ndarray - array of Timestep times. Only exists after calling - :meth:`AnalysisBase.run` + Array of times of the Timesteps that were analyzed. + Only exists after calling :meth:`AnalysisBase.run`. frames: numpy.ndarray - array of Timestep frame indices. Only exists after calling - :meth:`AnalysisBase.run` + Array of frame indices that were analyzed. + Only exists after calling :meth:`AnalysisBase.run`. results: :class:`Results` - results of calculation are stored after call - to :meth:`AnalysisBase.run` + Results of calculation are stored here, after call + to :meth:`AnalysisBase.run`. + n_frames: int + number of *analyzed* frames, i.e., after taking into account + the `start`, `stop`, and `step` values from + :meth:`AnalysisBase.run`. + Only exists after calling :meth:`AnalysisBase.run`. + start: int + Frame index of the first trajectory frame that was analyzed. + Only exists after calling :meth:`AnalysisBase.run`. + stop: int + Frame index of the last trajectory frame that was analyzed. + Only exists after calling :meth:`AnalysisBase.run`. + step: int + Every `step` frame was analyzed, as ``trajectory[star:stop:step]``. + Only exists after calling :meth:`AnalysisBase.run`. Example From 09bf82652c1a0d2154170d318360f5e485426943 Mon Sep 17 00:00:00 2001 From: Oliver Beckstein Date: Mon, 14 Jul 2025 10:04:49 -0700 Subject: [PATCH 2/3] Apply suggestions from code review Co-authored-by: Rocco Meli --- package/MDAnalysis/analysis/base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package/MDAnalysis/analysis/base.py b/package/MDAnalysis/analysis/base.py index 95b20173d4..c2586b701e 100644 --- a/package/MDAnalysis/analysis/base.py +++ b/package/MDAnalysis/analysis/base.py @@ -185,7 +185,7 @@ class AnalysisBase(object): :class:`MDAnalysis.analysis.results.Results` container. .. Note:: - The instance attributes are populated during and on conclusion of + The instance attributes are created during and on conclusion of calling the :meth:`AnalysisBase.run` method. @@ -219,7 +219,7 @@ class AnalysisBase(object): Frame index of the last trajectory frame that was analyzed. Only exists after calling :meth:`AnalysisBase.run`. step: int - Every `step` frame was analyzed, as ``trajectory[star:stop:step]``. + Every `step` frame was analyzed, as ``trajectory[start:stop:step]``. Only exists after calling :meth:`AnalysisBase.run`. From ce14e6e1b05c2b85e0dbad0e947db52f976920b7 Mon Sep 17 00:00:00 2001 From: Oliver Beckstein Date: Mon, 14 Jul 2025 10:05:50 -0700 Subject: [PATCH 3/3] Update base.py with suggestion --- package/MDAnalysis/analysis/base.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package/MDAnalysis/analysis/base.py b/package/MDAnalysis/analysis/base.py index c2586b701e..f18b866951 100644 --- a/package/MDAnalysis/analysis/base.py +++ b/package/MDAnalysis/analysis/base.py @@ -186,7 +186,8 @@ class AnalysisBase(object): .. Note:: The instance attributes are created during and on conclusion of - calling the :meth:`AnalysisBase.run` method. + calling the :meth:`AnalysisBase.run` method. Accessing an attribute + before it has been created will raise an :exc:`AttributeError`. Parameters