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.

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


Return dictionary representation of the output

property calculation_type[source]

Returns the calculation type (what io.vasp.outputs calls run_type)

property completed[source]

Did the calculation complete


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

property cp2k_version[source]

The cp2k version used in the calculation

property is_hubbard[source]

returns True if hubbard +U correction was used

property is_metal[source]

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

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.

property num_warnings[source]

How many warnings showed up during the run


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


Parse the lattice parameters (initial) from the output file


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


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.

  • 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


Get the total energy from a CP2K calculation. Presently, the energy reported in the trajectory ( 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.


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


Get the forces from the output file


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


parse the hirshfeld population analysis for each step


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 the initial structure from the main cp2k output file


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


Parse the ionic step info. If already parsed, this will just assimilate.


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 the mulliken population analysis info for each step :return:


Parse the geometry optimization information


Retrieve the overlap condition number :return:


Parse the DFT+U params


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


Parse the SCF cycles (not usually important)


Retrieve the most import SCF parameters: the max number of scf cycles (max_scf), the convergence cutoff for scf (eps_scf), :return:


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 the timing info (how long did the run take).


Parse total numbers (not usually important)

property project_name[source]

What project name was used for this calculation


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 Outcar class

General pattern reading. Uses monty’s regrep method. Takes the same arguments.

  • 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[“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 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.

  • 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.[“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.


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.

property run_type[source]

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

property spin_polarized[source]

Was the calculation spin polarized

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.

  • 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


  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


Parses energy file for calculations with multiple ionic steps.