public void redo() { IAtomContainer relevantContainer = ChemModelManipulator.getRelevantAtomContainer(chemModel, oldAtom); AtomContainerManipulator.replaceAtomByAtom(relevantContainer, oldAtom, newAtom); }
public void undo() { IAtomContainer relevantContainer = ChemModelManipulator.getRelevantAtomContainer(chemModel, newAtom); AtomContainerManipulator.replaceAtomByAtom(relevantContainer, newAtom, oldAtom); }
AtomContainerManipulator.replaceAtomByAtom(readData, original, replacement);
public void replaceAtom(IAtom atomnew, IAtom atomold) { IAtomContainer relevantContainer = ChemModelManipulator .getRelevantAtomContainer(chemModel, atomold); AtomContainerManipulator.replaceAtomByAtom(relevantContainer, atomold, atomnew); updateAtom(atomnew); structureChanged(); if (undoredofactory != null && undoredohandler != null) { IUndoRedoable undoredo = undoredofactory.getReplaceAtomEdit( chemModel, atomold, atomnew, "Replace Atom"); undoredohandler.postEdit(undoredo); } }
if (aliasAtom.getPoint2d() != null) newPseudoAtom.setPoint2d(aliasAtom.getPoint2d()); if (aliasAtom.getPoint3d() != null) newPseudoAtom.setPoint3d(aliasAtom.getPoint3d()); AtomContainerManipulator.replaceAtomByAtom(container, aliasAtom, newPseudoAtom); } else if (line.startsWith("M ISO")) { try { pseudoAtom.setPoint3d(prevAtom.getPoint3d()); AtomContainerManipulator.replaceAtomByAtom(container, prevAtom, pseudoAtom); } catch (NumberFormatException exception) { String error = "Error (" + exception.toString() + ") while parsing line " + linecount + ": " + line
newPseudoAtom.setPoint3d(aliasAtom.getPoint3d()); AtomContainerManipulator.replaceAtomByAtom(container, aliasAtom, newPseudoAtom); } else if (line.startsWith("M ISO")) { try { pseudoAtom.setPoint3d(prevAtom.getPoint3d()); AtomContainerManipulator.replaceAtomByAtom(container, prevAtom, pseudoAtom); } catch (NumberFormatException exception) { String error = "Error (" + exception.toString() + ") while parsing line " + linecount + ": " + line
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); } } } }
pseudo.setImplicitHydrogenCount(0); IAtomContainer mol = atomToMol.get(old); AtomContainerManipulator.replaceAtomByAtom(mol, old, pseudo); atomToMol.put(pseudo, mol); atoms.set(e.getKey(), pseudo);
@Test public void testReplaceAtom_stereochemistry() throws Exception { IChemObjectBuilder bldr = SilentChemObjectBuilder.getInstance(); SmilesParser smipar = new SmilesParser(bldr); IAtomContainer mol = smipar.parseSmiles("N[C@H](CC)O"); IAtom newAtom = bldr.newInstance(IAtom.class, "Cl"); newAtom.setImplicitHydrogenCount(0); AtomContainerManipulator.replaceAtomByAtom(mol, mol.getAtom(0), newAtom); assertThat(SmilesGenerator.isomeric().create(mol), is("Cl[C@H](CC)O")); }
/** * Labels the atom at the specified index with the provide label. If the * atom was not already a pseudo atom then the original atom is replaced. * * @param container structure * @param index atom index to replace * @param label the label for the atom * @see IPseudoAtom#setLabel(String) */ static void label(final IAtomContainer container, final int index, final String label) { final IAtom atom = container.getAtom(index); final IPseudoAtom pseudoAtom = atom instanceof IPseudoAtom ? (IPseudoAtom) atom : container.getBuilder() .newInstance(IPseudoAtom.class); if (atom.equals(pseudoAtom)) { pseudoAtom.setLabel(label); } else { pseudoAtom.setSymbol(label); pseudoAtom.setAtomicNumber(0); pseudoAtom.setPoint2d(atom.getPoint2d()); pseudoAtom.setPoint3d(atom.getPoint3d()); pseudoAtom.setMassNumber(atom.getMassNumber()); pseudoAtom.setFormalCharge(atom.getFormalCharge()); pseudoAtom.setValency(atom.getValency()); pseudoAtom.setLabel(label); // XXX: would be faster to track all replacements and do it all in one AtomContainerManipulator.replaceAtomByAtom(container, atom, pseudoAtom); } }
/** * Labels the atom at the specified index with the provide label. If the * atom was not already a pseudo atom then the original atom is replaced. * * @param container structure * @param index atom index to replace * @param label the label for the atom * @see IPseudoAtom#setLabel(String) */ static void label(final IAtomContainer container, final int index, final String label) { final IAtom atom = container.getAtom(index); final IPseudoAtom pseudoAtom = atom instanceof IPseudoAtom ? (IPseudoAtom) atom : container.getBuilder() .newInstance(IPseudoAtom.class); if (atom.equals(pseudoAtom)) { pseudoAtom.setLabel(label); } else { pseudoAtom.setSymbol(label); pseudoAtom.setAtomicNumber(0); pseudoAtom.setPoint2d(atom.getPoint2d()); pseudoAtom.setPoint3d(atom.getPoint3d()); pseudoAtom.setMassNumber(atom.getMassNumber()); pseudoAtom.setFormalCharge(atom.getFormalCharge()); pseudoAtom.setValency(atom.getValency()); pseudoAtom.setLabel(label); // XXX: would be faster to track all replacements and do it all in one AtomContainerManipulator.replaceAtomByAtom(container, atom, pseudoAtom); } }
AtomContainerManipulator.replaceAtomByAtom(query, org, rep);
@Test public void testReplaceAtom() { IAtomContainer container = DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainer.class); IAtom atom1 = DefaultChemObjectBuilder.getInstance().newInstance(IAtom.class, "C"); atom1.setCharge(1.0); IAtom atom2 = DefaultChemObjectBuilder.getInstance().newInstance(IAtom.class, "N"); container.addAtom(atom1); container.addAtom(atom2); container.addBond(new Bond(atom1, atom2, Order.SINGLE)); IAtom atom3 = DefaultChemObjectBuilder.getInstance().newInstance(IAtom.class, "Br"); AtomContainerManipulator.replaceAtomByAtom(container, atom2, atom3); Assert.assertEquals(atom3, container.getAtom(1)); }
@Test public void testReplaceAtom_lonePair() { IAtomContainer container = DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainer.class); IAtom atom1 = DefaultChemObjectBuilder.getInstance().newInstance(IAtom.class, "C"); atom1.setCharge(1.0); IAtom atom2 = DefaultChemObjectBuilder.getInstance().newInstance(IAtom.class, "N"); container.addAtom(atom1); container.addAtom(atom2); container.addBond(new Bond(atom1, atom2, Order.SINGLE)); container.addLonePair(1); IAtom atom3 = DefaultChemObjectBuilder.getInstance().newInstance(IAtom.class, "Br"); AtomContainerManipulator.replaceAtomByAtom(container, atom2, atom3); Assert.assertEquals(atom3, container.getLonePair(0).getAtom()); }
@Test public void testReplaceAtom_singleElectron() { IAtomContainer container = DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainer.class); IAtom atom1 = DefaultChemObjectBuilder.getInstance().newInstance(IAtom.class, "C"); atom1.setCharge(1.0); IAtom atom2 = DefaultChemObjectBuilder.getInstance().newInstance(IAtom.class, "N"); container.addAtom(atom1); container.addAtom(atom2); container.addBond(new Bond(atom1, atom2, Order.SINGLE)); container.addSingleElectron(1); IAtom atom3 = DefaultChemObjectBuilder.getInstance().newInstance(IAtom.class, "Br"); AtomContainerManipulator.replaceAtomByAtom(container, atom2, atom3); Assert.assertEquals(atom3, container.getSingleElectron(0).getAtom()); }