Skip to content

Commit

Permalink
Updated atom ID representation order to match AtomGroup (#4191)
Browse files Browse the repository at this point in the history
* Updated atom ID representation order to match AtomGroup
  • Loading branch information
ztimol authored Jul 31, 2023
1 parent 44733fc commit f3e40d4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
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
6 changes: 5 additions & 1 deletion package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ The rules for this file:
* release numbers follow "Semantic Versioning" http://semver.org

------------------------------------------------------------------------------
??/??/?? IAlibay, jaclark5, MohitKumar020291, orionarcher, xhgchen

??/??/?? IAlibay, jaclark5, MohitKumar020291, orionarcher, xhgchen, ztimol

* 2.6.0

Expand All @@ -29,6 +30,9 @@ Enhancements
(Issue #3546)

Changes
* Atom ID representation order updated to match that of associated
AtomGroup indices.
(PR #4191, Issue #4181)
* Package license has been updated to GPLv3+ to better reflect the
compatibility of GPLv2+ with Apache and GPLv3 licenced codes (PR #4219).
* All new contributions are now made under LGPLv2.1+ (PR #4219).
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"""
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

0 comments on commit f3e40d4

Please sign in to comment.