Permalink
Browse files

Consider implicit hydrogens in exact mass utility.

Signed-off-by: Egon Willighagen <egonw@users.sourceforge.net>
  • Loading branch information...
1 parent 7433ac1 commit 0e85729059561ce277945c0517081158e176875a @johnmay johnmay committed with egonw Apr 4, 2014
@@ -196,11 +196,21 @@ public static double getTotalCharge(IAtomContainer atomContainer) {
*/
@TestMethod("testGetTotalExactMass_IAtomContainer")
public static double getTotalExactMass(IAtomContainer atomContainer) {
- double mass = 0.0;
- for (IAtom atom : atomContainer.atoms()) {
- mass += atom.getExactMass();
+ try {
+
+ Isotopes isotopes = Isotopes.getInstance();
+ double mass = 0.0;
+ double hExactMass = isotopes.getMajorIsotope(1).getExactMass();
+ for (IAtom atom : atomContainer.atoms()) {
+ if (atom.getImplicitHydrogenCount() == null)
+ throw new IllegalArgumentException("an atom had with unknown (null) implicit hydrogens");
+ mass += atom.getExactMass();
+ mass += atom.getImplicitHydrogenCount() * hExactMass;
+ }
+ return mass;
+ } catch (IOException e) {
+ throw new RuntimeException("Isotopes definitions could not be loaded", e);
}
- return mass;
}
/**
@@ -528,7 +528,7 @@ private IAtomContainer getChiralMolTemplate() {
mol.getAtom(1).setExactMass(34.96885268);
double totalExactMass = AtomContainerManipulator.getTotalExactMass(mol);
- Assert.assertEquals(46.96885268,totalExactMass,0.000001);
+ Assert.assertEquals(49.992327775,totalExactMass,0.000001);
}
@Test(expected = IllegalArgumentException.class)

0 comments on commit 0e85729

Please sign in to comment.