Esempio n. 1
0
 def __buildChemCompSearchIndex(self, procName, ccIdList, descrD, limitPerceptions=False, quietFlag=False):
     """Internal method return a dictionary of extracted chemical component descriptors and formula."""
     rL = []
     fL = []
     try:
         for ccId in ccIdList:
             if ccId not in self.__ccObjD:
                 logger.error("%s missing chemical definition for %s", procName, ccId)
                 fL.append(ccId)
                 continue
             dataContainer = self.__ccObjD[ccId]
             # ----
             oemf = OeMoleculeFactory()
             if quietFlag:
                 oemf.setQuiet()
             tId = oemf.setChemCompDef(dataContainer)
             if tId != ccId:
                 logger.error("%s %s chemical component definition import error", procName, ccId)
                 fL.append(ccId)
                 continue
             # ----
             oemf.clearExternalDescriptors()
             for smi in descrD[ccId] if ccId in descrD else []:
                 oemf.addExternalDescriptor("smiles", smi, "chemaxon-smiles")
             # ----
             relD = oemf.buildRelated(limitPerceptions=limitPerceptions)
             logger.debug("%s %s related molecular forms %d", procName, ccId, len(relD))
             if relD:
                 rL.extend([relD[v] for v in relD])
             else:
                 fL.append(ccId)
     except Exception as e:
         logger.exception("%s failing with %s", procName, str(e))
     return rL, fL
Esempio n. 2
0
    def __buildChemCompSearchIndex(self, ccObjD, descrD, limitPerceptions=False, molLimit=None):
        """Internal method return a dictionary of extracted chemical component descriptors and formula."""
        rD = {}
        try:
            for ii, ccId in enumerate(ccObjD, 1):
                if molLimit and ii > molLimit:
                    break
                # ----
                oemf = OeMoleculeFactory()
                oemf.setQuiet()
                tId = oemf.setChemCompDef(ccObjD[ccId])
                if tId != ccId:
                    logger.error("%s chemical component definition import error", ccId)
                # ----
                oemf.clearExternalDescriptors()
                for smi in descrD[ccId] if ccId in descrD else []:
                    oemf.addExternalDescriptor("smiles", smi, "chemaxon-smiles")
                # ----
                smiD = oemf.buildRelated(limitPerceptions=limitPerceptions)
                logger.debug("%s related molecular forms %d", ccId, len(smiD))
                rD.update(smiD)
        except Exception as e:
            logger.exception("Failing with %s", str(e))

        return rD
    def testBuildRelatedExtra(self):
        """Test build molecules chemical definitions including extra chemaxon descriptors"""

        try:
            caxP = ChemAxonDescriptorProvider(
                ccUrlTarget=self.__ccUrlTarget,
                birdUrlTarget=self.__birdUrlTarget,
                cachePath=self.__cachePath,
                useCache=True,
                ccFileNamePrefix="cc-abbrev")
            ok = caxP.testCache()
            self.assertTrue(ok)
            descrD = caxP.getDescriptorIndex()
            #
            ccMolD = self.__getChemCompDefs()
            oemf = OeMoleculeFactory(quietMode=True)
            relD = {}
            for ccId, ccObj in list(ccMolD.items())[:100]:
                # ----
                tId = oemf.setChemCompDef(ccObj)
                self.assertEqual(tId, ccId)
                #
                oemf.clearExternalDescriptors()
                for smi in descrD[ccId] if ccId in descrD else []:
                    oemf.addExternalDescriptor("smiles", smi,
                                               "chemaxon-smiles")
                #
                tD = oemf.buildRelated(limitPerceptions=False)
                logger.info("%s related molecular forms %d", ccId, len(tD))
                relD.update(tD)
            logger.info("Total molecular forms (%d)", len(relD))

            # ----
        except Exception as e:
            logger.exception("Failing with %s", str(e))
            self.fail()