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
Added two test cases for bugs in IsotopePatternGenerator. #251
Conversation
…ndicates generator is saving state where it shouldn't. Second bug indicates generator is not considering charge properly
Just to note, the first one may not be a bug, but might be poor design. The second one is. That's why I was asking about issues (a Github issue would let me link to the commit) |
Any fix? We had major problems before with tests used as feature requests... the number of failures quickly runs away. |
Thats why I wanted to start an issue - the first one is possibly not a bug and maybe more of a design or documentation issue. I don't use this part of the code enough to know which way it should be, so while I can provide the fix, it may actually be the wrong thing to do The second one appears to be a bug, but I don't have a fix right now. |
The first one is a simple fix... but this is in the code...
Want me to fix? It looks intentional. I would argue the second one is a feature request. Unless the code is meant to handle charges it's not a bug. Given the progeny this code of is of I won't hold my breath on a fix and think the correct thing to do here is document the exception. |
In fact... I don't even think the second one is fixable? The MF has no association of the element with the charge, and a charge does not always mean +1/-1 proton. |
yes, regarding the first, I also saw that message. Based on that it looks intentional. In which case we should just update the document to indicate that if you cant reuse an instance of this class. If you do, then you need to make a new one. |
Also is the test wrong...? Formulas work like this right... you don't add and remove H with a charge.
|
The second one seems to be a bug. This is actually based on a report from |
Hmm, you have a point. |
Yeah me and Daniel were discussing this the other day in another context (which I can't remember) but basically there aren't any implicit hydrogens in formulas, the isotope pattern isn't adding/removing any. |
Looking again that comment regarding the first one is because it does it one atom at a time so that can be updated. |
yes, looks like the code doesn't handle charges explicitly, but does via formulae. So C6H11O6Na (negatively charged) does end up with a different mass than the neutral formula. So the code seems to be working (but should be documented for people like me :) |
How would you document it...? Seems obvious to me because the charge isn't associated with an atom so we can't adjust/correct for it. |
Indicate that setting the charge on the formula (since the formula object has a method to set charge) does not actually change anything. And instead, if you want a charged formula, specify the appropriate formula? |
Okay done... however I also realised there is an elegant fix to the rcdk problem. Whilst setCharge should not change the hydrogen count... doesn't mean we can't have a convenience method to (de)protonate. I feel this can safely change both the charge and hydrogen count as it's all in the name and is clearly something a user would want to do. Was tempted by IChemObjectBuilder bldr = SilentChemObjectBuilder.getInstance();
IMolecularFormula mf = MolecularFormulaManipulator.getMolecularFormula("[C6H5O]-", bldr);
assertTrue(MolecularFormulaManipulator.adjustProtonation(mf, +1));
assertThat(MolecularFormulaManipulator.getString(mf), is("C6H6O"));
assertThat(mf.getCharge(), is(0));
assertThat(mf.getIsotopeCount(), is(3)); |
Ah, nice. This is what I had initially thought should be happening |
First bug indicates generator is saving state where it shouldn't. Second bug indicates generator is not considering charge properly. I will file the bug reports separately