def testFingerPrintSearch(self): oemp = OeMoleculeProvider(**self.__myKwargs) # This will reload the oe binary cache. oeMol = oemp.getMol("004") self.assertGreaterEqual(len(list(oeMol.GetAtoms())), 12) # ok = oemp.testCache() ccmP = ChemCompIndexProvider(**self.__myKwargs) ccIdxD = ccmP.getIndex() ok = ccmP.testCache(minCount=self.__minCount) self.assertTrue(ok) minScore = 0.50 maxResults = 50 numMols = 50 oesU = OeSearchUtils(oemp, fpTypeList=self.__fpTypeList) # ---- startTime = time.time() for ccId, _ in list(ccIdxD.items())[:numMols]: for fpType in self.__fpTypeList: oeMol = oemp.getMol(ccId) retStatus, mL = oesU.searchFingerPrints( oeMol, fpType=fpType, minFpScore=minScore, maxFpResults=maxResults) self.assertTrue(retStatus) self.assertTrue(self.__resultContains(ccId, mL)) # self.assertGreaterEqual(len(mL), 1) logger.info("%s fingerprints search on %d in (%.4f seconds)", len(self.__fpTypeList), numMols, time.time() - startTime)
def __fingerPrintSearch(self, numMols, **kwargs): maxFpResults = kwargs.get("maxFpResults", 50) limitPerceptions = kwargs.get("limitPerceptions", False) fpTypeCuttoffList = kwargs.get("fpTypeCuttoffList", [("TREE", 0.6)]) buildTypeList = kwargs.get("buildTypeList", ["oe-iso-smiles"]) # oesmP, ccIdxD = self.__getSearchDataProviders(**kwargs) oesU = OeSearchUtils(oesmP, fpTypeList=[tup[0] for tup in fpTypeCuttoffList]) oeioU = OeIoUtils() # This will reload the oe binary cache. oeMol = oesmP.getMol("004") self.assertGreaterEqual(len(list(oeMol.GetAtoms())), 12) missedFpD = {} missedBuildD = {} numMols = min(len(ccIdxD), numMols) if numMols else len(ccIdxD) logger.info("Begin finger print search on %d molecules", numMols) # ---- startTime = time.time() 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 selfHit = False for fpType, minFpScore in fpTypeCuttoffList: retStatus, mL = oesU.searchFingerPrints( oeMol, fpType=fpType, minFpScore=minFpScore, maxFpResults=maxFpResults) self.assertTrue(retStatus) # matchedSelf = self.__resultContains(ccId, mL) selfHit = selfHit or matchedSelf if not matchedSelf: missedFpD.setdefault(ccId, []).append( (buildType, fpType, len(mL))) # if not selfHit: missedBuildD.setdefault(ccId, []).append(buildType) # ------ for ccId, bTL in missedBuildD.items(): logger.info("%s missed all fptypes: buildtype list %r", ccId, bTL) if ccId in missedFpD: logger.info("%s unmatched by fpTypes %r", ccId, missedFpD[ccId]) # ---- logger.info("%s fingerprints search on %d in (%.4f seconds)", len(fpTypeCuttoffList), numMols, time.time() - startTime) # ---- return True