def testCartesianProduct(self): log("testCartesianProduct") rxn = rdChemReactions.ChemicalReaction() rgroups = [[Chem.MolFromSmiles("C")] * 10, [Chem.MolFromSmiles("N")] * 5, [Chem.MolFromSmiles("O")] * 6] cartProd = rdChemReactions.CartesianProductStrategy() cartProd.Initialize(rxn, rgroups) self.assertEquals(cartProd.GetNumPermutations(), 10 * 5 * 6) groups = [] count = 0 print(cartProd.__bool__()) while cartProd: groups.append(tuple(cartProd.next())) # count += 1 # assert count <= cartProd.GetNumPermutations() self.assertEquals(len(groups), 10 * 5 * 6) # see if we are equal to the Python implementation g = list( itertools.product(list(range(10)), list(range(5)), list(range(6)))) self.assertEquals(set(g), set(groups)) copy.copy(cartProd)
def testTimings(self): log("testTimings") rxn = rdChemReactions.ChemicalReaction() rgroups = [[Chem.MolFromSmiles("C")] * 17000, [Chem.MolFromSmiles("N")] * 50000, [Chem.MolFromSmiles("O")] * 4000] cartProd = rdChemReactions.CartesianProductStrategy() randProd = rdChemReactions.RandomSampleStrategy() randAllBBs = rdChemReactions.RandomSampleAllBBsStrategy() for r in [cartProd, randProd, randAllBBs]: r.Initialize(rxn, rgroups) num = 10000000 t1 = time.time() r.Skip(num) t2 = time.time() print("%s Skipped %s in %s seconds" % (r, num, t2 - t1))