Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Consider implicit hydrogens in natural abundance utility.

Signed-off-by: Egon Willighagen <egonw@users.sourceforge.net>
  • Loading branch information...
commit 9ee71fb71eb52531fdee176b200d45f18b25fade 1 parent 0e85729
@johnmay johnmay authored egonw committed
View
24 ...tandard/src/main/java/org/openscience/cdk/tools/manipulator/AtomContainerManipulator.java
@@ -252,11 +252,25 @@ public static double getNaturalExactMass(IAtomContainer atomContainer) {
*/
@TestMethod("testGetTotalNaturalAbundance_IAtomContainer")
public static double getTotalNaturalAbundance(IAtomContainer atomContainer) {
- double abundance = 1.0;
- for (IAtom iAtom : atomContainer.atoms()) abundance = abundance * iAtom.getNaturalAbundance();
-
-
- return abundance/Math.pow(100,atomContainer.getAtomCount());
+ try {
+ Isotopes isotopes = Isotopes.getInstance();
+ double abundance = 1.0;
+ double hAbundance = isotopes.getMajorIsotope(1).getNaturalAbundance();
+
+ int nImplH = 0;
+
+ for (IAtom atom : atomContainer.atoms()) {
+ if (atom.getImplicitHydrogenCount() == null)
+ throw new IllegalArgumentException("an atom had with unknown (null) implicit hydrogens");
+ abundance *= atom.getNaturalAbundance();
+ for (int h = 0; h < atom.getImplicitHydrogenCount(); h++)
+ abundance *= hAbundance;
+ nImplH += atom.getImplicitHydrogenCount();
+ }
+ return abundance / Math.pow(100, nImplH + atomContainer.getAtomCount());
+ } catch (IOException e) {
+ throw new RuntimeException("Isotopes definitions could not be loaded", e);
+ }
}
/**
View
2  ...ard/src/test/java/org/openscience/cdk/tools/manipulator/AtomContainerManipulatorTest.java
@@ -577,7 +577,7 @@ public void getNaturalExactMassNeedsAtomicNumber() {
mol.getAtom(1).setNaturalAbundance(75.78);
double totalAbudance = AtomContainerManipulator.getTotalNaturalAbundance(mol);
- Assert.assertEquals(0.74969154,totalAbudance,0.000001);
+ Assert.assertEquals(0.749432,totalAbudance,0.000001);
}
/**
Please sign in to comment.
Something went wrong with that request. Please try again.