Skip to content

Commit

Permalink
Using u._topology.bonds rather than u.bonds.
Browse files Browse the repository at this point in the history
It is a million times faster to access.
See MDAnalysis#2396 (comment)
  • Loading branch information
Paul Smith committed Mar 9, 2020
1 parent 920e8dc commit 9389ecf
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion package/MDAnalysis/analysis/hydrogenbonds/hbond_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,11 @@ def _get_dh_pairs(self):

# If donors_sel is not provided, use topology to find d-h pairs
if not self.donors_sel:
if not (hasattr(self.u, 'bonds') and len(self.u.bonds) != 0):

# We're using u._topology.bonds rather than u.bonds as it is a million times faster to access.
# This is because u.bonds also calculates properties of each bond (e.g bond length).
# See https://github.com/MDAnalysis/mdanalysis/issues/2396#issuecomment-596251787
if not (hasattr(self.u._topology, 'bonds') and len(self.u._topology.bonds.values) != 0):
raise NoDataError('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 '
Expand Down

0 comments on commit 9389ecf

Please sign in to comment.