Loading [MathJax]/jax/output/CommonHTML/jax.js

User Tools

Site Tools


events:2016_summer_school:gpw
# Matt Watkins for the CP2K-UK summer school 2016
#
# heavily lifted from Marcella Iannuzzi's previous presentations, e.g
# https://www.cp2k.org/_media/events:2015_cecam_tutorial:iannuzzi_gpw_gapw_b.pdf
#
# Matt Watkins
# School of Mathematics and Physics, University of Lincoln, UK

GPW (GAPW) electronic structure calculations

DFT

Why DFT?

  • Explicit inclusion of electronic structure
  • predictable accuracy (at least when benchmarked for related systems)
  • many observables available (spectroscopy)
  • cheaper (better scaling) than many wavefunction based approaches
  • ab initio molecular dynamics / Monte Carlo

Hohenberg-Kohn Theorems

Theorem 1

  • the potential and hence the total energy are a unique functional of the electronic density, n(r)

n(r)Vext(r,R)

Theorem 2

  • the total energy is variational

E[n]E[nGS]

the energy has several components:

Etot[n]=Ekin[n]+Eext[n]+EH[n]+EXC[n]

  • Ekin - kinetic energy of electrons
  • Eext - energy due to external potential (pseudo potentials, external bias or electric fields … )
  • EH - Hartree energy, classical electrostatic interactions
  • Exc - non-classical Coulomb energy: electron correlation

Kohn-Sham: non-interacting electrons

We map the problem of interacting electrons onto an equivalent one with non-interacting electrons with an altered external potential (xc).

We expand the density as a sum of one electron orbital contributions

Electronic density

n(r)=ifiψi(r)2

where fi is the occupation number of the ith orbital

Kinetic energy of non-interacting electrons

Ts[n]=ifiψi(r)122ψi(r)

Electronic interaction with the external potential

Eext[n]=rn(r)Vext(r)dr,Vext=IZIrRI

with the exact solution as a Slater determinant of the lowest N orbitals

Ψ=1N!det[ψ1ψ2ψ3ψN]

KS equations

Using the 2nd Hohenberg-Kohn theorem, we find the electron density that minimises the energy of the system.

But, like in Hartree-Fock theory, we have to ensure that the electron orbitals are orthonormal to prevent the system imploding.

Orthogonality constraint

ΩKS[ψi]=EKS[n]ijϵijψi(r)ψj(r)dr

Variational search in the space of the orbitals

We correct the non-interacting electron model by adding in an (in principle unknown) XC potential that accounts for all quantum mechanical many-body interactions (electron-electron repulsion)

Classical election-electron repulsion

J[n]=12rdrrdrn(r)n(r)rr=12rn(r)VH(r)dr

Kohn-Sham functional

EKS[n]=Ts[n]+Eext[n]+J[n]+EXC[n]

EXC[n]=Ekin[n]Ts[n]+Eee[n]J[n]

