Skip to content

AttributeError when using MDAnalysis.analysis.hydrogenbonds.hbond_analysis with topology file without bonds information #2396

@VOD555

Description

@VOD555

Expected behavior

When given a universe without bonds attribute, should raise Exception

  Cannot assign donor-hydrogen pairs via topology as no bonded information is present.                           
  Please either: load a topology file with bonded information; use the guess_bonds() 
  topology guesser; or set HydrogenBondAnalysis.donors_sel so that a distance cutoff                              
  can be used.

Actual behavior

And AttributeError was raised:

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
~/anaconda3/envs/py36/lib/python3.6/site-packages/MDAnalysis/core/universe.py in __getattr__(self, key)
    509         try:
--> 510             segment = self._instant_selectors[key]
    511         except KeyError:

KeyError: 'bonds'

During handling of the above exception, another exception occurred:

AttributeError                            Traceback (most recent call last)
<ipython-input-12-763dc8d4b193> in <module>
----> 1 gro.bonds

~/anaconda3/envs/py36/lib/python3.6/site-packages/MDAnalysis/core/universe.py in __getattr__(self, key)
    510             segment = self._instant_selectors[key]
    511         except KeyError:
--> 512             raise AttributeError('No attribute "{}".'.format(key))
    513         else:
    514             warnings.warn("Instant selector Universe.<segid> "

AttributeError: No attribute "bonds".

Code to reproduce the behavior

Show us how to reproduce the failiure. If you can, use trajectory files from the test data.

import MDAnalysis
from MDAnalysis.analysis.hydrogenbonds.hbond_analysis import HydrogenBondAnalysis
from MDAnalysisTests.datafiles import GRO

kwargs = {
        'donors_sel': None,
        'hydrogens_sel': None,
        'acceptors_sel': None,
        'd_h_cutoff': 1.2,
        'd_a_cutoff': 3.0,
        'd_h_a_angle_cutoff': 120.0
        }

u = MDAnalysis.Universe(GRO)
h = HydrogenBondAnalysis(u, **kwargs)
h._get_dh_pairs()

Currently version of MDAnalysis

  • Which version are you using?
    0.21.0
  • Which version of Python?
    3.6.9

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions