/** * 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 boolean isMajor(IIsotope atom) { Integer mass = atom.getMassNumber(); if (mass == null) return false; try { Isotopes instance = Isotopes.getInstance(); IIsotope major = instance.getMajorIsotope(atom.getAtomicNumber()); if (major == null) return false; // no major isotope return major.getMassNumber().equals(mass); } catch (IOException e) { logger.error("Could not load Isotope data: ", e.getMessage()); return false; } }
private static boolean isMajor(IIsotope atom) { Integer mass = atom.getMassNumber(); if (mass == null) return false; try { Isotopes instance = Isotopes.getInstance(); IIsotope major = instance.getMajorIsotope(atom.getAtomicNumber()); if (major == null) return false; // no major isotope return major.getMassNumber().equals(mass); } catch (IOException e) { logger.error("Could not load Isotope data: ", e.getMessage()); return false; } }
private boolean isMajorIsotope(IAtom atom) { if (atom.getMassNumber() == null) return false; try { IIsotope major = Isotopes.getInstance().getMajorIsotope(atom.getSymbol()); return major != null && major.getMassNumber().equals(atom.getMassNumber()); } catch (IOException ex) { return false; } }
private boolean isMajorIsotope(IAtom atom) { if (atom.getMassNumber() == null) { return false; } try { IIsotope major = Isotopes.getInstance().getMajorIsotope(atom.getSymbol()); return major != null && major.getMassNumber().equals(atom.getMassNumber()); } catch (IOException ex) { return false; } }
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; } }
/** * Get the summed mass number of all isotopes from an MolecularFormula. It * assumes isotope masses to be preset, and returns 0.0 if not. * * @param formula The IMolecularFormula to calculate * @return The summed nominal mass of all atoms in this MolecularFormula */ public static double getTotalMassNumber(IMolecularFormula formula) { double mass = 0.0; for (IIsotope isotope : formula.isotopes()) { try { IIsotope isotope2 = Isotopes.getInstance().getMajorIsotope(isotope.getSymbol()); if (isotope2 != null) { mass += isotope2.getMassNumber() * formula.getIsotopeCount(isotope); } } catch (IOException e) { e.printStackTrace(); } } return mass; }
/** * Get the summed natural abundance of all atoms in an AtomContainer * * @param atomContainer The IAtomContainer to manipulate * @return The summed natural abundance of all atoms in this AtomContainer. */ public static double getTotalNaturalAbundance(IAtomContainer atomContainer) { 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); } }
private int determineIsotope(IAtom atom) { Integer mass = atom.getMassNumber(); IIsotope major = null; if (mass == null) return 0; try { major = Isotopes.getInstance().getMajorIsotope(atom.getSymbol()); } catch (IOException e) { // ignored } if (!writeMajorIsotopes.isSet() && major != null && mass.equals(major.getMassNumber())) mass = null; if (mass != null) { mass -= major != null ? major.getMassNumber() : 0; return mass >= -3 && mass <= 4 ? mass : 0; } return 0; }
public int getMassNumber(IAtom o) { if (o != null && !(o instanceof IPseudoAtom) && o.getMassNumber() == null) { try { // Integer atomicNumber = ac.getAtom(i).getAtomicNumber(); // System.out.println("atomicNumber " + atomicNumber); int massNumber = Isotopes.getInstance().getMajorIsotope(o.getAtomicNumber()).getMassNumber(); return massNumber; } catch (Exception e) { //e.printStackTrace(); return 11; } } else if (o instanceof IPseudoAtom) { //PseudoAtoms // Integer atomicNumber = ac.getAtom(i).getAtomicNumber(); // System.out.println("atomicNumber " + atomicNumber); return 11;//less than carbon for 'R' } return 0; } }
/** * Returns true if the mass number of this element is set and not * equal the mass number of the most abundant isotope of this element. * * @param atom {@link IAtom} which is being examined * @param container {@link IAtomContainer} of which the atom is part * @param model the {@link RendererModel} * @return true, when mass number information should be depicted */ @Override public boolean showCarbon(IAtom atom, IAtomContainer container, RendererModel model) { Integer massNumber = atom.getMassNumber(); if (massNumber != null) { try { Integer expectedMassNumber = Isotopes.getInstance().getMajorIsotope(atom.getSymbol()).getMassNumber(); if (!massNumber.equals(expectedMassNumber)) return true; } catch (IOException e) { logger.warn(e); } } return super.showCarbon(atom, container, model); } }
/** * Elements without a major isotope should return null. */ @Test public void testMajorUnstableIsotope() throws Exception { Isotopes isotopes = Isotopes.getInstance(); assertNull(isotopes.getMajorIsotope("Es")); }
@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())); }
@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 testGetMajorIsotope_String() throws Exception { Isotopes isofac = Isotopes.getInstance(); IIsotope isotope = isofac.getMajorIsotope("Te"); Assert.assertEquals(129.9062244, isotope.getExactMass(), 0.0001); }
@Test public void testGetMajorIsotope_int() throws Exception { Isotopes isofac = Isotopes.getInstance(); IIsotope isotope = isofac.getMajorIsotope(17); Assert.assertEquals("Cl", isotope.getSymbol()); }
@Test public void noNullPointerForStaticIsotopes() throws Exception { Isotopes is = Isotopes.getInstance(); IIsotope carbon = is.getMajorIsotope("C"); MolecularFormula mf = new MolecularFormula(); mf.addIsotope(carbon, 10); MolecularFormulaManipulator.getNaturalExactMass(mf); }
@Test public void testGetMajorIsotopeMass_IMolecularFormula() throws Exception { IMolecularFormula formula = new MolecularFormula(); formula.addIsotope(builder.newInstance(IIsotope.class, "C")); formula.addIsotope(builder.newInstance(IIsotope.class, "H"), 4); double expectedMass = 0.0; expectedMass += Isotopes.getInstance().getMajorIsotope("C").getExactMass(); expectedMass += 4.0 * Isotopes.getInstance().getMajorIsotope("H").getExactMass(); double totalExactMass = MolecularFormulaManipulator.getMajorIsotopeMass(formula); Assert.assertEquals(expectedMass, totalExactMass, 0.000001); }
/** Test formula mass calculation */ @Test public void testGetMajorIsotopeMolecularFormula_String_IChemObjectBuilder() throws Exception { IMolecularFormula mf2 = MolecularFormulaManipulator.getMajorIsotopeMolecularFormula("C11H17", builder); Assert.assertEquals(28, MolecularFormulaManipulator.getAtomCount(mf2)); Assert.assertEquals(2, mf2.getIsotopeCount()); IIsotope carbon = Isotopes.getInstance().getMajorIsotope("C"); IIsotope hydrogen = Isotopes.getInstance().getMajorIsotope("H"); double totalMass = carbon.getExactMass() * 11; totalMass += hydrogen.getExactMass() * 17; Assert.assertEquals(totalMass, MolecularFormulaManipulator.getTotalExactMass(mf2), 0.0000001); }
@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)); }