StructureResonanceGenerator { public IAtomContainerSet getContainers(IAtomContainer molecule) { IAtomContainerSet setOfCont = molecule.getBuilder().newInstance(IAtomContainerSet.class); IAtomContainerSet setOfMol = getStructures(molecule); if (setOfMol.getAtomContainerCount() == 0) return setOfCont; List<IBond> bondList = new ArrayList<IBond>(); for (int i = 1; i < setOfMol.getAtomContainerCount(); i++) { IAtomContainer mol = setOfMol.getAtomContainer(i); for (int j = 0; j < mol.getBondCount(); j++) { IBond bond = molecule.getBond(j); if (!mol.getBond(j).getOrder().equals(bond.getOrder())) { if (!bondList.contains(bond)) bondList.add(bond); } } } if (bondList.size() == 0) return null; int[] flagBelonging = new int[bondList.size()]; for (int i = 0; i < flagBelonging.length; i++) flagBelonging[i] = 0; int[] position = new int[bondList.size()]; int maxGroup = 1; List<IBond> newBondList = new ArrayList<IBond>(); newBondList.add(bondList.get(0)); int pos = 0; for (int i = 0; i < newBondList.size(); i++) { if (i == 0) flagBelonging[i] = maxGroup; else { if (flagBelonging[position[i]] == 0) { maxGroup++; flagBelonging[position[i]] = maxGroup; } } IBond bondA = newBondList.get(i); for (int ato = 0; ato < 2; ato++) { IAtom atomA1 = bondA.getAtom(ato); List<IBond> bondA1s = molecule.getConnectedBondsList(atomA1); for (int j = 0; j < bondA1s.size(); j++) { IBond bondB = bondA1s.get(j); if (!newBondList.contains(bondB)) for (int k = 0; k < bondList.size(); k++) if (bondList.get(k).equals(bondB)) if (flagBelonging[k] == 0) { flagBelonging[k] = maxGroup; pos++; newBondList.add(bondB); position[pos] = k; } } } if (newBondList.size() - 1 == i) for (int k = 0; k < bondList.size(); k++) if (!newBondList.contains(bondList.get(k))) { newBondList.add(bondList.get(k)); position[i + 1] = k; break; } } for (int i = 0; i < maxGroup; i++) { IAtomContainer container = molecule.getBuilder().newInstance(IAtomContainer.class); for (int j = 0; j < bondList.size(); j++) { if (flagBelonging[j] != i + 1) continue; IBond bond = bondList.get(j); IAtom atomA1 = bond.getBegin(); IAtom atomA2 = bond.getEnd(); if (!container.contains(atomA1)) container.addAtom(atomA1); if (!container.contains(atomA2)) container.addAtom(atomA2); container.addBond(bond); } setOfCont.addAtomContainer(container); } return setOfCont; } StructureResonanceGenerator();  StructureResonanceGenerator(boolean lookingSymmetry); void setReactions(List<IReactionProcess> newReactionsList); List<IReactionProcess> getReactions(); void setMaximalStructures(int maxStruct); int getMaximalStructures(); void setDefaultReactions(); IAtomContainerSet getStructures(IAtomContainer molecule); IAtomContainerSet getContainers(IAtomContainer molecule); IAtomContainer getContainer(IAtomContainer molecule, IAtom atom); IAtomContainer getContainer(IAtomContainer molecule, IBond bond);  }
@Test @Category(SlowTest.class) public void testGetContainers_IAtomContainer() throws Exception { IAtomContainer molecule = builder.newInstance(IAtomContainer.class); molecule.addAtom(builder.newInstance(IAtom.class, "O")); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(0, 1, IBond.Order.SINGLE); molecule.addBond(1, 2, IBond.Order.DOUBLE); molecule.getAtom(0).setFormalCharge(-1); addExplicitHydrogens(molecule); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(molecule); lpcheck.saturate(molecule); Assert.assertEquals(6, molecule.getAtomCount()); StructureResonanceGenerator gRI = new StructureResonanceGenerator(); IAtomContainerSet containers = gRI.getContainers(molecule); Assert.assertEquals(1, containers.getAtomContainerCount()); Assert.assertEquals(3, containers.getAtomContainer(0).getAtomCount()); Assert.assertEquals(2, containers.getAtomContainer(0).getBondCount()); }
@Test public void testGetContainers2Groups() throws Exception { IAtomContainer molecule = builder.newInstance(IAtomContainer.class); molecule.addAtom(new Atom("C")); molecule.addAtom(new Atom("C")); molecule.addBond(0, 1, IBond.Order.SINGLE); molecule.getBond(0).setID("bond_0"); molecule.addAtom(new Atom("C")); molecule.addBond(1, 2, IBond.Order.DOUBLE); molecule.getBond(1).setID("bond_1"); molecule.addAtom(new Atom("C")); molecule.getAtom(3).setFormalCharge(+1); molecule.addBond(2, 3, IBond.Order.SINGLE); molecule.getBond(2).setID("bond_2"); molecule.addAtom(new Atom("C")); molecule.addBond(3, 4, IBond.Order.SINGLE); molecule.getBond(3).setID("bond_3"); molecule.addAtom(new Atom("C")); molecule.addBond(4, 5, IBond.Order.SINGLE); molecule.getBond(4).setID("bond_4"); molecule.addAtom(new Atom("C")); molecule.addBond(5, 6, IBond.Order.DOUBLE); molecule.getBond(5).setID("bond_5"); molecule.addAtom(new Atom("C")); molecule.addBond(6, 7, IBond.Order.SINGLE); molecule.getBond(6).setID("bond_6"); molecule.getAtom(7).setFormalCharge(+1); addExplicitHydrogens(molecule); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(molecule); lpcheck.saturate(molecule); StructureResonanceGenerator sRG = new StructureResonanceGenerator(); IAtomContainerSet setOfContainers = sRG.getContainers(molecule); Assert.assertEquals(2, setOfContainers.getAtomContainerCount()); for (int i = 0; i < 2; i++) { Assert.assertEquals(3, setOfContainers.getAtomContainer(i).getAtomCount()); Assert.assertEquals(2, setOfContainers.getAtomContainer(i).getBondCount()); } }
@Test @Category(SlowTest.class) public void testGetContainersFluoromethylbenzene() throws Exception { IAtomContainer molecule = builder.newInstance(IAtomContainer.class); molecule.addAtom(builder.newInstance(IAtom.class, "F")); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(0, 1, IBond.Order.SINGLE); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(1, 2, IBond.Order.DOUBLE); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(2, 3, IBond.Order.SINGLE); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(3, 4, IBond.Order.DOUBLE); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(4, 5, IBond.Order.SINGLE); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(5, 6, IBond.Order.DOUBLE); molecule.addBond(6, 1, IBond.Order.SINGLE); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(6, 7, IBond.Order.SINGLE); addExplicitHydrogens(molecule); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(molecule); lpcheck.saturate(molecule); StructureResonanceGenerator gRI = new StructureResonanceGenerator(); IAtomContainerSet setOfContainers = gRI.getContainers(molecule); Assert.assertEquals(1, setOfContainers.getAtomContainerCount()); IAtomContainer container = setOfContainers.getAtomContainer(0); Assert.assertEquals(15, molecule.getAtomCount()); Assert.assertEquals(7, container.getAtomCount()); Assert.assertEquals(15, molecule.getBondCount()); Assert.assertEquals(7, container.getBondCount()); }
@Test @Category(SlowTest.class) public void testGetContainersFluorobenzene() throws Exception { IAtomContainer molecule = builder.newInstance(IAtomContainer.class); molecule.addAtom(builder.newInstance(IAtom.class, "F")); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(0, 1, IBond.Order.SINGLE); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(1, 2, IBond.Order.DOUBLE); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(2, 3, IBond.Order.SINGLE); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(3, 4, IBond.Order.DOUBLE); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(4, 5, IBond.Order.SINGLE); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(5, 6, IBond.Order.DOUBLE); molecule.addBond(6, 1, IBond.Order.SINGLE); addExplicitHydrogens(molecule); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(molecule); lpcheck.saturate(molecule); StructureResonanceGenerator gRI = new StructureResonanceGenerator(); IAtomContainerSet setOfContainers = gRI.getContainers(molecule); Assert.assertEquals(1, setOfContainers.getAtomContainerCount()); IAtomContainer container = setOfContainers.getAtomContainer(0); Assert.assertEquals(12, molecule.getAtomCount()); Assert.assertEquals(7, container.getAtomCount()); Assert.assertEquals(12, molecule.getBondCount()); Assert.assertEquals(7, container.getBondCount()); }
@Test @Category(SlowTest.class) public void test1Propene2chloro() throws Exception { IAtomContainer molecule = builder.newInstance(IAtomContainer.class); molecule.addAtom(builder.newInstance(IAtom.class, "Cl")); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(0, 1, IBond.Order.SINGLE); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(1, 2, IBond.Order.DOUBLE); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(1, 3, IBond.Order.SINGLE); addExplicitHydrogens(molecule); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(molecule); lpcheck.saturate(molecule); StructureResonanceGenerator gRI = new StructureResonanceGenerator(); IAtomContainerSet setOfContainers = gRI.getContainers(molecule); Assert.assertEquals(1, setOfContainers.getAtomContainerCount()); Assert.assertEquals(3, setOfContainers.getAtomContainer(0).getAtomCount()); }
@Test @Category(SlowTest.class) public void testBenzene1bromo4methoxy() throws Exception { IAtomContainer molecule = builder.newInstance(IAtomContainer.class); molecule.addAtom(builder.newInstance(IAtom.class, "F")); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(0, 1, IBond.Order.SINGLE); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(1, 2, IBond.Order.DOUBLE); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(2, 3, IBond.Order.SINGLE); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(3, 4, IBond.Order.DOUBLE); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(4, 5, IBond.Order.SINGLE); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(5, 6, IBond.Order.DOUBLE); molecule.addBond(6, 1, IBond.Order.SINGLE); molecule.addAtom(builder.newInstance(IAtom.class, "O")); molecule.addBond(6, 7, IBond.Order.SINGLE); addExplicitHydrogens(molecule); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(molecule); lpcheck.saturate(molecule); StructureResonanceGenerator gRI = new StructureResonanceGenerator(); IAtomContainerSet setOfContainers = gRI.getContainers(molecule); Assert.assertEquals(1, setOfContainers.getAtomContainerCount()); Assert.assertEquals(8, setOfContainers.getAtomContainer(0).getAtomCount()); }
@Test public void testBenzene1bromo4methoxy_with() throws Exception { IAtomContainer molecule = builder.newInstance(IAtomContainer.class); molecule.addAtom(builder.newInstance(IAtom.class, "Br")); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(0, 1, IBond.Order.SINGLE); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(1, 2, IBond.Order.SINGLE); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(2, 3, IBond.Order.DOUBLE); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(3, 4, IBond.Order.SINGLE); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(4, 5, IBond.Order.DOUBLE); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(5, 6, IBond.Order.SINGLE); molecule.addBond(6, 1, IBond.Order.DOUBLE); molecule.addAtom(builder.newInstance(IAtom.class, "O")); molecule.addBond(6, 7, IBond.Order.SINGLE); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(7, 8, IBond.Order.SINGLE); addExplicitHydrogens(molecule); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(molecule); lpcheck.saturate(molecule); StructureResonanceGenerator gRI = new StructureResonanceGenerator(); IAtomContainerSet setOfContainers = gRI.getContainers(molecule); Assert.assertEquals(1, setOfContainers.getAtomContainerCount()); Assert.assertEquals(8, setOfContainers.getAtomContainer(0).getAtomCount()); }
@Test public void testBenzylamine() throws Exception { IAtomContainer molecule = builder.newInstance(IAtomContainer.class); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(0, 1, IBond.Order.SINGLE); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(1, 2, IBond.Order.DOUBLE); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(2, 3, IBond.Order.SINGLE); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(3, 4, IBond.Order.DOUBLE); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(4, 5, IBond.Order.SINGLE); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(5, 6, IBond.Order.DOUBLE); molecule.addBond(6, 1, IBond.Order.SINGLE); molecule.addAtom(builder.newInstance(IAtom.class, "N")); molecule.addBond(0, 7, IBond.Order.SINGLE); addExplicitHydrogens(molecule); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(molecule); lpcheck.saturate(molecule); StructureResonanceGenerator gRI = new StructureResonanceGenerator(); IAtomContainerSet setOfContainers = gRI.getContainers(molecule); Assert.assertEquals(1, setOfContainers.getAtomContainerCount()); Assert.assertEquals(6, setOfContainers.getAtomContainer(0).getAtomCount()); }
@Test public void testBenzylamine_Aromatic() throws Exception { IAtomContainer molecule = builder.newInstance(IAtomContainer.class); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(0, 1, IBond.Order.SINGLE); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(1, 2, IBond.Order.DOUBLE); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(2, 3, IBond.Order.SINGLE); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(3, 4, IBond.Order.DOUBLE); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(4, 5, IBond.Order.SINGLE); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(5, 6, IBond.Order.DOUBLE); molecule.addBond(6, 1, IBond.Order.SINGLE); molecule.addAtom(builder.newInstance(IAtom.class, "N")); molecule.addBond(0, 7, IBond.Order.SINGLE); addExplicitHydrogens(molecule); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(molecule); lpcheck.saturate(molecule); Assert.assertTrue(Aromaticity.cdkLegacy().apply(molecule)); StructureResonanceGenerator gRI = new StructureResonanceGenerator(); IAtomContainerSet setOfContainers = gRI.getContainers(molecule); Assert.assertNotNull(setOfContainers); Assert.assertEquals(1, setOfContainers.getAtomContainerCount()); Assert.assertEquals(6, setOfContainers.getAtomContainer(0).getAtomCount()); }
@Test public void testBenzylamine_Aromatic_lookingSymmetry() throws Exception { IAtomContainer molecule = builder.newInstance(IAtomContainer.class); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(0, 1, IBond.Order.SINGLE); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(1, 2, IBond.Order.DOUBLE); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(2, 3, IBond.Order.SINGLE); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(3, 4, IBond.Order.DOUBLE); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(4, 5, IBond.Order.SINGLE); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(5, 6, IBond.Order.DOUBLE); molecule.addBond(6, 1, IBond.Order.SINGLE); molecule.addAtom(builder.newInstance(IAtom.class, "N")); molecule.addBond(0, 7, IBond.Order.SINGLE); addExplicitHydrogens(molecule); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(molecule); lpcheck.saturate(molecule); Assert.assertTrue(Aromaticity.cdkLegacy().apply(molecule)); StructureResonanceGenerator gRI = new StructureResonanceGenerator(true); IAtomContainerSet setOfContainers = gRI.getContainers(molecule); Assert.assertNull(setOfContainers); }