diff --git a/package/CHANGELOG b/package/CHANGELOG index dc691287805..d40a3b41a21 100644 --- a/package/CHANGELOG +++ b/package/CHANGELOG @@ -86,6 +86,8 @@ Enhancements * Improve the distance search in water bridge analysis with capped_distance (PR #2480) Changes + * Removed instant selectors on Universe and Group objects (e.g. AtomGroup.C, + Segment.r1, Universe.s4AKE). Use select_atoms instead (Issue #1377) * Calling Universe() now raises a TypeError advising you to use Universe.empty. Universe.empty() now no longer has n_atoms=0 as default. (Issue #2527) * deprecated `start`, `stop`, and `step` keywords have been removed from `__init__` diff --git a/package/MDAnalysis/core/groups.py b/package/MDAnalysis/core/groups.py index d9da8dd7c2c..952ce6534be 100644 --- a/package/MDAnalysis/core/groups.py +++ b/package/MDAnalysis/core/groups.py @@ -2203,55 +2203,19 @@ class AtomGroup(GroupBase): :class:`AtomGroup` instances are always bound to a :class:`MDAnalysis.core.universe.Universe`. They cannot exist in isolation. - .. rubric:: Deprecated functionality - - *Instant selectors* will be removed in the 1.0 release. See issue `#1377 - `_ for more details. - - :class:`Atoms` can also be accessed in a Pythonic fashion by using the - :class:`Atom` name as an attribute. For instance, :: - - ag.CA - - will provide an :class:`AtomGroup` of all CA :class:`Atoms` in the - group. These *instant selector* attributes are auto-generated for - each atom name encountered in the group. - - Notes - ----- - The name-attribute instant selector access to :class:`Atoms` is mainly - meant for quick interactive work. Thus it either returns a single - :class:`Atom` if there is only one matching :class:`Atom`, *or* a - new :class:`AtomGroup` for multiple matches. This makes it difficult to use - the feature consistently in scripts. - See Also -------- :class:`MDAnalysis.core.universe.Universe` - .. deprecated:: 0.16.2 *Instant selectors* of :class:`AtomGroup` will be removed in the 1.0 - release. See :ref:`Instant selectors ` for details - and alternatives. + release. + .. versionchanged:: 1.0.0 + Removed instant selectors, use select_atoms('name ...') to select + atoms by name. """ - def __getitem__(self, item): - # DEPRECATED in 0.16.2 - # REMOVE in 1.0 - # - # u.atoms['HT1'] access, otherwise default - if isinstance(item, string_types): - try: - return self._get_named_atom(item) - except (AttributeError, selection.SelectionError): - pass - return super(AtomGroup, self).__getitem__(item) - def __getattr__(self, attr): - # DEPRECATED in 0.16.2 - # REMOVE in 1.0 - # # is this a known attribute failure? # TODO: Generalise this to cover many attributes if attr in ('fragments', 'fragindices', 'n_fragments', 'unwrap'): @@ -2260,12 +2224,6 @@ def __getattr__(self, attr): # raise NDE(_ATTR_ERRORS[attr]) raise NoDataError("AtomGroup.{} not available; this requires Bonds" "".format(attr)) - elif hasattr(self.universe._topology, 'names'): - # Ugly hack to make multiple __getattr__s work - try: - return self._get_named_atom(attr) - except selection.SelectionError: - pass raise AttributeError("{cls} has no attribute {attr}".format( cls=self.__class__.__name__, attr=attr)) @@ -3256,8 +3214,8 @@ class ResidueGroup(GroupBase): .. deprecated:: 0.16.2 *Instant selectors* of Segments will be removed in the 1.0 release. - See :ref:`Instant selectors ` for details and - alternatives. + .. versionchanged:: 1.0.0 + Removed instant selectors, use select_atoms instead """ @property @@ -3419,8 +3377,8 @@ class SegmentGroup(GroupBase): .. deprecated:: 0.16.2 *Instant selectors* of Segments will be removed in the 1.0 release. - See :ref:`Instant selectors ` for details and - alternatives. + .. versionchanged:: 1.0.0 + Removed instant selectors, use select_atoms instead """ @property @@ -3841,8 +3799,11 @@ class Segment(ComponentBase): .. deprecated:: 0.16.2 *Instant selectors* of :class:`Segments` will be removed in the - 1.0 release. See :ref:`Instant selectors ` for - details and alternatives. + 1.0 release. + .. versionchanged:: 1.0.0 + Removed instant selectors, use either segment.residues[...] to select + residue by number, or segment.residues[segment.residue.resnames = ...] + to select by resname. """ def __repr__(self): me = ' will be removed in " - "1.0. Use Segment.residues[N-1] instead.", - DeprecationWarning) - return rg - # Resname accesss - if hasattr(self.residues, 'resnames'): - try: - return self.residues._get_named_residue(attr) - except selection.SelectionError: - pass - raise AttributeError("{cls} has no attribute {attr}" - "".format(cls=self.__class__.__name__, attr=attr)) # Accessing these attrs doesn't trigger an update. The class and instance # methods of UpdatingAtomGroup that are used during __init__ must all be diff --git a/package/MDAnalysis/core/topologyattrs.py b/package/MDAnalysis/core/topologyattrs.py index 56d5879a4ca..13dd7f4940b 100644 --- a/package/MDAnalysis/core/topologyattrs.py +++ b/package/MDAnalysis/core/topologyattrs.py @@ -45,7 +45,6 @@ import numpy as np import warnings -from numpy.lib.utils import deprecate from ..lib.util import (cached, convert_aa_code, iterable, warn_if_not_unique, unique_int_1d) @@ -481,63 +480,6 @@ class Atomnames(AtomAttr): def _gen_initial_values(na, nr, ns): return np.array(['' for _ in range(na)], dtype=object) - def getattr__(atomgroup, name): - try: - return atomgroup._get_named_atom(name) - except selection.SelectionError: - six.raise_from( - AttributeError("'{0}' object has no attribute '{1}'".format( - atomgroup.__class__.__name__, name)), - None) - - def _get_named_atom(group, name): - """Get all atoms with name *name* in the current AtomGroup. - - For more than one atom it returns a list of :class:`Atom` - instance. A single :class:`Atom` is returned just as such. If - no atoms are found, a :exc:`SelectionError` is raised. - - .. versionadded:: 0.9.2 - - .. deprecated:: 0.16.2 - *Instant selectors* will be removed in the 1.0 release. - Use ``AtomGroup.select_atoms('name ')`` instead. - See issue `#1377 - `_ for - more details. - - """ - # There can be more than one atom with the same name - atomlist = group.atoms.unique[group.atoms.unique.names == name] - if len(atomlist) == 0: - raise selection.SelectionError( - "No atoms with name '{0}'".format(name)) - elif len(atomlist) == 1: - # XXX: keep this, makes more sense for names - atomlist = atomlist[0] - warnings.warn("Instant selector AtomGroup[''] or AtomGroup. " - "is deprecated and will be removed in 1.0. " - "Use AtomGroup.select_atoms('name ') instead.", - DeprecationWarning) - return atomlist - - # AtomGroup already has a getattr -# transplants[AtomGroup].append( -# ('__getattr__', getattr__)) - - transplants[Residue].append( - ('__getattr__', getattr__)) - - # this is also getitem for a residue - transplants[Residue].append( - ('__getitem__', getattr__)) - - transplants[AtomGroup].append( - ('_get_named_atom', _get_named_atom)) - - transplants[Residue].append( - ('_get_named_atom', _get_named_atom)) - def phi_selection(residue): """AtomGroup corresponding to the phi protein backbone dihedral C'-N-CA-C. @@ -1383,63 +1325,6 @@ class Resnames(ResidueAttr): def _gen_initial_values(na, nr, ns): return np.array(['' for _ in range(nr)], dtype=object) - def getattr__(residuegroup, resname): - try: - return residuegroup._get_named_residue(resname) - except selection.SelectionError: - six.raise_from( - AttributeError("'{0}' object has no attribute '{1}'".format( - residuegroup.__class__.__name__, resname)), - None) - - transplants[ResidueGroup].append(('__getattr__', getattr__)) - # This transplant is hardcoded for now to allow for multiple getattr things - #transplants[Segment].append(('__getattr__', getattr__)) - - def _get_named_residue(group, resname): - """Get all residues with name *resname* in the current ResidueGroup - or Segment. - - For more than one residue it returns a - :class:`MDAnalysis.core.groups.ResidueGroup` instance. A single - :class:`MDAnalysis.core.group.Residue` is returned for a single match. - If no residues are found, a :exc:`SelectionError` is raised. - - .. versionadded:: 0.9.2 - - .. deprecated:: 0.16.2 - *Instant selectors* will be removed in the 1.0 release. - Use ``ResidueGroup[ResidueGroup.resnames == '']`` - or ``Segment.residues[Segment.residues == '']`` - instead. - See issue `#1377 - `_ for - more details. - - """ - # There can be more than one residue with the same name - residues = group.residues.unique[ - group.residues.unique.resnames == resname] - if len(residues) == 0: - raise selection.SelectionError( - "No residues with resname '{0}'".format(resname)) - warnings.warn("Instant selector ResidueGroup. " - "or Segment. " - "is deprecated and will be removed in 1.0. " - "Use ResidueGroup[ResidueGroup.resnames == ''] " - "or Segment.residues[Segment.residues == ''] " - "instead.", - DeprecationWarning) - if len(residues) == 1: - # XXX: keep this, makes more sense for names - return residues[0] - else: - # XXX: but inconsistent (see residues and Issue 47) - return residues - - transplants[ResidueGroup].append( - ('_get_named_residue', _get_named_residue)) - def sequence(self, **kwargs): """Returns the amino acid sequence. @@ -1627,60 +1512,6 @@ class Segids(SegmentAttr): def _gen_initial_values(na, nr, ns): return np.array(['' for _ in range(ns)], dtype=object) - def getattr__(segmentgroup, segid): - try: - return segmentgroup._get_named_segment(segid) - except selection.SelectionError: - six.raise_from( - AttributeError("'{0}' object has no attribute '{1}'".format( - segmentgroup.__class__.__name__, segid)), - None) - - transplants[SegmentGroup].append( - ('__getattr__', getattr__)) - - def _get_named_segment(group, segid): - """Get all segments with name *segid* in the current SegmentGroup. - - For more than one residue it returns a - :class:`MDAnalysis.core.groups.SegmentGroup` instance. A single - :class:`MDAnalysis.core.group.Segment` is returned for a single match. - If no residues are found, a :exc:`SelectionError` is raised. - - .. versionadded:: 0.9.2 - - .. deprecated:: 0.16.2 - *Instant selectors* will be removed in the 1.0 release. - Use ``SegmentGroup[SegmentGroup.segids == '']`` instead. - See issue `#1377 - `_ for - more details. - - """ - # Undo adding 's' if segid started with digit - if segid.startswith('s') and len(segid) >= 2 and segid[1].isdigit(): - segid = segid[1:] - - # There can be more than one segment with the same name - segments = group.segments.unique[ - group.segments.unique.segids == segid] - if len(segments) == 0: - raise selection.SelectionError( - "No segments with segid '{0}'".format(segid)) - warnings.warn("Instant selector SegmentGroup. " - "is deprecated and will be removed in 1.0. " - "Use SegmentGroup[SegmentGroup.segids == ''] " - "instead.", - DeprecationWarning) - if len(segments) == 1: - # XXX: keep this, makes more sense for names - return segments[0] - else: - # XXX: but inconsistent (see residues and Issue 47) - return segments - - transplants[SegmentGroup].append( - ('_get_named_segment', _get_named_segment)) def _check_connection_values(func): """ diff --git a/package/MDAnalysis/core/universe.py b/package/MDAnalysis/core/universe.py index 15869d08b50..5006ed24032 100644 --- a/package/MDAnalysis/core/universe.py +++ b/package/MDAnalysis/core/universe.py @@ -41,33 +41,6 @@ :func:`Merge` function. -Working with Universes -====================== - - -Quick segid selection ---------------------- - -.. deprecated:: 0.16.2 - Instant selectors will be removed in the 1.0 release. See issue `#1377 - `_ for more details. - - -If the loaded topology provided segids, then these are made accessible -as attributes of the Universe. If the segid starts with a number such -as '4AKE', the letter 's' will be prepended to the segid. -For example:: - - import MDAnalysis as mda - from MDAnalysisTests.datafiles import PSF, DCD - - u = mda.Universe(PSF, DCD) - u.select_atoms('segid 4AKE') # selects all segments with segid 4AKE - -If only a single segment has that segid then a Segment object will -be returned, otherwise a SegmentGroup will be returned. - - Classes ======= @@ -223,33 +196,6 @@ def _generate_from_topology(universe): universe.segments = SegmentGroup( np.arange(universe._topology.n_segments), universe) - # Update Universe namespace with segids - # Many segments can have same segid, so group together first - # - # DEPRECATED in 0.16.2 - # REMOVE in 1.0 - # See https://github.com/MDAnalysis/mdanalysis/issues/1377 - try: - # returns dict of segid:segment - segids = universe.segments.groupby('segids') - except AttributeError: - # no segids, don't do this step - pass - else: - for segid, segment in segids.items(): - if not segid: # ignore blank segids - continue - - # cannot start attribute with number - if segid[0].isdigit(): - # prefix 's' if starts with number - name = 's' + segid - else: - name = segid - # if len 1 SegmentGroup, convert to Segment - if len(segment) == 1: - segment = segment[0] - universe._instant_selectors[name] = segment class Universe(object): """The MDAnalysis Universe contains all the information describing the system. @@ -369,8 +315,9 @@ class Universe(object): bonds, angles, dihedrals master ConnectivityGroups for each connectivity type - .. versionchanged:: 0.21.0 + .. versionchanged:: 1.0.0 Universe() now raises an error. Use Universe(None) or :func:`Universe.empty()` instead. + Removed instant selectors. """ # Py3 TODO # def __init__(self, topology=None, *coordinates, all_coordinates=False, @@ -392,7 +339,6 @@ def __init__(self, *args, **kwargs): in_memory = kwargs.pop('in_memory', False) in_memory_step = kwargs.pop('in_memory_step', 1) - self._instant_selectors = {} # for storing segments. Deprecated? self._trajectory = None # managed attribute holding Reader self._cache = {} self._anchor_name = anchor_name @@ -549,25 +495,6 @@ def empty(cls, n_atoms, n_residues=1, n_segments=1, return u - def __getattr__(self, key): - # This implements the instant selector of segments from a Universe. - # It is implemented as __getattr__ so a deprecation warning can be - # issued when the feature is used. Instant selectors are deprecated - # since version 0.16.2 and are tareted to be deleted in version 1.0. - # self._instant_selectors is populated in self._process_attr and - # created at the beginning of __init__. - try: - segment = self._instant_selectors[key] - except KeyError: - six.raise_from(AttributeError('No attribute "{}".'.format(key)), None) - else: - warnings.warn("Instant selector Universe. " - "is deprecated and will be removed in 1.0. " - "Use SegmentGroup[SegmentGroup.segids == ''] " - "instead.", - DeprecationWarning) - return segment - @property def universe(self): # for Writer.write(universe), see Issue 49 @@ -789,8 +716,6 @@ def anchor_name(self, name): self._anchor_name = str(name) if not name is None else name self.make_anchor() # add anchor again - - @property def is_anchor(self): """Is this Universe an anchoring for unpickling AtomGroups""" @@ -1329,7 +1254,6 @@ def delete_impropers(self, values): """ self._delete_topology_objects('impropers', values) - # TODO: Maybe put this as a Bond attribute transplant # Problems: Can we transplant onto Universe? # Probably a smarter way to do this too, could generate diff --git a/package/doc/sphinx/source/documentation_pages/selections.rst b/package/doc/sphinx/source/documentation_pages/selections.rst index 8941e8edd0c..44dd2dd0c08 100644 --- a/package/doc/sphinx/source/documentation_pages/selections.rst +++ b/package/doc/sphinx/source/documentation_pages/selections.rst @@ -300,110 +300,6 @@ across frames:: >>> static_ag -.. _instance-selectors: - -Instant selectors -================= - -.. deprecated:: 0.16.2 - *Instant selectors* will be removed in the 1.0 release in order to - streamline the MDAnalysis user interface. They do not seem to be - widely used anymore, can produce cryptic error messages, and are - not considered "Pythonic" (and therefore not very intuitive for new - users). See issue `#1377 - `_ for more - details. - - -For interactive work it becomes rather tedious to type common selection strings -repeatedly. MDAnalysis automatically generates a number of *instant selectors* -as attributes of the :class:`~MDAnalysis.core.universe.Universe` and number of -other levels of the structural hierarchy, namely for -:class:`~MDAnalysis.core.groups.AtomGroup`, -:class:`~MDAnalysis.core.groups.Residue`, -:class:`~MDAnalysis.core.groups.ResidueGroup`, -:class:`~MDAnalysis.core.groups.Segment` and -:class:`~MDAnalysis.core.groups.SegmentGroup`. - -Segment selector ----------------- - -.. deprecated:: 0.16.2 - Use ``SegmentGroup[SegmentGroup.segids == '']`` instead. Note that this - *always* returns a :class:`SegmentGroup` and *never* a :class:`Segment` - (unlike the instant selector). - -- ``universe.`` or ``universe.s`` (if ** starts with a - number) -- returns a :class:`~MDAnalysis.core.groups.Segment` -- works for :class:`~MDAnalysis.core.universe.Universe` and :class:`~MDAnalysis.core.groups.SegmentGroup` -- example - >>> u.s4AKE - - -Resid selector --------------- - -.. deprecated:: 0.16.2 - Use ``Segment.residues[N-1]`` instead. - -- ``seg.r`` selects residue with number ```` -- returns a :class:`~MDAnalysis.core.groups.Residue` -- works for :class:`~MDAnalysis.core.groups.Segment` and :class:`~MDAnalysis.core.groups.SegmentGroup` -- example - >>> u.s4AKE.r100 - - -Residue name selector ---------------------- - -.. deprecated:: 0.16.2 - Use ``ResidueGroup[ResidueGroup.resnames == '']`` or - ``Segment.residues[Segment.residues == '']`` instead. Note that this - *always* returns a :class:`ResidueGroup` and *never* a :class:`Residue` - (unlike the instant selector). - -- ``seg.`` selects residues with residue name ```` -- returns a :class:`~MDAnalysis.core.groups.ResidueGroup` -- works for :class:`~MDAnalysis.core.groups.Segment` and :class:`~MDAnalysis.core.groups.SegmentGroup` -- examples - >>> u.s4AKE.MET - , , , , , ]> - >>> u.s4AKE.CYS - ]> - >>> u.s4AKE.TRP - NoDataError: No atoms defined for AtomGroup -- The result is always a :class:`~MDAnalysis.core.groups.ResidueGroup`; if no - residues can be found then a :exc:`MDAnalysis.NoDataError` is raised. - -Atom name selector ------------------- - -.. deprecated:: 0.16.2 - Use ``AtomGroup.select_atoms('name ')`` instead. Note that this - *always* returns an :class:`AtomGroup` and *never* an :class:`Atom` (unlike - the instant selector). - -- ``g.`` selects a single atom or a group of atoms with name - ```` -- returns - - a :class:`~MDAnalysis.core.groups.Atom` if only a single atom was found, - - a :class:`~MDAnalysis.core.groups.AtomGroup` if more than one atom was - found, or - - raises a :exc:`MDAnalysis.SelectionError` if no atom was found. -- works for any group derived from :class:`~MDAnalysis.core.groups.AtomGroup` - (i.e. all the ones mentioned above) -- examples - >>> u.atoms.CG - >>> - >>> u.s4AKE.CG - - >>> u.s4AKE.r100.CA - < Atom 1516: name 'CA' of type '23' of resname 'GLY', resid 100 and segid '4AKE'> - >>> u.s4AKE.r100.CB - SelectionError: No atom in residue GLY with name CB - - .. _ordered-selections-label: Ordered selections diff --git a/testsuite/MDAnalysisTests/coordinates/base.py b/testsuite/MDAnalysisTests/coordinates/base.py index be65b9e993d..eb509c82193 100644 --- a/testsuite/MDAnalysisTests/coordinates/base.py +++ b/testsuite/MDAnalysisTests/coordinates/base.py @@ -101,8 +101,8 @@ def test_coordinates(self): err_msg="wrong coordinates for A10:CA") def test_distances(self): - NTERM = self.universe.atoms.N[0] - CTERM = self.universe.atoms.C[-1] + NTERM = self.universe.select_atoms('name N')[0] + CTERM = self.universe.select_atoms('name C')[-1] d = mda.lib.mdamath.norm(NTERM.position - CTERM.position) assert_almost_equal(d, self.ref_distances['endtoend'], diff --git a/testsuite/MDAnalysisTests/coordinates/test_gro.py b/testsuite/MDAnalysisTests/coordinates/test_gro.py index cbaacaf15c2..873936f6607 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_gro.py +++ b/testsuite/MDAnalysisTests/coordinates/test_gro.py @@ -73,8 +73,8 @@ def test_distances(self, universe): # NOTe that the prec is only 1 decimal: subtracting two low precision # coordinates low prec: 9.3455122920041109; high prec (from pdb): # 9.3513174 - NTERM = universe.atoms.N[0] - CTERM = universe.atoms.C[-1] + NTERM = universe.select_atoms('name N')[0] + CTERM = universe.select_atoms('name C')[-1] d = mda.lib.mdamath.norm(NTERM.position - CTERM.position) assert_almost_equal(d, self.ref_distances['endtoend'], self.prec - 1, err_msg="distance between M1:N and G214:C") @@ -116,8 +116,8 @@ def test_distances(self, universe): # Arrays are not almost equal distance between M1:N and G214:C # ACTUAL: 0.93455122920041123 # DESIRED: 0.93513173999999988 - NTERM = universe.atoms.N[0] - CTERM = universe.atoms.C[-1] + NTERM = universe.select_atoms('name N')[0] + CTERM = universe.select_atoms('name C')[-1] d = mda.lib.mdamath.norm(NTERM.position - CTERM.position) # coordinates in nm assert_almost_equal(d, RefAdK.ref_distances['endtoend'] / 10.0, diff --git a/testsuite/MDAnalysisTests/coordinates/test_pdb.py b/testsuite/MDAnalysisTests/coordinates/test_pdb.py index 1bec2eb05f2..afde00786c3 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_pdb.py +++ b/testsuite/MDAnalysisTests/coordinates/test_pdb.py @@ -674,8 +674,8 @@ def test_coordinates(self, universe): err_msg="wrong coordinates for A10:CA") def test_distances(self, universe): - NTERM = universe.atoms.N[0] - CTERM = universe.atoms.C[-1] + NTERM = universe.select_atoms('name N')[0] + CTERM = universe.select_atoms('name C')[-1] d = mda.lib.mdamath.norm(NTERM.position - CTERM.position) assert_almost_equal(d, self.ref_distances['endtoend'], self.prec, err_msg="wrong distance between M1:N and G214:C") diff --git a/testsuite/MDAnalysisTests/coordinates/test_pqr.py b/testsuite/MDAnalysisTests/coordinates/test_pqr.py index 3c38232c1d0..dd4d745deea 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_pqr.py +++ b/testsuite/MDAnalysisTests/coordinates/test_pqr.py @@ -50,7 +50,7 @@ def test_total_charge(self): "Total charge (in CHARMM) does not match expected value.") def test_hydrogenCharges(self): - assert_almost_equal(self.universe.atoms.H.charges, + assert_almost_equal(self.universe.select_atoms('name H').charges, self.ref_charmm_Hcharges, 3, "Charges for H atoms do not match.") diff --git a/testsuite/MDAnalysisTests/core/test_atomgroup.py b/testsuite/MDAnalysisTests/core/test_atomgroup.py index 5b4e242707b..14d3b853d15 100644 --- a/testsuite/MDAnalysisTests/core/test_atomgroup.py +++ b/testsuite/MDAnalysisTests/core/test_atomgroup.py @@ -1005,13 +1005,6 @@ def test_pbcflag(self, ag, ref_PBC): assert_almost_equal(ag.principal_axes(pbc=True), ref_PBC['PAxes'], self.prec) -def test_instantselection_termini(): - """Test that instant selections work, even for residues that are also termini (Issue 70)""" - universe = mda.Universe(PSF, DCD) - assert_equal(universe.residues[20].CA.name, 'CA', "CA of MET21 is not selected correctly") - del universe - - class TestAtomGroup(object): """Tests of AtomGroup; selections are tested separately. @@ -1055,12 +1048,6 @@ def test_getitem_slice2(self, universe): assert_equal(universe.atoms[0:8:2].ix, universe.atoms.ix[0:8:2]) - def test_getitem_str(self, universe): - ag1 = universe.atoms['HT1'] - # select_atoms always returns an AtomGroup even if single result - ag2 = universe.select_atoms('name HT1')[0] - assert_equal(ag1, ag2) - def test_getitem_IE(self, universe): d = {'A': 1} with pytest.raises(IndexError): @@ -1438,13 +1425,6 @@ def test_residues(self, universe): "Direct selection from residue group does not match " "expected I101.") - # remove in 1.0 - def test_segments(self, universe): - u = universe - with pytest.warns(DeprecationWarning): - assert len(u.segments.s4AKE.atoms) == len(u.select_atoms( - 'segid 4AKE').atoms), "Direct selection of segment 4AKE from segments failed." - def test_index_integer(self, universe): u = universe a = u.atoms[100] @@ -1598,12 +1578,6 @@ def test_set_names(self, universe): for a, b in zip(ag, names): assert_equal(a.name, b) - def test_nonexistent_instantselector_raises_AttributeError(self, universe): - def access_nonexistent_instantselector(): - universe.atoms.NO_SUCH_ATOM - with pytest.raises(AttributeError): - access_nonexistent_instantselector() - def test_atom_order(self, universe): assert_equal(universe.atoms.indices, sorted(universe.atoms.indices)) diff --git a/testsuite/MDAnalysisTests/core/test_groups.py b/testsuite/MDAnalysisTests/core/test_groups.py index 1599e0d1ba7..c3cd9e17393 100644 --- a/testsuite/MDAnalysisTests/core/test_groups.py +++ b/testsuite/MDAnalysisTests/core/test_groups.py @@ -1239,53 +1239,6 @@ def test_PDB_atom_repr(self): assert_equal("", u.atoms[0].__repr__()) -class TestInstantSelectorDeprecationWarnings(object): - @pytest.fixture() - def u(self): - return make_Universe(("resids", "resnames", "segids", "names")) - - def test_AtomGroup_warn_getitem(self, u): - name = u.atoms[0].name - with pytest.deprecated_call(): - u.atoms[name] - - def test_AtomGroup_nowarn_getitem_index(self, u): - with no_deprecated_call(): - u.atoms[0] - - def test_AtomGroup_nowarn_segids_attribute(self, u): - with no_deprecated_call(): - getattr(u.atoms, 'segids') - - def test_AtomGroup_warn_getattr(self, u): - name = u.atoms[0].name - with pytest.deprecated_call(): - getattr(u.atoms, name) - - def test_ResidueGroup_warn_getattr_resname(self, u): - name = u.residues[0].resname - with pytest.deprecated_call(): - getattr(u.residues, name) - - def test_Segment_warn_getattr_resname(self, u): - name = u.residues[0].resname - with pytest.deprecated_call(): - getattr(u.segments[0], name) - - def test_Segment_warn_getattr_rRESNUM(self, u): - with pytest.deprecated_call(): - getattr(u.segments[0], 'r1') - - def test_SegmentGroup_warn_getattr(self, u): - name = u.segments[0].segid - with pytest.deprecated_call(): - getattr(u.segments, name) - - def test_SegmentGroup_nowarn_getitem(self, u): - with no_deprecated_call(): - u.segments[0] - - @pytest.fixture() def attr_universe(): return make_Universe(('names', 'resids', 'segids')) @@ -1424,4 +1377,4 @@ def test_decorator(self, compound, pbc, unwrap): with pytest.raises(ValueError): self.dummy_funtion(compound=compound, pbc=pbc, unwrap=unwrap) else: - assert_equal(self.dummy_funtion(compound=compound, pbc=pbc, unwrap=unwrap), 0) \ No newline at end of file + assert_equal(self.dummy_funtion(compound=compound, pbc=pbc, unwrap=unwrap), 0) diff --git a/testsuite/MDAnalysisTests/core/test_segment.py b/testsuite/MDAnalysisTests/core/test_segment.py index 1bb92ca98ef..7b31722cb36 100644 --- a/testsuite/MDAnalysisTests/core/test_segment.py +++ b/testsuite/MDAnalysisTests/core/test_segment.py @@ -64,20 +64,3 @@ def test_advanced_slicing(self, sB): def test_atom_order(self, universe): assert_equal(universe.segments[0].atoms.indices, sorted(universe.segments[0].atoms.indices)) - - -# remove in 1.0 -def test_generated_residueselection(): - """Test that a generated residue group always returns a ResidueGroup (Issue 47) - unless there is a single residue (Issue 363 change)""" - universe = mda.Universe(PSF, DCD) - with pytest.warns(DeprecationWarning): - # only a single Cys in AdK - cys = universe.s4AKE.CYS - assert isinstance(cys, mda.core.groups.Residue), \ - "Single Cys77 is NOT returned as a single Residue (Issue 47)" - - # multiple Met - met = universe.s4AKE.MET - assert isinstance(met, mda.core.groups.ResidueGroup), \ - "Met selection does not return a ResidueGroup" diff --git a/testsuite/MDAnalysisTests/core/test_topologyattrs.py b/testsuite/MDAnalysisTests/core/test_topologyattrs.py index 23c03172c3c..93e4e716e5d 100644 --- a/testsuite/MDAnalysisTests/core/test_topologyattrs.py +++ b/testsuite/MDAnalysisTests/core/test_topologyattrs.py @@ -276,56 +276,6 @@ def test_set_residues(self, attr): np.array([23, 504, 27])) -class TestResnames(TestResidueAttr): - values = np.array(['VAL', 'LYS', 'VAL', 'POPG'], dtype=np.object) - attrclass = tpattrs.Resnames - - def test_residuegroup_getattr_single(self): - u = make_Universe(('resnames',)) - - res = u.residues.RsB - - assert isinstance(res, groups.Residue) - assert res == u.residues[1] - - def test_residuegroup_getattr_multiple(self): - u = make_Universe(('resnames',)) - u.residues[:10].resnames = 'ABC' - - rg = u.residues.ABC - - assert isinstance(rg, groups.ResidueGroup) - assert len(rg) == 10 - - def test_residuegroup_getattr_AE(self): - u = make_Universe(('resnames',)) - with pytest.raises(AttributeError): - getattr(u.residues, 'foo') - - - def test_segment_getattr_singular(self): - u = make_Universe(('resnames',)) - - res = u.segments[0].RsB - - assert isinstance(res, groups.Residue) - assert res == u.residues[1] - - def test_segment_getattr_multiple(self): - u = make_Universe(('resnames',)) - u.residues[:3].resnames = 'bar' - - rg = u.segments[0].bar - - assert isinstance(rg, groups.ResidueGroup) - assert len(rg) == 3 - - def test_segment_getattr_AE(self): - u = make_Universe(('resnames',)) - with pytest.raises(AttributeError): - getattr(u.segments[0], 'foo') - - class TestSegmentAttr(TopologyAttrMixin): """Test segment-level TopologyAttrs. @@ -454,43 +404,6 @@ def _check_crosslevel_fail(item, attr): setattr(item, attr, 1.0) -class TestInstantSelectorDeprecation(object): - """Test the deprecation warnings for instant selectors - - Instant selectors are deprecated since version 0.16.2. PR #1403 introduced - deprecation warnings for these selectors. - """ - @staticmethod - @pytest.fixture() - def universe(): - return mda.Universe(PSF, DCD) - - @pytest.mark.parametrize('instruction', ( - 'universe.atoms.CA', - 'universe.residues.LYS', - 'universe.segments.s4AKE', - 'universe.s4AKE', - )) - def test_deprecation(self, universe, instruction): - """Test that the warnings are issued when required. - """ - with pytest.deprecated_call(): - exec(instruction) #pylint: disable=W0122 - - @pytest.mark.parametrize('instruction', ( - 'universe.atoms', - 'universe.residues', - 'universe.segments', - )) - def test_no_deprecation(self, universe, instruction): - """Test that the warnings are not issued when they should not. - - See issue #1476. - """ - with no_deprecated_call(): - exec(instruction) #pylint: disable=W0122 - - class TestRecordTypes(object): def test_record_types_default(self): u = make_Universe() diff --git a/testsuite/MDAnalysisTests/core/test_universe.py b/testsuite/MDAnalysisTests/core/test_universe.py index bde306efec5..7e379d3f4b5 100644 --- a/testsuite/MDAnalysisTests/core/test_universe.py +++ b/testsuite/MDAnalysisTests/core/test_universe.py @@ -291,22 +291,6 @@ def test_set_dimensions(self, dtype): assert u.dimensions.dtype == np.float32 -# remove for 1.0 -def test_chainid_quick_select(): - # check that chainIDs get grouped together when making the quick selectors - # this pdb file has 2 segments with chainID A - u = mda.Universe(PDB_chainidrepeat) - - with pytest.warns(DeprecationWarning): - for sg in (u.A, u.B): - assert isinstance(sg, mda.core.groups.SegmentGroup) - for seg in (u.C, u.D): - assert isinstance(seg, mda.core.groups.Segment) - assert len(u.A.atoms) == 10 - assert len(u.B.atoms) == 10 - assert len(u.C.atoms) == 5 - assert len(u.D.atoms) == 7 - class TestTransformations(object): """Tests the transformations keyword """ @@ -1152,4 +1136,3 @@ def test_empty_creation_raises_error(self): with pytest.raises(TypeError) as exc: u = mda.Universe() assert 'Universe.empty' in str(exc.value) - \ No newline at end of file