private static void replaceReferencesWithClones(IChemModel chemModel) throws CDKException { // we make references in products/reactants clones, since same compounds // in different reactions need separate layout (different positions etc) if (chemModel.getReactionSet() != null) { for (IReaction reaction : chemModel.getReactionSet().reactions()) { int i = 0; IAtomContainerSet products = reaction.getProducts(); for (IAtomContainer product : products.atomContainers()) { try { products.replaceAtomContainer(i, (IAtomContainer) product.clone()); } catch (CloneNotSupportedException e) { } i++; } i = 0; IAtomContainerSet reactants = reaction.getReactants(); for (IAtomContainer reactant : reactants.atomContainers()) { try { reactants.replaceAtomContainer(i, (IAtomContainer) reactant.clone()); } catch (CloneNotSupportedException e) { } i++; } } } }
@Test public void testReplaceAtomContainer_int_IAtomContainer() { IAtomContainerSet som = (IAtomContainerSet) newChemObject(); IAtomContainer ac1 = som.getBuilder().newInstance(IAtomContainer.class); IAtomContainer ac2 = som.getBuilder().newInstance(IAtomContainer.class); IAtomContainer ac3 = som.getBuilder().newInstance(IAtomContainer.class); som.addAtomContainer(ac1); som.addAtomContainer(ac2); Assert.assertEquals(ac2, som.getAtomContainer(1)); som.replaceAtomContainer(1, ac3); Assert.assertEquals(ac3, som.getAtomContainer(1)); }