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()
예제 #2
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()
예제 #3
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))
예제 #4
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 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()
예제 #6
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))