# 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.

as_dict()[source]

Return dictionary representation of the output

property completed[source]

Did the calculation complete

convergence()[source]

Check whether or not the SCF and geometry optimization cycles converged.

property cp2k_version[source]

The cp2k version used in the calculation

property is_metal[source]

Was a band gap found? i.e. is it a metal

property num_warnings[source]

How many warnings showed up during the run

parse_atomic_kind_info()[source]

Parse info on what atomic kinds are present and what basis/pseudopotential is describing each of them.

parse_cell_params()[source]

Parse the lattice parameters (initial) from the output file

parse_cp2k_params()[source]

Parse the CP2K general parameters from CP2K output file into a dictionary.

parse_dft_params()[source]

Parse the DFT parameters (as well as functional, HF, vdW params)

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 the output file

parse_files()[source]

Identify files present in the directory with the cp2k output file. Looks for trajectories, dos, and cubes

parse_forces()[source]

Get the forces from the output file

parse_global_params()[source]

Parse the GLOBAL section parameters from CP2K output file into a dictionary.

parse_hirshfeld()[source]

parse the hirshfeld population analysis for each step

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_initial_structure()[source]

Parse the initial structure from the main cp2k output file

parse_input()[source]

Load in the input set from the input file (if it can be found)

parse_ionic_steps()[source]

Parse the ionic step info

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_mulliken()[source]

Parse the mulliken population analysis info for each step :return:

parse_opt_steps()[source]

Parse the geometry optimization information

parse_scf_opt()[source]

Parse the SCF cycles (not usually important)

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_stresses()[source]

Get the stresses from the output file.

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.

parse_timing()[source]

Parse the timing info (how long did the run take).

parse_total_numbers()[source]

Parse total numbers (not usually important)

property project_name[source]

What project name was used for this calculation

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)[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.

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 the capturing group is defined without name in row_pattern, or a dict in case that named capturing groups are defined by row_pattern.

property run_type[source]

What type of run (Energy, MD, etc.) was performed

property spin_polarized[source]

Was the calculation spin polarized

gauss_smear(data, width)[source]

Return a gaussian smeared DOS

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

1. orbital decomposed DOS dict: i.e. pdoss = {specie: {orbital.s: {Spin.up: … }, orbital.px: {Spin.up: … } …}}

2. energy levels of this dos file

3. fermi energy (in eV).

DOS object is not created here

Return type

Everything necessary to create a dos object, in dict format

parse_energy_file(energy_file)[source]

Parses energy file for calculations with multiple ionic steps.