The exact functional form for the electron-electron repulsion is not known, but various levels of approximation are available (Jacob's Ladder).

The existence of this functional is guaranteed by the 1st Hohenberg-Kohn Theroem.

This maps mathematically onto the familiar Hartree-Fock model of electronic structure.

KS equations

HKSψi=[122+VKS]ψi=ijϵijψj

We can transform the generalised eigenvalue problem given by the KS equations above, to get rid of the nasty sum on the right hand side. In this case ϵij is diagonal, and we get an eigenvalue problem:

[122+VKS]ψi=ϵiψi

- KS equations look like the Schr¨odinger equations - coupled and highly non-linear (VKS depends on the orbitals!) - self consistent solution (Self Consistent Field - the VKS is consistent with the orbitals) - KS scheme is, in principle, exact (if we knew the exact EXC)

Self-consistency

generate an initial guess, from a superposition of atomic densities (typical PW code) or atomic block diagonal density matrix (CP2K)

  1. generate a starting density n0
  2. generate the KS potential V0KS
  3. solve the KS equations ϵ,ψ

then repeat until convergence

  1. calculate the new density n1
  2. calculate the new KS potential V1KS
  3. new orbitals and energies ϵ1,ψ1

calculate properties from final density and orbitals

Stopping criteria in CP2K are:

  • the largest MO derivative (ECαi) is smaller than `EPS_SCF` (OT)
  • the largest change in the density matrix (P) is smaller than `EPS_SCF` (traditional diagonalization).

Basis Set Representation(s)

to actually do calculations we need to expand the KS equations into a basis. In CP2K we use Gaussian functions as the primary basis set:

the KS orbitals are then represented as

ψi(r)=αCαiϕα(r)

the density as

n(r)=iαβfiCαiCβiϕα(r)ϕβ(r)=Pαβϕα(r)ϕβ(r)

where the density matrix P is defined.

There is a complication - the basis functions are not orthogonal. We have an *overlap matrix*, S,

Sαβ=rϕα(r)ϕβ(r)dr

KS total energy

E[{ψi};{RI}]=T[{ψi}]+Eext[n]+EH[n]+EXC[n]+EII

for local of semi-local functionals or

E[{ψi};{RI}]=T[{ψi}]+Eext[n]+EH[n]+EXC[{ψi}]+EII

for hybrid functionals.

Where E[{ψi};{RI}] indicates that the energy depends on the (occupied) KS orbitals (which then give a density) and parametrically on all the I nuclear coordinates, RI.

Matrix formulation of the KS equations

using the variational principle we get

K(C)C=T(C)+Vext(C)+VH(C)+VXC(C)=SCϵ

Algorithmic challenges

  • construct the Kohn-Sham matrix
    • Hartree potential
    • XC potential
    • HF/exact exchange
    • core/pseudopotential terms
  • fast and efficient minimization of the energy functional
  • efficient calculation of the density matrix and construction of the Molecular Orbitals (C)

Construction of the KS matrix should be (and is in CP2K) linear scaling (O(N)) in basis set size. CP2K does this using dual basis set (GPW) techniques - coming up.

Minimization / diagonalization is harder - linear scaling routines are available but are only more efficient for large systems and require considerable computational resources.

GPW method in CP2K

after the general discussion of DFT above, what does CP2K do to solve the KS equations efficiently?

What should you know / look out for, to get good use of the code?

Gaussians and Plane Wave method (GPW)

GPW ingredients

As the name suggests, this method uses two different types of functions

  1. localized Gaussians, centred at atomic positions
  2. plane waves

The idea of GPW is to use the plane-waves as an auxiliary basis, primarily to construct the Hartree potential.

This leads to linear scaling KS construction for Gaussian Type Orbitals (GTO)

Guassian basis sets (many matrix elements can be done analytically)

we go a bit further than implied above - to be more accurate, we *contract* several Gaussians to form approximate atomic orbitals ϕα(r)=mdmαgm(r) where a primitive cartesian Gaussian centred at the origin is given by gm(r)=xmxymyzmzeαmr2 and mx+my+mz=l, the angular momentum quantum number of the functions.

  • Pseudo potentials
  • Plane waves auxiliary basis for Coulomb integrals
  • Regular grids and FFT for the density
  • Sparse matrices (KS and P)
  • Efficient screening

Gaussian Basis set

  • localised atom-centred GTO basis

ϕα(r)=mdmαgm(r)

  • expansion of the density using the density matrix

n(r)=αβPαβϕα(r)ϕβ(r)

  • operator matrices are sparse. By neglecting overlap elements smaller than some number indirectly specified by `EPS_DEFAULT`, the Gaussian functions are localized with finite support. This means that S,H and P are sparse.

Sαβ=rϕα(r)ϕβ(r)dr Hαβ=rϕα(r)VKS(r)ϕβ(r)dr

Data files

Parameter files distributed with CP2K in $CP2K_ROOT/cp2k/data

(testchroot)mattw@localhost:~/progs/cp2k$ ls cp2k/data/
ALL_BASIS_SETS     BASIS_MOLOPT    DFTB             GTH_POTENTIALS  NLCC_POTENTIALS  nm12_parameters.xml     vdW_kernel_table.dat
ALL_POTENTIALS     BASIS_RI_cc-TZ  ECP_POTENTIALS   HFX_BASIS       POTENTIAL        rVV10_kernel_table.dat
BASIS_ADMM         BASIS_SET       EMSL_BASIS_SETS  HF_POTENTIALS   README           t_c_g.dat
BASIS_ADMM_MOLOPT  BASIS_ZIJLSTRA  GTH_BASIS_SETS   MM_POTENTIAL    dftd3.dat        t_sh_p_s_c.dat

contains sets of basis sets (*BASIS_SET*) and pseudopotentials (*POTENTIAL* except MM_POTENTIAL, which is for classical calculations)

Also parameter files for

  • screened exact exchange `t_c_g.dat`
  • Grimme type dispersion `dftd3.dat`
  • non-local dispersion functionals `vdW_kernel_table.dat, rVV10_kernel_table.dat`

Basis set libraries

There are two main types of basis sets supplied with CP2K

  • GTH_BASIS_SETS: atomically optimized sets. These were the first shipped with the code and vary systematically in quality from DZ to QZ for lighter elements. Can be very good for molecular systems, but can be very bad for condensed matter systems.
  • BASIS_MOLOPT: molcularly optimized basis sets. These cover most elements of the periodic table, but only with fairly good quality DZVP-MOLOPT-SR-GTH. Should be a good starting point for most condensed matter calculations.

The basis set files provide the contraction coefficients (dmα) and exponents (αm) of the Gaussian functions.

ϕα(r)=mdmαgm(r) gm(r)=xmxymyzmzeαmr2

Generally the first column is the exponents (αm above) and the later columns give the dmα, each column being a set α. Details can be found in the header of the BASIS_MOLOPT file.

N  DZVP-MOLOPT-SR-GTH DZVP-MOLOPT-SR-GTH-q5
 1
 2 0 2 5 2 2 1
      7.341988051825  0.113789156500  0.077765588400 -0.053744330400 -0.007627243700  0.033688455200
      2.542637110957  0.097294516500  0.108655219900 -0.165752516200  0.015163333100  0.109813343200
      0.888574967229 -0.445077422600 -0.374125427100 -0.317365165600 -0.129388247500  0.856542971300
      0.333802200435 -0.584142233900  0.024021712400 -0.312039675200  0.554905847400  0.509681657500
      0.112012109029 -0.139562383500  0.979415132500 -0.117936008100  1.001020469600  0.047030652200

Here there are Gaussians with five different exponents ( in Bohr2). From these 5 sets of functions are built, two s functions (2nd and 3rd columns), 2 sets of p functions (4th and fifth columns) and one set of d functions (last column).

Note that the contraction coefficients are not varied during calculation. For the nitrogen basis above we have 2+2×3+1×5=13 variables to optimize for each nitrogen atom in the system.

(CP2K tends to use general contractions for efficiency, allowing maximum use of recursion relations to generate matrix elements for high angular momentum functions).

GTH pseudopotentials

Accurate and transferable with few parameters. Include scalar relativistic effects. Available for all atoms Zion<86

  • Norm-conserving, separable, dual-space
  • Local PP : short-range and long-range terms

VPPloc(r)=4i=1CPPi(2αPPr)2i2e(αPPr)2Zionrerf(αPPr)

first term in sum is short ranged, and analytically calculated in Gaussian basis. Second term is long ranged, and merged into the electrostatic calculation (see later)

  • non-local PP with Gaussian type operators

VPPnl(r,r)=lmijrplmihlijplmjr

rplmi=NliYlm(ˆr)rl+2i2e12(rrl)2

You can scan through potentials available at here

Original papers: Goedeker, Teter, Hutter, PRB 54 (1996), 1703 and Hartwigsen, Goedeker, Hutter, PRB 58 (1998) 3641

Electrostatics

  • long-range term: Non-local Hartree Potential

Poisson equation solved using the auxiliary plane-wave basis EH[ntot]=12rdrrdrn(r)n(r)rr

where ntot includes the nuclear charge as well as the electronic. (The nuclear charge density is (of course) represented as a Gaussian distribution with parameter RcI chosen to cancel a similar term from the local part of the pseudopotential)

  • FFT (scaling as NlogN) gives

˜n(r)=1ΩG˜n(G)eiGr)

