CP2K

CP2K is a quantum chemistry software package that can perform atomistic simulations of solid state, liquid, molecular, periodic, material, crystal, and biological systems. CP2K provides a general framework for different modeling methods such as DFT using the mixed Gaussian and plane waves approaches Gaussian and Plane Waves (GPW) and Gaussian and Augmented Plane Wave (GAPW) methods. Supported theory levels include DFTB, LDA, GGA, MP2, RPA, GW, and semi-empirical methods.

The dual-basis representation of the electron density employed by the CP2K engine requires a larger number of settings compared to other methods. While this increases the complexity of the settings, it also makes the CP2K engine more flexible. This added flexibility can be leveraged to enhance the performance of the CP2K engine

Required Settings

  • basis:

    The basis keyword is used to specify the name of a general basis set for a given kind in CP2K. Two types of basis sets are available: all-electron basis sets and valence electrons basis sets. The former is only available for the Gaussian and Plane Waves (GAPW) method.

    graph LR
    
    GAPW --> all_basis[All electron basis set]
    GAPW --> pseudo_basis[valence electrons basis set]
    GPW --> pseudo_basis[Valence electrons basis set]
    

    Three sources of basis sets are available:

    1. Default CP2K basis sets: These are located in the CP2K repository and are distributed with CP2K. To use one of these basis sets, simply specify the name of the basis set.
    2. CP2K engine basis sets: These basis sets are generated using the Basis Set Exchange and distributed through the nmcp2kbasis package, which is delivered together with QuantumPatch. To use one of these basis sets, simply specify the name of the basis set.
    3. Manual basis sets: Additional basis sets can be downloaded from Basis Set Exchange or other sources and stored locally. To use one of these basis sets, specify the path to the basis set file using the BASIS_SET_FILE_NAME key.

    For options i and ii, only the name of the basis set needs to be specified. For option iii, the path to the basis set file must be specified using the BASIS_SET_FILE_NAME keyword.

    CP2K keyword: CP2K_INPUT/FORCE_EVAL/SUBSYS/KIND/BASIS

    Default value: -.

  • functional

    This keyword specifies the exchange-correlation functional for DFT calculations.

    Some functionals, which are available:

    • B3LYP
    • PBE

    Additional functionals, including modern long-range separated and hybrid functionals are availble (see cp2k documentation) or can be added upon request.

    CP2K keyword: CP2K_INPUT/ATOM/METHOD/XC/XC_FUNCTIONAL

    Default value: -.

Main Optional Settings

  • offset:

    The offset keyword is used to set the size of the simulation box. It determines the size of the simulation box relative to the size of the molecule being simulated. If the linear size of the molecule is given by a, b, and c, then the simulation box size will be (a + offset), (b + offset), and (c + offset) when using the MT (Martyna Tuckermann) Poisson solver (see POISSON_SOLVER keyword). If the WAVELET Poisson solver is used, the simulation box size will be (max + offset), where max = max(a, b, c), since the WAVELET solver is only implemented for a cubic cell.

    WAVELET solver is somewhat slower than MT, and it needs a cubic simulation cell, but it needs smaller offsets than MT. MT solver allows rectangular cell, but the offset should be somewhat larger.

    Keyword type: simple keyword (see Note).

    CP2K key: CP2K_INPUT/FORCE_EVAL/MM/POISSON.

    Default value: WAVELET.

    Possible values: WAVELET, MT.

    Note: When using the MT (Martyna Tuckermann) Poisson solver with the offset keyword, the molecule, along with its partial charges, will be (by default) rotated so that it aligns with the principal axes of inertia of the molecule. This decreases the overall volume of the simulation box. This is a feature implemented within the CP2K Engine, and not a core functionality of CP2K itself.

  • cutoff:

    Defines planewave cutoff (in Ry) for the finest level of multi-grid. The higher the planewave cutoff, the finer the grid.

  • rel_cutoff:

    Controls which product Gaussians are mapped onto which level of multi-grid. Recommended values for rel_cutoff is 30/35 for "normal"/last step. Together with keyword "cutoff" and "box_size", "rel_cutoff" are three most important keywords affecting the integration grid and the accuracy of a calculation.

    Recommended values for the normal and last steps are as follows:

  • poisson_solver: Specify which kind of solver to use to solve the Poisson equation, directly sets CP2K keyword POISSON_SOLVER.

    Possible values: MT, WAVELET.

    Default value: WAVELET.

    Notes: other CP2K keyword values are not available.

