MolecularFormulaManipulator { public static double getTotalNaturalAbundance(IMolecularFormula formula) { double abundance = 1.0; for (IIsotope isotope : formula.isotopes()) { if (isotope.getNaturalAbundance() == null) return 0.0; abundance = abundance * Math.pow(isotope.getNaturalAbundance(), formula.getIsotopeCount(isotope)); } return abundance / Math.pow(100, getAtomCount(formula)); }  static int getAtomCount(IMolecularFormula formula); static int getElementCount(IMolecularFormula formula, IElement element); static int getElementCount(IMolecularFormula formula, IIsotope isotope); static int getElementCount(IMolecularFormula formula, String symbol); static List<IIsotope> getIsotopes(IMolecularFormula formula, IElement element); static List<IElement> elements(IMolecularFormula formula); static boolean containsElement(IMolecularFormula formula, IElement element); static IMolecularFormula removeElement(IMolecularFormula formula, IElement element); static String getString(IMolecularFormula formula, String[] orderElements,
                                   boolean setOne); static String getString(IMolecularFormula formula, String[] orderElements,
                                   boolean setOne, boolean setMassNumber); static String getString(IMolecularFormula formula); static String getString(IMolecularFormula formula, boolean setOne); static String getString(IMolecularFormula formula, boolean setOne, boolean setMassNumber); static List<IIsotope> putInOrder(String[] orderElements, IMolecularFormula formula); @Deprecated static String getHillString(IMolecularFormula formula); static String getHTML(IMolecularFormula formula); static String getHTML(IMolecularFormula formula, boolean chargeB, boolean isotopeB); static String getHTML(IMolecularFormula formula, String[] orderElements, boolean showCharge, boolean showIsotopes); static IMolecularFormula getMolecularFormula(String stringMF, IChemObjectBuilder builder); static IMolecularFormula getMajorIsotopeMolecularFormula(String stringMF, IChemObjectBuilder builder); static IMolecularFormula getMolecularFormula(String stringMF, IMolecularFormula formula); @Deprecated static double getTotalExactMass(IMolecularFormula formula); static double getTotalMassNumber(IMolecularFormula formula); static double getMass(IMolecularFormula mf, int flav); static double getMass(IMolecularFormula mf); @Deprecated static double getNaturalExactMass(IMolecularFormula formula); @Deprecated static double getMajorIsotopeMass(IMolecularFormula formula); static double getTotalNaturalAbundance(IMolecularFormula formula); static double getDBE(IMolecularFormula formula); static IMolecularFormula getMolecularFormula(IAtomContainer atomContainer); static IMolecularFormula getMolecularFormula(IAtomContainer atomContainer, IMolecularFormula formula); static IAtomContainer getAtomContainer(IMolecularFormula formula); static IAtomContainer getAtomContainer(IMolecularFormula formula, IAtomContainer atomContainer); static IAtomContainer getAtomContainer(String formulaString, IChemObjectBuilder builder); static String[] generateOrderEle(); static boolean compare(IMolecularFormula formula1, IMolecularFormula formula2); static List<IElement> getHeavyElements(IMolecularFormula formula); static String simplifyMolecularFormula(String formula); static boolean adjustProtonation(IMolecularFormula mf, int hcnt); static IMolecularFormula getMostAbundant(IMolecularFormula mf); static IMolecularFormula getMostAbundant(IAtomContainer mol); static final int MolWeight; static final int MolWeightIgnoreSpecified; static final int MonoIsotopic; static final int MostAbundant; static final Comparator<IIsotope> NAT_ABUN_COMP; }
@Test public void testGetTotalNaturalAbundance_IMolecularFormula() throws Exception { IMolecularFormula formula = new MolecularFormula(); IIsotope carb = builder.newInstance(IIsotope.class, "C"); carb.setNaturalAbundance(98.93); IIsotope cl = builder.newInstance(IIsotope.class, "Cl"); cl.setNaturalAbundance(75.78); formula.addIsotope(carb); formula.addIsotope(cl); double totalAbudance = MolecularFormulaManipulator.getTotalNaturalAbundance(formula); Assert.assertEquals(0.74969154, totalAbudance, 0.000001); }
@Test public void testGetTotalNaturalAbundance_IMolecularFormula2() throws Exception { IMolecularFormula formula1 = new MolecularFormula(); IIsotope br1 = builder.newInstance(IIsotope.class, "Br"); br1.setNaturalAbundance(49.31); IIsotope br2 = builder.newInstance(IIsotope.class, "Br"); br2.setNaturalAbundance(50.69); formula1.addIsotope(br1); formula1.addIsotope(br2); Assert.assertEquals(2, formula1.getIsotopeCount(), 0.000001); double totalAbudance = MolecularFormulaManipulator.getTotalNaturalAbundance(formula1); Assert.assertEquals(0.24995235, totalAbudance, 0.000001); }
@Test public void testGetTotalNaturalAbundance_IMolecularFormula3() throws Exception { IMolecularFormula formula2 = new MolecularFormula(); IIsotope br1 = builder.newInstance(IIsotope.class, "Br"); br1.setNaturalAbundance(50.69); IIsotope br2 = builder.newInstance(IIsotope.class, "Br"); br2.setNaturalAbundance(50.69); formula2.addIsotope(br1); formula2.addIsotope(br2); Assert.assertEquals(1, formula2.getIsotopeCount(), 0.000001); double totalAbudance = MolecularFormulaManipulator.getTotalNaturalAbundance(formula2); Assert.assertEquals(0.25694761, totalAbudance, 0.000001); }
@Test public void testGetTotalNaturalAbundance_IMolecularFormula4() throws Exception { IMolecularFormula formula2 = new MolecularFormula(); IIsotope br1 = builder.newInstance(IIsotope.class, "Br"); br1.setNaturalAbundance(50.69); formula2.addIsotope(br1); formula2.addIsotope(br1); Assert.assertEquals(1, formula2.getIsotopeCount()); double totalAbudance = MolecularFormulaManipulator.getTotalNaturalAbundance(formula2); Assert.assertEquals(0.25694761, totalAbudance, 0.000001); }