Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated atom ID representation order to match AtomGroup #4191

Merged
merged 14 commits into from
Jul 31, 2023
1 change: 1 addition & 0 deletions package/AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ Chronological list of authors
- Daniel J. Evans
- Mohit Kumar
- Shubham Kumar
- Zaheer Timol

External code
-------------
Expand Down
2 changes: 2 additions & 0 deletions package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ Changes
* GSD is no longer a core dependency of MDAnalysis. It must be installed
ztimol marked this conversation as resolved.
Show resolved Hide resolved
independently if you wish to read HOOMD trajectory files.
(PR #4174, Issue #3819)
* Atom ID representation order updated to match that of associated AtomGroup indices.
ztimol marked this conversation as resolved.
Show resolved Hide resolved
(PR #4191, Issue #4181)

Deprecations
* MDAnalysis no longer officially supports 32 bit installations (they are
Expand Down
7 changes: 4 additions & 3 deletions package/MDAnalysis/core/topologyobjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class TopologyObject(object):
via the ``is_guessed`` managed property.
.. versionadded:: 0.11.0
Added the `value` method to return the size of the object
.. versionchanged:: 2.6.0
Updated Atom ID representation order to match that of AtomGroup indices
"""
__slots__ = ("_ix", "_u", "btype", "_bondtype", "_guessed", "order")

Expand Down Expand Up @@ -116,13 +118,12 @@ def __hash__(self):
return hash((self._u, tuple(self.indices)))

def __repr__(self):
indices = (self.indices if self.indices[0] < self.indices[-1]
else self.indices[::-1])
"Return representation in same order of AtomGroup indices"
ztimol marked this conversation as resolved.
Show resolved Hide resolved
ztimol marked this conversation as resolved.
Show resolved Hide resolved
return "<{cname} between: {conts}>".format(
cname=self.__class__.__name__,
conts=", ".join([
"Atom {0}".format(i)
for i in indices]))
for i in self.indices]))

def __contains__(self, other):
"""Check whether an atom is in this :class:`TopologyObject`"""
Expand Down
10 changes: 5 additions & 5 deletions testsuite/MDAnalysisTests/core/test_topologyobjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def test_angle(self, PSFDCD):
def test_angle_repr(self, PSFDCD):
angle = PSFDCD.atoms[[30, 10, 20]].angle

assert_equal(repr(angle), '<Angle between: Atom 20, Atom 10, Atom 30>')
assert_equal(repr(angle), '<Angle between: Atom 30, Atom 10, Atom 20>')

def test_angle_180(self):
# we edit the coordinates, so make our own universe
Expand All @@ -183,7 +183,7 @@ def test_dihedral_repr(self, PSFDCD):
dihedral = PSFDCD.atoms[[4, 7, 8, 1]].dihedral

assert_equal(repr(dihedral),
'<Dihedral between: Atom 1, Atom 8, Atom 7, Atom 4>')
'<Dihedral between: Atom 4, Atom 7, Atom 8, Atom 1>')

# Improper_Dihedral class check
def test_improper(self, PSFDCD):
Expand All @@ -197,12 +197,12 @@ def test_improper_repr(self, PSFDCD):

assert_equal(
repr(imp),
'<ImproperDihedral between: Atom 1, Atom 8, Atom 7, Atom 4>')
'<ImproperDihedral between: Atom 4, Atom 7, Atom 8, Atom 1>')

def test_ureybradley_repr(self, PSFDCD):
ub = PSFDCD.atoms[[30, 10]].ureybradley

assert_equal(repr(ub), '<UreyBradley between: Atom 10, Atom 30>')
assert_equal(repr(ub), '<UreyBradley between: Atom 30, Atom 10>')

def test_ureybradley_repr_VE(self, PSFDCD):
with pytest.raises(ValueError):
Expand All @@ -221,7 +221,7 @@ def test_cmap_repr(self, PSFDCD):

assert_equal(
repr(cmap),
'<CMap between: Atom 2, Atom 1, Atom 8, Atom 7, Atom 4>')
'<CMap between: Atom 4, Atom 7, Atom 8, Atom 1, Atom 2>')

def test_cmap_repr_VE(self, PSFDCD):
with pytest.raises(ValueError):
Expand Down
Loading