dfttools.parsers
¶
dfttools.parsers.elk
¶
Parsing ELK files.
-
class
dfttools.parsers.elk.
Bands
(file)[source]¶ Class for parsing band structure from BAND.OUT file.
Args:
data (string): contents of Elk BAND.OUT file
-
class
dfttools.parsers.elk.
Input
(file)[source]¶ Class for parsing elk.in input file.
Args:
data (string): contents of elk.in file
-
class
dfttools.parsers.elk.
Output
(file)[source]¶ Class for parsing INFO.OUT of elk output.
Args:
data (string): contents of INFO.OUT file
-
class
dfttools.parsers.elk.
UnitCellsParser
(file)[source]¶ Class for parsing elk GEOMETRY_OPT.OUT.
Args:
data (string): contents of GEOMETRY_OPT.OUT file
-
dfttools.parsers.elk.
unitcells
¶ alias of
UnitCellsParser
dfttools.parsers.generic
¶
Contains helper routines to parse text.
-
class
dfttools.parsers.generic.
AbstractJSONParser
(data)[source]¶ A root class for JSON parsers.
Args:
data (str): text representation of JSON to parse.
-
class
dfttools.parsers.generic.
AbstractParser
(file)[source]¶ A root class for text parsers.
Args:
data (str): text to parse or a file to read.
-
class
dfttools.parsers.generic.
StringParser
(string)[source]¶ Simple parser for a string with position memory.
This class can be used to parse words, numbers, floats and arrays from a given string. Based on re, it provides the basic functionality for the rest of parsing libraries.
Args:
string (str): input string to be parsed.Note
The input string can be further accessed by
self.string
field. The contents of the string is not copied.-
closest
(exprs)[source]¶ Returns the closest match of a set of expressions.
Args:
exprs (list): a set of expressions being matched.Returns:
Index of the closest expression. The distance is measured to the beginnings of matches. Returns None if none of expressions matched.Example:
>>> sp = StringParser("This is a large string") >>> sp.closest(("a","string","this")) 2
-
distance
(expression, n=1, default=None)[source]¶ Calculates distance to nth occurrence of expression in characters.
Args:
expression (str,re.RegexObject): expression to match. If expression is str then the case is ignored.Kwargs:
n (int): consequetive number of expression to calculate distance to;
default: return value if StopIteration occurs. Ignored if None.
Returns:
Numbers of characters between caret position and nth occurrence of expression or default if too few occurrences found.Raises:
StopIteration: No occurrences left in the string.
-
floatAfter
(after, n=None)[source]¶ Reads floats from string after the next regular expression. Returns the caret to initial position. Particularly useful for getting value for parameter name.
Args:
after (re.RegexObject) - pattern to skip;Kwargs:
n (array,int,str,re.RegexObject): specifies either shape of the numpy array returned or the regular expression to stop matching before;Returns:
If n is specified returns a numpy array of a given shape filled with floats from string. Otherwise returns a single float.Raises:
StopIteration: Not enough floats left in the string.Example:
>>> sp = StringParser("apples = 3.4; bananas = 7") >>> sp.floatAfter("bananas") 7.0 >>> sp.floatAfter("apples") 3.4
-
goto
(expression, n=1)[source]¶ Goes to the beginning of nth occurrence of expression in the string.
Args:
expression (str,re.RegexObject): expression to match. If expression is str then the case is ignored.Kwargs:
n (int): number of occurrences to match.Raises:
StopIteration: No occurrences left in the string.
-
intAfter
(after, n=None)[source]¶ Reads integers from string after the next regular expression. Returns the caret to initial position. Particularly useful for getting value for parameter name.
Args:
after (re.RegexObject) - pattern to skip;Kwargs:
n (array,int,str,re.RegexObject): specifies either shape of the numpy array returned or the regular expression to stop matching before;Returns:
If n is specified returns a numpy array of a given shape filled with integers from string. Otherwise returns a single int.Raises:
StopIteration: Not enough integers left in the string.Example:
>>> sp = StringParser("cows = 3, rabbits = 5") >>> sp.intAfter("rabbits") 5 >>> sp.intAfter("cows") 3
-
matchAfter
(after, match, n=None)[source]¶ Matches pattern after another pattern and returns caret to initial position. Particularly useful for getting value for parameter name. Supports matching arrays via keyword parameter n.
Args:
after (re.RegexObject): pattern to skip;
match (re.RegexObject): pattern to match;
Kwargs:
n (array,int,str,re.RegexObject): specifies either shape of the numpy array returned or the regular expression to stop matching before;Returns:
If n is specified returns a numpy array of a given shape filled with matches from string. Otherwise returns a single match.Raises:
StopIteration: Not enough matches left in the string.The function is equal to
>>> sp = StringParser("Some string") >>> sp.save() >>> sp.skip(after) >>> result = sp.nextMatch(match, n = n) >>> sp.pop()
-
nextFloat
(n=None)[source]¶ Reads floats from string.
Kwargs:
n (array,int,str,re.RegexObject): specifies either shape of the numpy array returned or the regular expression to stop matching before;Returns:
If n is specified returns a numpy array of a given shape filled with floats from string. Otherwise returns a single float. The caret is put behind the last float read.Raises:
StopIteration: Not enough floats left in the string.Example:
>>> sp = StringParser("1.9 2.8 3.7 56.2E-2 abc") >>> sp.nextFloat(2) array([ 1.9, 2.8]) >>> sp.nextFloat("abc") array([ 3.7 , 0.562])
-
nextInt
(n=None)[source]¶ Reads integers from string.
Kwargs:
n (array,int,str,re.RegexObject): specifies either shape of the numpy array returned or the regular expression to stop matching before;Returns:
If n is specified returns a numpy array of a given shape filled with integers from string. Otherwise returns a single int. The caret is put behind the last integer read.Raises:
StopIteration: Not enough integers left in the string.Example:
>>> sp = StringParser("1 2 3 4 5 6 7 8 9 abc 10") >>> sp.nextInt((2,3)) array([[1, 2, 3], [4, 5, 6]]) >>> sp.nextInt("abc") array([ 7., 8., 9.])
-
nextLine
(n=None)[source]¶ Reads lines from string.
Kwargs:
n (array,int,str,re.RegexObject): specifies either shape of the numpy array returned or the regular expression to stop matching before;Returns:
If n is specified returns a numpy array of a given shape filled with lines from string. Otherwise returns a single line. The caret is put behind the last line read.Raises:
StopIteration: Not enough lines left in the string.
-
nextMatch
(match, n=None)[source]¶ Basic function for matching data.
Args:
match (re.RegexObject): object to match;Kwargs:
n (array,int,str,re.RegexObject): specifies either shape of the numpy array returned or the regular expression to stop matching before;Returns:
If n is specified returns a numpy array of a given shape filled with matches from string. Otherwise returns a single match. The caret is put behind the last match.Raises:
StopIteration: Not enough matches left in the string.
-
pop
()[source]¶ Returns to the previously saved position of the parser.
Raises:
IndexError: No saved positions left.
-
present
(expression)[source]¶ Test the string for the presence of expression.
Args:
expression (str,re.RegexObject): expression to match. If expression is str then the case is ignored.Returns:
True if expression is matched to the right of current position of the caret.
-
save
()[source]¶ Saves the current position of the parser.
Example:
sp = StringParser("A very important integer 123 describes something.") sp.skip("very") # The caret is set to the right of "very" sp.save() # The caret position is saved sp.skip("describes") # The caret is set to the right of "describes" # Now the call to StringParser.nextInt() will yield StopIteration. # To return the caret to the previously saved position # StringParser.pop() is used. sp.pop() # Now it is possible to read the integer sp.nextInt()
-
skip
(expression, n=1)[source]¶ Skips n occurrences of expression in the string.
Args:
expression (str,re.RegexObject): expression to match. If expression is str then the case is ignored.Kwargs:
n (int): number of occurrences to skip.Raises:
StopIteration: No occurrences left in the string.
-
-
dfttools.parsers.generic.
parse
¶ alias of
StringParser
dfttools.parsers.openmx
¶
Parsing OpenMX files.
-
class
dfttools.parsers.openmx.
Bands
(file)[source]¶ Class for parsing band structure from openmx.Band file.
Args:
data (string): contents of OpenMX Band file-
bands
()[source]¶ Retrieves bands.
Returns:
A UnitCell object with band energies.Note
This method can be shortcut
dfttools.simple.parse(file,"band-structure")
.
Retrieves user-specified K-point captions.
Returns:
A dict with k-point number - k-point caption pairs.
-
-
class
dfttools.parsers.openmx.
Input
(file)[source]¶ Class for parsing parameter values from OpenMX input files.
Args:
data (str): contents of OpenMX input file-
getFloat
(parameter)[source]¶ A shortcut to parser.StringParser.matchAfter designed to obtain float parameter values from textual configuration files.
Args:
parameter (str): parameter nameReturns:
parameter value
-
getInt
(parameter)[source]¶ A shortcut to parser.StringParser.matchAfter designed to obtain integer parameter values from textual configuration files.
Args:
parameter (str): parameter nameReturns:
parameter value
-
getNonSpaced
(parameter)[source]¶ A shortcut to parser.StringParser.matchAfter designed to obtain parameter values without spaces from textual configuration files.
Args:
parameter (str): parameter nameReturns:
parameter value
-
getWord
(parameter)[source]¶ A shortcut to parser.StringParser.matchAfter designed to obtain word-like parameter values from textual configuration files.
Args:
parameter (str): parameter nameReturns:
parameter value
-
unitCell
(l=None, r=None, tolerance=1e-12)[source]¶ Retrieves atomic position data.
Kwargs:
l,r (UnitCell): left lead and right lead cells. This information is required for parsing the cell from NEGF calculation input file;
tolerance (float): a tolerance for comparing atomic position data from the keywords and from the file itself in
aBohr
.Returns:
An input unit cell.Raises:
ValueError: left and right lead cells are not specified for NEGF input file.Note
This method can be shortcut
dfttools.simple.parse(file,"unit-cell")
.
-
-
class
dfttools.parsers.openmx.
JSON_DOS
(data)[source]¶ Parses JSON with OpenMX density of states.
Args:
data (str): contents of OpenMX JSON DoS file.
-
class
dfttools.parsers.openmx.
Output
(file)[source]¶ Class for parsing parameter values from OpenMX output files.
Args:
data (string): contents of OpenMX output file-
convergence
()[source]¶ Retrieves convergence error values.
Returns:
A numpy array of convergence errors.
-
neutral_charge
()[source]¶ Retrieves the number of valence electrons in the calculation for the charge neutral system.
Returns:
The number of electrons.
-
populations
()[source]¶ Retrieves Mulliken populations during scf process.
Returns:
A numpy array where the first index corresponds to iteration number and the second one is atomic ID. The populations are renormalized to reproduce the total charge.
-
total
()[source]¶ Retrieves total energy calculated.
Returns:
An array of floats with total energy per each SCF cycle.
-
unitCells
(startingCell, noraise=False)[source]¶ Retrieves atomic positions data for relax calculation.
Args:
startingCell (qetools.cell.Cell): a unit cell from the input file. It is required since no chemical captions are written in the output.Kwargs:
noraise (bool): retirieves as much structures as possible without raising exceptions.Returns:
A set of all unit cells found.
-
-
class
dfttools.parsers.openmx.
Transmission
(file)[source]¶ Class for parsing transmission from openmx.tran file.
Args:
data (string): contents of openmx.tran file
-
dfttools.parsers.openmx.
joint_populations
(files)[source]¶ Collects several files with Lowdin populations and parses them into a single object.
Args:
files (list of str): file contents in an array.Returns:
A dict with joint JSON data.
-
dfttools.parsers.openmx.
populations
(s)[source]¶ Parses JSON with Lowdin populations. Replaces corresponding arrays with numpy objects. Adds units where needed.
Args:
s (str): file contents.Returns:
A dict with JSON data.
-
dfttools.parsers.openmx.
transmission
¶ alias of
Transmission
dfttools.parsers.qe
¶
Parsing Quantum Espresso files.
-
class
dfttools.parsers.qe.
Bands
(file)[source]¶ Class for parsing output files created by bands.x binary of Quantum Espresso package.
Args:
data (str): string with the contents of the bands.x output file.-
bands
(basis)[source]¶ Retrieves the bands.
Args:
basis (types.Basis): the reciprocal unit cell of the band structure.Returns:
A unit cell containing band energies.
-
ne
()[source]¶ Retrieves number of bands from the output file header.
Returns:
Integer number of bands.
-
-
class
dfttools.parsers.qe.
Cond
(file)[source]¶ Class for parsing output files created by pwcond.x binary of Quantum Espresso package.
Args:
data (str): string with the contents of the output file.-
transmission
(kind='resolved')[source]¶ Retrives transmission data from pwcond output file.
Kwargs:
- kind (str): either “resolved”, “total”, “states_in” or
“states_out”.
- resolved: retrieves transmisson matrix elements btw pairs of states;
- total: retrieves total transmission for all incoming states;
- states_in, states_out: retrieves only incoming or outgoing states without forming pairs and obtaining transmissions.
Warning
The “resolved” mode essentially picks all transmission matrix elements available in the input. Therefore it will not record incident states without corresponding outgoing states. However these states will show up in “total” regime with zero transmission.
Returns:
A numpy array of records with states and transmission:
- energy (float): energy of the state in eV;
- kx,ky (float): x and y components of k-vectors;
- incoming (float): z component of k-vector of incoming state (only for kind == “resolved” or kind == “total” or kind == “states_in”);
- outgoing (float): z component of k-vector of outgoing state (only for kind == “resolved” or kind == “states_out”);
- transmission (float): corresponding transmission matrix element or total transmission (only for kind == “resolved” or kind == “total”).
The k vector projections are given in units of reciprocal lattice.
-
-
class
dfttools.parsers.qe.
Input
(file)[source]¶ Class for parsing input file for pw.x binary of a Quantum Espresso package.
Args:
data (str): string with the contents of the input file.
-
class
dfttools.parsers.qe.
Output
(file)[source]¶ Class for parsing output files created by pw.x binary of Quantum Espresso package.
Args:
data (str): string with the contents of the output file.-
bands
(index=-1, skipVCRelaxException=False)[source]¶ Retrieves bands.
Kwargs:
index (int or None): index of a band structure or
None
if all band structures need to be parsed. Supports negative indexing.skipVCRelaxException (bool): forces to skip variable cell relaxation exception. In this very special case no reciprocal lattice vectors are provided for the new cells in the output file.
Returns:
A set of Cell objects with bands data stored inCell.values
. Specifically,Cell.values
is a n by m array where n is a number of k points and m is a number of bands.Raises:
Exception: if a variable cell calculation data found.
-
fermi
()[source]¶ Retrieves Fermi energies.
Returns:
A numpy array containing Fermi energies for each MD step.
-
force
()[source]¶ Retrieves total force.
Returns:
A numpy array containing total forces for each self-consistent calculation.
-
routineError
()[source]¶ Checks “error in routine” entry in the file.
Returns:
String with textual information about the error. Returns None if no error recorded.
-
scf_accuracy
()[source]¶ Retrieves scf convergence history.
Returns:
A numpy array containing estimated errors after all scf steps during calculations. The energies are given in eV.
-
scf_failed
()[source]¶ Checks for “convergence NOT achieved” signature.
Returns:
True if the signature is present.
-
scf_steps
()[source]¶ Retrieved number of scf steps.
Returns:
A numpy array containing numbers of consequetive scf steps performed to reach convergences.
-
success
()[source]¶ Checks for success signature in the end of the file.
Returns:
True if the signature is present.
-
threads
()[source]¶ Retrieves the number of MPI threads.
Returns:
A number of MPI threads for this calculation as an integer.
-
time
()[source]¶ Retrieves cpu times.
Returns:
Time stamps measured by Quantum Espresso in a numpy array.
-
-
class
dfttools.parsers.qe.
Proj
(file)[source]¶ Class for parsing output files created by projwfc.x binary of Quantum Espresso package.
Args:
data (str): string with the contents of the output file.-
basis
()[source]¶ Retrieves the localized basis set.
Returns:
A numpy array of records:
- state (int): ID of the state as provided by Quantum Espresso;
- atom (int): ID of particular atom in the unit cell;
- atomName (str): chemical caption;
- wfc (int): particular wave function ID;
- m,l (float): quantum numbers for collinear calculation;
- j,m_j,l (float): quantum numbers for non-collinear calculation.
-
dfttools.parsers.structure
¶
Parsing various atomic structure files.
-
class
dfttools.parsers.structure.
GaussianCube
(file)[source]¶ Class for parsing Gaussian CUBE files.
Args:
data (str): string with the contents of the Gaussian CUBE file.
-
class
dfttools.parsers.structure.
XSF
(file)[source]¶ Class for parsing xcrysden files commonly used in solid state visualisations.
Args:
data (str): string with the contents of the xsf file.
-
class
dfttools.parsers.structure.
XYZ
(file)[source]¶ Class for parsing XYZ structure files.
Args:
data (str): string with the contents of the XYZ file.
-
dfttools.parsers.structure.
cube
¶ alias of
GaussianCube
dfttools.parsers.vasp
¶
Parsing VASP files.