Пример #1
0
    def __getOEMol(self, ccPath):
        """Test case -  build OE molecule using 3D data in the definition source data"""
        self.__lfh.write("\nStarting OeShapeSearchtests __getOEMol\n")
        try:
            oem = OeBuildMol(verbose=self.__verbose, log=self.__lfh)
            myReader = PdbxIoAdapter(self.__verbose, self.__lfh)
            ok = myReader.read(pdbxFilePath=ccPath)
            self.assertTrue(ok)
            #
            # myReader.write(pdbxFilePath="TMP.cif")
            #
            for container in myReader.getContainerList():
                oem.set(container.getName(),
                        dcChemCompAtom=container.getObj("chem_comp_atom"),
                        dcChemCompBond=container.getObj("chem_comp_bond"))
                oem.build3D(coordType="model")
                if self.__debug:
                    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())

            return oem.getMol()

        except:  # noqa: E722 pylint: disable=bare-except
            traceback.print_exc(file=self.__lfh)
            self.fail()
Пример #2
0
    def testCreateStoreOE(self):
        """Test case -  build persistent store of OE molecules using the contents of the persistent store
        of chemical component defintions.
        """
        startTime = time.time()
        self.__lfh.write(
            "\nStarting OePersistFullDictTests testCreateStoreOE at %s\n" %
            (time.strftime("%Y %m %d %H:%M:%S", time.localtime())))
        try:
            myPersist = PdbxPersist(self.__verbose, self.__lfh)
            indexD = myPersist.getIndex(dbFileName=self.__persistStorePathCC)  # noqa: F841 pylint: disable=unused-variable
            myPersist.open(dbFileName=self.__persistStorePathCC)
            containerNameList = myPersist.getStoreContainerIndex()

            oem = OeBuildMol(verbose=self.__verbose, log=self.__lfh)
            molList = []
            for ccId in containerNameList:
                ccAt = myPersist.fetchObject(containerName=ccId,
                                             objectName="chem_comp_atom")
                ccBnd = myPersist.fetchObject(containerName=ccId,
                                              objectName="chem_comp_bond")
                if ccAt is None or ccBnd is None:
                    continue
                #
                oem.set(ccId, dcChemCompAtom=ccAt, dcChemCompBond=ccBnd)
                oem.build3D()
                if self.__debug:
                    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())
                molD = {}
                molD["name"] = ccId
                molD["oeb"] = oem.serialize()
                molList.append(molD)

            myPersist.close()
            #
            oeP = OePersist(self.__verbose, self.__lfh)
            oeP.setMoleculeList(moleculeList=molList)
            oeP.store(dbFileName=self.__storePath)
            mL = oeP.getIndex(dbFileName=self.__storePath)
            #
            if self.__debug:
                self.__lfh.write(
                    "OePersistTests(testCreateStore) molecule list %r\n" % mL)

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

        endTime = time.time()
        self.__lfh.write(
            "\nCompleted OePersistFullDictTests testCreateStoreOE at %s (%d seconds)\n"
            % (time.strftime("%Y %m %d %H:%M:%S",
                             time.localtime()), endTime - startTime))
    def testBuildFromFiles(self):
        """Test case -  build OE molecule from definition file source data."""
        self.__lfh.write("\nStarting OeBuildMolTests testBuildFromFiles\n")
        try:
            oem = OeBuildMol(verbose=self.__verbose, log=self.__lfh)
            for pth in self.__pathList:
                myReader = PdbxIoAdapter(self.__verbose, self.__lfh)
                ok = myReader.read(pdbxFilePath=pth)
                self.assertTrue(ok)
                # myReader.write(pdbxFilePath="TMP.cif")
                for container in myReader.getContainerList():
                    oem.set(container.getName(),
                            dcChemCompAtom=container.getObj("chem_comp_atom"),
                            dcChemCompBond=container.getObj("chem_comp_bond"))
                    oem.build3D(coordType="model")
                    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())

        except:  # noqa: E722 pylint: disable=bare-except
            traceback.print_exc(file=self.__lfh)
            self.fail()
Пример #4
0
    def testDepictSMILES(self):
        """Test case -  create depiction from SMILES descriptor."""
        self.__lfh.write("\nStarting OeDepictTests testDepictSMILES\n")
        try:
            imagePath = os.path.join(self.__testoutput, "benzene.svg")
            oem = OeBuildMol(verbose=self.__verbose, log=self.__lfh)
            ok = oem.importSmiles("c1ccccc1")
            self.assertTrue(ok)

            oed = OeDepict(verbose=self.__verbose, log=self.__lfh)
            oed.setMolTitleList([("benzene", oem, "Title for benzene")])
            oed.setDisplayOptions(labelAtomName=False,
                                  labelAtomCIPStereo=True,
                                  labelAtomIndex=False,
                                  labelBondIndex=False,
                                  bondDisplayWidth=1.0)
            oed.setGridOptions(rows=1, cols=1)
            oed.prepare()
            oed.write(imagePath)
        except:  # noqa: E722 pylint: disable=bare-except
            traceback.print_exc(file=self.__lfh)
            self.fail()
Пример #5
0
 def testDepictOneSDF(self):
     """Test case -  get, read, build OE molecule from SDF file, and depict the molecule."""
     self.__lfh.write("\nStarting OeDepictTests testDepictOneSDF\n")
     try:
         oem = OeBuildMol(verbose=self.__verbose, log=self.__lfh)
         if oem.importFile(self.__sdfFilePath, type="3D"):
             self.__lfh.write("Title              = %s\n" % oem.getTitle())
         #
         imagePath = os.path.join(self.__testoutput, "ATP.svg")
         oed = OeDepict(verbose=self.__verbose, log=self.__lfh)
         oed.setMolTitleList([("ATP", oem, "Title for ATP")])
         oed.setDisplayOptions(labelAtomName=True,
                               labelAtomCIPStereo=True,
                               labelAtomIndex=False,
                               labelBondIndex=False,
                               bondDisplayWidth=0.5)
         oed.setGridOptions(rows=1, cols=1)
         oed.prepare()
         oed.write(imagePath)
     except:  # noqa: E722 pylint: disable=bare-except
         traceback.print_exc(file=self.__lfh)
         self.fail()
Пример #6
0
    def testFetchOne(self):
        """Test case -  fetch all of the molecules in the persistent store one by one.  Each fetch reopens
        the store.
        """
        startTime = time.time()
        self.__lfh.write(
            "\nStarting OePersistFullDictTests testFetchOne at %s\n" %
            (time.strftime("%Y %m %d %H:%M:%S", time.localtime())))
        try:
            myPersist = OePersist(self.__verbose, self.__lfh)
            moleculeNameList = myPersist.getIndex(dbFileName=self.__storePath)
            #
            oem = OeBuildMol(verbose=self.__verbose, log=self.__lfh)
            for ccId in moleculeNameList:
                molD = myPersist.fetchOneMolecule(dbFileName=self.__storePath,
                                                  moleculeName=ccId)
                # name = molD['name']
                ok = oem.deserialize(molD["oeb"])
                if not ok:
                    self.__lfh.write("Deserialized status %s = %s\n" %
                                     (ccId, ok))
                    continue

                if self.__debug:
                    self.__lfh.write("Deserialized SMILES (canonical) = %s\n" %
                                     oem.getCanSMILES())
                    self.__lfh.write("Deserialized SMILES (isomeric)  = %s\n" %
                                     oem.getIsoSMILES())

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

        endTime = time.time()
        self.__lfh.write(
            "\nCompleted OePersistFullDictTests testFetchOne at %s (%d seconds)\n"
            % (time.strftime("%Y %m %d %H:%M:%S",
                             time.localtime()), endTime - startTime))
 def testBuildMolFromSDF(self):
     """Test case -  read a test SDF file and build the corresponding OEGraphMol"""
     self.__lfh.write("\nStarting OeBuildMolTests testBuildolFromSDF\n")
     try:
         oem = OeBuildMol(verbose=self.__verbose, log=self.__lfh)
         if oem.importFile(self.__sdfFilePath, type="3D"):
             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())
         else:
             self.__lfh.write("SDF read failed for %s\n" %
                              self.__sdfFilePath)
     except:  # noqa: E722 pylint: disable=bare-except
         traceback.print_exc(file=self.__lfh)
         self.fail()
    def testSerialize3D(self):
        """Test case -  build OE molecule using 3D data in the definition source data file
        then serialize and deserialize this molecule.

        """
        self.__lfh.write("\nStarting OeBuildMolTests testSerialize3D\n")
        try:
            oem = OeBuildMol(verbose=self.__verbose, log=self.__lfh)
            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.build3D(coordType="model")
                    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()
