/** * Utility to determine if the specified mass is the major isotope for the given atomic number. * * @param number atomic number * @param mass atomic mass * @return the mass is the major mass for the atomic number */ private boolean isMajorIsotope(int number, int mass) { try { IIsotope isotope = Isotopes.getInstance().getMajorIsotope(number); return isotope != null && isotope.getMassNumber().equals(mass); } catch (IOException e) { return false; } }
private static void configureAtoms(IAtomContainer mol) { try { Isotopes.getInstance().configureAtoms(mol); } catch (Exception exc) { logger.error("Could not configure molecule!"); logger.debug(exc); } }
/** * Mass number for a atom with a given atomic number and exact mass. * * @param atomicNumber atomic number * @param exactMass exact mass * @return the mass number (or null) if no mass number was found * @throws IOException isotope configuration could not be loaded */ private Integer massNumber(int atomicNumber, double exactMass) throws IOException { String symbol = PeriodicTable.getSymbol(atomicNumber); IIsotope isotope = Isotopes.getInstance().getIsotope(symbol, exactMass, 0.001); return isotope != null ? isotope.getMassNumber() : null; }
/** * @throws java.io.IOException if there is error in getting the {@link IsotopeFactory} */ public PubChemXMLHelper(IChemObjectBuilder builder) throws IOException { this.builder = builder; factory = Isotopes.getInstance(); }
/** * 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); } }
Double exactMass = isotope.getExactMass(); if (massNum == null || massNum == 0) { IIsotope majorIsotope = Isotopes.getInstance().getMajorIsotope(isotope.getSymbol()); if (majorIsotope != null) exactMass = majorIsotope.getExactMass(); } else { if (exactMass == null) { IIsotope temp = Isotopes.getInstance().getIsotope(isotope.getSymbol(), massNum); if (temp != null) exactMass = temp.getExactMass();
@Test public void configureDoesNotSetMajorIsotope() throws Exception { IAtom atom = new Atom("CH4"); Isotopes isotopes = Isotopes.getInstance(); IIsotope major = isotopes.getMajorIsotope(atom.getSymbol()); assertThat(major, is(notNullValue())); assertThat(major.getMassNumber(), is(12)); isotopes.configure(atom); assertThat(atom.getMassNumber(), is(nullValue())); }
/** * @cdk.bug 3534288 */ @Test(expected = IllegalArgumentException.class) public void testNonexistingElement() throws Exception { Isotopes isofac = Isotopes.getInstance(); IAtom xxAtom = new Atom("Xx"); isofac.configure(xxAtom); }
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(); else { IIsotope isotope = isotopes.getIsotope(atom.getSymbol(), atom.getMassNumber()); if (isotope == null) mw += isotopes.getNaturalMass(atom); else mw += isotope.getExactMass();
@Test public void testGetIsotopes() throws Exception { Isotopes isofac = Isotopes.getInstance(); IIsotope[] list = isofac.getIsotopes(); Assert.assertTrue(list.length > 200); }
@Test public void testIsElement_String() throws Exception { Isotopes isofac = Isotopes.getInstance(); Assert.assertTrue(isofac.isElement("C")); }
@Test public void testGetSize() throws Exception { Isotopes isofac = Isotopes.getInstance(); Assert.assertTrue(isofac.getSize() > 0); }
@Test public void testMassNumberDisplayWithDefinedIsotopes() throws Exception { IsotopeFactory ifac = Isotopes.getInstance(); IChemObjectBuilder bldr = SilentChemObjectBuilder.getInstance(); IMolecularFormula mf = bldr.newInstance(IMolecularFormula.class); mf.addIsotope(ifac.getMajorIsotope("C"), 7); mf.addIsotope(ifac.getMajorIsotope("O"), 3); mf.addIsotope(ifac.getMajorIsotope("H"), 3); mf.addIsotope(ifac.getMajorIsotope("Br"), 1); mf.addIsotope(ifac.getIsotope("Br", 81), 1); Isotopes.clearMajorIsotopes(mf); assertThat(MolecularFormulaManipulator.getString(mf, false, false), is("C7H3Br2O3")); assertThat(MolecularFormulaManipulator.getString(mf, false, true), is("C7H3Br[81]BrO3")); }
/** * @throws java.io.IOException if there is error in getting the {@link IsotopeFactory} */ public PubChemXMLHelper(IChemObjectBuilder builder) throws IOException { this.builder = builder; factory = Isotopes.getInstance(); }
@Test public void testGetNaturalMass_IElement() throws Exception { Isotopes isofac = Isotopes.getInstance(); Assert.assertEquals(1.0079760, isofac.getNaturalMass(new Element("H")), 0.1); }
@Test public void protonateDeuteratedPhenolate() throws Exception { IChemObjectBuilder bldr = SilentChemObjectBuilder.getInstance(); IMolecularFormula mf = bldr.newInstance(IMolecularFormula.class); // [C6DH4O]- (parser not good enough ATM so need to create like this) IIsotope deuterium = Isotopes.getInstance().getIsotope("H", 2); IIsotope hydrogen = Isotopes.getInstance().getMajorIsotope(1); mf.addIsotope(deuterium, 1); mf.addIsotope(hydrogen, 4); mf.addIsotope(Isotopes.getInstance().getMajorIsotope(6), 6); mf.addIsotope(Isotopes.getInstance().getMajorIsotope(8), 1); mf.setCharge(-1); assertTrue(MolecularFormulaManipulator.adjustProtonation(mf, +1)); assertThat(MolecularFormulaManipulator.getString(mf), is("C6H6O")); assertThat(mf.getCharge(), is(0)); assertThat(mf.getIsotopeCount(), is(4)); assertThat(mf.getIsotopeCount(deuterium), is(1)); assertThat(mf.getIsotopeCount(hydrogen), is(5)); }
@Test public void molecularWeight() throws InvalidSmilesException, IOException { SmilesParser smipar = new SmilesParser(SilentChemObjectBuilder.getInstance()); IAtomContainer mol = smipar.parseSmiles("[13CH4]CO"); double molecularWeight = AtomContainerManipulator.getMolecularWeight(mol); double naturalExactMass = AtomContainerManipulator.getNaturalExactMass(mol); Isotopes isotopes = Isotopes.getInstance(); for (IAtom atom : mol.atoms()) { if (atom.getMassNumber() == null) atom.setExactMass(isotopes.getMajorIsotope(atom.getAtomicNumber()) .getExactMass()); else isotopes.configure(atom); } double exactMass = AtomContainerManipulator.getTotalExactMass(mol); assertThat(molecularWeight, closeTo(48.069, 0.001)); assertThat(naturalExactMass, closeTo(47.076, 0.001)); assertThat(exactMass, closeTo(48.053, 0.001)); }
@Test public void testConfigure_IAtom() throws Exception { Isotopes isofac = Isotopes.getInstance(); Atom atom = new Atom("H"); isofac.configure(atom); Assert.assertEquals(1, atom.getAtomicNumber().intValue()); }
@Test public void testGetIsotopes_String() throws Exception { Isotopes isofac = Isotopes.getInstance(); IIsotope[] list = isofac.getIsotopes("He"); Assert.assertEquals(8, list.length); }
public int getAtomicNumber(IAtom o) { if (o != null && !(o instanceof IPseudoAtom) && o.getAtomicNumber() == null) { try { int massNumber = Isotopes.getInstance().getMajorIsotope(o.getAtomicNumber()).getAtomicNumber(); return massNumber; } catch (Exception e) { //e.printStackTrace(); return 6; } } else if (o instanceof IPseudoAtom) { return 6;//less than carbon for 'R' } return 0; } }