-
Notifications
You must be signed in to change notification settings - Fork 673
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
HydrogenBondAnalysis: KeyError for heavy atoms when selection is updated #1687
Comments
@danijoo are you able to reproduce the error with the latest release 0.16.2, too? (It is generally safe to upgrade within the minor release number and there were various bug fixes 0.16.0 --> 0.16.2 and there was a fix for HBanalysis although it is likely not fixing your problem, but still, we need to work from the latest release.) Are you able to reproduce the error with one of the existing trajectories, e.g., from MDAnalysis.tests.datafiles import TPR, XTC If yes, then it is a lot easier for a developer to have a look at it. I would consider providing a repoducible failure the biggest contribution a user can make to fixing a bug. My experience is that with a reproducible failure, developers are much more likely to "just have a quick look" and then actually get to fixing it. On the other hand, finding a test/failure first is probably the number one reason why issues don't get addressed promptly. |
ping @danijoo – it would really help if you could provide more information and address the questions. Thanks. |
@orbeckst - I am having this same issue as I am trying it with RNA molecule adding new donors and acceptors. for resid in rna.residues.resids:
h = MDAnalysis.analysis.hbonds.HydrogenBondAnalysis(u, 'nucleic and resid %d' % (resid), 'nucleic and not resid %d' % (resid), update_selection1=False, update_selection2=False, distance=2.5, angle=120.0, distance_type="hydrogen", donors=("ADE N6", "URA N3", "GUA N1", "GUA N2", "CYT N4", "ADE O2'", "URA O2'", "GUA O2'", "CYT O2'"), acceptors=("ADE N1", "ADE N7", "ADE N3", "URA O4", "URA O2", "GUA O6", "GUA N7", "GUA N3", "CYT N3", "CYT O2"))
h.run()
h.generate_table()
print h.table
hblist = np.array(h.count_by_type()) The code works fine for some residues and then gives the error for count_by_type() call:
based on I tried your test datafiles, and they worked fine until for the last GLY residue I got error saying "No acceptors in selection 1" which should just continue with a warning maybe. But, the index error above is something different. Any idea what could be wrong? |
I guess it is an error caused by some inconsistency in topology. actually, having a really big trajectory file, I did not want to run the analysis over all the frames and there is no option to skip frames, so I wrote a dcd file skipping frames and selecting only RNA. Before that I also wrote a pdb file to use as a topology and read those into an Universe to use for hbond analysis. This was giving the error. rna = u.select_atoms("nucleic")
#rna.write("nucleic.pdb")
#with MDAnalysis.Writer("nucleic.dcd", rna.n_atoms) as W:
# for ts in u.trajectory[0::50]:
# W.write(rna)
#u = mda.Universe("nucleic.pdb", "nucleic.dcd") When I switched back to full trajectory and psf it worked. |
There is: in the HydrogenBondAnalysis.run() method: h.run(step=20) |
I guess I missed it. Thanks! |
I was just trying this, but it does not seem to skip the frames. I also tried it with your test data files which has 10 frames. I tried step=2 and step=5. I got the table showing the h-bonds in all the frames. |
Sorry, if this is not working as documented then it's a bug. Can you please open a new issue with this bug? Thanks!
…--
Oliver Beckstein
email: [email protected]
Am Oct 23, 2018 um 09:08 schrieb Abhishek Kognole ***@***.***>:
There is: in the HydrogenBondAnalysis.run() method:
I was just trying this, but it does not seem to skip the frames. I also tried it with your test data files which has 10 frames. I tried step=2 and step=5. I got the table showing the h-bonds in all the frames.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
I can reproduce this error with the test data files on the latest develop (0.19.1-dev) import MDAnalysis as mda; from MDAnalysis.tests.datafiles import TPR, XTC
import MDAnalysis.analysis.hbonds
u = mda.Universe(TPR, XTC)
h = MDAnalysis.analysis.hbonds.HydrogenBondAnalysis(u, 'protein', 'resname SOL')
h.run()
h.count_by_type() raises KeyError:
|
@richardjgowers this is not a good bug to have hanging around for the workshop... |
@orbeckst I wasn't planning on using this class, I've never understood how it works. It looks like it builds the lookup table for donors once and when you update selections this becomes wrong (after a single frame) |
Fair enough, but even if you're not using, someone might to do a problem during the "open session". It is quite possible that this is broken with updating groups. |
Yes, it is broken, and I documented it a long time ago ... Assumptions: selections have not changed (because we are simply looking at the last content of the donors and donor hydrogen lists) mdanalysis/package/MDAnalysis/analysis/hbonds/hbond_analysis.py Lines 1395 to 1426 in c9a37e3
|
Admittedly, the groups in my example #1687 (comment) are not even changing – they are just |
I am infinitely in favor of 2. |
On a related note, we should probably try to find hydrogens via bonds if we have them, as the first choice before |
Yeah I opened #2120 for the lifetime tool (which expects the AGs to be made a priori), could be possible to share |
Expected behaviour
When I want to get hydrogen bonding frequencies (
h.count_by_type()
) in combination with theupdate_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
Currently version of MDAnalysis:
The text was updated successfully, but these errors were encountered: