PyFrag
Public Member Functions | Public Attributes | List of all members
qmworks.plams.tools.kftools.KFReader Class Reference
Inheritance diagram for qmworks.plams.tools.kftools.KFReader:
Inheritance graph
[legend]
Collaboration diagram for qmworks.plams.tools.kftools.KFReader:
Collaboration graph
[legend]

Public Member Functions

def __init__ (self, path, blocksize=4096, autodetect=True)
 
def read (self, section, variable)
 
def __iter__ (self)
 

Public Attributes

 path
 
 endian
 
 word
 

Detailed Description

A class for efficient Python-native reader of binary files in KF format.

This class offers read-only access to any fragment of data from a KF file. Unlike other Python KF readers, this one does not use the Fortran binary ``dmpkf`` to process KF files, but instead reads and interprets raw binary data straight from the file, on Python level. That approach results in significant speedup (by a factor of few hundreds for large files extracted variable by variable).

The constructor argument *path* should be a string with a path (relative or absolute) to an existing KF file.

*blocksize* indicates the length of basic KF file block. So far, all KF files produced by any of ADFSuite programs have the same block size of 4096 bytes. Unless you're doing something *very* special, you should not touch this value.

Organization of data inside KF file can depend on a machine on which this file was produced. Two parameters can vary: the length of integer (32 or 64 bit) and endian (little or big). These parameters have to be determined before any reading can take place, otherwise the results will have no sense. If the constructor argument *autodetect* is ``True``, the constructor attempts to automatically detect the format of a given KF file, allowing to read files created on a machine with different endian or integer length. This automatic detection is enabled by default and it is advised to leave it that way. If you wish to disable it, you should set ``endian`` and ``word`` attributes manually before reading anything (see the code for details).

.. note ::

    This class consists of quite technical, low level code. If you don't need to modify or extend |KFReader|, you can safely ignore all private methods, all you need is :meth:`~KFReader.read` and occasionally :meth:`~KFReader.__iter__`

Member Function Documentation

◆ __iter__()

def qmworks.plams.tools.kftools.KFReader.__iter__ (   self)
Iteration yields pairs of section name and variable name.
Here is the call graph for this function:

◆ read()

def qmworks.plams.tools.kftools.KFReader.read (   self,
  section,
  variable 
)
Extract and return data for a *variable* located in a *section*.

For single-value numerical or boolean variables returned value is a single number or bool. For longer variables this method returns a list of values. For string variables a single string is returned.
Here is the call graph for this function:
Here is the caller graph for this function:

The documentation for this class was generated from the following file: