Skip to content

Smart Reprs for Groups #1223

@richardjgowers

Description

@richardjgowers

In PR #1222 we fix the reprto match old behaviour, but this makes Residue/SegmentGroup representation a little long as it will always print the repr of each member:

u = mda.Universe(PSF, DCD)

rg = u.residues[:10]

<ResidueGroup [<Residue MET, 1>, <Residue ARG, 2>, <Residue ILE, 3>, <Residue ILE, 4>, <Residue LEU, 5>, <Residue LEU, 6>, <Residue GLY, 7>, <Residue ALA, 8>, <Residue PRO, 9>, <Residue GLY, 10>]>

TODO:

  • Implement both __str__ and __repr__ for AtomGroup, ResidueGroup, and SegmentGroup. Ideally this is done in a generic way in GroupBase
  • __repr__ is to be short and terse (similar to how AtomGroup is now) ie '<ResidueGroup with 5 Residues>'
  • __str__ is to be long, pretty and informational, similar to how ResidueGroup is currently, so AtomGroup needs a similar treatment.
  • the str representation needs to truncate itself if the Group is over 10 members, and instead only show the first and last three members in a verbose way. This is similar to how long numpy arrays truncate the repr of themselves:
np.arange(10000)
array([   0,    1,    2, ..., 9997, 9998, 9999])

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions