def testThreadedRunner(self): path = os.path.join(os.environ['RDBASE'], 'Code', 'GraphMol', 'test_data', 'pains.smi') with open(path) as f: smiles = [f.strip() for f in f.readlines()][1:] self.assertEquals(len(smiles), 3) params = FilterCatalog.FilterCatalogParams() params.AddCatalog(FilterCatalogParams.FilterCatalogs.PAINS_A) params.AddCatalog(FilterCatalogParams.FilterCatalogs.PAINS_B) params.AddCatalog(FilterCatalogParams.FilterCatalogs.PAINS_C) fc = FilterCatalog.FilterCatalog(params) results = FilterCatalog.RunFilterCatalog(fc, smiles) self.assertEquals(len(results), 3) descriptions = [ "hzone_phenol_A(479)", "cyano_imine_B(17)", "keto_keto_gamma(5)" ] for i, res in enumerate(results): self.assertTrue(len(res) > 0) self.assertEquals(res[0].GetDescription(), descriptions[i]) # Test with some bad input smiles = ['mydoghasfleas'] results = FilterCatalog.RunFilterCatalog(fc, smiles, numThreads=3) self.assertEquals(len(results[0]), 1) self.assertEquals(results[0][0].GetDescription(), "no valid RDKit molecule")
def testThreadedPythonFilter(self): class MWFilter(FilterCatalog.FilterMatcher): def __init__(self, minMw, maxMw): FilterCatalog.FilterMatcher.__init__(self, "MW violation") self.minMw = minMw self.maxMw = maxMw def IsValid(self): return True def HasMatch(self, mol): mw = rdMolDescriptors.CalcExactMolWt(mol) res = not self.minMw <= mw <= self.maxMw Chem.MolFromSmiles("---") Chem.LogErrorMsg("dasfsadf") return res path = os.path.join(os.environ['RDBASE'], 'Code', 'GraphMol', 'test_data', 'pains.smi') with open(path) as f: smiles = [f.strip() for f in f.readlines()][1:] print("1") self.assertEqual(len(smiles), 3) print("2") entry = FilterCatalog.FilterCatalogEntry("MW Violation", MWFilter(100, 500)) fc = FilterCatalog.FilterCatalog() fc.AddEntry(entry) self.assertTrue(entry.GetDescription() == "MW Violation") print("running") results = FilterCatalog.RunFilterCatalog(fc, smiles * 10, numThreads=3)