Пример #9
0
    def __getMiscFile(self, ccPath, suppressHydrogens=False, importType="2D"):
        """Fetch a miscellaneous chemical file (ccPath) and build OE molecules
        for comparison and depiction.

        """
        try:
            oem = OeBuildMol(verbose=self.__verbose, log=self.__lfh)
            if oem.importFile(ccPath, type=importType):
                if self.__verbose:
                    self.__lfh.write("+OEAlignDepilsct.__getMiscFile()\n")
                    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())
            else:
                self.__lfh.write(
                    "+OEAlignDepict.__getMiscFile() Read failed for %s\n" %
                    ccPath)
                return None, None, None
            #
            # oem.build2D()
            ccId = oem.getTitle()
            if suppressHydrogens:
                tMol = oem.getGraphMolSuppressH()
            else:
                tMol = oem.getMol()

            molXyzL = []
            if importType == "3D":
                for ii, atm in enumerate(tMol.GetAtoms()):
                    xyzL = OEFloatArray(3)
                    tMol.GetCoords(atm, xyzL)
                    molXyzL.append(
                        (ii, atm.GetIdx(), atm.GetAtomicNum(), atm.GetName(),
                         atm.GetType(), "%.3f" % xyzL[0], "%.3f" % xyzL[1],
                         "%.3f" % xyzL[2]))
            fD = {}
            fD = {
                "Formula": oem.getFormula(),
                "SMILES": oem.getCanSMILES(),
                "SMILES_STEREO": oem.getIsoSMILES(),
                "InChI": oem.getInChI(),
                "InChIKey": oem.getInChIKey(),
                "xyz": molXyzL,
            }

            for ii, atm in enumerate(tMol.GetAtoms()):
                xyzL = OEFloatArray(3)
                tMol.GetCoords(atm, xyzL)
                if self.__verbose:
                    self.__lfh.write(
                        "OeAlignDepict.__getMiscFile - atom  %d %s %s %s %s %r\n"
                        % (ii, atm.GetIdx(), atm.GetAtomicNum(), atm.GetName(),
                           atm.GetType(), xyzL))

            return (ccId, tMol, fD)
        except:  # noqa: E722 pylint: disable=bare-except
            traceback.print_exc(file=self.__lfh)
            # self.fail()

        return None, None, None
Пример #10
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)
Пример #11
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
Пример #12
0
    def testCreateStoreOE(self):
        """Test case -  build persistent store of serialized OE molecules using the contents of the chemical
        dictionary persistent store containing all of chemical component defintions.

        ***NOTE - This will display diagnostics from OE toolkit for molecules with
           problematic features.  These issues will not impact the shape search.

        """
        startTime = time.time()
        self.__lfh.write(
            "\nStarting OeShapeSearchtests testCreateCoreOE at %s\n" %
            time.strftime("%Y %m %d %H:%M:%S", time.localtime()))
        try:
            # Get handle for
            myPersist = PdbxPersist(self.__verbose, self.__lfh)
            indexD = myPersist.getIndex(dbFileName=self.__persistStorePathCC)  # noqa: F841 pylint: disable=unused-variable
            myPersist.open(dbFileName=self.__persistStorePathCC)
            containerNameList = myPersist.getStoreContainerIndex()
            oem = OeBuildMol(verbose=self.__verbose, log=self.__lfh)
            molList = []
            for ccId in containerNameList:
                ccAt = myPersist.fetchObject(containerName=ccId,
                                             objectName="chem_comp_atom")
                ccBnd = myPersist.fetchObject(containerName=ccId,
                                              objectName="chem_comp_bond")
                if ccAt is None or ccBnd is None:
                    continue
                #
                oem.set(ccId, dcChemCompAtom=ccAt, dcChemCompBond=ccBnd)
                ok = oem.build3D()
                if ok:
                    if self.__debug:
                        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())
                    molD = {}
                    molD["name"] = ccId
                    molD["oeb"] = oem.serialize()
                    molList.append(molD)
                else:
                    self.__lfh.write(
                        "+WARN - failed to build OE molecule for %s\n" % ccId)

            myPersist.close()
            #
            oeP = OePersist(self.__verbose, self.__lfh)
            oeP.setMoleculeList(moleculeList=molList)
            oeP.store(dbFileName=self.__storePath)
            mL = oeP.getIndex(dbFileName=self.__storePath)
            #
            if self.__debug:
                self.__lfh.write(
                    "OePersistTests(testCreateStore) molecule list %r\n" % mL)

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

        endTime = time.time()
        self.__lfh.write(
            "\nCompleted OeShapeSearchtests testCreateOEStore at %s (%d seconds)\n"
            % (time.strftime("%Y %m %d %H:%M:%S",
                             time.localtime()), endTime - startTime))