From dec5f33752c57e07a061e6630d98a82f5660e13d Mon Sep 17 00:00:00 2001 From: Tushar Anand Date: Thu, 16 Mar 2023 22:47:28 +0530 Subject: [PATCH] Changed variable asel to sample_atom_group --- package/MDAnalysis/analysis/rms.py | 2 +- package/MDAnalysis/coordinates/DCD.py | 10 +++++----- package/MDAnalysis/coordinates/base.py | 10 +++++----- package/MDAnalysis/coordinates/memory.py | 16 ++++++++-------- testsuite/MDAnalysisTests/analysis/test_align.py | 2 +- testsuite/MDAnalysisTests/coordinates/base.py | 8 ++++---- .../MDAnalysisTests/coordinates/test_dcd.py | 8 ++++---- .../MDAnalysisTests/coordinates/test_memory.py | 8 ++++---- testsuite/MDAnalysisTests/core/test_atom.py | 4 ++-- 9 files changed, 34 insertions(+), 34 deletions(-) diff --git a/package/MDAnalysis/analysis/rms.py b/package/MDAnalysis/analysis/rms.py index 2e2f55c5599..03e5f6e9726 100644 --- a/package/MDAnalysis/analysis/rms.py +++ b/package/MDAnalysis/analysis/rms.py @@ -810,7 +810,7 @@ def __init__(self, atomgroup, **kwargs): in_memory=True).run() # 3) reference = average structure - ref_coordinates = u.trajectory.timeseries(asel=protein).mean(axis=1) + ref_coordinates = u.trajectory.timeseries(sample_atom_group=protein).mean(axis=1) # make a reference structure (need to reshape into a 1-frame # "trajectory") reference = mda.Merge(protein).load_new(ref_coordinates[:, None, :], diff --git a/package/MDAnalysis/coordinates/DCD.py b/package/MDAnalysis/coordinates/DCD.py index 305abd74fcf..1c09f6fb1c3 100644 --- a/package/MDAnalysis/coordinates/DCD.py +++ b/package/MDAnalysis/coordinates/DCD.py @@ -277,7 +277,7 @@ def dt(self): return self.ts.dt def timeseries(self, - asel=None, + sample_atom_group=None, start=None, stop=None, step=None, @@ -286,7 +286,7 @@ def timeseries(self, Parameters ---------- - asel : :class:`~MDAnalysis.core.groups.AtomGroup` + sample_atom_group : :class:`~MDAnalysis.core.groups.AtomGroup` The :class:`~MDAnalysis.core.groups.AtomGroup` to read the coordinates from. Defaults to None, in which case the full set of coordinate data is returned. @@ -318,11 +318,11 @@ def timeseries(self, start, stop, step = self.check_slice_indices(start, stop, step) - if asel is not None: - if len(asel) == 0: + if sample_atom_group is not None: + if len(sample_atom_group) == 0: raise ValueError( "Timeseries requires at least one atom to analyze") - atom_numbers = list(asel.indices) + atom_numbers = list(sample_atom_group.indices) else: atom_numbers = list(range(self.n_atoms)) diff --git a/package/MDAnalysis/coordinates/base.py b/package/MDAnalysis/coordinates/base.py index 051e3e59f26..10958416ee7 100644 --- a/package/MDAnalysis/coordinates/base.py +++ b/package/MDAnalysis/coordinates/base.py @@ -981,7 +981,7 @@ def __repr__(self): natoms=self.n_atoms )) - def timeseries(self, asel: Optional['AtomGroup']=None, + def timeseries(self, sample_atom_group: Optional['AtomGroup']=None, start: Optional[int]=None, stop: Optional[int]=None, step: Optional[int]=None, order: Optional[str]='fac') -> np.ndarray: @@ -989,7 +989,7 @@ def timeseries(self, asel: Optional['AtomGroup']=None, Parameters ---------- - asel : AtomGroup (optional) + sample_atom_group : AtomGroup (optional) The :class:`~MDAnalysis.core.groups.AtomGroup` to read the coordinates from. Defaults to ``None``, in which case the full set of coordinate data is returned. @@ -1021,11 +1021,11 @@ def timeseries(self, asel: Optional['AtomGroup']=None, start, stop, step = self.check_slice_indices(start, stop, step) nframes = len(range(start, stop, step)) - if asel is not None: - if len(asel) == 0: + if sample_atom_group is not None: + if len(sample_atom_group) == 0: raise ValueError( "Timeseries requires at least one atom to analyze") - atom_numbers = asel.indices + atom_numbers = sample_atom_group.indices natoms = len(atom_numbers) else: natoms = self.n_atoms diff --git a/package/MDAnalysis/coordinates/memory.py b/package/MDAnalysis/coordinates/memory.py index 8c2b459128d..040cf370e49 100644 --- a/package/MDAnalysis/coordinates/memory.py +++ b/package/MDAnalysis/coordinates/memory.py @@ -488,18 +488,18 @@ def _reopen(self): self.ts.frame = -1 self.ts.time = -1 - def timeseries(self, asel=None, start=0, stop=-1, step=1, order='afc'): + def timeseries(self, sample_atom_group=None, start=0, stop=-1, step=1, order='afc'): """Return a subset of coordinate data for an AtomGroup in desired column order. If no selection is given, it will return a view of the underlying array, while a copy is returned otherwise. Parameters --------- - asel : AtomGroup (optional) + sample_atom_group : AtomGroup (optional) Atom selection. Defaults to ``None``, in which case the full set of coordinate data is returned. Note that in this case, a view of the underlying numpy array is returned, while a copy of the - data is returned whenever `asel` is different from ``None``. + data is returned whenever `sample_atom_group` is different from ``None``. start : int (optional) the start trajectory frame stop : int (optional) @@ -556,17 +556,17 @@ def timeseries(self, asel=None, start=0, stop=-1, step=1, order='afc'): [slice(None)] * (2-f_index)) # Return a view if either: - # 1) asel is None - # 2) asel corresponds to the selection of all atoms. + # 1) sample_atom_group is None + # 2) sample_atom_group corresponds to the selection of all atoms. array = array[tuple(basic_slice)] - if (asel is None or asel is asel.universe.atoms): + if (sample_atom_group is None or sample_atom_group is sample_atom_group.universe.atoms): return array else: - if len(asel) == 0: + if len(sample_atom_group) == 0: raise ValueError("Timeseries requires at least one atom " "to analyze") # If selection is specified, return a copy - return array.take(asel.indices, a_index) + return array.take(sample_atom_group.indices, a_index) def _read_next_timestep(self, ts=None): """copy next frame into timestep""" diff --git a/testsuite/MDAnalysisTests/analysis/test_align.py b/testsuite/MDAnalysisTests/analysis/test_align.py index a3adc835a48..44d5c054240 100644 --- a/testsuite/MDAnalysisTests/analysis/test_align.py +++ b/testsuite/MDAnalysisTests/analysis/test_align.py @@ -401,7 +401,7 @@ def _get_aligned_average_positions(ref_files, ref, select="all", **kwargs): u = mda.Universe(*ref_files, in_memory=True) prealigner = align.AlignTraj(u, ref, select=select, **kwargs).run() ag = u.select_atoms(select) - reference_coordinates = u.trajectory.timeseries(asel=ag).mean(axis=1) + reference_coordinates = u.trajectory.timeseries(sample_atom_group=ag).mean(axis=1) rmsd = sum(prealigner.results.rmsd/len(u.trajectory)) return reference_coordinates, rmsd diff --git a/testsuite/MDAnalysisTests/coordinates/base.py b/testsuite/MDAnalysisTests/coordinates/base.py index 9a684588917..82a5a2009e5 100644 --- a/testsuite/MDAnalysisTests/coordinates/base.py +++ b/testsuite/MDAnalysisTests/coordinates/base.py @@ -486,15 +486,15 @@ def test_timeseries_values(self, reader, slice): step=slice[2], order='fac') assert_allclose(timeseries, positions) - @pytest.mark.parametrize('asel', ("index 1", "index 2", "index 1 to 3")) - def test_timeseries_asel_shape(self, reader, asel): - atoms = mda.Universe(reader.filename).select_atoms(asel) + @pytest.mark.parametrize('sample_atom_group', ("index 1", "index 2", "index 1 to 3")) + def test_timeseries_sample_atom_group_shape(self, reader, sample_atom_group): + atoms = mda.Universe(reader.filename).select_atoms(sample_atom_group) timeseries = reader.timeseries(atoms, order='fac') assert(timeseries.shape[0] == len(reader)) assert(timeseries.shape[1] == len(atoms)) assert(timeseries.shape[2] == 3) - def test_timeseries_empty_asel(self, reader): + def test_timeseries_empty_sample_atom_group(self, reader): atoms = mda.Universe(reader.filename).select_atoms(None) with pytest.raises(ValueError, match="Timeseries requires at least"): reader.timeseries(atoms) diff --git a/testsuite/MDAnalysisTests/coordinates/test_dcd.py b/testsuite/MDAnalysisTests/coordinates/test_dcd.py index a431cac2ab4..4858cd41f06 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_dcd.py +++ b/testsuite/MDAnalysisTests/coordinates/test_dcd.py @@ -224,16 +224,16 @@ def test_timeseries_order(order, shape, universe_dcd): [9, 4, 2, 0, 50]]) def test_timeseries_atomindices(indices, universe_dcd): allframes = universe_dcd.trajectory.timeseries(order='afc') - asel = universe_dcd.atoms[indices] - xyz = universe_dcd.trajectory.timeseries(asel=asel, order='afc') + sample_atom_group = universe_dcd.atoms[indices] + xyz = universe_dcd.trajectory.timeseries(sample_atom_group=sample_atom_group, order='afc') assert len(xyz) == len(indices) assert_array_almost_equal(xyz, allframes[indices]) def test_timeseries_empty_selection(universe_dcd): with pytest.raises(ValueError): - asel = universe_dcd.select_atoms('name FOO') - universe_dcd.trajectory.timeseries(asel=asel) + sample_atom_group = universe_dcd.select_atoms('name FOO') + universe_dcd.trajectory.timeseries(sample_atom_group=sample_atom_group) def test_reader_set_dt(): diff --git a/testsuite/MDAnalysisTests/coordinates/test_memory.py b/testsuite/MDAnalysisTests/coordinates/test_memory.py index 6e516714018..ecd024bb143 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_memory.py +++ b/testsuite/MDAnalysisTests/coordinates/test_memory.py @@ -155,23 +155,23 @@ def test_timeseries_subarray_view(self, reader): def test_timeseries_view_from_universe_atoms(self, ref, reader): # timeseries() is expected to provide a view of the underlying array - # also in the special case when asel=universe.atoms. + # also in the special case when sample_atom_group=universe.atoms. selection = ref.universe.atoms - assert reader.timeseries(asel=selection).base is reader.get_array() + assert reader.timeseries(sample_atom_group=selection).base is reader.get_array() def test_timeseries_view_from_select_all(self, ref, reader): # timeseries() is expected to provide a view of the underlying array # also in the special case when using "all" in selections. selection = ref.universe.select_atoms("all") assert_equal(reader.timeseries( - asel=selection).base is reader.get_array(), + sample_atom_group=selection).base is reader.get_array(), True) def test_timeseries_noview(self, ref, reader): # timeseries() is expected NOT to provide a view of the underlying array # for any other selection than "all". selection = ref.universe.select_atoms("name CA") - assert reader.timeseries(asel=selection).base is not reader.get_array() + assert reader.timeseries(sample_atom_group=selection).base is not reader.get_array() def test_repr(self, reader): str_rep = str(reader) diff --git a/testsuite/MDAnalysisTests/core/test_atom.py b/testsuite/MDAnalysisTests/core/test_atom.py index 35d5d67477a..5372b6abe59 100644 --- a/testsuite/MDAnalysisTests/core/test_atom.py +++ b/testsuite/MDAnalysisTests/core/test_atom.py @@ -81,8 +81,8 @@ def test_attributes_positions(self, atom): assert_almost_equal(a.position, pos) def test_atom_selection(self, universe, atom): - asel = universe.select_atoms('atom 4AKE 67 CG').atoms[0] - assert atom == asel + sample_atom_group = universe.select_atoms('atom 4AKE 67 CG').atoms[0] + assert atom == sample_atom_group def test_hierarchy(self, universe, atom): u = universe