Additional basi set and pseudopotential settings:

  • BASIS_SET_FILE_NAME

    Specifies the path to basis set file. Relative or absolute paths are possible.

    Possible values: str **

    Some basis sets available in CP2K engine are as follows. def2 family basis sets in DEF2_ALL files are:

    * def2-SV(P)
    * def2-SVP
    * def2-SVPD
    * def2-TZVP
    * def2-TZVPP
    * def2-TZVPPD
    * def2-QZVP
    * def2-QZVPP
    

    Pople basis sets available from EMSL_BASIS_SETS file:

    * 6-31G*
    * 6-31G**
    * 6-31++G**
    * 6-311G
    * 6-311G**
    * 6-311++G
    * 6-311++G**
    
  • POTENTIAL_FILE_NAME https://manual.cp2k.org/trunk/CP2K_INPUT/FORCE_EVAL/SUBSYS/KIND.html#list_POTENTIAL_FILE_NAME name of the file with pseuodopotential. For GAPW and all-electron basis, default value "ALL" is set. If using all-electron basis, this keyword thus does not have to be specified.

  • potential The type (ECP, ALL, GTH, UPS) and name of the pseudopotential for the defined kind. https://manual.cp2k.org/trunk/CP2K_INPUT/FORCE_EVAL/SUBSYS/KIND/POTENTIAL.html name of the pseudopotential to use. For any all-electron basis set, this is always "ALL", and different options exist for basis sets with pseudopotentials. See also POTENTIAL_FILE_NAME.

Settings of the self-consistent (SCF) loop.

  • eps_scf

    This keyword sets the target accuracy for the self-consistent field (SCF) convergence.

    Type of keyword: simple.

    CP2K keyword: CP2K_INPUT/FORCE_EVAL/DFT/SCF.

    Valid values: float.

    Units: Hartree.

    Default value: 1.0E-5.

  • max_scf:

    This keyword sets the maximum number of self-consistent field (SCF) steps. If the outer self-consistent loop (key outer_scf) is used, the default value may not be suitable and a different value is recommended.

    Type of keyword: simple.

    CP2K keyword: CP2K_INPUT/FORCE_EVAL/DFT/MAX_SCF.

    Valid values: non-negative integers.

    Default value: 100.

  • stepsize:

    This keyword sets the initial stepsize used for line search. Negative values leaves the choice to CP2K depending on the preconditioner. Values larger than 0.3 may cause instability in the convergence, while lower values may lead to slower convergence.

    Type of keyword: simple.

    Valid values: float.

    Recommended value: 0.1.

  • minimizer: Minimizer to be used with the orbital transformation (OT) method. Recommended method is DIIS. CG method, on the other hand, is more stable, and can be used in a fallback.

    Type of keyword: simple.

    CP2K keyword: CP2K_INPUT/FORCE_EVAL/DFT/SCF/OT.html#MINIMIZER.

    Valid values: non-negative integers.

    Default value: 100.

  • outer_scf: Outer self-consistent loop, which helps to faster converge.

  • max_scf_outer_scf: Maximum number of outer_scf steps. Recommended value is 5.

  • preconvergence

    If set to true, this keyword activates preconvergence, which uses different settings such as cutoffs, offsets, and a functional called cutoff_0, rel_cutoff_0, offset_0 to obtain an initial guess for the wavefunction. This initial wavefunction will be used for the productive run. Preconvergence is strongly recommended for a first step in a vacuum and is particularly useful for hybrid functionals, where GGA functionals are used.

    Type of keyword: composite. Valid values: false or true. Default value: false.

  • ignore_preconv_convergence

    If set to true, this keyword enables the use of the wavefunction from a preconvergence run even if it does not converge. This means that the wavefunction will be used for the productive run regardless of its convergence status during preconvergence. If set to false, the program may fall back to using the conjugate gradient (CG) method, which can be slower.

    Valid values: true or false.

  • functional_0, cutoff_0, rel_cutoff_0, offset_0: the same as keywords without "_0", keywords using for preconvergence step. (see "preconvergence").


