-
Notifications
You must be signed in to change notification settings - Fork 826
Open
Description
Expected behaviour
When I want to get hydrogen bonding frequencies (h.count_by_type()) in combination with the update_selections flag, it should built the proper frequencies table.
Actual behaviour
Under some circumstances, if update_selection is set to true, a given index might not be present in self._s2_donors when the heavy atom lookup table is built. This leads to a crash when the heavy atoms are generated because the key is not present in the lookup table. This happens mostly when the selection that is set to update includes solvent or other rapid exchanging residues.
Code to reproduce the behaviour
import MDAnalysis as mda
u = mda.Universe(top, trj)
# this works
h = mda.analysis.hbonds.HydrogenBondAnalysis(u, "resid 1-5", "resname SOL", update_selection1=False, update_selection2=False)
h.run()
h.generate_table()
frequencies = h.count_by_type()
# this fails
h = mda.analysis.hbonds.HydrogenBondAnalysis(u, "resid 1-5", "resname SOL", update_selection1=False, update_selection2=True)
h.run()
h.generate_table()
frequencies = h.count_by_type()
Traceback (most recent call last):
File "<ipython-input-7-438a429831da>", line 16, in <module>
frequencies = h.count_by_type()
File "/home/bauer/.local/lib/python3.6/site-packages/MDAnalysis/analysis/hbonds/hbond_analysis.py", line 1149, in count_by_type
r.donor_heavy_atom[:] = [h2donor[idx] for idx in r.donor_index]
File "/home/bauer/.local/lib/python3.6/site-packages/MDAnalysis/analysis/hbonds/hbond_analysis.py", line 1149, in <listcomp>
r.donor_heavy_atom[:] = [h2donor[idx] for idx in r.donor_index]
KeyError: 29971Currently version of MDAnalysis:
import sys
import MDAnalysis as md
md.__version__
# '0.16.0'
sys.version
# '3.6.2 (default, Jul 20 2017, 03:52:27) \n[GCC 7.1.1 20170630]'
Reactions are currently unavailable