Esempio n. 1
0
    def __getCCDefFile(self, ccPath, suppressHydrogens=False):
        """Fetch the molecule definition (ccPath) and build OE molecules
        for comparison and depiction.

        """
        #
        oem = OeBuildMol(verbose=self.__verbose, log=self.__lfh)
        ccId = oem.setChemCompPath(ccPath)
        oem.build2D()

        if self.__verbose:
            self.__lfh.write("+OEAlignDepilsct.__getCCDefFile() for %s\n" %
                             ccId)
            self.__lfh.write("  Title              = %s\n" % oem.getTitle())
            self.__lfh.write("  SMILES             = %s\n" %
                             oem.getCanSMILES())
            self.__lfh.write("  SMILES (stereo)    = %s\n" %
                             oem.getIsoSMILES())
            self.__lfh.write("  Formula (Hill)     = %s\n" % oem.getFormula())
            self.__lfh.write("  InChI key          = %s\n" % oem.getInChIKey())
            self.__lfh.write("  InChI              = %s\n" % oem.getInChI())

        fD = {}
        fD = {
            "Formula": oem.getFormula(),
            "SMILES": oem.getCanSMILES(),
            "SMILES_STEREO": oem.getIsoSMILES(),
            "InChI": oem.getInChI(),
            "InChIKey": oem.getInChIKey()
        }

        if suppressHydrogens:
            return (ccId, oem.getGraphMolSuppressH(), fD)
        else:
            return (ccId, oem.getMol(), fD)
Esempio n. 2
0
 def getFromPathList(self,
                     pathList,
                     use3D=True,
                     coordType="model",
                     setTitle=True):
     """ Return a list of OE mols constructed from the input pathList of chemical definitions.
     """
     oemList = []
     try:
         for pth in pathList:
             myReader = PdbxIoAdapter(self.__verbose, self.__lfh)
             ok = myReader.read(pdbxFilePath=pth)  # noqa: F841 pylint: disable=unused-variable
             for container in myReader.getContainerList():
                 oem = OeBuildMol(verbose=self.__verbose, log=self.__lfh)
                 oem.setDebug(self.__debug)
                 oem.set(container.getName(),
                         dcChemCompAtom=container.getObj("chem_comp_atom"),
                         dcChemCompBond=container.getObj("chem_comp_bond"))
                 if use3D:
                     oem.build3D(coordType=coordType, setTitle=setTitle)
                 else:
                     oem.build2D(setTitle=setTitle)
                 #
                 oemList.append(oem)
                 #
                 if self.__debug:
                     self.__lfh.write(
                         "+OeChemCompIoUtils.getOeMols() Title              = %s\n"
                         % oem.getTitle())
                     self.__lfh.write(
                         "+OeChemCompIoUtils.getOeMols() SMILES (canonical) = %s\n"
                         % oem.getCanSMILES())
                     self.__lfh.write(
                         "+OeChemCompIoUtils.getOeMols() SMILES (isomeric)  = %s\n"
                         % oem.getIsoSMILES())
     except Exception as e:
         if self.__verbose:
             self.__lfh.write("+OeChemCompIoUtils.getOeMols() Failed %s\n" %
                              str(e))
             traceback.print_exc(file=self.__lfh)
     return oemList
    def testSerialize2D(self):
        """Test case -  build OE molecule using 2D data in the definition source data file
        then serialize and deserialize this molecule.
        """
        self.__lfh.write("\nStarting OeBuildMolTests testSerialize2D\n")
        try:
            oem = OeBuildMol(verbose=self.__verbose, log=self.__lfh)
            oem.setDebug(True)
            for pth in self.__pathList:
                myReader = PdbxIoAdapter(self.__verbose, self.__lfh)
                ok = myReader.read(pdbxFilePath=pth)
                myReader.write(
                    pdbxFilePath=os.path.join(self.__testoutput, "TMP.cif"))
                for container in myReader.getContainerList():
                    oem.set(container.getName(),
                            dcChemCompAtom=container.getObj("chem_comp_atom"),
                            dcChemCompBond=container.getObj("chem_comp_bond"))
                    oem.build2D()
                    self.__lfh.write("Title              = %s\n" %
                                     oem.getTitle())
                    self.__lfh.write("SMILES (canonical) = %s\n" %
                                     oem.getCanSMILES())
                    self.__lfh.write("SMILES (isomeric)  = %s\n" %
                                     oem.getIsoSMILES())
                    oeS = oem.serialize()
                    #
                    self.__lfh.write("Serialized string length = %d\n" %
                                     len(oeS))
                    #
                    oemD = OeBuildMol(verbose=self.__verbose, log=self.__lfh)
                    ok = oemD.deserialize(oeS)
                    self.__lfh.write("Deserialized status = %s\n" % ok)
                    self.__lfh.write("Deserialized SMILES (canonical) = %s\n" %
                                     oemD.getCanSMILES())
                    self.__lfh.write("Deserialized SMILES (isomeric)  = %s\n" %
                                     oemD.getIsoSMILES())

        except:  # noqa: E722 pylint: disable=bare-except
            traceback.print_exc(file=self.__lfh)
            self.fail()