Skip to content

Commit

Permalink
Changed variable asel to sample_atom_group
Browse files Browse the repository at this point in the history
  • Loading branch information
Tushar Anand authored and Tushar Anand committed Mar 16, 2023
1 parent c452da7 commit dec5f33
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 34 deletions.
2 changes: 1 addition & 1 deletion package/MDAnalysis/analysis/rms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, :],
Expand Down
10 changes: 5 additions & 5 deletions package/MDAnalysis/coordinates/DCD.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.
Expand Down Expand Up @@ -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))

Expand Down
10 changes: 5 additions & 5 deletions package/MDAnalysis/coordinates/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -981,15 +981,15 @@ 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:
"""Return a subset of coordinate data for an AtomGroup
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.
Expand Down Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions package/MDAnalysis/coordinates/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"""
Expand Down
2 changes: 1 addition & 1 deletion testsuite/MDAnalysisTests/analysis/test_align.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions testsuite/MDAnalysisTests/coordinates/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions testsuite/MDAnalysisTests/coordinates/test_dcd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
8 changes: 4 additions & 4 deletions testsuite/MDAnalysisTests/coordinates/test_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions testsuite/MDAnalysisTests/core/test_atom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit dec5f33

Please sign in to comment.