Пример #1
0
    def test0FilterCatalogEntry(self):
        matcher = FilterCatalog.SmartsMatcher("Aromatic carbon chain")
        self.assertTrue(not matcher.IsValid())

        pat = Chem.MolFromSmarts("c:c:c:c:c")
        matcher.SetPattern(pat)
        matcher.SetMinCount(1)

        entry = FilterCatalog.FilterCatalogEntry("Bar", matcher)
        if FilterCatalog.FilterCatalogCanSerialize():
            pickle = entry.Serialize()
        else:
            pickle = None

        self.assertTrue(entry.GetDescription() == "Bar")
        self.assertTrue(matcher.GetMinCount() == 1)
        self.assertTrue(matcher.GetMaxCount() == 2**32 - 1)
        self.assertTrue(matcher.IsValid())

        entry.SetDescription("Foo")
        self.assertTrue(entry.GetDescription() == "Foo")

        mol = Chem.MolFromSmiles("c1ccccc1")
        self.assertTrue(matcher.HasMatch(mol))

        matcher = FilterCatalog.SmartsMatcher(pat)
        self.assertEqual(str(matcher), "Unnamed SmartsMatcher")
        self.assertTrue(matcher.GetMinCount() == 1)
        self.assertTrue(matcher.HasMatch(mol))
        matches = matcher.GetMatches(mol)

        matcher = FilterCatalog.ExclusionList()
        matcher.SetExclusionPatterns([matcher])
        self.assertTrue(not matcher.HasMatch(mol))
Пример #2
0
 def testAddEntry(self):
     sm = FilterCatalog.SmartsMatcher("Too many carbons", "[#6]", 40 + 1)
     entry = FilterCatalog.FilterCatalogEntry("Bar", sm)
     fc = FilterCatalog.FilterCatalog()
     fc.AddEntry(entry)
     del entry
     del fc
Пример #3
0
    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)
Пример #4
0
    def testPyFilter(self):
        class MyFilterMatcher(FilterCatalog.FilterMatcher):
            def IsValid(self):
                return True

            def HasMatch(self, mol):
                return True

            def GetMatches(self, mol, vect):
                v = FilterCatalog.MatchTypeVect()
                v.append(FilterCatalog.IntPair(1, 1))
                match = FilterCatalog.FilterMatch(self, v)
                vect.append(match)
                return True

        func = MyFilterMatcher("FilterMatcher")
        self.assertEquals(func.GetName(), "FilterMatcher")
        mol = Chem.MolFromSmiles("c1ccccc1")
        self.assertEquals(func.HasMatch(mol), True)

        or_match = FilterMatchOps.Or(func, func)
        self.assertEquals([[tuple(x) for x in filtermatch.atomPairs]
                           for filtermatch in or_match.GetMatches(mol)],
                          [[(1, 1)], [(1, 1)]])

        not_match = FilterMatchOps.Not(func)
        print(not_match)
        self.assertEquals(not_match.HasMatch(mol), False)
        # test memory
        del func

        self.assertEquals(not_match.HasMatch(mol), False)
        self.assertEquals([[tuple(x) for x in filtermatch.atomPairs]
                           for filtermatch in not_match.GetMatches(mol)], [])

        entry = FilterCatalog.FilterCatalogEntry(
            "Bar", MyFilterMatcher("FilterMatcher"))
        fc = FilterCatalog.FilterCatalog()
        fc.AddEntry(entry)

        catalogEntry = fc.GetFirstMatch(mol)
        print(catalogEntry.GetDescription())
def buildFilterCatalog():

    inhousefilter = pd.read_csv(
        'SubstructureFilter_HitTriaging_wPubChemExamples.csv')
    inhouseFiltersCat = FilterCatalog.FilterCatalog()
    for i in range(inhousefilter.shape[0]):
        mincount = 1
        if inhousefilter['MIN_COUNT'][i] != 0:
            mincount = int(inhousefilter['MIN_COUNT'][i])
        pname = inhousefilter['PATTERN_NAME'][i]
        sname = inhousefilter['SET_NAME'][i]
        pname_final = '{0}_min({1})__{2}__{3}__{4}'.format(
            pname, mincount, inhousefilter['SEVERITY_SCORE'][i],
            inhousefilter['COVALENT'][i], inhousefilter['SPECIAL_MOL'][i])
        fil = FilterCatalog.SmartsMatcher(pname_final,
                                          inhousefilter['SMARTS'][i], mincount)
        inhouseFiltersCat.AddEntry(
            FilterCatalog.FilterCatalogEntry(pname_final, fil))
        inhouseFiltersCat.GetEntry(i).SetProp('Scope', sname)
    return inhouseFiltersCat
Пример #6
0
    def testMWFilter(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)
                return not self.minMw <= mw <= self.maxMw

        entry = FilterCatalog.FilterCatalogEntry("MW Violation",
                                                 MWFilter(100, 500))
        fc = FilterCatalog.FilterCatalog()
        fc.AddEntry(entry)
        self.assertTrue(entry.GetDescription() == "MW Violation")

        mol = Chem.MolFromSmiles("c1ccccc1")
        catalogEntry = fc.GetFirstMatch(mol)