Exemple #1
0
    def testMCSAlignPairDepict(self):
        """Test case -  Simple pairwise MCSS alignment  -  Each aligned pair output to a separate image file"""
        try:
            oed = OeDepictMCSAlignPage()
            oed.setDisplayOptions(labelAtomName=True,
                                  labelAtomCIPStereo=True,
                                  labelAtomIndex=False,
                                  labelBondIndex=False,
                                  highlightStyleFit="ballAndStickInverse",
                                  bondDisplayWidth=0.5)

            oed.setRefMol(self.__oeMolD[self.__refId], self.__refId)
            fitTupList = self.__getMolDepictList(self.__idList)

            for fitTup in fitTupList:
                oed.setFitMol(fitTup[0], fitTup[1])
                imgPath = os.path.join(
                    self.__workPath,
                    "ref-" + self.__refId + "-trg-" + fitTup[1] + ".svg")
                logger.info("Using image path %r", imgPath)
                aML = oed.alignPair(imagePath=imgPath)
                # self.assertGreater(len(aML), 2)
                if aML:
                    for (rCC, rAt, tCC, tAt) in aML:
                        logger.debug("%5s %-5s %5s %-5s", rCC, rAt, tCC, tAt)
        except Exception as e:
            logger.exception("Failing with %s", str(e))
            self.fail()
