Skip to content

Commit

Permalink
deprecate core.universe.as_Universe
Browse files Browse the repository at this point in the history
- see #2920
- add deprecation note
- add test
- update CHANGELOG for 1.0.1
  • Loading branch information
orbeckst committed Aug 27, 2020
1 parent 31832d0 commit 41ab4d1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
1 change: 1 addition & 0 deletions package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Deprecations
* waterdynamics.HydrogenBondLifetimes will be removed in 2.0.0 and
replaced with hydrogenbonds.HydrogenBondAnalysis.lifetime() (#2547)
* lib.util.echo() will be removed in 2.0.0
* core.universe.as_Universe() will be removed in 2.0.0


06/09/20 richardjgowers, kain88-de, lilyminium, p-j-smith, bdice, joaomcteixeira,
Expand Down
4 changes: 3 additions & 1 deletion package/MDAnalysis/core/universe.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@
from .topologyattrs import AtomAttr, ResidueAttr, SegmentAttr
from .topologyobjects import TopologyObject

from ..lib.util import deprecate

logger = logging.getLogger("MDAnalysis.core.universe")


Expand Down Expand Up @@ -1293,7 +1295,7 @@ def _fragdict(self):
return fragdict


# TODO: what is the point of this function???
@deprecate(release="1.0.1", remove="2.0.0")
def as_Universe(*args, **kwargs):
"""Return a universe from the input arguments.

Expand Down
34 changes: 19 additions & 15 deletions testsuite/MDAnalysisTests/core/test_universe.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ def test_add_charges(self, universe, toadd, attrname, default):

assert hasattr(universe.atoms, attrname)
assert getattr(universe.atoms, attrname)[0] == default

@pytest.mark.parametrize(
'attr,values', (
('bonds', [(1, 0), (1, 2)]),
Expand Down Expand Up @@ -636,7 +636,7 @@ def test_add_connection(self, universe, attr, values):
def add_connection_error(self, universe, attr, values):
with pytest.raises(ValueError):
universe.add_TopologyAttr(attr, values)


def _a_or_reversed_in_b(a, b):
"""
Expand Down Expand Up @@ -694,7 +694,7 @@ def _check_invalid_addition(self, u, attr, to_add, err_msg):
with pytest.raises(ValueError) as excinfo:
_add_func(to_add)
assert err_msg in str(excinfo.value)

@pytest.mark.parametrize(
'attr,values', small_atom_indices
)
Expand Down Expand Up @@ -752,23 +752,23 @@ def test_add_topologyobjects_wrong_universe_error(self, universe, empty, attr, v
'attr,values', large_atom_indices
)
def test_add_topologygroups_to_populated(self, universe, attr, values):
topologygroup = mda.core.topologyobjects.TopologyGroup(np.array(values),
topologygroup = mda.core.topologyobjects.TopologyGroup(np.array(values),
universe)
self._check_valid_added_to_populated(universe, attr, values, topologygroup)

@pytest.mark.parametrize(
'attr,values', small_atom_indices
)
def test_add_topologygroup_wrong_universe_error(self, universe, empty, attr, values):
tg = mda.core.topologyobjects.TopologyGroup(np.array(values),
tg = mda.core.topologyobjects.TopologyGroup(np.array(values),
universe)
self._check_invalid_addition(empty, attr, tg, 'different Universes')

@pytest.mark.parametrize(
'attr,values', small_atom_indices
)
def test_add_topologygroup_different_universe(self, universe, empty, attr, values):
tg = mda.core.topologyobjects.TopologyGroup(np.array(values),
tg = mda.core.topologyobjects.TopologyGroup(np.array(values),
universe)
self._check_valid_added_to_empty(empty, attr, values, tg.to_indices())

Expand Down Expand Up @@ -809,7 +809,7 @@ def test_add_wrong_number_of_atoms_error(self, universe, attr, n):
'tuples with {} atom indices').format(attr, n)
idx = [(0, 1), (0, 1, 2), (8, 22, 1, 3), (5, 3, 4, 2)]
self._check_invalid_addition(universe, attr, idx, errmsg)

def test_add_bonds_refresh_fragments(self, empty):
with pytest.raises(NoDataError):
getattr(empty.atoms, 'fragments')
Expand All @@ -833,7 +833,7 @@ def test_roundtrip(self, empty, attr, values):
_delete_func(values)
u_attr = getattr(empty, attr)
assert len(u_attr) == 0

class TestDeleteTopologyObjects(object):

TOP = {'bonds': [(0, 1), (2, 3), (3, 4), (4, 5), (7, 8)],
Expand Down Expand Up @@ -879,7 +879,7 @@ def _check_valid_deleted(self, u, attr, values, to_delete):
assert len(u_attr) == original_length-len(values)

not_deleted = [x for x in self.TOP[attr] if list(x) not in values]
assert all([x in u_attr.indices or x[::-1] in u_attr.indices
assert all([x in u_attr.indices or x[::-1] in u_attr.indices
for x in not_deleted])

def _check_invalid_deleted(self, u, attr, to_delete, err_msg):
Expand Down Expand Up @@ -923,7 +923,7 @@ def test_delete_atomgroup_wrong_universe_error(self, universe, universe2, attr,
def test_delete_missing_atomgroup(self, universe, attr, values):
ag = [universe.atoms[x] for x in values]
self._check_invalid_deleted(universe, attr, ag, 'Cannot delete nonexistent')

@pytest.mark.parametrize(
'attr,values', existing_atom_indices
)
Expand Down Expand Up @@ -969,7 +969,7 @@ def test_delete_topologygroup_different_universe(self, universe, universe2, attr
arr = np.array(values)
tg = mda.core.topologyobjects.TopologyGroup(arr, universe2)
self._check_valid_deleted(universe, attr, values, tg.to_indices())

@pytest.mark.parametrize(
'attr,n', (
('bonds', 2),
Expand All @@ -982,8 +982,8 @@ def test_delete_wrong_number_of_atoms_error(self, universe, attr, n):
idx = [(0, 1), (0, 1, 2), (8, 22, 1, 3), (5, 3, 4, 2)]
errmsg = ('{} must be an iterable of '
'tuples with {} atom indices').format(attr, n)
self._check_invalid_deleted(universe, attr, idx, errmsg)
self._check_invalid_deleted(universe, attr, idx, errmsg)

@pytest.mark.parametrize(
'attr,values', existing_atom_indices
)
Expand Down Expand Up @@ -1020,7 +1020,7 @@ def test_roundtrip(self, universe, attr, values):

assert_array_equal(u_attr.indices, nu_attr.indices)


class TestAllCoordinatesKwarg(object):
@pytest.fixture(scope='class')
def u_GRO_TRR(self):
Expand Down Expand Up @@ -1131,3 +1131,7 @@ def test_empty_creation_raises_error(self):
with pytest.raises(TypeError) as exc:
u = mda.Universe()
assert 'Universe.empty' in str(exc.value)

def test_as_Universe_deprecation():
with pytest.deprecated_call():
_ = mda.core.universe.as_Universe(PSF, DCD)

0 comments on commit 41ab4d1

Please sign in to comment.