Skip to content

Commit

Permalink
Issue 1868 dihedralrepr (#1869)
Browse files Browse the repository at this point in the history
* fixes #1869 
* fixed order of indices in Angle/Dihedral/Improper repr
* tests for issue 1868
  • Loading branch information
richardjgowers authored and orbeckst committed Apr 19, 2018
1 parent 41d48e4 commit 092d5a5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
3 changes: 2 additions & 1 deletion package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ The rules for this file:
* release numbers follow "Semantic Versioning" http://semver.org

------------------------------------------------------------------------------
??/??/18
??/??/18 richardjgowers

* 0.18.1

Enhancements

Fixes
* Fixed order of indices in Angle/Dihedral/Improper repr

Changes

Expand Down
3 changes: 2 additions & 1 deletion package/MDAnalysis/core/topologyobjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ def __hash__(self):
return hash((self._u, tuple(self.indices)))

def __repr__(self):
indices = sorted(self.indices)
indices = (self.indices if self.indices[0] < self.indices[-1]
else self.indices[::-1])
return "<{cname} between: {conts}>".format(
cname=self.__class__.__name__,
conts=", ".join([
Expand Down
17 changes: 17 additions & 0 deletions testsuite/MDAnalysisTests/core/test_topologyobjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ def test_angle(self, PSFDCD):
assert_almost_equal(angle.angle(), 107.20893, self.precision)
assert_almost_equal(angle.value(), 107.20893, self.precision)

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>')

def test_angle_180(self):
# we edit the coordinates, so make our own universe
u = mda.Universe(PSF, DCD)
Expand All @@ -174,13 +179,25 @@ def test_dihedral(self, PSFDCD):
assert_almost_equal(dihedral.dihedral(), 18.317778, self.precision)
assert_almost_equal(dihedral.value(), 18.317778, self.precision)

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>')

# Improper_Dihedral class check
def test_improper(self, PSFDCD):
imp = PSFDCD.atoms[4].impropers[0]

assert_almost_equal(imp.improper(), -3.8370631, self.precision)
assert_almost_equal(imp.value(), -3.8370631, self.precision)

def test_improper_repr(self, PSFDCD):
imp = PSFDCD.atoms[[4, 7, 8, 1]].improper

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

class TestTopologyGroup(object):
"""Tests TopologyDict and TopologyGroup classes with psf input"""
Expand Down

0 comments on commit 092d5a5

Please sign in to comment.