MQ Intro
MQ Intro
Numerical Methods in
Quantum Mechanics
Paolo Giannozzi
University of Udine
Introduction 1
0.1 About Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
0.1.1 Compilers . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
0.1.2 Visualization Tools . . . . . . . . . . . . . . . . . . . . . . 2
0.1.3 Mathematical Libraries . . . . . . . . . . . . . . . . . . . 2
0.1.4 Pitfalls in C-Fortran interlanguage calls . . . . . . . . . . 3
0.2 Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
i
3.3 Code: crossection . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
3.3.1 Laboratory . . . . . . . . . . . . . . . . . . . . . . . . . . 30
6 Self-consistent Field 47
6.1 The Hartree Approximation . . . . . . . . . . . . . . . . . . . . . 47
6.2 Hartree Equations . . . . . . . . . . . . . . . . . . . . . . . . . . 48
6.2.1 Eigenvalues and Hartree energy . . . . . . . . . . . . . . . 49
6.3 Self-consistent potential . . . . . . . . . . . . . . . . . . . . . . . 50
6.3.1 Self-consistent potential in atoms . . . . . . . . . . . . . . 50
6.4 Code: helium hf radial . . . . . . . . . . . . . . . . . . . . . . . . 51
6.4.1 Laboratory . . . . . . . . . . . . . . . . . . . . . . . . . . 52
8 Molecules 60
8.1 Born-Oppenheimer approximation . . . . . . . . . . . . . . . . . 60
8.2 Potential Energy Surface . . . . . . . . . . . . . . . . . . . . . . . 61
8.3 Diatomic molecules . . . . . . . . . . . . . . . . . . . . . . . . . . 62
8.4 Code: h2 hf gauss . . . . . . . . . . . . . . . . . . . . . . . . . . 63
8.4.1 Gaussian integrals . . . . . . . . . . . . . . . . . . . . . . 64
8.4.2 Laboratory . . . . . . . . . . . . . . . . . . . . . . . . . . 65
ii
9 Electrons in periodic potential 67
9.1 Crystalline solids . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
9.1.1 Periodic Boundary Conditions . . . . . . . . . . . . . . . 68
9.1.2 Bloch Theorem . . . . . . . . . . . . . . . . . . . . . . . . 69
9.1.3 The empty potential . . . . . . . . . . . . . . . . . . . . . 69
9.1.4 Solution for the crystal potential . . . . . . . . . . . . . . 70
9.1.5 Plane-wave basis set . . . . . . . . . . . . . . . . . . . . . 71
9.2 Code: periodicwell . . . . . . . . . . . . . . . . . . . . . . . . . . 73
9.2.1 Laboratory . . . . . . . . . . . . . . . . . . . . . . . . . . 74
10 Pseudopotentials 75
10.1 Three-dimensional crystals . . . . . . . . . . . . . . . . . . . . . . 75
10.2 Plane waves, core states, pseudopotentials . . . . . . . . . . . . . 76
10.3 Code: cohenbergstresser . . . . . . . . . . . . . . . . . . . . . . . 77
10.3.1 Laboratory . . . . . . . . . . . . . . . . . . . . . . . . . . 79
12 Density-Functional Theory 86
12.1 Hohenberg-Kohn theorem . . . . . . . . . . . . . . . . . . . . . . 86
12.2 Kohn-Sham equations . . . . . . . . . . . . . . . . . . . . . . . . 87
12.3 Approximated functionals . . . . . . . . . . . . . . . . . . . . . . 88
12.4 Structure of a DFT code . . . . . . . . . . . . . . . . . . . . . . . 89
12.4.1 Matrix elements of the potential . . . . . . . . . . . . . . 90
12.4.2 FFT and FFT grids . . . . . . . . . . . . . . . . . . . . . 91
12.4.3 Computing the charge density . . . . . . . . . . . . . . . . 92
12.4.4 Computing the potential . . . . . . . . . . . . . . . . . . . 93
iii
Introduction
0.1.1 Compilers
In order to run a code written in any programming language, we must first
translate it into machine language, i.e. a language that the computer can
understand. The translation is done by an interpreter or by a compiler: the
former translates and immediately executes each instruction, the latter takes
the file, produces the so-called object code that together with other object codes
and with libraries is finally assembled into an executable file. Python, Java (or at
1
an higher level, Matlab, Mathematica) are examples of “interpreted” language.
Fortran, C, C++ are “compiled” languages.
Our codes are written in Fortran 90 (or 95, or later). This is a sophisti-
cated and complex language offering dynamical memory management, arrays
operations (e.g. matrix-vector products), modular and object-based structure.
Fortran 90 maintains a wide compatibility with existing Fortran 77 codes, while
remaining as efficient as Fortran 77 was. It is worth mentioning that the first
applications of computers to physics go back to well before the birth of modern
computer languages like C++, python, or even C: there is a large number of
codes and libraries written in Fortran 77 (or even Fortran 66!) and still widely
used in physics. Even among physicist, however, Fortran is no longer as com-
mon and widespread as it used to be. Resources are still easy to find: see for
instance the web page mentioned in the bibliography section. The codes them-
selves are very simple and make little usage of advanced language features. In
any case, there is no problem if a student prefers to use a more widespread
language like C/C++. A version of all codes in C is also available, with no
warranty about the quality of the C code in terms of elegance and good coding
practice.
In all cases, you need a C or Fortran compiler. The C compiler gcc is
free and can be installed on all operating systems (in Linux PCs it is always
present). Less-then-archaic versions of gcc include a Fortran compiler, called
gfortran.
2
routines for all CPU-intensive calculations. The latter are available in highly
optimized form for many different architectures.
BLAS and LAPACK routines are written in Fortran 77. They are often
found precompiled on many machines and can be linked directly by the com-
piler by adding -llapack -lblas. If called by a C code, it may be needed to
add an underscore ( ) in the calling program, as in: dsyev , dgemm . This is
due to different C-Fortran conventions for the naming of “symbols” (i.e. com-
piled routines). Note that the C compiler may also need -lm to link general
mathematical libraries (i.e. operations like the square root).
3
0.2 Bibliography