Exemple #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))
Exemple #2
0
  def testFunctionalGroupHierarchy(self):
    fc = FilterCatalog.GetFunctionalGroupHierarchy()

    matches = [(Chem.MolFromSmiles("CCl"), ['Halogen.Aliphatic', 'Halogen.NotFluorine.Aliphatic']),
               (Chem.MolFromSmiles("c1ccccc1Cl"),
                ['Halogen.Aromatic', 'Halogen.NotFluorine.Aromatic']),
               (Chem.MolFromSmiles("c1ccccc1F"), ['Halogen.Aromatic']), (
                 Chem.MolFromSmiles("CBr"), ['Halogen.Aliphatic', 'Halogen.NotFluorine.Aliphatic',
                                             'Halogen.Bromine.Aliphatic'])]

    catalogs = [fc]
    if FilterCatalog.FilterCatalogCanSerialize():
      pickle = fc.Serialize()
      fc2 = FilterCatalog.FilterCatalog(pickle)
      catalogs.append(fc2)

    for fc in catalogs:
      # test GetMatches API
      for mol, res in matches:
        entries = list(fc.GetMatches(mol))
        for entry in entries:
          hits = [match.filterMatch.GetName() for match in entry.GetFilterMatches(mol)]
          self.assertEquals(res, hits)

      # test GetFilterMatches API
      for mol, res in matches:
        self.assertEquals(res, [match.filterMatch.GetName() for match in fc.GetFilterMatches(mol)])
Exemple #3
0
    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)")