Lecture notes
Numerical Methods in
Quantum Mechanics
Corso di Laurea Magistrale in Fisica
Interateneo Trieste – Udine
Anno accademico 2012/2013
Paolo Giannozzi
University of Udine
Contains software and material written by
Furio Ercolessi1 and Stefano de Gironcoli2
1Formerly at University of Udine
2SISSA - Trieste
Last modified May 23, 2013
Contents
1
About Software . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1
Compilers . . . . . . . . . . . . . . . . . . . . . . . . . . .
1
Visualization Tools . . . . . . . . . . . . . . . . . . . . . .
2
. . . . . . . . . . . . . . . . . . .
2
Pitfalls in C-Fortran interlanguage calls . . . . . . . . . .
3
. . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4
5
The harmonic oscillator . . . . . . . . . . . . . . . . . . . . . . .
5
. . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6
. . . . . . . . . . . . . . . . . . . . . . . .
6
Comparison with classical probability density . . . . . . .
8
Quantum mechanics and numerical codes: some observations . .
9
Quantization . . . . . . . . . . . . . . . . . . . . . . . . .
9
A pitfall: pathological asymptotic behavior . . . . . . . .
9
Numerov’s method . . . . . . . . . . . . . . . . . . . . . . . . . .
10
Code: harmonic0 . . . . . . . . . . . . . . . . . . . . . . .
12
Code: harmonic1 . . . . . . . . . . . . . . . . . . . . . . .
13
Laboratory . . . . . . . . . . . . . . . . . . . . . . . . . .
15
odinger equation for central potentials
16
Variable separation . . . . . . . . . . . . . . . . . . . . . . . . . .
16
Radial equation . . . . . . . . . . . . . . . . . . . . . . . .
18
Coulomb potential . . . . . . . . . . . . . . . . . . . . . . . . . .
18
Energy levels . . . . . . . . . . . . . . . . . . . . . . . . .
20
Radial wave functions . . . . . . . . . . . . . . . . . . . .
20
Code: hydrogen radial . . . . . . . . . . . . . . . . . . . . . . . .
21
Logarithmic grid . . . . . . . . . . . . . . . . . . . . . . .
21
Improving convergence with perturbation theory . . . . .
22
Laboratory . . . . . . . . . . . . . . . . . . . . . . . . . .
24
25
Short reminder of the theory of scattering . . . . . . . . . . . . .
25
Scattering of H atoms from rare gases . . . . . . . . . . . . . . .
27
Derivation of Van der Waals interaction . . . . . . . . . .
27
i
Code: crossection . . . . . . . . . . . . . . . . . . . . . . . . . . .
28
Laboratory . . . . . . . . . . . . . . . . . . . . . . . . . .
30
32
Variational Principle . . . . . . . . . . . . . . . . . . . . . . . . .
32
Demonstration of the variational principle . . . . . . . . .
32
Alternative demonstration of the variational principle . .
33
Ground state energy . . . . . . . . . . . . . . . . . . . . .
34
Variational method in practice . . . . . . . . . . . . . . .
35
Secular problem . . . . . . . . . . . . . . . . . . . . . . . . . . . .
35
Expansion into a basis set of orthonormal functions
. . .
36
Plane-wave basis set . . . . . . . . . . . . . . . . . . . . . . . . .
38
Code: pwell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
39
Diagonalization routines . . . . . . . . . . . . . . . . . . .
40
Laboratory . . . . . . . . . . . . . . . . . . . . . . . . . .
41
42
Non-orthonormal basis set . . . . . . . . . . . . . . . . . . . . . .
42
Gaussian functions . . . . . . . . . . . . . . . . . . . . . .
44
Exponentials . . . . . . . . . . . . . . . . . . . . . . . . .
44
Code: hydrogen gauss . . . . . . . . . . . . . . . . . . . . . . . .
44
Laboratory . . . . . . . . . . . . . . . . . . . . . . . . . .
46
47
The Hartree Approximation . . . . . . . . . . . . . . . . . . . . .
47
Hartree Equations . . . . . . . . . . . . . . . . . . . . . . . . . .
48
Eigenvalues and Hartree energy . . . . . . . . . . . . . . .
49
Self-consistent potential . . . . . . . . . . . . . . . . . . . . . . .
50
Self-consistent potential in atoms . . . . . . . . . . . . . .
50
Code: helium hf radial . . . . . . . . . . . . . . . . . . . . . . . .
51
Laboratory . . . . . . . . . . . . . . . . . . . . . . . . . .
52
The Hartree-Fock approximation
53
Hartree-Fock method . . . . . . . . . . . . . . . . . . . . . . . . .
53
Coulomb and exchange potentials . . . . . . . . . . . . . .
55
Correlation energy . . . . . . . . . . . . . . . . . . . . . .
56
The Helium atom . . . . . . . . . . . . . . . . . . . . . . .
57
Code: helium hf gauss . . . . . . . . . . . . . . . . . . . . . . . .
57
Laboratory . . . . . . . . . . . . . . . . . . . . . . . . . .
59
60
Born-Oppenheimer approximation . . . . . . . . . . . . . . . . .
60
Potential Energy Surface . . . . . . . . . . . . . . . . . . . . . . .
61
Diatomic molecules . . . . . . . . . . . . . . . . . . . . . . . . . .
62
. . . . . . . . . . . . . . . . . . . . . . . . . .
63
Gaussian integrals . . . . . . . . . . . . . . . . . . . . . .
63
Laboratory . . . . . . . . . . . . . . . . . . . . . . . . . .
64
ii
Electrons in a periodic potential
66
Crystalline solids . . . . . . . . . . . . . . . . . . . . . . . . . . .
66
. . . . . . . . . . . . . . .
67
Bloch Theorem . . . . . . . . . . . . . . . . . . . . . . . .
68
The empty potential . . . . . . . . . . . . . . . . . . . . .
68
Solution for the crystal potential . . . . . . . . . . . . . .
69
Plane-wave basis set . . . . . . . . . . . . . . . . . . . . .
70
Code: periodicwell . . . . . . . . . . . . . . . . . . . . . . . . . .
72
Laboratory . . . . . . . . . . . . . . . . . . . . . . . . . .
73
74
10.1 Three-dimensional crystals . . . . . . . . . . . . . . . . . . . . . .
74
10.2 Plane waves, core states, pseudopotentials . . . . . . . . . . . . .
75
10.3 Code: cohenbergstresser . . . . . . . . . . . . . . . . . . . . . . .
76
10.3.1 Laboratory . . . . . . . . . . . . . . . . . . . . . . . . . .
78
11 Exact diagonalization of quantum spin models
79
11.1 The Heisenberg model . . . . . . . . . . . . . . . . . . . . . . . .
79
11.2 Hilbert space in spin systems . . . . . . . . . . . . . . . . . . . .
80
11.3 Iterative diagonalization . . . . . . . . . . . . . . . . . . . . . . .
81
11.4 Code: heisenberg exact . . . . . . . . . . . . . . . . . . . . . . 82
11.4.1 Computer Laboratory . . . . . . . . . . . . . . . . . . . .
83
A From two-body to one-body problem
85
B Accidental degeneracy and dynamical symmetry
87
C Composition of angular momenta: the coupled representation 88
90
D.1 Perturbative Treatment for Helium atom . . . . . . . . . . . . . .
91
D.2 Variational treatment for Helium atom . . . . . . . . . . . . . . .
92
D.3 ”Exact” treatment for Helium atom
. . . . . . . . . . . . . . . .
93
D.3.1 Laboratory . . . . . . . . . . . . . . . . . . . . . . . . . .
95
96
E.1 Search of the zeros of a function
. . . . . . . . . . . . . . . . . .
96
Bisection method . . . . . . . . . . . . . . . . . . . . . . .
96
Newton-Raphson method . . . . . . . . . . . . . . . . . .
97
Secant method . . . . . . . . . . . . . . . . . . . . . . . .
97
iii
Introduction
The aim of these lecture notes is to provide an introduction to methods and
techniques used in the numerical solution of simple (non-relativistic) quantum-
mechanical problems, with special emphasis on atomic and condensed-matter
physics. The practical sessions are meant to be a sort of “computational lab-
oratory”, introducing the basic ingredients used in the calculation of materials
properties at a much larger scale. The latter is a very important field of today’s
computational physics, due to its technological interest and potential applica-
tions.
The codes provided during the course are little more than templates. Stu-
dents are expected to analyze them, to run them under various conditions, to
examine their behavior as a function of input data, and most important, to
interpret their output from a physical point of view. The students will be asked
to extend or modify those codes, by adding or modifying some functionalities.
For further insight on the theory of Quantum Mechanics, many excellent
textbooks are available (e.g. Griffiths, Schiff, or the ever-green Dirac and Lan-
dau). For further insight on the properly computational aspects of this course,
we refer to the specialized texts quotes in the Bibliography section, and in
particular to the book of Thijssen.
0.1
About Software
This course assumes some basic knowledge of how to write and execute simple
programs, and how to plot their results. All that is needed is a fortran or C
compiler and some visualization software. The target machine is a PC running
Linux, but other operating systems can be used as well (including Mac OS-X
and Windows), as long as the mentioned software is installed and working, and
if you know how to use it in oractise.
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.
This is a sophisticated and com-
plex language offering dynamical memory management, arrays operations (e.g.
matrix-vector products), modular and object-based structure. Fortran 90 how-
ever can be as efficient as Fortran 77 and maintains a wide compatibility with
existing Fortran 77 codes. 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 still a large number of codes
and libraries written in Fortran 77 (or even Fortran 66!) widely used in physics.
Fortran 90 (or even Fortran 77, in this respect) is not a well known language.
There are however many available resources (see for instance the web page
mentioned in the bibliography section) and the codes themselves are very simple
and make little usage of advanced language features. In any case, there are no
objections if a student prefers to use a more widespread language like C. A
version of all codes in C is also available (no warranty about the quality of the
C code in terms of elegance and good coding practice).
In all cases, we need a C or Fortran 90 compiler. In PCs running Linux, the
C compiler gcc is basically part of the operating system and is always present.
Recent versions of gcc also include a Fortran compiler, called gfortran. If this
is absent, or it is not easy to install it, one can download the free and rather
reliable compiler, g951. It is possible to install on Mac OS-X and on Windows either gcc with gfortran or g95.
0.1.2
Visualization Tools
Visualization of data produced by the codes (wave functions, charge densities,
various other quantities) has a central role in the analysis and understanding
of the results. Code gnuplot can be used to make two-dimensional or three-
dimensional plots of data or of analytical expressions. gnuplot is open-source
software, available for all operating systems and usually found pre-installed on
Linux PCs. An introduction to gnuplot, with many links to more resources,
can be found here: http://www.gnuplot.info/help.html.
Another software that can be used is xmgrace2. This is also open-source and highly portable, has a graphical user interface and thus it is easier to use
than gnuplot, whose syntax is not always easy to remember.
0.1.3
Mathematical Libraries
The usage of efficient mathematical libraries is crucial in “serious” calculations.
Some of the codes use routines from the BLAS3 (Basic Linear Algebra Sub-programs) library and from LAPACK4 (Linear Algebra PACKage). The latter
2http://plasma-gate.weizmann.ac.il/Grace
2
is an important and well-known library for all kinds of linear algebra oper-
ations: solution of linear systems, eigenvalue problems, etc. LAPACK calls
BLAS 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. BLAS and LA-
PACK are often available in many operating systems and can be linked directly
by the compiler by adding -llapack -lblas. In the case of C compiler, 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 “sym-
bols” (i.e. compiled routines). Note that the C compiler may also need -lm to
link general mathematical libraries (i.e. operations like the square root).
0.1.4
Pitfalls in C-Fortran interlanguage calls
In addition to the above-mentioned potential mismatches between C and For-
tran naming conventions, there are a few more pitfalls one has to be aware of
when Fortran 77 routines are called by C (or vice versa).
• Fortran passes pointers to subroutines and functions; C passes values. In
order to call a Fortran routine from C, all C variables appearing in the
call must be either pointers or arrays.
• Indices of vectors and arrays start from 0 in C, from 1 in Fortran (unless
differently specified in array declaration or allocation).
• Matrices in C are stored in memory row-wise, that is: a[i][j+1] follows
a[i][j] in memory. In Fortran, they are stored column-wise (the other
way round!): a(i+1,j) follows a(i,j) in memory.
An additional problem is that C does not provide run-time allocatable matrices
like Fortran does, but only