public static void removeEmptyContainers(IChemModel chemModel) { Iterator<IAtomContainer> it = ChemModelManipulator .getAllAtomContainers(chemModel).iterator(); while (it.hasNext()) { IAtomContainer ac = it.next(); if (ac.getAtomCount() == 0) { chemModel.getMoleculeSet().removeAtomContainer(ac); } } if (chemModel.getMoleculeSet().getAtomContainerCount() == 0) chemModel.getMoleculeSet().addAtomContainer( chemModel.getBuilder().newInstance(IAtomContainer.class)); }
private static void removeDuplicateMolecules(IChemModel chemModel) { // we remove molecules which are in MoleculeSet as well as in a reaction IReactionSet reactionSet = chemModel.getReactionSet(); IAtomContainerSet moleculeSet = chemModel.getMoleculeSet(); if (reactionSet != null && moleculeSet != null) { List<IAtomContainer> aclist = ReactionSetManipulator .getAllAtomContainers(reactionSet); for (int i = moleculeSet.getAtomContainerCount() - 1; i >= 0; i--) { for (int k = 0; k < aclist.size(); k++) { String label = moleculeSet.getAtomContainer(i).getID(); if (aclist.get(k).getID().equals(label)) { chemModel.getMoleculeSet().removeAtomContainer(i); break; } } } } }
chemModelRelay.getChemModel().getMoleculeSet().removeAtomContainer(droppedContainer);
public static void removeElectronContainer(IAtomContainerSet set, IElectronContainer electrons) { for (IAtomContainer atomContainer : set.atomContainers()) { if (atomContainer.contains(electrons)) { atomContainer.removeElectronContainer(electrons); IAtomContainerSet molecules = ConnectivityChecker.partitionIntoMolecules(atomContainer); if (molecules.getAtomContainerCount() > 1) { set.removeAtomContainer(atomContainer); for (int k = 0; k < molecules.getAtomContainerCount(); k++) { set.addAtomContainer(molecules.getAtomContainer(k)); } } return; } } }
public static void removeAtomAndConnectedElectronContainers(IAtomContainerSet set, IAtom atom) { for (IAtomContainer atomContainer : set.atomContainers()) { if (atomContainer.contains(atom)) { atomContainer.removeAtom(atom); IAtomContainerSet molecules = ConnectivityChecker.partitionIntoMolecules(atomContainer); if (molecules.getAtomContainerCount() > 1) { set.removeAtomContainer(atomContainer); for (int k = 0; k < molecules.getAtomContainerCount(); k++) { set.addAtomContainer(molecules.getAtomContainer(k)); } } return; } } }
public void redo() { chemModel.getMoleculeSet().removeAtomContainer(movedContainer); IReaction reaction = chemModel.getBuilder().newInstance(IReaction.class); reaction.setID(reactionID); IAtomContainer mol=chemModel.getBuilder().newInstance(IAtomContainer.class,movedContainer); mol.setID(movedContainer.getID()); if(reactantOrProduct) reaction.addReactant(mol); else reaction.addProduct(mol); if(chemModel.getReactionSet()==null) chemModel.setReactionSet(chemModel.getBuilder().newInstance(IReactionSet.class)); chemModel.getReactionSet().addReaction(reaction); chemModel.getMoleculeSet().removeAtomContainer(oldContainer); }
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; }
+ order); if (toadd != ac) { atomContainers.removeAtomContainer(toadd); ac.add(toadd);
public void redo() { chemModel.getMoleculeSet().removeAtomContainer(movedContainer); if(chemModel.getReactionSet()==null) chemModel.setReactionSet(chemModel.getBuilder().newInstance(IReactionSet.class)); IReaction reaction = ReactionSetManipulator.getReactionByReactionID(chemModel.getReactionSet(), reactionID); if(reaction==null){ reaction = chemModel.getBuilder().newInstance(IReaction.class); reaction.setID(reactionID); chemModel.getReactionSet().addReaction(reaction); } IAtomContainer mol=chemModel.getBuilder().newInstance(IAtomContainer.class,movedContainer); mol.setID(movedContainer.getID()); if(reactantOrProduct) reaction.addReactant(mol); else reaction.addProduct(mol); chemModel.getMoleculeSet().removeAtomContainer(oldContainer); if(chemModel.getMoleculeSet().getAtomContainerCount()==0) chemModel.getMoleculeSet().addAtomContainer(chemModel.getBuilder().newInstance(IAtomContainer.class)); }
+ order); if (toadd != ac) { atomContainers.removeAtomContainer(toadd); ac.add(toadd);
/** * Adds a new Molecule to the MoleculeSet inside a given ChemModel. * Creates a MoleculeSet if none is contained. * * @param chemModel The ChemModel object. * @return The created Molecule object. */ public static IAtomContainer createNewMolecule(IChemModel chemModel) { // Add a new molecule either the set of molecules IAtomContainer molecule = chemModel.getBuilder().newInstance(IAtomContainer.class); if (chemModel.getMoleculeSet() != null) { IAtomContainerSet moleculeSet = chemModel.getMoleculeSet(); for (int i = 0; i < moleculeSet.getAtomContainerCount(); i++) { if (moleculeSet.getAtomContainer(i).getAtomCount() == 0) { moleculeSet.removeAtomContainer(i); i--; } } moleculeSet.addAtomContainer(molecule); } else { IAtomContainerSet moleculeSet = chemModel.getBuilder().newInstance(IAtomContainerSet.class); moleculeSet.addAtomContainer(molecule); chemModel.setMoleculeSet(moleculeSet); } return molecule; }
public void undo() { if(chemModel.getMoleculeSet()==null) chemModel.setMoleculeSet(chemModel.getBuilder().newInstance(IAtomContainerSet.class)); chemModel.getMoleculeSet().addAtomContainer(oldContainer); IAtomContainerSet reactantsorproducts; if(reactantOrProduct) reactantsorproducts = ReactionSetManipulator.getReactionByReactionID(chemModel.getReactionSet(), reactionID).getReactants(); else reactantsorproducts = ReactionSetManipulator.getReactionByReactionID(chemModel.getReactionSet(), reactionID).getProducts(); IReaction reaction = ReactionSetManipulator.getReactionByReactionID(chemModel.getReactionSet(), reactionID); int count=0; for(IAtomContainer mol : reactantsorproducts.atomContainers()){ if(mol.getID().equals(movedContainer.getID())){ reactantsorproducts.removeAtomContainer(count); break; } count++; } if(reaction.getReactantCount()==0 && reaction.getProductCount()==0) chemModel.getReactionSet().removeReaction(reaction); if(chemModel.getReactionSet().getReactionCount()==0) chemModel.setReactionSet(null); }
@Test public void testRemoveAtomContainer_IAtomContainer() { IAtomContainerSet som = (IAtomContainerSet) newChemObject(); IAtomContainer ac1 = som.getBuilder().newInstance(IAtomContainer.class); IAtomContainer ac2 = som.getBuilder().newInstance(IAtomContainer.class); som.addAtomContainer(ac1); som.addAtomContainer(ac2); som.removeAtomContainer(ac1); Assert.assertEquals(1, som.getAtomContainerCount()); Assert.assertEquals(ac2, som.getAtomContainer(0)); }
public static void makeProductInExistingReaction(ControllerHub controllerhub, String reactionId, IAtomContainer newContainer, IAtomContainer oldcontainer) { IChemModel chemModel = controllerhub.getChemModel(); IReaction reaction = ReactionSetManipulator.getReactionByReactionID(chemModel.getReactionSet(), reactionId); IAtomContainer mol=newContainer.getBuilder().newInstance(IAtomContainer.class,newContainer); mol.setID(newContainer.getID()); reaction.addProduct(mol); chemModel.getMoleculeSet().removeAtomContainer(oldcontainer); if(chemModel.getMoleculeSet().getAtomContainerCount()==0) chemModel.getMoleculeSet().addAtomContainer(chemModel.getBuilder().newInstance(IAtomContainer.class)); if(controllerhub.getUndoRedoFactory()!=null && controllerhub.getUndoRedoHandler()!=null){ IUndoRedoable undoredo = controllerhub.getUndoRedoFactory().getMakeReactantOrProductInExistingReactionEdit(chemModel, newContainer, oldcontainer, reactionId, false, "Make Reactant in "+reactionId); controllerhub.getUndoRedoHandler().postEdit(undoredo); } controllerhub.structureChanged(); }
public static void makeReactantInExistingReaction(ControllerHub controllerhub, String reactionId, IAtomContainer newContainer, IAtomContainer oldcontainer) { IChemModel chemModel = controllerhub.getChemModel(); IReaction reaction = ReactionSetManipulator.getReactionByReactionID(chemModel.getReactionSet(), reactionId); IAtomContainer mol=newContainer.getBuilder().newInstance(IAtomContainer.class,newContainer); mol.setID(newContainer.getID()); reaction.addReactant(mol); chemModel.getMoleculeSet().removeAtomContainer(oldcontainer); if(chemModel.getMoleculeSet().getAtomContainerCount()==0) chemModel.getMoleculeSet().addAtomContainer(chemModel.getBuilder().newInstance(IAtomContainer.class)); if(controllerhub.getUndoRedoFactory()!=null && controllerhub.getUndoRedoHandler()!=null){ IUndoRedoable undoredo = controllerhub.getUndoRedoFactory().getMakeReactantOrProductInExistingReactionEdit(chemModel, newContainer, oldcontainer, reactionId, true, "Make Reactant in "+reactionId); controllerhub.getUndoRedoHandler().postEdit(undoredo); } controllerhub.structureChanged(); }
@Test public void testRemoveAtomContainer_int() { IAtomContainerSet som = (IAtomContainerSet) newChemObject(); IAtomContainer ac1 = som.getBuilder().newInstance(IAtomContainer.class); IAtomContainer ac2 = som.getBuilder().newInstance(IAtomContainer.class); som.addAtomContainer(ac1); som.addAtomContainer(ac2); som.removeAtomContainer(0); Assert.assertEquals(1, som.getAtomContainerCount()); Assert.assertEquals(ac2, som.getAtomContainer(0)); }
@Test public void testBug2679343() { IAtomContainerSet som = (IAtomContainerSet) newChemObject(); IAtomContainer ac1 = som.getBuilder().newInstance(IAtomContainer.class); IAtomContainer ac2 = som.getBuilder().newInstance(IAtomContainer.class); som.addAtomContainer(ac1); som.addAtomContainer(ac2); som.addAtomContainer(ac2); Assert.assertEquals(3, som.getAtomContainerCount()); som.removeAtomContainer(ac2); Assert.assertEquals(1, som.getAtomContainerCount()); }
public static void makeReactantInNewReaction(ControllerHub controllerhub, IAtomContainer newContainer, IAtomContainer oldcontainer) { IChemModel chemModel = controllerhub.getChemModel(); IReaction reaction = newContainer.getBuilder().newInstance(IReaction.class); reaction.setID(newReactionId(controllerhub)); IAtomContainer mol=newContainer.getBuilder().newInstance(IAtomContainer.class,newContainer); mol.setID(newContainer.getID()); reaction.addReactant(mol); IReactionSet reactionSet = chemModel.getReactionSet(); if (reactionSet == null) { reactionSet = chemModel.getBuilder().newInstance(IReactionSet.class); } reactionSet.addReaction(reaction); chemModel.setReactionSet(reactionSet); chemModel.getMoleculeSet().removeAtomContainer(oldcontainer); if(chemModel.getMoleculeSet().getAtomContainerCount()==0) chemModel.getMoleculeSet().addAtomContainer(chemModel.getBuilder().newInstance(IAtomContainer.class)); if(controllerhub.getUndoRedoFactory()!=null && controllerhub.getUndoRedoHandler()!=null){ IUndoRedoable undoredo = controllerhub.getUndoRedoFactory().getMakeReactantOrProductInNewReactionEdit(chemModel, newContainer, oldcontainer, true, "Make Reactant in new Reaction"); controllerhub.getUndoRedoHandler().postEdit(undoredo); } controllerhub.structureChanged(); }
public static void makeProductInNewReaction(ControllerHub controllerhub, IAtomContainer newContainer, IAtomContainer oldcontainer) { IChemModel chemModel = controllerhub.getChemModel(); IReaction reaction = newContainer.getBuilder().newInstance(IReaction.class); reaction.setID(newReactionId(controllerhub)); IAtomContainer mol=newContainer.getBuilder().newInstance(IAtomContainer.class,newContainer); mol.setID(newContainer.getID()); reaction.addProduct(mol); IReactionSet reactionSet = chemModel.getReactionSet(); if (reactionSet == null) { reactionSet = chemModel.getBuilder().newInstance(IReactionSet.class); } reactionSet.addReaction(reaction); chemModel.setReactionSet(reactionSet); chemModel.getMoleculeSet().removeAtomContainer(oldcontainer); if(chemModel.getMoleculeSet().getAtomContainerCount()==0) chemModel.getMoleculeSet().addAtomContainer(chemModel.getBuilder().newInstance(IAtomContainer.class)); if(controllerhub.getUndoRedoFactory()!=null && controllerhub.getUndoRedoHandler()!=null){ IUndoRedoable undoredo = controllerhub.getUndoRedoFactory().getMakeReactantOrProductInNewReactionEdit(chemModel, newContainer, oldcontainer, false, "Make Reactant in new Reaction"); controllerhub.getUndoRedoHandler().postEdit(undoredo); } controllerhub.structureChanged(); }
moleculeToAddTo.add(toRemove); updateAtoms(toRemove, toRemove.atoms()); newMoleculeSet.removeAtomContainer(toRemove);