Exemple #1
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())
Exemple #2
0
    def test1FilterMatchOps(self):
        mol = Chem.MolFromSmiles("c1ccccc1")

        pat = Chem.MolFromSmarts("c:c:c:c:c")
        matcher = FilterCatalog.SmartsMatcher("Five aromatic carbons", pat)
        self.assertTrue(matcher.GetMinCount() == 1)
        self.assertTrue(matcher.HasMatch(mol))
        matches = matcher.GetMatches(mol)

        matcher2 = FilterCatalog.ExclusionList()
        matcher2.SetExclusionPatterns([matcher])
        self.assertTrue(not matcher2.HasMatch(mol))

        and_match = FilterMatchOps.And(matcher, matcher2)
        self.assertTrue(not and_match.HasMatch(mol))
        not_match = FilterMatchOps.Not(and_match)
        self.assertTrue(not_match.HasMatch(mol))
        or_match = FilterMatchOps.Or(matcher, matcher2)
        self.assertTrue(or_match.HasMatch(mol))

        print(and_match)
        print(or_match)
        print(not_match)