/** * Returns the molecular mass of the IAtomContainer. For the calculation it * uses the masses of the isotope mixture using natural abundances. * * @param atomContainer * @cdk.keyword mass, molecular * @see #getMolecularWeight(IAtomContainer) */ public static double getNaturalExactMass(IAtomContainer atomContainer) { try { Isotopes isotopes = Isotopes.getInstance(); double hydgrogenMass = isotopes.getNaturalMass(Elements.HYDROGEN); double mass = 0.0; for (final IAtom atom : atomContainer.atoms()) { if (atom.getAtomicNumber() == null) throw new IllegalArgumentException("an atom had with unknown (null) atomic number"); if (atom.getImplicitHydrogenCount() == null) throw new IllegalArgumentException("an atom had with unknown (null) implicit hydrogens"); mass += isotopes.getNaturalMass(Elements.ofNumber(atom.getAtomicNumber()).toIElement()); mass += hydgrogenMass * atom.getImplicitHydrogenCount(); } return mass; } catch (IOException e) { throw new RuntimeException("Isotopes definitions could not be loaded", e); } }
try { Isotopes isotopes = Isotopes.getInstance(); double hmass = isotopes.getNaturalMass(Elements.HYDROGEN); double mw = 0.0; for (final IAtom atom : mol.atoms()) { mw += hmass * atom.getImplicitHydrogenCount(); if (atom.getMassNumber() == null) mw += isotopes.getNaturalMass(atom); else if (atom.getExactMass() != null) mw += atom.getExactMass(); IIsotope isotope = isotopes.getIsotope(atom.getSymbol(), atom.getMassNumber()); if (isotope == null) mw += isotopes.getNaturalMass(atom); else mw += isotope.getExactMass();
@Test public void testGetNaturalMass_IElement() throws Exception { Isotopes isofac = Isotopes.getInstance(); Assert.assertEquals(1.0079760, isofac.getNaturalMass(new Element("H")), 0.1); }
mass = isotopes.getNaturalMass(a);
@Test public void testGetNaturalExactMass_IMolecularFormula() throws Exception { IMolecularFormula formula = new MolecularFormula(); formula.addIsotope(builder.newInstance(IIsotope.class, "C")); formula.addIsotope(builder.newInstance(IIsotope.class, "Cl")); double expectedMass = 0.0; expectedMass += Isotopes.getInstance().getNaturalMass(builder.newInstance(IElement.class, "C")); expectedMass += Isotopes.getInstance().getNaturalMass(builder.newInstance(IElement.class, "Cl")); double totalExactMass = MolecularFormulaManipulator.getNaturalExactMass(formula); Assert.assertEquals(expectedMass, totalExactMass, 0.000001); }
@Test public void testGetNaturalExactMass_IAtomContainer() throws Exception { IChemObjectBuilder builder = DefaultChemObjectBuilder.getInstance(); IAtomContainer mol = builder.newInstance(IAtomContainer.class); mol.addAtom(new Atom("C")); mol.addAtom(new Atom("Cl")); mol.getAtom(0).setImplicitHydrogenCount(4); mol.getAtom(1).setImplicitHydrogenCount(1); double expectedMass = 0.0; expectedMass += Isotopes.getInstance().getNaturalMass(builder.newInstance(IElement.class, "C")); expectedMass += Isotopes.getInstance().getNaturalMass(builder.newInstance(IElement.class, "Cl")); expectedMass += 5 * Isotopes.getInstance().getNaturalMass(builder.newInstance(IElement.class, "H")); double totalExactMass = AtomContainerManipulator.getNaturalExactMass(mol); Assert.assertEquals(expectedMass, totalExactMass, 0.000001); }