def __exhaustiveSubStructureSearch(self, numMols, **kwargs):
     """Exhaustive substructure search."""
     try:
         limitPerceptions = kwargs.get("limitPerceptions", False)
         buildTypeList = kwargs.get("buildTypeList", ["oe-iso-smiles"])
         oesmP, ccIdxD = self.__getSearchDataProviders(**kwargs)
         oesU = OeSearchUtils(oesmP, fpTypeList=[])
         oeioU = OeIoUtils()
         #
         for ccId, ccD in list(ccIdxD.items())[:numMols]:
             matchCount = 0
             mtS = set()
             for buildType in buildTypeList:
                 if buildType in ccD:
                     oeMol = oeioU.descriptorToMol(
                         ccD[buildType],
                         buildType,
                         limitPerceptions=limitPerceptions,
                         messageTag=ccId + ":" + buildType)
                     if not oeMol:
                         logger.error(
                             "%s %s build query molecule build fails (skipping)",
                             ccId, buildType)
                         continue
                     # ----
                     startTime = time.time()
                     retStatus, mL = oesU.searchSubStructure(
                         oeMol, matchOpts="graph-strict")
                     if not retStatus:
                         logger.info("%s match fails for build type %s",
                                     ccId, buildType)
                     elif not self.__resultContains(ccId, mL):
                         logger.info(
                             "%s failed match length %d build type %s in (%.4f seconds)",
                             ccId, len(mL), buildType,
                             time.time() - startTime)
                     elif self.__resultContains(ccId, mL):
                         mtS.update([m.ccId for m in mL])
                         matchCount += 1
                     self.assertTrue(retStatus)
                     self.assertTrue(self.__resultContains(ccId, mL))
             if matchCount:
                 logger.info("%s MATCHES %d: %r", ccId, matchCount, mtS)
             else:
                 logger.info("%s NO MATCHES", ccId)
             # ----
         return True
     except Exception as e:
         logger.exception("Failing with %s", str(e))
         self.fail()
     return False
Пример #2
0
 def testSubStructureSearch(self):
     oemp = OeMoleculeProvider(**self.__myKwargs)
     ok = oemp.testCache()
     ccmP = ChemCompIndexProvider(**self.__myKwargs)
     ccIdxD = ccmP.getIndex()
     ok = ccmP.testCache(minCount=self.__minCount)
     self.assertTrue(ok)
     oesU = OeSearchUtils(oemp, fpTypeList=self.__fpTypeList)
     numMols = 10
     for ccId, _ in list(ccIdxD.items())[:numMols]:
         # ----
         startTime = time.time()
         oeMol = oemp.getMol(ccId)
         retStatus, mL = oesU.searchSubStructure(oeMol, matchOpts="relaxed")
         logger.info("%s match length %d in (%.4f seconds)", ccId, len(mL),
                     time.time() - startTime)
         self.assertTrue(retStatus)
         self.assertTrue(self.__resultContains(ccId, mL))
 def __exhaustiveSubStructureSearch(self, numMols, **kwargs):
     """Exhaustive substructure search."""
     try:
         limitPerceptions = kwargs.get("limitPerceptions", False)
         buildTypeList = kwargs.get("buildTypeList", ["oe-iso-smiles"])
         oesmP, ccIdxD = self.__getSearchDataProviders(**kwargs)
         oesU = OeSearchUtils(oesmP, fpTypeList=[])
         oeioU = OeIoUtils()
         #
         for ccId, ccD in list(ccIdxD.items())[:numMols]:
             for buildType in buildTypeList:
                 if buildType in ccD:
                     oeMol = oeioU.descriptorToMol(
                         ccD[buildType],
                         buildType,
                         limitPerceptions=limitPerceptions,
                         messageTag=ccId + ":" + buildType)
                     if not oeMol:
                         continue
                     # ----
                     startTime = time.time()
                     retStatus, mL = oesU.searchSubStructure(
                         oeMol, matchOpts="graph-strict")
                     if not self.__resultContains(ccId, mL):
                         logger.info(
                             "%s match length %d build type %s in (%.4f seconds)",
                             ccId, len(mL), buildType,
                             time.time() - startTime)
                     self.assertTrue(retStatus)
                     self.assertTrue(self.__resultContains(ccId, mL))
             # ----
         return True
     except Exception as e:
         logger.exception("Failing with %s", str(e))
         self.fail()
     return False