Skip to content

Commit

Permalink
Fixes in light of MDAnalysis 0.11.0.
Browse files Browse the repository at this point in the history
Fixed resnum functionality, and made updates to use the new APIs in
MDAnalysis for internal Universe handling.
  • Loading branch information
dotsdl committed Sep 9, 2015
1 parent ca21f33 commit 0531fd3
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 31 deletions.
9 changes: 5 additions & 4 deletions docs/Sim.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ also give it a topology and/or trajectory files as we would to an MDAnalysis
**Universe** ::
>>> from mdsynthesis import Sim
>>> s = Sim('scruffy', universe=['path/to/topology', 'path/to/trajectory'])
>>> s = Sim('scruffy')
>>> s.universes.add('main', 'path/to/topology', 'path/to/trajectory')

This will create a directory ``scruffy`` that contains a single file
(``Sim.<uuid>.h5``). That file is a persistent representation of the **Sim** on disk.
Expand Down Expand Up @@ -81,8 +82,8 @@ but they should actually go from 10 to 223. If we can't change the topology to r
this, we could set the resnums for these residues to the canonical values ::

>>> prot = s.universe.selectAtoms('protein')
>>> prot.residues.set_resnum(prot.residues.resids() + 9)
>>> prot.residues.resnums()
>>> prot.residues.set_resnum(prot.residues.resids + 9)
>>> prot.residues.resnums
array([ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
Expand All @@ -109,7 +110,7 @@ and we might save selections using resnums as well. However, resnums aren't
stored in the topology, so to avoid having to reset resnums manually each time
we load the **Universe**, we can just store the resnum definition with ::

>>> s.universes.resnums('main', s.universe.residues.resnums())
>>> s.universes.resnums('main', s.universe.residues.resnums)

and the resnum definition will be applied to the **Universe** both now and every
time it is activated.
Expand Down
4 changes: 2 additions & 2 deletions mdsynthesis/aggregators.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ def add(self, handle, *selection):
# Conversion function, leave strings alone,
# turn AtomGroups into their indices
def conv(x):
return x if isinstance(x, basestring) else x.indices()
return x if isinstance(x, basestring) else x.indices

self._backend.add_selection(
self._treant._uname, handle, *map(conv, selection))
Expand Down Expand Up @@ -459,7 +459,7 @@ def asAtomGroup(self, handle):
# - a list of strings
# - a numpy array of indices
if isinstance(selstring[0], basestring):
return self._treant.universe.selectAtoms(*selstring)
return self._treant.universe.select_atoms(*selstring)
else:
return self._treant.universe.atoms[selstring]

Expand Down
48 changes: 24 additions & 24 deletions mdsynthesis/tests/test_treants.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,29 +100,29 @@ def test_set_resnums(self, treant):
"""Test that we can add resnums to a universe."""
treant.universes.add('lolcats', GRO, XTC)

protein = treant.universe.selectAtoms('protein')
resids = protein.residues.resids()
protein = treant.universe.select_atoms('protein')
resids = protein.residues.resids
protein.residues.set_resnum(resids + 3)

treant.universes.resnums('lolcats',
treant.universe.atoms.resnums())
treant.universe.residues.resnums)

treant.universes['lolcats']

protein = treant.universe.selectAtoms('protein')
assert (resids + 3 == protein.residues.resnums()).all()
protein = treant.universe.select_atoms('protein')
assert (resids + 3 == protein.residues.resnums).all()

# BUG IN MDANALYSIS PREVENTS RESETTING OF RESNUMS
# protein.residues.set_resnum(resids + 6)
# test resetting of resnums
protein.residues.set_resnum(resids + 6)

# assert (protein.residues.resnums == resids + 6).all()
# treant.universes.resnums('lolcats',
# treant.universe.atoms.resnums())
assert (protein.residues.resnums == resids + 6).all()
treant.universes.resnums('lolcats',
treant.universe.residues.resnums)

# treant.universes['lolcats']
treant.universes['lolcats']

# protein = treant.universe.selectAtoms('protein')
# assert (resids + 6 == protein.residues.resnums()).all()
protein = treant.universe.select_atoms('protein')
assert (resids + 6 == protein.residues.resnums).all()

def test_KeyError(self, treant):
"""Test that a KeyError raised when trying to activate a Universe
Expand Down Expand Up @@ -151,12 +151,12 @@ def test_add_selection(self, treant):
treant.selections.add('CA', 'protein and name CA')
treant.selections.add('someres', 'resid 12')

CA = treant.universe.selectAtoms('protein and name CA')
someres = treant.universe.selectAtoms('resid 12')
CA = treant.universe.select_atoms('protein and name CA')
someres = treant.universe.select_atoms('resid 12')

assert (CA.indices() == treant.selections['CA'].indices()).all()
assert (someres.indices() ==
treant.selections['someres'].indices()).all()
assert (CA.indices == treant.selections['CA'].indices).all()
assert (someres.indices ==
treant.selections['someres'].indices).all()

def test_remove_selection(self, treant):
"""Test universe removal"""
Expand Down Expand Up @@ -206,18 +206,18 @@ def test_add_selections_multiple_strings_via_add(self, treant):
treant.selections.add('funky town', 'name N', 'name CA')
assert 'funky town' in treant.selections

ref = treant.universe.selectAtoms('name N', 'name CA')
ref = treant.universe.select_atoms('name N', 'name CA')
sel = treant.selections['funky town']
assert (ref.indices() == sel.indices()).all()
assert (ref.indices == sel.indices).all()

def test_add_selections_multiple_strings_via_setitem(self, treant):
"""Add a selection that has multiple selection strings"""
treant.selections['funky town 2'] = 'name N', 'name CA'
assert 'funky town 2' in treant.selections

ref = treant.universe.selectAtoms('name N', 'name CA')
ref = treant.universe.select_atoms('name N', 'name CA')
sel = treant.selections['funky town 2']
assert (ref.indices() == sel.indices()).all()
assert (ref.indices == sel.indices).all()

def test_add_selection_as_atomgroup_via_add(self, treant):
"""Make an arbitrary AtomGroup then save selection as AG"""
Expand All @@ -227,7 +227,7 @@ def test_add_selection_as_atomgroup_via_add(self, treant):
assert 'ag sel' in treant.selections

ag2 = treant.selections['ag sel']
assert (ag.indices() == ag2.indices()).all()
assert (ag.indices == ag2.indices).all()

def test_add_selection_as_atomgroup_via_setitem(self, treant):
"""Make an arbitrary AtomGroup then save selection as AG"""
Expand All @@ -237,7 +237,7 @@ def test_add_selection_as_atomgroup_via_setitem(self, treant):
assert 'ag sel 2' in treant.selections

ag2 = treant.selections['ag sel 2']
assert (ag.indices() == ag2.indices()).all()
assert (ag.indices == ag2.indices).all()


class TestReadOnly:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
'pandas>=0.16.1',
'tables>=3.2.0',
'h5py>=2.5.0',
'MDAnalysis<=0.10.0',
'MDAnalysis>=0.11.0',
'scandir>=1.0',
'PyYAML>=3.11'
],
Expand Down

0 comments on commit 0531fd3

Please sign in to comment.