/** * Returns an element according to a given atomic number. * *@param atomicNumber The elements atomic number *@return The Element */ public IElement getElement(int atomicNumber) { return getMajorIsotope(atomicNumber); }
/** * Checks whether the given element exists. * * @param elementName The element name to test * @return True is the element exists, false otherwise */ public boolean isElement(String elementName) { return (getElement(elementName) != null); }
public void undo() throws CannotUndoException { this.atom.setSymbol(formerSymbol); try { IsotopeFactory ifac = XMLIsotopeFactory.getInstance(atom.getBuilder()); this.atom.setMassNumber(ifac.getMajorIsotope(formerSymbol).getMassNumber()); chemModelRelay.updateAtom(atom); ifac.configure(atom); } catch (OptionalDataException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
/** * Configures an atom. Finds the correct element type * by looking at the atoms element symbol. If the element symbol is not recognised, it will * throw an {@link IllegalArgumentException}. * * @param atom The atom to be configured * @return The configured atom */ public IAtom configure(IAtom atom) { IIsotope isotope; if (atom.getMassNumber() == null) return atom; else isotope = getIsotope(atom.getSymbol(), atom.getMassNumber()); if (isotope == null) throw new IllegalArgumentException("Cannot configure an unrecognized element/mass: " + atom.getMassNumber() + " " + atom); return configure(atom, isotope); }
clone = (IAtomContainer) container.clone(); factory = Isotopes.getInstance(); factory.configureAtoms(clone); } catch (CloneNotSupportedException | IOException e) { logger.debug(e); IAtom currentAtom = clone.getAtom(i); Double mass = factory.getMajorIsotope(currentAtom.getSymbol()).getExactMass(); if (mass == null) mass = factory.getNaturalMass(currentAtom);
@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")); }
IIsotope c = ifac.getMajorIsotope("C"); IIsotope[] carbons = ifac.getIsotopes("C"); IIsotope c13 = carbons[5]; // 13 IIsotope h = ifac.getMajorIsotope("H");
/** * Gets the natural mass of this element, defined as average of masses of isotopes, * weighted by abundance. * * @param element the element in question * @return The natural mass value */ public double getNaturalMass(IElement element) { IIsotope[] isotopes = getIsotopes(element.getSymbol()); double summedAbundances = 0; double summedWeightedAbundances = 0; double getNaturalMass = 0; for (int i = 0; i < isotopes.length; i++) { summedAbundances += isotopes[i].getNaturalAbundance(); summedWeightedAbundances += isotopes[i].getNaturalAbundance() * isotopes[i].getExactMass(); getNaturalMass = summedWeightedAbundances / summedAbundances; } return getNaturalMass; }
/** * Configures atoms in an AtomContainer to * carry all the correct data according to their element type. * *@param container The AtomContainer to be configured */ public void configureAtoms(IAtomContainer container) { for (int f = 0; f < container.getAtomCount(); f++) { configure(container.getAtom(f)); } }
@Test public void testMassNumberDisplay() throws Exception { IsotopeFactory ifac = Isotopes.getInstance(); IIsotope br81 = ifac.getIsotope("Br", 81); IChemObjectBuilder bldr = SilentChemObjectBuilder.getInstance(); IMolecularFormula mf = bldr.newInstance(IMolecularFormula.class); mf.addIsotope(new Atom("C"), 7); mf.addIsotope(new Atom("O"), 3); mf.addIsotope(new Atom("H"), 3); mf.addIsotope(new Atom("Br"), 1); mf.addIsotope(ifac.getIsotope("Br", 81), 1); assertThat(MolecularFormulaManipulator.getString(mf, false, false), is("C7H3Br2O3")); assertThat(MolecularFormulaManipulator.getString(mf, false, true), is("C7H3Br[81]BrO3")); }
clone = (IAtomContainer) container.clone(); factory = Isotopes.getInstance(); factory.configureAtoms(clone); } catch (CloneNotSupportedException | IOException e) { logger.debug(e); IAtom currentAtom = clone.getAtom(i); Double mass = factory.getMajorIsotope(currentAtom.getSymbol()).getExactMass(); if (mass == null) mass = factory.getNaturalMass(currentAtom);
/** * Configures an atom. Finds the correct element type * by looking at the atoms element symbol. If the element symbol is not recognised, it will * throw an {@link IllegalArgumentException}. * * @param atom The atom to be configured * @return The configured atom */ public IAtom configure(IAtom atom) { IIsotope isotope; if (atom.getMassNumber() == null) return atom; else isotope = getIsotope(atom.getSymbol(), atom.getMassNumber()); if (isotope == null) throw new IllegalArgumentException("Cannot configure an unrecognized element/mass: " + atom.getMassNumber() + " " + atom); return configure(atom, isotope); }
/** * Gets the natural mass of this element, defined as average of masses of isotopes, * weighted by abundance. * * @param element the element in question * @return The natural mass value */ public double getNaturalMass(IElement element) { IIsotope[] isotopes = getIsotopes(element.getSymbol()); double summedAbundances = 0; double summedWeightedAbundances = 0; double getNaturalMass = 0; for (int i = 0; i < isotopes.length; i++) { summedAbundances += isotopes[i].getNaturalAbundance(); summedWeightedAbundances += isotopes[i].getNaturalAbundance() * isotopes[i].getExactMass(); getNaturalMass = summedWeightedAbundances / summedAbundances; } return getNaturalMass; }
/** * Configures atoms in an AtomContainer to * carry all the correct data according to their element type. * *@param container The AtomContainer to be configured */ public void configureAtoms(IAtomContainer container) { for (int f = 0; f < container.getAtomCount(); f++) { configure(container.getAtom(f)); } }
/** * Returns an Element with a given element symbol. * *@param symbol The element symbol for the requested element *@return The configured element */ public IElement getElement(String symbol) { return getMajorIsotope(symbol); }
/** * Checks whether the given element exists. * * @param elementName The element name to test * @return True is the element exists, false otherwise */ public boolean isElement(String elementName) { return (getElement(elementName) != null); }
public void redo() throws CannotRedoException { this.atom.setSymbol(symbol); try { IsotopeFactory ifac = XMLIsotopeFactory.getInstance(atom.getBuilder()); this.atom.setMassNumber(ifac.getMajorIsotope(symbol).getMassNumber()); chemModelRelay.updateAtom(atom); ifac.configure(atom); } catch (OptionalDataException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
private void fixHydrogenIsotopes(IAtomContainer molecule, IsotopeFactory isotopeFactory) { for (IAtom atom : AtomContainerManipulator.getAtomArray(molecule)) { if (atom instanceof IPseudoAtom) { IPseudoAtom pseudo = (IPseudoAtom) atom; if ("D".equals(pseudo.getLabel())) { IAtom newAtom = molecule.getBuilder().newInstance(IAtom.class, atom); newAtom.setSymbol("H"); newAtom.setAtomicNumber(1); isotopeFactory.configure(newAtom, isotopeFactory.getIsotope("H", 2)); AtomContainerManipulator.replaceAtomByAtom(molecule, atom, newAtom); } else if ("T".equals(pseudo.getLabel())) { IAtom newAtom = molecule.getBuilder().newInstance(IAtom.class, atom); newAtom.setSymbol("H"); newAtom.setAtomicNumber(1); isotopeFactory.configure(newAtom, isotopeFactory.getIsotope("H", 3)); AtomContainerManipulator.replaceAtomByAtom(molecule, atom, newAtom); } } } }