pymatgen.io.cp2k.outputs module
This module defines the Cp2k output parser along with a few other functions for parsing cp2k-related outputs.
- class Cp2kOutput(filename, verbose=False, auto_load=False)[source]
Bases:
object
Class for parsing output file from CP2K. The CP2K output file is very flexible in the way that it is returned. This class will automatically parse parameters that should always be present, but other parsing features may be called depending on the run type.
Initialize the Cp2kOutput object.
- Parameters:
filename – (str) Name of the CP2K output file to parse
verbose – (bool) Whether or not to parse with verbosity (will parse lots of data that may not be useful)
auto_load (bool) – Whether or not to automatically load basic info like energies and structures.
- property calculation_type[source]
Returns the calculation type (what io.vasp.outputs calls run_type)
- property is_molecule[source]
Returns True if the cp2k output was generated for a molecule (i.e. no periodicity in the cell). Returns false otherwise.
- parse_atomic_kind_info()[source]
Parse info on what atomic kinds are present and what basis/pseudopotential is describing each of them.
- parse_cp2k_params()[source]
Parse the CP2K general parameters from CP2K output file into a dictionary.
- parse_dos(pdos_files=None, ldos_files=None, sigma=0)[source]
Parse the pdos_ALPHA files created by cp2k, and assimilate them into a CompleteDos object. Either provide a list of PDOS file paths, or use glob to find the .pdos_ALPHA extension in the calculation directory.
- Parameters:
pdos_files (list) – list of pdos file paths, otherwise they will be inferred
ldos_Files (list) – list of ldos file paths, otherwise they will be inferred
sigma (float) – Gaussian smearing parameter, if desired. Because cp2k is generally used as a gamma-point only code, this is often needed to get smooth DOS that are comparable to k-point averaged DOS
- parse_energies()[source]
Get the total energy from a CP2K calculation. Presently, the energy reported in the trajectory (pos.xyz) file takes presidence over the energy reported in the main output file. This is because the trajectory file keeps track of energies in between restarts, while the main output file may or may not depending on whether a particular machine overwrites or appends it.
- parse_files()[source]
Identify files present in the directory with the cp2k output file. Looks for trajectories, dos, and cubes
- parse_global_params()[source]
Parse the GLOBAL section parameters from CP2K output file into a dictionary.
- parse_homo_lumo()[source]
Find the HOMO - LUMO gap in [eV]. Returns the last value. For gaps/eigenvalues decomposed by spin up/spin down channel and over many ionic steps, see parse_mo_eigenvalues()
- parse_ionic_steps()[source]
Parse the ionic step info. If already parsed, this will just assimilate.
- parse_mo_eigenvalues()[source]
Parse the MO eigenvalues from the cp2k output file. Will get the eigenvalues (and band gap) at each ionic step (if more than one exist).
Everything is decomposed by spin channel. If calculation was performed without spin polarization, then only Spin.up will be present, which represents the average of up and down.
- parse_scf_params()[source]
Retrieve the most import SCF parameters: the max number of scf cycles (max_scf), the convergence cutoff for scf (eps_scf), :return:
- parse_structures(trajectory_file=None, lattice_file=None)[source]
Parses the structures from a cp2k calculation. Static calculations simply use the initial structure. For calculations with ionic motion, the function will look for the appropriate trajectory and lattice files based on naming convention. If no file is given, and no file is found, it is assumed that the lattice/structure remained constant, and the initial lattice/structure is used. Cp2k does not output the trajectory in the main output file by default, so non static calculations have to reference the trajectory file.
- ran_successfully()[source]
Sanity checks that the program ran successfully. Looks at the bottom of the CP2K output file for the “PROGRAM ENDED” line, which is printed when successfully ran. Also grabs the number of warnings issued.
- read_pattern(patterns, reverse=False, terminate_on_match=False, postprocess=<class 'str'>)[source]
This function originally comes from pymatgen.io.vasp.outputs Outcar class
General pattern reading. Uses monty’s regrep method. Takes the same arguments.
- Parameters:
patterns (dict) – A dict of patterns, e.g., {“energy”: r”energy\(sigma->0\)\s+=\s+([\d\-.]+)”}.
reverse (bool) – Read files in reverse. Defaults to false. Useful for large files, esp OUTCARs, especially when used with terminate_on_match.
terminate_on_match (bool) – Whether to terminate when there is at least one match in each key in pattern.
postprocess (callable) – A post processing function to convert all matches. Defaults to str, i.e., no change.
- Renders accessible:
Any attribute in patterns. For example, {“energy”: r”energy\(sigma->0\)\s+=\s+([\d\-.]+)”} will set the value of self.data[“energy”] = [[-1234], [-3453], …], to the results from regex and postprocess. Note that the returned values are lists of lists, because you can grep multiple items on one line.
- read_table_pattern(header_pattern, row_pattern, footer_pattern, postprocess=<class 'str'>, attribute_name=None, last_one_only=True, strip=None)[source]
This function originally comes from pymatgen.io.vasp.outputs Outcar class
Parse table-like data. A table composes of three parts: header, main body, footer. All the data matches “row pattern” in the main body will be returned.
- Parameters:
header_pattern (str) – The regular expression pattern matches the table header. This pattern should match all the text immediately before the main body of the table. For multiple sections table match the text until the section of interest. MULTILINE and DOTALL options are enforced, as a result, the “.” meta-character will also match “n” in this section.
row_pattern (str) – The regular expression matches a single line in the table. Capture interested field using regular expression groups.
footer_pattern (str) – The regular expression matches the end of the table. E.g. a long dash line.
postprocess (callable) – A post processing function to convert all matches. Defaults to str, i.e., no change.
attribute_name (str) – Name of this table. If present the parsed data will be attached to “data. e.g. self.data[“efg”] = […]
last_one_only (bool) – All the tables will be parsed, if this option is set to True, only the last table will be returned. The enclosing list will be removed. i.e. Only a single table will be returned. Default to be True.
strip (list) – Whether or not to strip contents out of the file before reading for a table pattern. This is mainly used by parse_scf_opt(), to strip HFX info out of the SCF loop start or DFT+U warnings out of the SCF loop iterations.
- Returns:
List of tables. 1) A table is a list of rows. 2) A row if either a list of attribute values in case the capturing group is defined without name in row_pattern, or a dict in case that named capturing groups are defined by row_pattern.
- parse_dos(dos_file=None, spin_channel=None, total=False, sigma=0)[source]
Parse a single DOS file created by cp2k. Must contain one PDOS snapshot. i.e. you cannot use this cannot deal with multiple concatenated dos files.
- Parameters:
dos_file (list) – list of pdos_ALPHA file paths
spin_channel (int) – Which spin channel the file corresponds to. By default, CP2K will write the file with ALPHA or BETA in the filename (for spin up or down), but you can specify this here, in case you have a manual file name. spin_channel == 1 –> spin up, spin_channel == -1 –> spin down.
total (bool) – Whether to grab the total occupations, or the orbital decomposed ones.
sigma (float) – width for gaussian smearing, if desired
- Returns:
orbital decomposed DOS dict: i.e. pdoss = {specie: {orbital.s: {Spin.up: … }, orbital.px: {Spin.up: … } …}}
energy levels of this dos file
fermi energy (in eV).
DOS object is not created here
- Return type:
Everything necessary to create a dos object, in dict format