In the G space representation the Poisson equation is diagonal and the Hartree energy is easily evaluated

EH[ntot]=2πΩG˜n(G)˜n(G)G2

  • The electrostatic energy converges rapidly with the grid spacing / planewave cutoff

Real space integration

Finite cutoff and simulation box define a realspace grid

  • density collocation

n(r)=αβPαβϕα(r)ϕβ(r)αβPαβˉϕαβ(r)=n(R) where n(R) is the density at grid points in the cell, and ˉϕαβ are the products of two basis functions.

  • numerical approximation of the gradient n(R)n(R)
  • ϵxc and derivatives evaluated on the grid

vXC[n](r)VXC(R)=ϵxcn(R)

  • real space integration

HμνHXC=μVH,XC(r)νRVH,XC(R)ˉϕαβ(R)

If you have PRINT_LEVEL MEDIUM you can see at each SCF cycle some details of this process - particularly how many electrons and the core charge mapped onto the grids. For instance, for CH2O and a CUTOFF of 400 Ry with GTH pseudos Trace(PS): 12.0000000000

Electronic density on regular grids:        -11.9999999997        0.0000000003
Core density on regular grids:               11.9999999994       -0.0000000006
Total charge density on r-space grids:       -0.0000000003
Total charge density g-space grids:          -0.0000000003