Exemple #2
0
    def testMCSAlignListDepict(self):
        """Test case -  List view of MCS alignment on single image -"""
        try:
            pairList = [(tup[0].upper(), self.__oeMolD[tup[0].upper()],
                         tup[1].upper(), self.__oeMolD[tup[1].upper()])
                        for tup in self.__pairIdList]
            oed = OeDepictMCSAlignPage()
            oed.setDisplayOptions(
                imageSizeX=1500,
                imageSizeY=1500,
                labelAtomName=True,
                labelAtomCIPStereo=True,
                labelAtomIndex=False,
                labelBondIndex=False,
                highlightStyleFit="ballAndStickInverse",
                gridRows=3,
                gridCols=3,
                bondDisplayWidth=1.0,
            )
            oed.setPairMolList(pairList)
            imageFile = os.path.join(self.__workPath,
                                     "mcs-align-with-list-single.svg")
            aML = oed.alignOneWithList(imagePath=imageFile)
            self.assertGreater(len(aML), 2)
            if aML:
                for (rCC, rAt, tCC, tAt) in aML:
                    logger.debug("%5s %-5s %5s %-5s", rCC, rAt, tCC, tAt)

        except Exception as e:
            logger.exception("Failing with %s", str(e))
            self.fail()
    def __pairDepictPage(self,
                         imagePath,
                         refId,
                         refTitle,
                         refMol,
                         fitId,
                         fitTitle,
                         fitMol,
                         matchOpts="strict"):
        """Depict pairwise alignment of the input reference and fit molecules.

        Args:
            imagePath (str): path to image (format by path extension)
            refId (str): reference molecule identifier
            refTitle (str): reference molecule title
            refMol (obj): reference OE molecule object
            fitId (str): fit molecule identifier
            fitTitle (str): fit molecule title
            fitMol (obj): fit OE molecule object
            matchOpts (str, optional): alignment criteria (relaxed|relaxed-stereo|strict). Defaults to "strict".

        Returns:
            (list): atom mapping in all aligned figures
                    [(reference component Id, reference atom name, fit chemical component Id, fit atom name)
        """
        aML = []
        try:
            oed = OeDepictMCSAlignPage()
            oed.setSearchType(sType=matchOpts)

            oed.setRefMol(refMol, refId, title=refTitle)
            oed.setFitMol(fitMol, fitId, title=fitTitle)
            oed.setDisplayOptions(
                imageSizeX=2000,
                imageSizeY=1000,
                labelAtomName=True,
                labelAtomCIPStereo=True,
                labelAtomIndex=False,
                labelBondIndex=False,
                highlightStyleFit="ballAndStickInverse",
                bondDisplayWidth=0.5,
                highLightMatchColorRef="green",
                highLightNotMatchColorRef="pink",
            )
            aML = oed.alignPair(imagePath=imagePath)
            if aML:
                for (rCC, rAt, tCC, tAt) in aML:
                    logger.debug("%5s %-5s %5s %-5s", rCC, rAt, tCC, tAt)
        except Exception as e:
            logger.exception("Failing with %s", str(e))
        return aML
 def __displayAlignedPair(self,
                          ccIdRef,
                          oeMolRef,
                          ccIdFit,
                          oeMolFit,
                          title=None):
     oed = OeDepictMCSAlignPage()
     oed.setDisplayOptions(labelAtomName=True,
                           labelAtomCIPStereo=True,
                           labelAtomIndex=False,
                           labelBondIndex=False,
                           highlightStyleFit="ballAndStickInverse",
                           bondDisplayWidth=0.5)
     oed.setRefMol(oeMolRef, ccIdRef)
     oed.setFitMol(oeMolFit, ccIdFit)
     myTitle = title if title else "compare"
     imgPath = os.path.join(
         self.__workPath, myTitle + "-" + ccIdRef + "-" + ccIdFit + ".svg")
     # logger.info("Using image path %r", imgPath)
     aML = oed.alignPair(imagePath=imgPath)
     if aML:
         for (rCC, rAt, tCC, tAt) in aML:
             logger.debug("%5s %-5s %5s %-5s", rCC, rAt, tCC, tAt)
     oed = OeDepictMCSAlignPage()
     oed.setDisplayOptions(labelAtomName=True,
                           labelAtomCIPStereo=True,
                           labelAtomIndex=False,
                           labelBondIndex=False,
                           highlightStyleFit="ballAndStickInverse",
                           bondDisplayWidth=0.5)
    def testRoundTrip(self):
        """Round trip smiles comparisons -"""
        try:
            ccMolD = self.__getChemCompDefs()
            # useCache = True
            # quietFlag = False
            # molBuildTypeL = ["model-xyz", "ideal-xyz", None]
            # molBuildTypeL = [None]
            buildTypeRef = "oe-iso-smiles"
            oemf1 = OeMoleculeFactory()
            oemf2 = OeMoleculeFactory()
            #
            for ccId, ccObj in ccMolD.items():
                # ----
                ccIt = iter(PdbxChemCompIt(ccObj))
                cc = next(ccIt)
                formula = cc.getFormulaWithCharge()
                # ccId = cc.getId()
                ccName = cc.getName()
                ifCharge = cc.getFormalChargeAsInt()
                isAmbiguous = cc.getAmbiguousFlag() in ["Y", "y"]
                isCurrent = cc.getReleaseStatus() in ["REL"]
                logger.debug("%s name %r formula %r charge %d", ccId, ccName,
                             formula, ifCharge)
                # ----
                ccId = oemf1.setChemCompDef(ccObj)
                ok = oemf1.build(molBuildType=buildTypeRef,
                                 limitPerceptions=False)
                if not ok:
                    logger.info(
                        "Build using %r failed for %s (ambiguous flag %r current %r)",
                        buildTypeRef, ccId, isAmbiguous, isCurrent)
                #
                isDiff = False
                #
                if isDiff:
                    genIsoSmi = oemf1.getCanSMILES()
                    oemf2 = OeMoleculeFactory()
                    oemf2.setDescriptor(genIsoSmi, "oe-iso-smiles", ccId)
                    oemf2.build(molBuildType="oe-iso-smiles",
                                limitPerceptions=False)
                    regenIsoSmi = oemf2.getIsoSMILES()
                    if genIsoSmi != regenIsoSmi:
                        logger.info(
                            "%s  regenerated ISOSMILES differ \n -- INP: %s\n -- OUT: %s",
                            ccId, genIsoSmi, regenIsoSmi)

                    oed = OeDepictMCSAlignPage()
                    oed.setDisplayOptions(
                        labelAtomName=True,
                        labelAtomCIPStereo=True,
                        labelAtomIndex=False,
                        labelBondIndex=False,
                        labelBondCIPStereo=True,
                        highlightStyleFit="ballAndStickInverse",
                        highLightNotMatchColorRef="pink",
                        bondDisplayWidth=0.5,
                    )
                    oed.setRefMol(oemf1.getGraphMol(), ccId)
                    oed.setFitMol(oemf2.getGraphMol(), ccId)
                    imgPath = os.path.join(
                        self.__workPath,
                        "compare-assigned-" + ccId + "-calc-" + ccId + ".svg")
                    logger.info("Using image path %r", imgPath)
                    aML = oed.alignPair(imagePath=imgPath)
                    if aML:
                        for (rCC, rAt, tCC, tAt) in aML:
                            logger.info("%5s %-5s %5s %-5s", rCC, rAt, tCC,
                                        tAt)
                else:
                    logger.debug("%s matched all cases", ccId)

        except Exception as e:
            logger.exception("Failing with %s", str(e))
            self.fail()
 def __displayAlignedDescriptorPair(self,
                                    ccId,
                                    descrRef,
                                    buildTypeRef,
                                    descrFit,
                                    buildTypeFit,
                                    title=None,
                                    limitPerceptions=True):
     oeioU = OeIoUtils()
     oeMolRef = oeioU.descriptorToMol(descrRef,
                                      buildTypeRef,
                                      limitPerceptions=limitPerceptions,
                                      messageTag=ccId + ":" + buildTypeRef)
     oeMolFit = oeioU.descriptorToMol(descrFit,
                                      buildTypeFit,
                                      limitPerceptions=limitPerceptions,
                                      messageTag=ccId + ":" + buildTypeFit)
     #
     oed = OeDepictMCSAlignPage()
     oed.setSearchType(sType="graph-relaxed", minAtomMatchFraction=0.50)
     oed.setDisplayOptions(labelAtomName=True,
                           labelAtomCIPStereo=True,
                           labelAtomIndex=False,
                           labelBondIndex=False,
                           highlightStyleFit="ballAndStickInverse",
                           bondDisplayWidth=0.5)
     oed.setRefMol(oeMolRef, ccId)
     oed.setFitMol(oeMolFit, ccId)
     myTitle = title if title else buildTypeRef + "-" + buildTypeFit
     imgPath = os.path.join(self.__workPath, myTitle + "-" + ccId + ".svg")
     logger.info("Using image path %r", imgPath)
     aML = oed.alignPair(imagePath=imgPath)
     if aML:
         logger.info("%s aligned image path %r", ccId, imgPath)
         for (rCC, rAt, tCC, tAt) in aML:
             logger.debug("%5s %-5s %5s %-5s", rCC, rAt, tCC, tAt)
