PartialFilledStructureMerger { public IAtomContainer generate(IAtomContainerSet atomContainers) throws CDKException { int iteration = 0; boolean structureFound = false; do { iteration++; boolean bondFormed; do { bondFormed = false; for (IAtomContainer ac : atomContainers.atomContainers()) { for (IAtom atom : AtomContainerManipulator.getAtomArray(ac)) { if (!satCheck.isSaturated(atom, ac)) { IAtom partner = getAnotherUnsaturatedNode(atom, ac, atomContainers); if (partner != null) { IAtomContainer toadd = AtomContainerSetManipulator.getRelevantAtomContainer( atomContainers, partner); double cmax1 = satCheck.getCurrentMaxBondOrder(atom, ac); double cmax2 = satCheck.getCurrentMaxBondOrder(partner, toadd); double max = Math.min(cmax1, cmax2); double order = Math.min(Math.max(1.0, max), 3.0); logger.debug("cmax1, cmax2, max, order: " + cmax1 + ", " + cmax2 + ", " + max + ", " + order); if (toadd != ac) { atomContainers.removeAtomContainer(toadd); ac.add(toadd); } ac.addBond(ac.getBuilder().newInstance(IBond.class, atom, partner, BondManipulator.createBondOrder(order))); bondFormed = true; } } } } } while (bondFormed); if (atomContainers.getAtomContainerCount() == 1 && satCheck.allSaturated(atomContainers.getAtomContainer(0))) { structureFound = true; } } while (!structureFound && iteration < 5); if (atomContainers.getAtomContainerCount() == 1 && satCheck.allSaturated(atomContainers.getAtomContainer(0))) { structureFound = true; } if (!structureFound) throw new CDKException("Could not combine the fragments to combine a valid, satured structure"); return atomContainers.getAtomContainer(0); } PartialFilledStructureMerger(); IAtomContainer generate(IAtomContainerSet atomContainers);  }
@Test public void testGenerate_IAtomContainerSet() throws Exception { SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance()); IAtomContainerSet acs = DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainerSet.class); acs.addAtomContainer(sp.parseSmiles("[CH2]CCC[CH2]")); acs.addAtomContainer(sp.parseSmiles("[C]1=C(C1)C[CH2]")); PartialFilledStructureMerger pfsm = new PartialFilledStructureMerger(); IAtomContainer result = pfsm.generate(acs); Assert.assertTrue(ConnectivityChecker.isConnected(result)); Assert.assertTrue(new SaturationChecker().allSaturated(result)); }
@Test public void testPartialFilledStructureMerger2() throws Exception { SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance()); IAtomContainerSet acs = DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainerSet.class); acs.addAtomContainer(sp.parseSmiles("[C]=[C]CC[CH2]")); acs.addAtomContainer(sp.parseSmiles("[C]([CH2])=C1CC1")); PartialFilledStructureMerger pfsm = new PartialFilledStructureMerger(); IAtomContainer result = pfsm.generate(acs); Assert.assertTrue(ConnectivityChecker.isConnected(result)); Assert.assertTrue(new SaturationChecker().allSaturated(result)); }
@Test public void testPartialFilledStructureMerger3() throws Exception { SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance()); IAtomContainerSet acs = DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainerSet.class); acs.addAtomContainer(sp.parseSmiles("[CH2]CCC[CH2]")); acs.addAtomContainer(sp.parseSmiles("[CH2]C[CH2]")); acs.addAtomContainer(sp.parseSmiles("[CH2][CH2]")); PartialFilledStructureMerger pfsm = new PartialFilledStructureMerger(); IAtomContainer result = pfsm.generate(acs); Assert.assertTrue(ConnectivityChecker.isConnected(result)); Assert.assertTrue(new SaturationChecker().allSaturated(result)); }
@Test public void testPartialFilledStructureMerger4() throws Exception { SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance()); IAtomContainerSet acs = DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainerSet.class); acs.addAtomContainer(sp.parseSmiles("[C]CCC[CH2]")); acs.addAtomContainer(sp.parseSmiles("[C]CC[CH2]")); acs.addAtomContainer(sp.parseSmiles("[CH2]")); PartialFilledStructureMerger pfsm = new PartialFilledStructureMerger(); IAtomContainer result = pfsm.generate(acs); Assert.assertTrue(ConnectivityChecker.isConnected(result)); Assert.assertTrue(new SaturationChecker().allSaturated(result)); }
@Test public void testPartialFilledStructureMerger5() throws Exception { SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance()); IAtomContainerSet acs = DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainerSet.class); acs.addAtomContainer(sp.parseSmiles("[C]1CCC1")); acs.addAtomContainer(sp.parseSmiles("[C]([CH2])CC[CH2]")); acs.addAtomContainer(sp.parseSmiles("[CH2]")); PartialFilledStructureMerger pfsm = new PartialFilledStructureMerger(); IAtomContainer result = pfsm.generate(acs); Assert.assertTrue(ConnectivityChecker.isConnected(result)); Assert.assertTrue(new SaturationChecker().allSaturated(result)); }