def testRemoveEntry(self): params = FilterCatalog.FilterCatalogParams( FilterCatalogParams.FilterCatalogs.ZINC) catalog = FilterCatalog.FilterCatalog(params) entry = catalog.GetEntryWithIdx(10) desc = entry.GetDescription() count = 0 descs = set([ catalog.GetEntryWithIdx(i).GetDescription() for i in range(catalog.GetNumEntries()) ]) for i in range(catalog.GetNumEntries()): if catalog.GetEntryWithIdx(i).GetDescription() == desc: count += 1 print("Count", count) sz = catalog.GetNumEntries() print("*" * 44) self.assertTrue(catalog.RemoveEntry(entry)) del entry self.assertTrue(catalog.GetNumEntries() == sz - 1) descs2 = set([ catalog.GetEntryWithIdx(i).GetDescription() for i in range(catalog.GetNumEntries()) ]) print(descs - descs2) newcount = 0 for i in range(catalog.GetNumEntries()): if catalog.GetEntryWithIdx(i).GetDescription() == desc: newcount += 1 self.assertEquals(count, newcount + 1)
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 testZinc(self): params = FilterCatalog.FilterCatalogParams(FilterCatalogParams.FilterCatalogs.ZINC) catalog = FilterCatalog.FilterCatalog(params) self.assertTrue(catalog.GetNumEntries()) m = Chem.MolFromSmiles("C" * 41) entry = catalog.GetFirstMatch(m) self.assertTrue(entry.GetDescription(), "Non-Hydrogen_atoms") m = Chem.MolFromSmiles("CN" * 20) entry = catalog.GetFirstMatch(m) self.assertEquals(catalog.GetFirstMatch(m), None)
def pains(self): """ Baell and Holloway (2010) New Substructure Filters for Removal of Pan Assay Interference Compounds (PAINS) from Screening Libraries and for Their Exclusion in Bioassays This filter finds promiscuous compounds that are likely to show activity regardless of the target. Returns: Boolean of whether the molecule triggers the PAINS filter. """ params = FilterCatalog.FilterCatalogParams() params.AddCatalog( FilterCatalog.FilterCatalogParams.FilterCatalogs.PAINS) catalog = FilterCatalog.FilterCatalog(params) return catalog.HasMatch(self.mol)
def brenk(self): """ Brenk (2008) Lessons Learnt from Assembling Screening Libraries for Drug Discovery for Neglected Diseases Brenk's Structural Alert filter finds fragments "putatively toxic, chemically reactive, metabolically unstable or to bear properties responsible for poor pharmacokinetics." Returns: Boolean of whether the molecule triggers the Brenk filter. """ params = FilterCatalog.FilterCatalogParams() params.AddCatalog( FilterCatalog.FilterCatalogParams.FilterCatalogs.BRENK) catalog = FilterCatalog.FilterCatalog(params) return catalog.HasMatch(self.mol)
def test2FilterCatalogTest(self): tests = ((FilterCatalogParams.FilterCatalogs.PAINS_A, 16), (FilterCatalogParams.FilterCatalogs.PAINS_B, 55), (FilterCatalogParams.FilterCatalogs.PAINS_C, 409), (FilterCatalogParams.FilterCatalogs.PAINS, 409 + 16 + 55)) for catalog_idx, num in tests: params = FilterCatalog.FilterCatalogParams() print("*" * 44) print("Testing:", catalog_idx, int(catalog_idx)) self.assertTrue(params.AddCatalog(catalog_idx)) catalog1 = FilterCatalog.FilterCatalog(params) if FilterCatalog.FilterCatalogCanSerialize(): pickle = catalog1.Serialize() catalog2 = FilterCatalog.FilterCatalog(pickle) catalogs = [catalog1, catalog2] else: catalogs = [catalog1] catalogs.append(FilterCatalog.FilterCatalog(catalog_idx)) for index, catalog in enumerate(catalogs): self.assertEqual(catalog.GetNumEntries(), num) if catalog_idx in [ FilterCatalogParams.FilterCatalogs.PAINS_A, FilterCatalogParams.FilterCatalogs.PAINS ]: # http://chemistrycompass.com/chemsearch/58909/ mol = Chem.MolFromSmiles( "O=C(Cn1cnc2c1c(=O)n(C)c(=O)n2C)N/N=C/c1c(O)ccc2c1cccc2" ) entry = catalog.GetFirstMatch(mol) for key in entry.GetPropList(): if key == "Reference": self.assertEquals( entry.GetProp(key), "Baell JB, Holloway GA. New Substructure Filters for " "Removal of Pan Assay Interference Compounds (PAINS) " "from Screening Libraries and for Their Exclusion in " "Bioassays. J Med Chem 53 (2010) 2719D40. " "doi:10.1021/jm901137j.") elif key == "Scope": self.assertEquals(entry.GetProp(key), "PAINS filters (family A)") self.assertEqual(entry.GetDescription(), "hzone_phenol_A(479)") result = catalog.GetMatches(mol) self.assertEquals(len(result), 1) for entry in result: for filtermatch in entry.GetFilterMatches(mol): self.assertEquals(str(filtermatch.filterMatch), "hzone_phenol_A(479)") atomPairs = [ tuple(x) for x in filtermatch.atomPairs ] self.assertEquals(atomPairs, [(0, 23), (1, 22), (2, 20), (3, 19), (4, 25), (5, 24), (6, 18), (7, 17), (8, 16), (9, 21)]) elif catalog_idx == FilterCatalogParams.FilterCatalogs.PAINS_B: mol = Chem.MolFromSmiles( "FC(F)(F)Oc1ccc(NN=C(C#N)C#N)cc1") # CHEMBL457504 entry = catalog.GetFirstMatch(mol) self.assertTrue(entry) self.assertEquals(entry.GetDescription(), "cyano_imine_B(17)") elif catalog_idx == FilterCatalogParams.FilterCatalogs.PAINS_C: mol = Chem.MolFromSmiles( "O=C1C2OC2C(=O)c3cc4CCCCc4cc13") # CHEMBL476649 entry = catalog.GetFirstMatch(mol) self.assertTrue(entry) self.assertEquals(entry.GetDescription(), "keto_keto_gamma(5)")
from rdkit import Chem from rdkit.Chem import AllChem from rdkit.Chem import FilterCatalog from rdkit.Chem.FilterCatalog import FilterCatalogParams import json, gzip from ijson import items from django.core.exceptions import ValidationError from threading import Thread import CloseableQueue #from multiprocessing.dummy import Pool from mol_parsing.functions import find_lib_type, read_input, write_json_results, write_results from mol_parsing.rdkit_parse import parse_mol_json, generate_mols_from_json from StringIO import StringIO params = FilterCatalog.FilterCatalogParams() params.AddCatalog(FilterCatalogParams.FilterCatalogs.PAINS_A) params.AddCatalog(FilterCatalogParams.FilterCatalogs.PAINS_B) params.AddCatalog(FilterCatalogParams.FilterCatalogs.PAINS_C) catalog = FilterCatalog.FilterCatalog(params) def request_params(request): """Function to handle the request parameters""" #screen_lib, mol_type = find_lib_type(request) screen_lib, mol_type = read_input(request) if "filter" in request.GET: filter = request.GET["filter"] if not (filter == "INCLUDE_MATCHING" or filter == "INCLUDE_NON_MATCHING" or filter == "INCLUDE_ALL"): raise ValidationError("Invalid filter value " + filter)
def __init__(self, n_cores=-1): params = FilterCatalog.FilterCatalogParams() params.AddCatalog(FilterCatalog.FilterCatalogParams.FilterCatalogs.PAINS) self.filter = FilterCatalog.FilterCatalog(params) self.n_cores = n_cores