Advanced settings

  • threads: number of OpenMP processed per job. CP2K usually scales sublinearly => using one core per molecule is desired. An exception are hybrids, which cpu*time may scale superlinerly if too little RAM is available. For GGA functional and typical OLED molecules with less or about 100 atoms and cutoffs / offsets mentioned above, one thread suffice. For B3LYP functional or other hybrid, normal steps (vaccuum step until the one before the last one) would need 4 threads, while the last step (the one with higher cutoff/rel_cutoff) would need 9 threads.

      CP2K any step GGA functional:
        functional: PBE
        threads: 1
    
      CP2K vacuum or intermediate step:
        functional: b3lyp
        threads: 4
        cutoff: 90
    
      CP2K last step:
        functional: b3lyp
        threads: 9
        cutoff: 200
    

    The keyword cutoff above that sets a real-space grid is responsible for necessity of having more threads. See more about recommended cutoff, rel_cutoff and offset.

  • copy_back_scratch: to see what happens 'under the hood', set it to true. CP2K simulation folders will be copied from scratch back to your submit directory. Possible values: false, true. Typical case when you may need this: you need to estimate a peak memory needed for simulation. In this case, take enough threads per job, so that the available RAM is for sure suffice and run some QuantumPatch simulations. Making:

      grep "peak memory" MainLog.out
    

    you will see the peak memory, and, dependent on your computer, how many threads you need per molecule. It is always a good idea to take fewer threads, unless for hybrids, which are slower if RAM is too small. Possible values: openmp, mpi.

  • partype: CP2K Parallelization strategy. Engine by default uses OpenMP parallelized CP2K version, cp2k.ssmp. Another option would be mpi, but it is unstable and needs a separate virtual environment installation.

    Possible values: openmp, mpi.

    Default value: openmp.

    Notes: Unless you are a developer, you will probably never need this keyword.


Advanced hybrid functional settings

  • eps_schwarz: Sets precision of the overlap matrix elements (section Hartree-Fock / screening). It is set to 1.0E-6 Hartree in the code, which provides a sound compromise between performance and accuracy. This is one of the most important setting that regulate hybrid functional performance. Default value of eps_schwarz, 1.0E-10 Hartree is not recommended yielding the simulation time increment of about 5 times (typical OLED molecules), and also RAM. One can probably increase eps_schwarz to 1.0E-5 Hartree and still have acceptable accuracy. Default value: 1.0E-6 Hartree. This default value is not intended to be changed unless you really need this.

  • max_memory: Defines the maximum amount of memory [MiB] to be consumed by the full HFX module. Only relevant for hybrid functionals. More information on cp2k tutorial: MAX_MEMORY. Critical parameter for hybrid functional performance. HF is only efficient if all required memory for HF simulations is available. If the available memory is smaller than that HF needs, performance will be greatly reduced. It is faster to take more cores if memory per one core is small than using one core with too little memory. Default value: 2500 MiB. Check if your supercomputer allows more/less memory per core and adjust accordingly.

  • preconvergence: What it does: If not set by a user, this keyword is controlled by QuantumPatch, not by CP2K Engine itself. QuantumPatch will set it to True if the wavefunction file (used for restart) from the previous QuantumPatch step not available. This happens at a first step of either of three charged state (neutral, positive, negative). If the user not set "pre" intial_guess: set by QP. 1-st iteration any charged state / vacuum: does not exist if using B3LYP at a vacuum step, the preconvergence with some GGA functional is strongly recommended. In other words:

      CP2K hybrid vacuum step:
        preconvergence: true
        functional_0: PBE
        functional: B3LYP
    

    This will first converge the molecule with PBE functional, and the file with saved wavefunction (*.wfn) will be used as an initial guess for B3LYP simulations. If the preconvergence not used, simulations take several times longer. If using cheap functional at first in order to get a good initial guess, not more than 10 expensive B3LYP iterations are needed to reach the convergence.

Settings that invoke other settings

Certain CP2K engine keywords are set to a specific value, which in turn triggers other keywords to be set based on the value of the former. It's important to note that any settings made by a user always have the highest priority and override keyword values that are set implicitly.

  • qs_method

    The qs_method keyword in CP2K corresponds to the CP2K keyword METHOD in the FORCE_EVAL/DFT/QS section, and can take on one of three values: GAPW, GPW, or LRIGPW. These correspond to abbreviations of three CP2K methods:

    • Gaussian and augmented plane waves method (GAPW)
    • Gaussian and plane waves method (GPW)
    • Local resolution of identity method (LRIGPW)

    Depending on which of the three methods is set, three other keywords will be set accordingly:

    graph TD
    qs_method --> BASIS_SET_FILE_NAME;
    qs_method --> POTENTIAL_FILE_NAME;
    qs_method --> potential;
    

    This is done according to the table below.

