Example #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))
Example #2
0
    def test3ExclusionFilter(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)

        exclusionFilter = FilterCatalog.ExclusionList()
        exclusionFilter.AddPattern(matcher)
        self.assertFalse(exclusionFilter.HasMatch(mol))

        matches2 = exclusionFilter.GetMatches(mol)

        self.assertTrue(matches)
        self.assertFalse(matches2)
Example #3
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)