/** * 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); }
/** * 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); }
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); } } } }
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); } } } }
@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")); }
@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")); }