The trace of the density matrix gives us the number of (valence) electrons in the system - 12 in this case

  1. 6 valence e for O
  2. 4 valence e for C
  3. 2 valence e for 2H

We see that 11.9999999997 electrons are mapped onto the grids, along with 11.9999999994 nuclear charge. You should aim for at a very minimum accuracy of 10−8. If not, increase the cutoff.

Energy ripples

Low density regions can cause unphysical behaviour of XC terms (such as n2nα)

GTH pseudos have small density at the core - graph of density and vXC through a water molecule. These spikes can cause ripples in the energy as atoms move relative to the grid. These can be very problematic when trying to calculate vibrational frequencies.

There are smoothing routines `&XC_GRID / XC_DERIV`, see the exercise converging_cutoff.

Avoid ripples with higher a cutoff, or GAPW methodology.

Whatever you do don't change settings between simulations you want to compare.

Multigrids

When we want to put (collocate) a Gaussian type function onto the realspace grid, we can gain efficiency by using multiple grids with differing cutoff / spacing.

More diffuse Gaussians can be collocated onto coarser grids

specified in input as:

  &MGRID
    CUTOFF 400
    REL_CUTOFF 60
    NGRIDS 5
  &END MGRID

you can see in the output

  -------------------------------------------------------------------------------
  ----                             MULTIGRID INFO                            ----
  -------------------------------------------------------------------------------
  count for grid        1:          24832          cutoff [a.u.]          200.00
  count for grid        2:          11934          cutoff [a.u.]           66.67
  count for grid        3:           6479          cutoff [a.u.]           22.22
  count for grid        4:           1976          cutoff [a.u.]            7.41
  count for grid        5:            215          cutoff [a.u.]            2.47
  total gridlevel count  :          45436

For this system (formaldeyhde with an aug-TZV2P-GTH basis) that 45436 density matrix elements (ˉϕαβ) were mapped onto the grids. To be efficient, all grids should be used.

To fully converge calculations both CUTOFF and REL_CUTOFF need to be increased together otherwise the highest grid may not be used.

