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); }
/** * Updates an atom with respect to its hydrogen count * *@param container * The AtomContainer to work on *@param atom * The Atom to update */ public void updateAtom(IAtom atom) { IAtomContainer container = ChemModelManipulator .getRelevantAtomContainer(chemModel, atom); if (container != null) { updateAtom(container, atom); } }
@Test public void testGetRelevantAtomContainer_IChemModel_IAtom() { IAtomContainer ac1 = ChemModelManipulator.getRelevantAtomContainer(chemModel, atomInMol1); Assert.assertEquals(molecule1, ac1); IAtomContainer ac2 = ChemModelManipulator.getRelevantAtomContainer(chemModel, atomInMol2); Assert.assertEquals(molecule2, ac2); }
/** * Determines if a user has made a proper selection for R-Group * manipulation. Proper means: make a selection that includes all * atoms/bonds that are bound together in a structure, not leaving any * orphans dangling. * * @param atc * @return */ private boolean isProperSelection(IAtomContainer atc) { boolean properSelection = true; completeSelection: for (IAtom atom : atc.atoms()) { IAtomContainer modelAtc = ChemModelManipulator .getRelevantAtomContainer(jcpPanel.getChemModel(), atom); List<IAtom> connectedAtoms = new ArrayList<IAtom>(); findConnectedAtoms(atom, modelAtc, connectedAtoms); for (IAtom modelAt : connectedAtoms) { if (!atc.contains(modelAt)) { properSelection = false; break completeSelection; } } } return properSelection; }
/** * Verifies if a merge is allowed from the R-Group's point of view. * Merging between the root structure and r-group substitutes is not allowed, * because it does not makes sense (plus the root structure could get lost). * @param hub controller hub that is about to do a merge. */ public boolean isMergeAllowed(IChemModelRelay hub) { //System.out.println("^^^ isMergeAllowed(IChemModelRelay hub)"); if (rGroupQuery!=null) { for (Iterator<IAtom> it = hub.getRenderer().getRenderer2DModel().getMerge().keySet().iterator(); it.hasNext();) { IAtom mergedAtom = it.next(); IAtom mergedPartnerAtom = hub.getRenderer().getRenderer2DModel().getMerge().get(mergedAtom); IAtomContainer container1 = ChemModelManipulator.getRelevantAtomContainer(hub.getChemModel(), mergedAtom); IAtomContainer container2 = ChemModelManipulator.getRelevantAtomContainer(hub.getChemModel(), mergedPartnerAtom); if(container1!=container2) { List<IAtomContainer> substitutes = rGroupQuery.getSubstituents(); if ((container1==rGroupQuery.getRootStructure() && substitutes.contains(container2)) || (container2==rGroupQuery.getRootStructure() && substitutes.contains(container1))) { JOptionPane.showMessageDialog(jcpPanel.getRenderPanel(), GT.get("This operation is not allowed in the R-Group configuration."), GT.get("R-Group alert"), JOptionPane.INFORMATION_MESSAGE); return false; } } } } return true; }
/** * Creates a new molecule based on a user selection, and removes the * selected atoms/bonds from the atom container where they are currently in. */ private IAtomContainer createMolecule(IAtomContainer atc, Map<IAtom, IAtomContainer> existingAtomDistr, Map<IBond, IAtomContainer> existingBondDistr) { for (IAtom atom : atc.atoms()) { IAtomContainer original = ChemModelManipulator .getRelevantAtomContainer(jcpPanel.getChemModel(), atom); existingAtomDistr.put(atom, original); original.removeAtom(atom); } for (IBond bond : atc.bonds()) { IAtomContainer original = ChemModelManipulator .getRelevantAtomContainer(jcpPanel.getChemModel(), bond); existingBondDistr.put(bond, original); original.removeBond(bond); } IAtomContainer molecule = atc.getBuilder().newInstance(IAtomContainer.class); molecule.add(atc); return molecule; }
@Test public void testGetRelevantAtomContainer_IChemModel_IBond() { IAtomContainer ac1 = ChemModelManipulator.getRelevantAtomContainer(chemModel, bondInMol1); Assert.assertEquals(molecule1, ac1); }
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); } }
public void actionPerformed(ActionEvent event) { IChemObject object = getSource(event); logger.debug("Showing object properties for: ", object); ChemObjectEditor editor = new AtomContainerEditor(); IAtomContainer relevantContainer = null; if(object instanceof IAtom) relevantContainer = ChemModelManipulator.getRelevantAtomContainer(jcpPanel.getChemModel(),(IAtom)object); if(object instanceof IBond) relevantContainer = ChemModelManipulator.getRelevantAtomContainer(jcpPanel.getChemModel(),(IBond)object); editor.setChemObject(relevantContainer); ChemObjectPropertyDialog frame = new ChemObjectPropertyDialog(JOptionPane.getFrameForComponent(editor), jcpPanel.get2DHub(), editor); frame.pack(); frame.setVisible(true); } }
public void addSingleElectron(IAtom atom) { IAtomContainer relevantContainer = ChemModelManipulator .getRelevantAtomContainer(chemModel, atom); ISingleElectron singleElectron = atom.getBuilder().newInstance(ISingleElectron.class,atom); relevantContainer.addSingleElectron(singleElectron); updateAtom(atom); if (undoredofactory != null && undoredohandler != null) { IUndoRedoable undoredo = undoredofactory.getSingleElectronEdit( relevantContainer, singleElectron, true, this, atom, "Add Single Electron"); undoredohandler.postEdit(undoredo); } }
/** * @cdk.bug 3530861 */ @Test(expected = IllegalArgumentException.class) public void testGetRelevantAtomContainer_NonExistentAtom() { IChemModel model = new org.openscience.cdk.silent.ChemModel(); ChemModelManipulator.getRelevantAtomContainer(model, new org.openscience.cdk.silent.Atom()); }
public void removeSingleElectron(IAtom atom) { IAtomContainer relevantContainer = ChemModelManipulator .getRelevantAtomContainer(chemModel, atom); if (relevantContainer.getConnectedSingleElectronsCount(atom) > 0) { ISingleElectron removedElectron = relevantContainer .removeSingleElectron(relevantContainer .getConnectedSingleElectronsCount(atom) - 1); updateAtom(atom); if (undoredofactory != null && undoredohandler != null) { IUndoRedoable undoredo = undoredofactory.getSingleElectronEdit( relevantContainer, removedElectron, false, this, atom, "Remove Single Electron"); undoredohandler.postEdit(undoredo); } } }
public IBond addBond(IAtom fromAtom, IAtom toAtom, IBond.Stereo stereo, IBond.Order order) { IBond newBond = chemModel.getBuilder().newInstance(IBond.class,fromAtom, toAtom, order, stereo); IAtomContainer fromContainer = ChemModelManipulator .getRelevantAtomContainer(chemModel, fromAtom); IAtomContainer toContainer = ChemModelManipulator .getRelevantAtomContainer(chemModel, toAtom); // we need to check if this merges two atom containers or not if (fromContainer != toContainer) { fromContainer.add(toContainer); chemModel.getMoleculeSet().removeAtomContainer(toContainer); } fromContainer.addBond(newBond); updateAtom(newBond.getAtom(0)); updateAtom(newBond.getAtom(1)); structureChanged(); return newBond; }
/** * Searches all the atoms attached to the Atoms in the given AtomContainer * and calculates the center point of them. * * @param sharedAtoms * The Atoms the attached partners are searched of * @return The Center Point of all the atoms found */ private Point2d getConnectedAtomsCenter(IAtomContainer sharedAtoms, IChemModel chemModel) { IAtomContainer conAtoms = sharedAtoms.getBuilder().newInstance(IAtomContainer.class); for (IAtom sharedAtom : sharedAtoms.atoms()) { conAtoms.addAtom(sharedAtom); IAtomContainer atomCon = ChemModelManipulator .getRelevantAtomContainer(chemModel, sharedAtom); for (IAtom atom : atomCon.getConnectedAtomsList(sharedAtom)) { conAtoms.addAtom(atom); } } return GeometryTools.get2DCenter(conAtoms); }
public IAtomContainer removeAtomWithoutUndo(IAtom atom) { IAtomContainer ac = atom.getBuilder().newInstance(IAtomContainer.class); if(rGroupHandler!=null && !rGroupHandler.checkRGroupOkayForDelete(atom, this)) return ac; ac.addAtom(atom); Iterator<IBond> connbonds = ChemModelManipulator .getRelevantAtomContainer(chemModel, atom) .getConnectedBondsList(atom).iterator(); while (connbonds.hasNext()) { IBond connBond = connbonds.next(); ac.addBond(connBond); } ChemModelManipulator.removeAtomAndConnectedElectronContainers( chemModel, atom); for (IBond bond : ac.bonds()) { if (bond.getAtom(0) == atom) updateAtom(bond.getAtom(1)); else updateAtom(bond.getAtom(0)); } structureChanged(); adjustRgroup(); return ac; }
public void makeAllImplicitExplicit() { IAtomContainer undoRedoContainer = chemModel.getBuilder() .newInstance(IAtomContainer.class); List<IAtomContainer> containers = ChemModelManipulator .getAllAtomContainers(chemModel); for (int i = 0; i < containers.size(); i++) { for (IAtom atom : containers.get(i).atoms()) { int hcount = atom.getImplicitHydrogenCount(); for (int k = 0; k < hcount; k++) { IAtom newAtom = this.addAtomWithoutUndo("H", atom, false); IAtomContainer atomContainer = ChemModelManipulator .getRelevantAtomContainer(getIChemModel(), newAtom); IBond newBond = atomContainer.getBond(atom, newAtom); undoRedoContainer.addAtom(newAtom); undoRedoContainer.addBond(newBond); } } } if (getUndoRedoFactory() != null && getUndoRedoHandler() != null) { IUndoRedoable undoredo = getUndoRedoFactory() .getAddAtomsAndBondsEdit(chemModel, undoRedoContainer, null, "Make implicit Hs explicit", this); getUndoRedoHandler().postEdit(undoredo); } structureChanged(); }
public IAtom addAtom(String atomType, IAtom atom, boolean makePseudoAtom) { IAtomContainer undoRedoContainer = atom.getBuilder().newInstance(IAtomContainer.class); undoRedoContainer.addAtom(addAtomWithoutUndo(atomType, atom, makePseudoAtom)); IAtomContainer atomContainer = ChemModelManipulator .getRelevantAtomContainer(getIChemModel(), undoRedoContainer .getAtom(0)); IBond newBond = atomContainer.getBond(atom, undoRedoContainer .getAtom(0)); undoRedoContainer.addBond(newBond); if (getUndoRedoFactory() != null && getUndoRedoHandler() != null) { IUndoRedoable undoredo = getUndoRedoFactory() .getAddAtomsAndBondsEdit(chemModel, undoRedoContainer, null, "Add Atom", this); getUndoRedoHandler().postEdit(undoredo); } return undoRedoContainer.getAtom(0); }
public void removeBondAndLoneAtoms(IBond bondToRemove) { IAtomContainer container = ChemModelManipulator .getRelevantAtomContainer(chemModel, bondToRemove.getAtom(0)); IAtomContainer undoRedoContainer = chemModel.getBuilder() .newInstance(IAtomContainer.class); undoRedoContainer.addBond(bondToRemove); removeBondWithoutUndo(bondToRemove); if (container != null) { for (int i = 0; i < 2; i++) { if (container.getConnectedAtomsCount(bondToRemove.getAtom(i)) == 0) { removeAtomWithoutUndo(bondToRemove.getAtom(i)); undoRedoContainer.addAtom(bondToRemove.getAtom(i)); } } } removeEmptyContainers(chemModel); IUndoRedoable undoredo = getUndoRedoFactory() .getRemoveAtomsAndBondsEdit(chemModel, undoRedoContainer, "Delete Bond", this); getUndoRedoHandler().postEdit(undoredo); if(rGroupHandler!=null && !rGroupHandler.checkRGroupOkayForDelete(undoRedoContainer, this)) { undoredo.undo(); return; } }
public void addNewBond(Point2d worldCoordinate, boolean makePseudoAtom) { IAtomContainer undoRedoContainer = getIChemModel().getBuilder() .newInstance(IAtomContainer.class); // add the first atom in the new bond String atomType = getController2DModel().getDrawElement(); IAtom atom = addAtomWithoutUndo(atomType, worldCoordinate, makePseudoAtom); undoRedoContainer.addAtom(atom); // add the second atom to this IAtom newAtom = addAtomWithoutUndo(atomType, atom, makePseudoAtom); undoRedoContainer.addAtom(newAtom); IAtomContainer atomContainer = ChemModelManipulator .getRelevantAtomContainer(getIChemModel(), newAtom); IBond newBond = atomContainer.getBond(atom, newAtom); undoRedoContainer.addBond(newBond); updateAtom(newBond.getAtom(0)); updateAtom(newBond.getAtom(1)); structureChanged(); if (undoredofactory != null && undoredohandler != null) { IUndoRedoable undoredo = undoredofactory.getAddAtomsAndBondsEdit( getIChemModel(), undoRedoContainer, null, "Add Bond", this); undoredohandler.postEdit(undoredo); } }