qs_method BASIS_SET_FILE_NAME POTENTIAL_FILE_NAME potential
GAPW ['DEF2_ALL', 'BASIS_RI_cc-TZ'] ALL_POTENTIALS ALL
GPW ['BASIS_MOLOPT', 'BASIS_RI_cc-TZ'] GTH_POTENTIALS GTH-PBE
LRIGPW ['BASIS_MOLOPT', 'BASIS_LRIGPW_AUXMOLOPT'] LRI-DZVP-MOLOPT-GTH-MEDIUM GTH-PBE

Note that POTENTIAL_FILE_NAME corresponds to a list of two values (although it can have one or more values in general), and in this case, CP2K will try to find the requested basis set in all listed files. Also note that BASIS_RI_cc-TZ is only needed for GW simulation, but it is set by default. For the LRIGPW method, the LRI auxiliary basis set (basis_set_lri) is set to LRI-DZVP-MOLOPT-GTH-MEDIUM in addition to the other settings.


Composite settings

Note: specific keywords set due to composite settings may be set to the value that you want explicitly. Direct setting by a user always has the highest priority.

Composite settings regulate values of two or more "simple" keywords, but their own values are not used by CP2K engine later. This distinguishes them from "setting that invoke other settings", which values are used later in line with their own values.

  • convergence

    Parameters that control convergence of the self-consistent loop:

    Keyword convergence sets values of six simple keywords as shown below:

    graph TD
    convergence --> eps_scf;
    convergence --> stepsize;
    convergence --> minimizer;
    convergence --> outer_scf;
    convergence --> max_scf;
    convergence --> max_scf_outer_scf;
    

    The values of mentioned keywords are set as follows depending on the value of convergence (first table), the second table explains which convergence to use in which case. Quick and reliable convergence can in most cases be achieved using normal convergence.

    First table

convergence eps_scf stepsize minimizer outer_scf max_scf max_scf_outer_scf
normal 1.0E-5 0.1 DIIS True 15 5
normal_for_pcs 1.0E-4 0.1 DIIS True 15 5
extreme 1.0E-5 0.1 CG True 15 5
superextreme 1.0E-5 0.1 CG False 500 -
superextreme_for_pcs 1.0E-4 0.1 CG False 500 -

Second table

convergence when to use
normal uncharged equilibration, charged equilibration
normal_for_pcs uncharged equilibration, charged equilibration, all steps but the last one but the accuracy may be insufficient
extreme fallback in the uncharged and charged loop
superextreme fallback in the charged loop in complicated cases
superextreme_for_pcs fallback in the charged loop in complicated cases, all steps but the last one but the accuracy may be insufficient

  • target_property: parameters that controls parameters of the simulation cell and real space grid depending on the property one is interested in at a current QuantumPatch step.

    Possible values of target_property are:

    • partial_charges
    • partial_charges_for_eaip
    • energy
    • energy_for_eaip
    • total_energy

    Keyword target_property sets values of six simple keywords as shown below. In addition to this, conditional_settings represents a list of lists. The latter represents a list of two dictionaries with one key:value pair each. The first pair is the one that will be looked up in settings. In it is found, the key from the second pair is set to a value from the second pair.

    graph TD
     target_property --> cutoff;
     target_property --> rel_cutoff;
     target_property --> offset;
     target_property --> cutoff_0;
     target_property --> rel_cutoff_0;
     target_property --> offset_0;
     target_property --> conditional_settings;
    

    An example of what conditional_settings represents (expressed in yaml format):

    conditional_settings: 
      functional: b3lyp
      functional_0: pbe
    

    This will change settings as follows: if the functional is B3LYP, functional_0 (the functional used for the pre-convergence) will be set to PBE.

    The table below shows how respecting keywords are set depending on the value of target_property.

target_property cutoff rel_cutoff offset cutoff_0 rel_cutoff_0 offset_0 conditional_settings
partial_charges 90 35 6 90 30 3 {functional: B3LYP}, {functional_0: PBE}
energy 200 35 3 200 35 3 -

TODO memory calibration

CP2K essential differences to other QuantumPatch engines

Except for CP2K, all other QuantumPatch engines are based on codes that use localized basis sets, e.g. Gaussian type orbitals (GTO) to represent electron density. This is a natural choice for simulating finite systems, e.g. molecules. For condensed matter systems like crystals, where electron density is delocalized, codes that use extended basis sets, e.g. plane waves (PW), are used. CP2K implements GPW method that uses mixed GTO+PW representation to take best of two worlds. In addition, GAPW method additionally treats hard and soft density domains separately.

graph TD
CP2K[CP2K methods] --> GAPW;
CP2K --> GPW;

The results of the search are