Exemple #7
0
 def __depictAlignedPair(self, oeMolRef, displayIdRef, oeMolFit,
                         displayIdFit, imagePath, **kwargs):
     """Depict pairwise MCSS alignment"""
     try:
         #
         oed = OeDepictMCSAlignPage()
         oed.setSearchType(sType="relaxed")
         #
         oed.setRefMol(oeMolRef, displayIdRef)
         oed.setFitMol(oeMolFit, displayIdFit)
         #
         # imagePath = self.__makeImagePath()
         # ---
         bondDisplayWidth = 10.0
         numAtomsRef = oeMolRef.NumAtoms()
         if numAtomsRef > 100 and numAtomsRef <= 200:
             bondDisplayWidth = 6.0
         elif numAtomsRef > 200:
             bondDisplayWidth = 4.0
         # ---
         oed.setDisplayOptions(
             imageSizeX=kwargs.get("imageSizeX", 2500),
             imageSizeY=kwargs.get("imageSizeX", 2500),
             labelAtomName=kwargs.get("labelAtomName", False),
             labelAtomCIPStereo=kwargs.get("labelAtomCIPStereo", True),
             labelAtomIndex=kwargs.get("labelAtomIndex", False),
             labelBondIndex=kwargs.get("labelBondIndex", False),
             labelBondCIPStereo=kwargs.get("labelBondCIPStereo", True),
             cellBorders=kwargs.get("cellBorders", True),
             bondDisplayWidth=bondDisplayWidth,
             highlightStyleFit=kwargs.get("highlightStyleFit",
                                          "ballAndStickInverse"),
         )
         #
         aML = oed.alignPair(imagePath=imagePath)
         logger.info("Aligned atom count %d", len(aML))
         #
         # self.assertGreater(len(aML), 1)
         # if aML:
         #    for (rCC, rAt, tCC, tAt) in aML:
         #        logger.debug("%5s %-5s %5s %-5s", rCC, rAt, tCC, tAt)
         return True
     except Exception as e:
         logger.exception("Failing with %s", str(e))
     return False
Exemple #8
0
    def testMCSRelaxAlignPairDepict(self):
        """Test case -  Relaxed pairwise MCSS alignment"""
        try:
            oed = OeDepictMCSAlignPage()
            oed.setSearchType(sType="relaxed")
            # oed.setDisplayOptions(
            #    labelAtomName=True, labelAtomCIPStereo=True, labelAtomIndex=False, labelBondIndex=False, highlightStyleFit="ballAndStickInverse", bondDisplayWidth=0.5
            # )

            oed.setRefMol(self.__oeMolD[self.__refId], self.__refId)
            fitTupList = self.__getMolDepictList(self.__idList)
            for fitTup in fitTupList:
                oed.setFitMol(fitTup[0], fitTup[1])
                fName = os.path.join(
                    self.__workPath, "relaxed-ref-" + self.__refId + "-trg-" +
                    fitTup[1] + ".svg")

                oed.setDisplayOptions(
                    imageSizeX=2000,
                    imageSizeY=1000,
                    labelAtomName=True,
                    labelAtomCIPStereo=True,
                    labelAtomIndex=False,
                    labelBondIndex=False,
                    highlightStyleFit="ballAndStickInverse",
                    bondDisplayWidth=1.0,
                )
                aML = oed.alignPair(imagePath=fName)
                logger.debug("refId %r fitId %r aML %r", self.__refId,
                             fitTup[1], len(aML))
                self.assertGreater(len(aML), 1)
                if aML:
                    for (rCC, rAt, tCC, tAt) in aML:
                        logger.debug("%5s %-5s %5s %-5s", rCC, rAt, tCC, tAt)
        except Exception as e:
            logger.exception("Failing with %s", str(e))
            self.fail()