Esempio n. 1
0
 def testReadDataFile(self):
     """Test case -  read chemical dictionary and create index
     """
     try:
         blockNameList = []
         myReader = ParseCifSimple(self.__pathPdbxDataFile, False, 0, 255,
                                   "?", self.__logFileName)
         blockNameList = myReader.GetBlockNames(blockNameList)
         #
         for blockName in blockNameList:
             block = myReader.GetBlock(blockName)
             tableNameList = []
             tableNameList = block.GetTableNames(tableNameList)
             for tableName in tableNameList:
                 table = block.GetTable(tableName)
                 columnNameList = table.GetColumnNames()
                 logger.debug("Table %s colunms %r", tableName,
                              columnNameList)
                 numRows = table.GetNumRows()
                 rowList = []
                 for iRow in range(0, numRows):
                     row = table.GetRow(iRow)
                     rowList.append(row)
                 logger.debug("table %s row length %d", tableName,
                              len(rowList))
     except Exception as e:
         logger.exception("Failing with %s", str(e))
         self.fail()
Esempio n. 2
0
    def __init__(self, fileName, parseLogFileName=None):
        self.__fileName = fileName

        if parseLogFileName is None:
            self.__cifFile = ParseCifSimple(self.__fileName, False, 0, 255,
                                            "?", "")
        else:
            self.__cifFile = ParseCifSimple(self.__fileName, False, 0, 255,
                                            "?", parseLogFileName)
Esempio n. 3
0
    def __readData(self, inputFilePath, readDef=None, maxLineLength=1024, logFilePath=None, cleanUp=False):
        """Internal method to read input file and return data as a list of DataContainer objects.
        readDef optionally contains a selection of data categories to be returned.    Diagnostics
        will be written to logFilePath (persisted if cleanuUp=False).

        Args:
            inputFilePath (string):  input file path
            readDef (CifFileReadDef object, optional): wrapped CifFileReadDef() object
            maxLineLength (int, optional): Maximum supported line length on input
            logFilePath (string, optional): Log file path
            cleanUp (bool, optional): Flag to remove temporary files on exit

        Returns:
            Tuple of lists : DataContainer List, Diagnostics (string) List

        """
        #
        startTime = time.time()
        containerList = []
        diagL = []
        try:
            if readDef:
                cifFileObj = ParseCifSelective(inputFilePath, readDef, verbose=self._verbose, intCaseSense=0, maxLineLength=maxLineLength, nullValue="?", parseLogFileName=logFilePath)
            else:
                cifFileObj = ParseCifSimple(inputFilePath, verbose=self._verbose, intCaseSense=0, maxLineLength=maxLineLength, nullValue="?", parseLogFileName=logFilePath)
            #
            # ---  Process/Handle read errors   ----
            #
            diagL = self.__processReadLogFile(inputFilePath)
            logger.debug("Diagnostic count %d values %r", len(diagL), diagL)
            #
            if self._timing:
                stepTime1 = time.time()
                logger.info("Timing parsed %r in %.4f seconds", inputFilePath, stepTime1 - startTime)
            #
            containerList = self.__processContent(cifFileObj)
            #
            self._cleanupFile(cleanUp, logFilePath)
            if self._timing:
                stepTime2 = time.time()
                logger.info("Timing api load in %.4f seconds read time %.4f seconds", stepTime2 - stepTime1, stepTime2 - startTime)
            #
            return containerList, diagL
        except (PdbxError, PdbxSyntaxError) as ex:
            self._cleanupFile(cleanUp, logFilePath)
            if self._raiseExceptions:
                raise_from(ex, None)
        except Exception as e:
            self._cleanupFile(cleanUp, logFilePath)
            msg = "Failing read for %s with %s" % (inputFilePath, str(e))
            self._logError(msg)

        return containerList, diagL
Esempio n. 4
0
class CifFile(object):
    """
    CifFile

    New method prototype --

    CifFile* ParseCifSimple(const std::string& fileName,
                            const bool verbose = false,
                            const unsigned int intCaseSense = 0,
                            const unsigned int maxLineLength = CifFile::STD_CIF_LINE_LENGTH,
                            const std::string& nullValue = CifString::UnknownValue,
                            const std::string& parseLogFileName = std::string());

    """
    def __init__(self, fileName, parseLogFileName=None):
        self.__fileName = fileName

        if parseLogFileName is None:
            self.__cifFile = ParseCifSimple(self.__fileName, False, 0, 255,
                                            "?", "")
        else:
            self.__cifFile = ParseCifSimple(self.__fileName, False, 0, 255,
                                            "?", parseLogFileName)

    def getCifFile(self):
        return self.__cifFile

    @classmethod
    def getFileExt(cls):
        return "cif"

    def write(self, fileName):
        self.__cifFile.Write(fileName)

    @classmethod
    def read(cls, fileName):
        return cls(fileName)