Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Topology groups and PDB files #1257

Open
mimischi opened this issue Mar 24, 2017 · 8 comments
Open

Topology groups and PDB files #1257

mimischi opened this issue Mar 24, 2017 · 8 comments

Comments

@mimischi
Copy link
Contributor

mimischi commented Mar 24, 2017

Just stumbled upon the problem, that accessing any method that involves topology groups does not work, when creating a Universe with a PDB or GRO file. Both the master version 0.15.0, as well as a freshly cloned develop version 0.16.0-dev do not work, while producing different errors.

It does work when loading the topology from the test suite, so I'm using that as the expected behaviour. An non-working example PDB file would be 1UBQ from PDB.

Expected behaviour

from MDAnalysis.tests.datafiles import PSF
u = mda.Universe(PSF)
u.dihedrals
<TopologyGroup containing 8921 Dihedrals>

Actual behaviour

MDAnalysis 0.15.0

u = mda.Universe('1ubq.pdb')
u.dihedrals
<TopologyGroup containing 0 Nones>

MDAnalysis 0.16.0-dev

u = mda.Universe('1ubq.pdb')
u.dihedrals
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-45-133525c932b4> in <module>()
      1 c = mda.Universe('1ubq.pdb')
----> 2 c.dihedrals

~/Code/mdanalysis/package/MDAnalysis/core/universe.pyc in dihedrals(self)
    516     def dihedrals(self):
    517         """Dihedral angles between atoms"""
--> 518         return self.atoms.dihedrals
    519 
    520     @property

~/Code/mdanalysis/package/MDAnalysis/core/groups.pyc in __getattr__(self, attr)
   1503                 pass
   1504         raise AttributeError("{cls} has no attribute {attr}".format(
-> 1505             cls=self.__class__.__name__, attr=attr))
   1506 
   1507     def __reduce__(self):

AttributeError: AtomGroup has no attribute dihedrals

The .angles method does not work either.

Looking through the issues I came across #1253, which sounds pretty familiar.

@richardjgowers
Copy link
Member

Hey, thanks for the report

So a pdb/gro doesn't technically define dihedrals or angles, but obviously they can be inferred from bonds. So in a way this is "working as intended".

There's currently u.atoms.guess_bonds() which will try to guess bonds (based on distances and guessed vdw radii), then angles, then dihedrals. If you call this explicitly you should get the bonds from your PDB file. (Assuming the vdw radius can be guessed for all atoms).

If you load a PDB with CONECT records, then you can't immediately use them to guess angles admittedly, maybe there should be a u.atoms.guess_angles() method too..

@mimischi
Copy link
Contributor Author

I see, you have to call u.atoms.guess_bonds() explicitly or set guess_bonds=True for the Universe object. Thanks!

Wouldn't it be beneficial to catch that exception in the current develop version?

@richardjgowers
Copy link
Member

Yeah the error message could definitely be better, like providing a customised AttributeError for a known list of things

@mimischi
Copy link
Contributor Author

I'd be happy to contribute if that's ok!

@richardjgowers
Copy link
Member

@mimischi yeah that would be great! I think if you extended the __getattr__ here to add a special case for bonds etc. If you're doing that, you should also write a test that checks the errormessage

@mimischi
Copy link
Contributor Author

mimischi commented Oct 25, 2017

Finally coming back to this issue, I noticed the depreciation warnings and #1377.

Does the issue now shift from AtomGroup.__getattr__ to Atom.__getattr__?

@mimischi
Copy link
Contributor Author

mimischi commented Nov 7, 2017

Ping 👋

@kain88-de
Copy link
Member

ping @richardjgowers can you comment on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants