Skip to content

Commit

Permalink
Consider implicit hydrogens in exact mass utility.
Browse files Browse the repository at this point in the history
Signed-off-by: Egon Willighagen <egonw@users.sourceforge.net>
  • Loading branch information
johnmay authored and egonw committed Apr 6, 2014
1 parent 7433ac1 commit 0e85729
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
Expand Up @@ -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;
}

/**
Expand Down
Expand Up @@ -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)
Expand Down

0 comments on commit 0e85729

Please sign in to comment.