Timings

At the end of the run you'll see timings - these can be very useful for understanding performance.

Here we can see the timings for the formaldehyde example. It is in a large box, and the operations on grids dominate the cost on a single processor.

 -------------------------------------------------------------------------------
 -                                                                             -
 -                                T I M I N G                                  -
 -                                                                             -
 -------------------------------------------------------------------------------
 SUBROUTINE                       CALLS  ASD         SELF TIME        TOTAL TIME
                                MAXIMUM       AVERAGE  MAXIMUM  AVERAGE  MAXIMUM
 CP2K                                 1  1.0    0.013    0.013   24.048   24.048
 qs_energies                          1  2.0    0.000    0.000   23.417   23.417
 scf_env_do_scf                       1  3.0    0.000    0.000   22.962   22.962
 scf_env_do_scf_inner_loop           14  4.0    0.001    0.001   22.962   22.962
 qs_ks_update_qs_env                 14  5.0    0.000    0.000   19.555   19.555
 rebuild_ks_matrix                   14  6.0    0.000    0.000   19.554   19.554
 qs_ks_build_kohn_sham_matrix        14  7.0    0.002    0.002   19.554   19.554
 qs_vxc_create                       14  8.0    0.000    0.000    8.977    8.977
 xc_vxc_pw_create                    14  9.0    0.273    0.273    8.977    8.977
 xc_rho_set_and_dset_create          14 10.0    0.086    0.086    8.147    8.147
 pw_transfer                        203  9.2    0.009    0.009    7.539    7.539
 fft_wrap_pw1pw2                    203 10.2    0.001    0.001    7.530    7.530
 pw_poisson_solve                    14  8.0    0.458    0.458    7.457    7.457
 xc_functional_eval                  14 11.0    0.000    0.000    7.395    7.395
 pbe_lda_eval                        14 12.0    7.394    7.394    7.394    7.394
 fft_wrap_pw1pw2_200                 87 10.8    0.400    0.400    7.147    7.147
 fft3d_s                            204 12.1    4.799    4.799    4.805    4.805
 qs_rho_update_rho                   15  5.0    0.000    0.000    3.631    3.631
 calculate_rho_elec                  15  6.0    0.711    0.711    3.631    3.631
 ps_wavelet_solve                    14  9.0    3.418    3.418    3.496    3.496
 density_rs2pw                       15  7.0    0.001    0.001    2.882    2.882
 sum_up_and_integrate                14  8.0    0.040    0.040    1.917    1.917
 integrate_v_rspace                  14  9.0    0.378    0.378    1.877    1.877
 potential_pw2rs                     14 10.0    0.005    0.005    1.498    1.498
 pw_gather_s                        104 11.5    1.274    1.274    1.274    1.274
 pw_scatter_s                        99 12.8    1.028    1.028    1.028    1.028
 pw_nn_compose_r                     84 10.5    0.968    0.968    0.968    0.968
 pw_poisson_rebuild                  14  9.0    0.000    0.000    0.897    0.897
 ps_wavelet_create                    1 10.0    0.000    0.000    0.897    0.897
 RS_z_slice_distribution              1 11.0    0.897    0.897    0.897    0.897
 qs_init_subsys                       1  2.0    0.001    0.001    0.567    0.567
 qs_env_setup                         1  3.0    0.000    0.000    0.563    0.563
 qs_env_rebuild_pw_env                2  3.5    0.000    0.000    0.563    0.563
 pw_env_rebuild                       1  5.0    0.000    0.000    0.563    0.563
 pw_grid_setup                        5  6.0    0.000    0.000    0.516    0.516
 pw_grid_setup_internal               5  7.0    0.012    0.012    0.516    0.516
 -------------------------------------------------------------------------------

Warnings

Also check if you get an output like

The number of warnings for this run is : 0

if there are warnings, you should try and understand why!

events/2016_summer_school/gpw.txt · Last modified: 2020/08/21 10:15 by 127.0.0.1