convention for TopologyObject repr ?

8 views
Skip to first unread message

Oliver Beckstein

unread,
Jun 20, 2023, 7:30:59 PM6/20/23
to mdnalysis-devel
Hi,

Why do we do something special to the order of atom indices in an TopologyObject when printing the repr? Namely in https://github.com/MDAnalysis/mdanalysis/blob/4f36e2a06eb2d04274dfe4510910986c2dd17681/package/MDAnalysis/core/topologyobjects.py#L118 

indices = (self.indices if self.indices[0] < self.indices[-1] else self.indices[::-1])

why do we reverse the order?

I found it quite confusing when I looked at a Dihedral object and the order of atoms was different from my carefully crafted order to define the dihedral:

>>> dih = u.atoms[[10, 0, 1, 3]].dihedral
>>> list(dih.atoms)
[<Atom 11: C5 of type opls_135 of resname V36, resid 1 and segid V36>,
 <Atom 1: C1 of type opls_465 of resname V36, resid 1 and segid V36>,
 <Atom 2: O2 of type opls_467 of resname V36, resid 1 and segid V36>,
 <Atom 4: C3 of type opls_468 of resname V36, resid 1 and segid V36>]
>>> repr(dih)
'<Dihedral between: Atom 3, Atom 1, Atom 0, Atom 10>'
I’d much rather have the actual order output, but I was wondering if there was any specific reason why we decided to manipulate the printed order?

Oliver

--
Oliver Beckstein (he/his/him)

email: orbe...@mdanalysis.org
twitter: @orbeckst
GitHub: @orbeckst

MDAnalysis – a NumFOCUS fiscally sponsored project





hugomac...@gmail.com

unread,
Jun 26, 2023, 6:35:19 PM6/26/23
to MDnalysis-devel
That seems strange and possibly confusing. 
With my user hat on I would want this changed, would you be able to raise an issue?
 Is the reordering only done for the `repr` of dihedral or is it some base behaviour of one of the underlying classes?

Cheers, 

Hugo. 

Oliver Beckstein

unread,
Jun 27, 2023, 7:25:33 PM6/27/23
to mdnalysis-devel
On Jun 26, 2023, at 3:35 PM, hugomac...@gmail.com <hugomac...@gmail.com> wrote:

That seems strange and possibly confusing. 
With my user hat on I would want this changed, would you be able to raise an issue?
 Is the reordering only done for the `repr` of dihedral or is it some base behaviour of one of the underlying classes?

It looked general to me but I didn’t test it further.

Oliver
Reply all
Reply to author
Forward
0 new messages