Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package/AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ Chronological list of authors
- Vedant Rathore
- Xiki Tempula
- Akshay Gupta
- Juan Eiros Zamora

External code
-------------
Expand Down
2 changes: 2 additions & 0 deletions package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ The rules for this file:
* 0.16.0

Enhancements
* Improved __str__ and __repr__ of 'GroupBase' class in
MDAnalysis.core.groups (addresses Issue #1223)
* Added dynamic selections (addresses Issues #175 and #1074).
* Added 'MemoryReader' class to allow manipulation of trajectory data
in-memory, which can provide substantial speed-ups to certain
Expand Down
13 changes: 9 additions & 4 deletions package/MDAnalysis/core/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,15 @@ def __repr__(self):
"".format(name.capitalize(), len(self), name,
"s"[len(self)==1:])) # Shorthand for a conditional plural 's'.

def __str__(self):
name = self.level.name
if len(self) <= 10:
return '<{}Group {}>'.format(name.capitalize(), repr(list(self)))
else:
return '<{}Group {}, ..., {}>'.format(name.capitalize(),
repr(list(self)[:3])[:-1],
repr(list(self)[-3:])[1:])

def __add__(self, other):
"""Concatenate the Group with another Group or Component of the same
level.
Expand Down Expand Up @@ -1649,8 +1658,6 @@ class ResidueGroup(GroupBase):
specific to ResidueGroups.

"""
def __repr__(self):
return '<ResidueGroup {}>'.format(repr(list(self.residues)))

@property
def atoms(self):
Expand Down Expand Up @@ -1748,8 +1755,6 @@ class SegmentGroup(GroupBase):
SegmentGroups.

"""
def __repr__(self):
return '<SegmentGroup {}>'.format(repr(list(self.segments)))

@property
def atoms(self):
Expand Down
28 changes: 26 additions & 2 deletions testsuite/MDAnalysisTests/core/test_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,10 +550,34 @@ def test_atomgroup_repr(self):
ag = self.u.atoms[:10]
assert_(repr(ag) == '<AtomGroup with 10 atoms>')

def test_atomgroup_str_short(self):
ag = self.u.atoms[:2]
assert_(str(ag) == '<AtomGroup [<Atom 1: N of type 56 of resname MET, resid 1 and segid 4AKE>, <Atom 2: HT1 of type 2 of resname MET, resid 1 and segid 4AKE>]>')

def test_atomgroup_str_long(self):
ag = self.u.atoms[:11]
assert_(str(ag).startswith('<AtomGroup [<Atom 1: N of type 56 of resname MET,'))
assert_('...' in str(ag))
assert_(str(ag).endswith(', resid 1 and segid 4AKE>]>'))

def test_residuegroup_repr(self):
rg = self.u.residues[:10]
assert_(repr(rg).startswith('<ResidueGroup [<Residue MET, 1>, '))
assert_(repr(rg) == '<ResidueGroup with 10 residues>')

def test_residuegroup_str_short(self):
rg = self.u.residues[:2]
assert_(str(rg) == '<ResidueGroup [<Residue MET, 1>, <Residue ARG, 2>]>')

def test_residuegroup_str_long(self):
rg = self.u.residues[:11]
assert_(str(rg).startswith('<ResidueGroup [<Residue MET, 1>,'))
assert_('...' in str(rg))
assert_(str(rg).endswith(', <Residue ALA, 11>]>'))

def test_segmentgroup_repr(self):
sg = self.u.segments[:10]
assert_(repr(sg) == '<SegmentGroup [<Segment 4AKE>]>')
assert_(repr(sg) == '<SegmentGroup with 1 segment>')

def test_segmentgroup_str(self):
sg = self.u.segments[:10]
assert_(str(sg) == '<SegmentGroup [<Segment 4AKE>]>')