Quantum Monte-Carlo Simulations of Atoms and Molecules
by
Roger Kjøde
THESIS for the degree of MASTER OF SCIENCE
Master in Computational Physics
Faculty of Mathematics and Natural Sciences Department of Physics
University of Oslo
June 2016
2
3
Preface
I always found the sciences interesting, so the step of enrolling at the Uni- versity in Oslo was an easy one. I believe I should know something about physics, but there is still a lot I don't know. (and I feel I should know.)
I started early with programming, when we got our rst computer. An Amstrad cpc 464. 1 MHz 64 kb ram computer. and I have been program- ming ever since.
In this thesis we use c++ and python. The main Monte-carlo algorithm is written in c++, and python is used to generate c++ code. Symbolic Python (Sympy) is used extensively in this thesis in order to autogenerate code.
Thanks to my supervisor Professor Morten Hjorth-Jensen for all help with this thesis.
4
Contents
1 Introduction 9
I Theory 11
2 Physical theory 13
2.1 The Schrödinger equation . . . 13
2.1.1 Time-independent Schrödinger equation . . . 14
2.1.2 The Schrödinger equation in 3 dimensions . . . 14
2.2 The potential . . . 15
2.3 The Born-Oppenheimer approximation . . . 16
2.4 Atomic units . . . 16
2.5 Scaling . . . 16
2.6 The variance. . . 17
2.7 Slater determinant . . . 17
2.8 Jastrow factor . . . 18
2.9 Full wave function . . . 18
2.10 Hartree-Fock . . . 18
2.11 Spin . . . 19
3 Quantum Monte-Carlo 21 3.1 Monte Carlo integration . . . 21
3.2 Importance sampling . . . 21
3.3 The Metropolis Algorithm . . . 22
3.4 Computing the energy . . . 23
3.5 The variational principle . . . 25
3.6 The Local energy . . . 26
4 Optimizations 27 4.1 Optimizing the Slater determinant . . . 27
4.2 Optimizing the Slater ratio . . . 28 5
6 CONTENTS
4.3 Optimizing the ∇i|S|/|S| ratio. . . 28
4.4 Optimizing the ∇2i|S|/|S| ratio. . . 29
4.5 Updating the inverse Slater determinant. . . 29
4.6 Optimizing the Jastrow ratio . . . 29
4.7 Optimizing the ∇JiJ Ratio. . . 30
4.8 Optimizing the ∇J2iJ Ratio . . . 31
5 Orbitals 33 5.1 Hydrogen orbitals . . . 33
5.2 Gaussian orbitals . . . 35
5.3 The gradient and laplacian of the orbitals. . . 39
6 Calculation of Molecules, Blocking and Optimized Varia- tional Parameters 41 6.1 Homonuclear Diatomic Molecules . . . 41
6.2 Random numbers . . . 42
6.3 Blocking . . . 43
6.4 Gradient descent . . . 43
6.5 Parallelization . . . 44
6.6 Errors . . . 45
7 How to code VMC 49 7.1 The C++ les . . . 49
7.2 The Python les . . . 50
7.3 C++ code . . . 50
7.3.1 Main MVC algorithm . . . 51
7.3.2 Local energy code . . . 53
7.3.3 Quantum Force . . . 57
7.3.4 Update inverse Slater determinant. . . 58
7.3.5 Oprimized code for Slater ratio. . . 60
7.3.6 Optimized code for Jastrow factor. . . 61
7.3.7 Cusp condition algorithm. . . 62
II Results 63
8 Results 65 8.1 The output . . . 658.2 About the tables. . . 66
8.3 Atoms . . . 67
8.3.1 Using Hydrogenic orbitals . . . 67
CONTENTS 7
8.3.2 Using Gaussian orbitals . . . 69
8.4 Molecules . . . 71
8.4.1 Using Hydrogenic orbitals . . . 71
8.4.2 Using Gaussian orbitals . . . 73
8.5 Time used in VMC. . . 75
8.6 Conclusion . . . 78
9 Conclusions 79 9.1 The point of the thesis . . . 79
9.2 C++ and Python . . . 79
9.3 Results . . . 79
9.4 Eniency of the code. . . 80
9.5 Further work . . . 80
III Appendix 81
A Programming languages 83 A.1 Computer programs in general . . . 83A.2 C++ . . . 83
A.2.1 Variables . . . 84
A.2.2 Arrays . . . 84
A.2.3 Includes . . . 84
A.2.4 Namespace . . . 85
A.2.5 Loops . . . 85
A.2.6 If test . . . 86
A.2.7 Case . . . 86
A.2.8 Objects . . . 87
A.2.9 Functions . . . 88
A.2.10 Accessibility levels . . . 88
A.2.11 Armadillo . . . 89
A.2.12 MPI . . . 89
A.2.13 Output . . . 90
A.3 Python . . . 90
A.3.1 Variables . . . 90
A.3.2 Loops . . . 91
A.3.3 If test . . . 91
A.3.4 Objects . . . 91
A.3.5 Exec . . . 92
A.3.6 Symbolic Python . . . 92
A.3.7 C++ code . . . 93
8 CONTENTS A.3.8 Printing to le. . . 93
Chapter 1 Introduction
The introduction of computers opens up a new world to the sciences. Prob- lems which before were impossible to solve are now possible to solve.
The aim of this thesis is to develop an Ab initio approach to dierent atomic and diatomic systems. We will use Monte-carlo methods to avoid heavy integrals when solving the Schrödinger equation. The Schrödinger equation cannot be solved analytically, except for some very trivial systems.
Our method of choice is Variational Monte-Carlo (VMC) which is used to nd the ground state of a quantum system.
We use trial wave functions to build a Slater determinant with is used in the simulation. We use both hydrogenic orbitals and Gaussian orbitals.
A correlation function (Jastrow factor) is used to improve the results. The Jastrow factor describes the particle-particle correlation of the system.
The goal is to nd the binding energy of the electrons in many dierent atoms and simple molecules. The calculations have been performed at the local supercomputing facility Abel. With Abel many simulations can be run in parallel. With Monte-Carlo paralellization is very easy.
In this thesis we will look at atoms with even number of electrons. We look at systems like He, Be, Ne, Ar and Kr. We also look at simple diatomic molecules, from the light H2 to the heavier O2. In theory we can solve for heavier atoms and molecules.
The code for this thesis can be found at https://github.com/rogerkj/
master. Here you will nd all the c++ code and all Python scripts used to generate the nal c++ code.
The prerequisite for reading this thesis is an understanding of basic calcu- 9
10 CHAPTER 1. INTRODUCTION lus and statistical methods. The goal is to make it understandable for most people, but an explanation of basic math is not included. An understanding of quantum physics is not required but will make this thesis easier to under- stand.
In Appendix A we give a basic introduction to c++ and Python pro- gramming. In this thesis we use the linear algebra library Armadillo, which makes the code easy to read.
The structure
• In chapter 2 we will develop the physics and methods used in this thesis.
The Schrödinger equation is used here.
• In chapter 3 we will then look at the Monte-Carlo method. We will develop the Metropolis algorithm and nd an expression for the local energy. We will also introduce importance sampling.
• In chapter 4 we will look at optimizations of the algorithm. Here we use the inverse Slater determinant to optimize the algorithm. The Jastrow factor will also be optimalized.
• In chaper 5 we will look at the orbitals used in this thesis. We use either hydrogenic orbitals or we use Gaussian orbitals.
• In chapter 6 we will look at at various topics as homonuclear molecules, random numbers, blocking, gradient descent, parallelization and a source of errors.
• In chapter 7 we will look at some of the code used in this thesis. Not all code will be discussed but the most important parts are emphasized in the main text.
• In chapter 8 we will look at the results from the VMC program devel- oped for this thesis.
• In chapter 9 we will conclude this thesis with a few words.
• In appendix A we give a short introduction to c++ and python pro- gramming.
Part I Theory
11
Chapter 2
Physical theory
2.1 The Schrödinger equation
The basis for this thesis is the Schrödinger equation, which represents the law of motion for quantum systems.
Here we give a brief survey of the essentials behind the Schrödinger equa- tion.
The time dependent Schrödinger equation (SE) for one particle moving in a potential V is: [1]
i~∂Ψ
∂t =− ~2 2m
∂2Ψ
∂x2 + ˆVΨ, (2.1)
where Ψ represents the wave function. The wavefunction Ψ is a function of time, t and position, x. The product Ψ∗Ψ = |Ψ|2 is interpreted as the probability density of a given state. In one dimension the probability for a particle to be between two points a and b is given as
Z b
a
|Ψ(x, t)|2dx, x∈[a, b]. (2.2) The probability is normalized
Z ∞
−∞
|Ψ(x, t)|2dx= 1. (2.3) We have also the corresponding quantum mechanical representations of the dierent classical operators: [7]
13
14 CHAPTER 2. PHYSICAL THEORY
Quantity Classical QM operator
Position r ˆr=r
momentum p pˆ =−i~∇
Orbital momentum L=r×p Lˆ =r×(−~∇) Kinetic energy T = (p)2/2m Tˆ =−(~2/2m)(∇)2
Total energy H = (p)2/2m+V(r) Hˆ =−(~2/2m)(∇)2 +V(r)
2.1.1 Time-independent Schrödinger equation
We use the method of separation of variables, and look for solutions for the product:
Ψ(x, t) = ψ(x)ϕ(t). (2.4)
We now insert this into the full SE and divide by ψϕwe get:
i~1 ϕ
dϕ
dt =−~2 2m
1 ψ
d2ψ
dx2 +V(x). (2.5)
We now see that the left side depends only on time tand the right side is only dependent on x. This means the expressions are constant. We will call this constant E. This gives us two equations:
dϕ
dt =−iE
~ ϕ, (2.6)
−~2 2m
d2ψ
dx2 +V ψ=Eψ (2.7)
Equation (2.7) is called the Time-independent Schrödinger equation.
Equation (2.6) has the solution:
ϕ(t) =e−iEt/~. (2.8)
This is just a phase and dissapears when we calculate Ψ∗Ψ.
2.1.2 The Schrödinger equation in 3 dimensions
We introduce the Laplacian in Cartesian coordinates: [1]
∇2 = ∂2
∂x2 + ∂2
∂y2 + ∂2
∂z2. (2.9)
2.2. THE POTENTIAL 15 The Time-independent Schrödinger equation then becomes
− ~2
2m∇2ψ+V ψ=Eψ. (2.10)
This is the main equation used in this thesis, and is often written as
Hψˆ =Eψ. (2.11)
Here Hˆ is the Hamiltonian.
We can also derive the time independent Schrödinger equation in another way. The classical Hamiltonian reads: [11]
H(x, p) = p2
2m +V(x). (2.12)
By substitution p= (~/i)(d/dx) [7] for the quantum mechanical momen- tum operator. This gives
Hˆ =−~2 2m
∂2
∂x2 +V(x). (2.13)
2.2 The potential
We now need a complete expression for Hˆ.
The Hamiltonian consists of two parts, kinetic and potential energy H(x) = ˆˆ T(x) + ˆV(x). (2.14) We look at the rst term, which is the kinetic energy,
T = P2 2M +
N
X
j=1
p2j
2m. (2.15)
We use the quantum operator pk → −i~∂/∂xk, taken from [7]. This gives us
Tˆ(x) =− ~2 2M∇20−
N
X
j=1
~2
2m∇2j. (2.16)
We now look at the potential part of the Hamiltonian [5], Vˆ(x) = −
N
X
j=1
Ze2 (4π0)rj +
N
X
i=1,i<j
e2
(4π0)rij. (2.17)
16 CHAPTER 2. PHYSICAL THEORY
2.3 The Born-Oppenheimer approximation
We know the proton-electron mass ratio is around 1/1836 and the neutron- electron mass ratio is about 1/1839. We will use the Born-Oppenheimer approximation [10] and consider only electronic degrees of freedom, The kinetic energy is then only given by the kinetic energy of the various electrons, namely,
Tˆ=−
N
X
j=1
~2
2m∇2j. (2.18)
2.4 Atomic units
In this thesis we use atomic units in our calculations. This means we set
m=e=~= 4π0 = 1. (2.19)
This gives us the equation:
h−
N
X
i=1
1 2∇2i −
N
X
i=1
Z ri +
N
X
i<j
1 rij
i
ψ(x) = Eψ(x). (2.20)
2.5 Scaling
We will work in atomic units. To convert between SI units we need to use the conversion factors of table 2.1 [7]
Table 2.1: Scaling table
Quantity Si Atomic Units
Electron mass, m 9.109∗10−31 kg 1
Charge, w 1.602∗10−19 C 1
Planck's reduced constant, ~ 1.055∗10−34 Js 1 Permibility, 4π0 1.113∗10−10C2J−1m−1 1
Energy, 4πe2oa0 27.211eV 1
Length, a0 = 4πme02~2 0.529∗10−10 1
2.6. THE VARIANCE. 17
2.6 The variance.
We can now look at the expectation value of the Hamiltonian hHi=
Z
ψ∗Hψdxˆ =E Z
|ψ|2dx=E. (2.21) We can also look at hH2i
hH2i= Z
ψ∗Hˆ2ψdx=E Z
ψ∗Hψdxˆ =E2 Z
|ψ|2dx=E2. (2.22) This gives us a variance and standard deviation of zero if we have the exact eigenfunctions, namely
σH2 =hH2i − hHi2 =E2−E2 = 0. (2.23) If this is to be true the wave function must be the exact correct wave- function. The variance is therefore a good measure of how good our trial wavefunction is.
2.7 Slater determinant
As a trial wavefunction we use a Slater determinant. [12] We see that if two rows are equal the determinant becomes zero. This follows from the Pauli principle [11] which states that the total wavefunction of a fermionic system has to be antisymmetric. As a consequence, when using a single-particle basis, no single-particle state can be occupied by more than one fermion. If two rows of the slater determinant is equal the determinant becomes zero.
The Slater determinant is antisymmetric under the interchange of any pair of fermions. The Slater determinant is given by
ψ = 1
√N
χ1(x1) χ2(x1) . . . χN(x1) χ1(x2) χ2(x2) . . . χN(x2)
... ... ... ...
χ1(xN) χ2(xN) . . . χN(xN)
, (2.24)
where the various functions χi represent single-particle states. We will use both hydrogenic and Gaussian orbitals to represent hese. Since the Hamilto- nian is spin independent, we can here split the Slater determinant into two parts. [7] This gives us
ψ ∝Det↑Det↓=|S ↑ ||S ↓ |. (2.25) We will use both hydrogenic orbitals and Gaussian orbitals.
18 CHAPTER 2. PHYSICAL THEORY
2.8 Jastrow factor
The Slater determinant is not the whole story. To include two-body and higher order correlation eects we need a Jastrow factor. [7] This factors cancels also out the divergency in the relative distance when two electrons get close to each other. The ideea is to make the trial wavefunction closer to the real one.
J =
N
Y
i<j
exp aijrij 1 +βrij
. (2.26)
Herei andj are indeces that refer to dierent particles. Hereaij is 0.5 if the spins of i and j are parallel and 0.25 if they are not.
We will later see if this Jastrow factor gives us a better result than without.
We will test both.
2.9 Full wave function
We have now the full wave function as the product of spin up and spin down Slater determinants and the jastrow factor
ψ =|S ↑ ||S ↓ |J. (2.27)
2.10 Hartree-Fock
The Hartree-Fock method is used to solve the time-independent Schrödinger equation.
This method uses ve major simplications. [13]
• The Born-Oppenheimer approximation is assumed
• Relativistic eects are neglected
• The solution is a linear combination of basis functions
• The ansatz for the ground state is a Slater determinant
• Electron correlations beyond one-particle-one-hole excitations are ne- glected
We will not develop the Hartree-Fock equations in this thesis as they are not directly used in Variational Monte Carlo, however we will later look at Gaussian orbitals which are a result of Hartree-Fock calculations.
2.11. SPIN 19
2.11 Spin
Spin is an intrinsic property of every elementary particle. [11] Half integer spin particles are called Fermions, and make up ordinary matter. Particles with integer spin are called Bosons, such as photons. Fermions must obey the Pauli exclusion principle, which states that no two particles can have the same quantum numbers. (They cannot be in the same position with the same spin)
We see this in the Slater determinant. If two rows are equal the determinant becomes zero.
20 CHAPTER 2. PHYSICAL THEORY
Chapter 3
Quantum Monte-Carlo
3.1 Monte Carlo integration
The Monte Carlo method is a stochastic method for integration using ran- dom variable. It can be used for any number of dimensions. Conventional integration gives us:
Z
Ω
f(x)dΩ =
m
X
i=1
wif(xi). (3.1)
Here wi are weights found by the distribution of the random numbers xi If the evaluation points are equally spaced the weights becomes the length of the interval divided by the number of integration points, m,
Z 1
0
f(x)dxdy= 1 m
Xm
i=1
f(xi) +O(1 m
. (3.2)
We can also do this in two dimensions (or any higher dimension) Z 1
0
Z 1
0
f(x)dx= 1 m2
Xm
i=1 m
X
j=1
f(xi, yj) +O(1 m
. (3.3)
Integration over a d-dimensional cube requires md integration points to get a 1/m order of accuracy. In Variational Monte Carlo which we will develop in this thesis (VMC) we have N particles and each of these have d dimensions so we havemdN integration points to get a1/morder of accuracy.
3.2 Importance sampling
In order to select properly and eciently the integration points, we will use importance sampling, where the Fokker-Planck equation is used to select new
21
22 CHAPTER 3. QUANTUM MONTE-CARLO integration points. The Fokker-Planck equation [10] is given as:
∂P(r, t)
∂t =D∇ ·h
∇ −F(r, t)
P(r, t)i
. (3.4)
The new suggested move part of the algorithm becomes [5]
rnew =rold+χ+DF(roldδt). (3.5) Here χ is a random number and F is the so-called quantum force given by: [6]
F(r, t) = 2
|ψ(r, t)|∇|ψ(r, t)|. (3.6) The factor used in the Metropolis test is then the Greens function. [3]
G(i→j)∝e(xi−xj−DδF(xi))2/4Dδτ. (3.7) These equations can be found in the les mcintegrator.cpp and Quantun- Force.cpp.
3.3 The Metropolis Algorithm
Here we will look at the Metropolis Algorithm [4], which is a Markov chain Monte Carlo (MCMC) method, generally used for sampling from multi- dimensional distributions.
Here we have a reversible Markov prosess. Using detailed balance we have the following ratio between probabilities
PiW(i→j) = PjW(j →i). (3.8) Here Pi is the probability density conguration of i and W(i → j) is the transition probability between states i and j.
We can write W(i→j)as a product between the probability of selection conguration j given i g(i → j) and the probability of accepting a move.
A(i→j)
Pig(i→j)A(i→j) = Pjg(j →i)A(j →i). (3.9)
3.4. COMPUTING THE ENERGY 23 Inserting the probability distribution as the wavefunction squared and the selection probability as the Green's function (See equation (3.7)) We get
|ψi|2G(i→j)A(i→j) =|ψj|2G(j →i)A(j →i). (3.10) A(j →i)
A(i→j) = G(i→j)|ψi|2
G(j →i)|ψj|2 ≡RG(j →i)Rψ(j →i)2. (3.11) A step from a position i to a new position j is automatically accepted so A(i→j) = 1
This leaves us with
A(j →i) =RG(j →i)rψ(j →i)2. (3.12) This gives us the acceptance/rejection rules:
A(i→j) =min(RG(i→j)Rψ(i→j)2,1). (3.13) In the case of VMC without importance sampling we have
A(i→j) =min(Rψ(i→j)2,1) = min(|ψi|2
|ψj|2,1). (3.14) With importance sampling we have the Metropolis/Hasting acceptance ratio given as the ratio of the trial wave function at the new and old positions is given by
R ≡ ψnew
ψold = |S|new↑
|S|old↑
|S|new↓
|S|old↓ Jnew
Jold . (3.15)
The acceptance/rejection ratio then becomes RS =R2G(old, new)
G(new, old) = |ψnew|2
|ψold|2
G(old, new)
G(new, old) (3.16) We use this in the le: mcintegrator.cpp.
3.4 Computing the energy
The expectation value of the energy is: [7]
hEi=
R dRψ∗(R) ˆH(R)ψ(R)
R dRψ∗(R)ψ(R) (3.17)
24 CHAPTER 3. QUANTUM MONTE-CARLO
Figure 3.1: Flowchart of VMC.
3.5. THE VARIATIONAL PRINCIPLE 25 We can rewrite this as
hEi =
R |ψ(R)|2 ˆHψ(R)ψ(R) dR
R |ψ(R|2dR =
Z |ψ(R)|2
R |ψ(R)|2dR
Hψ(R)ˆ ψ(R)
dR. (3.18) We now dene a probability distribution as: [5]
P(R) = |ψT(R)|2
R |ψT(R)|2dR. (3.19)
We dene the local energy as:
EL(R) = 1 ψT(R)
Hψˆ T(R). (3.20)
We will examine this equation in section 3.6.
The expectation value of the energy then becomes hEi=
Z
P(R)EL(R)dR. (3.21)
Since P(R) is a probability distribution we get: [5]
hEi ≈ 1 N
N
XEL(xi). (3.22)
This is the equation used to nd the energy of the system, and is listed in tables in chapter 8.
3.5 The variational principle
The variational principle states that the expectation value of the Hamiltonian is an upper bond to the true ground state energy E0
E0 ≤ hEi. (3.23)
We want to show this by setting the wave function as a sum of eigenstates:
ψT(R) = X
ψi(R). (3.24)
26 CHAPTER 3. QUANTUM MONTE-CARLO We insert this into equation (3.17)
hEi= P
mna∗manR
dRψ∗m(R)H(R)ψn(R) P
mna∗manR
dRψ∗m(R)ψn(R), (3.25)
= P
mna∗manR
dRψ∗m(R)En(R)ψn(R) P
na2n . (3.26)
This can be rewritten as [7]
P
na2nEn P
na2n ≥E0. (3.27)
This shows that the value forhEiis always greater than the true valueE0
3.6 The Local energy
We must nd an analytic expression for the local energy found in equation (3.20)
EL= 1
ψTHψT. (3.28)
EL= 1 ψT
−1 2
N
X
i=1
∇2i −
N
X
i=1 K
X
n=1
Zn
|Rn−ri| +1 2
n
X
i6=j
1
|ri−rj|
ψT. (3.29)
EL= 1 ψT
−1 2
N
X
i=1
∇2i ψT −
N
X
i=1 K
X
n=1
Zn
|Rn−ri| +1 2
n
X
i6=j
1
|ri−rj|. (3.30) We st examine the kinetic energy part. The other parts are trivial. We split the wavefunction into spin up, spin down and a Jastrow factor
∇2ψT
ψT = 1
S↑S↓J∇2(S↑S↓J) =∇(∇S↑S↓J+S↑∇S↓J+S↑s↓∇J), (3.31)
= 1 S↑
∇2S↑+ 1 S↓
∇2S ↓+1
J∇2J + 2( 1 S↑S↓
∇S↑∇S↓+ 1
S↑J∇S↑∇J + 1
S↓J∇S↓∇J).
(3.32) We will look deeper into these equations in chapter 4, where we will nd optimized equations for each term. The c++ implementation of these equations is found in chapter 7.
The implementation for this local energy is found in: LocalEnergyOpt.cpp.
Chapter 4
Optimizations
We here wish to optimize the program, and by using the inverse matrix of the Slater determinant we can save a lot of oating point operations.
Updating the invese for each cycle runs as O(N3) but the optimized algorithm explained below runs as O(N3/4). [7].
We will also look at optimizing the equations containing the Jastrow fac- tor.
4.1 Optimizing the Slater determinant
We dene the Slater matrix S as in equation (2.24) as:
Sij ≡χj(ri), (4.1)
where χj(rj) is thejth wavefuncion of the particle ri. Only the ith particle is moved in each cycle.
For the inverse of the Slater determinant we have from [2]
S−1 = 1
|S|adjS, (4.2)
where adjS is the transpose of the cofactor matrix.
We can rewrite this as the transpose of the cofactor matrix S−1 = CT
|S|, (4.3)
S−1ji = Cij
|S|. (4.4)
27
28 CHAPTER 4. OPTIMIZATIONS Now the determinant can be expressed as a cofactor expansion. (Cramer's rule) [7]
|S|=X
i
SijCji. (4.5)
Then we have:
Cjinew =Cjiold = (Sijold)−1|Sold|. (4.6) We use this as a basis for optimizing the code.
4.2 Optimizing the Slater ratio
We need to nd the Slater ratio
Rs= |S|new
|S|old, (4.7)
RS = |Sold|P
iSjinew(Sijold)−1
|Sold|P
iSjiold(Sijold)−1 , (4.8)
= P
iSjinew(Sijold)−1
Ijj . (4.9)
We can then use this as an optimization.
RS =X
i
χi(rjnew)(Sijold)−1. (4.10) The implementation of this is found in WaveFunction.cpp.
4.3 Optimizing the ∇
i|S|/|S| ratio.
We will now derive the ∇i|S|/|S| ratio using the inverse Slater matrix,
∇i|S|
|S| == ∇iP
kSjiCji P
kSjiCji , (4.11)
= ∇iP
kSji(Sij)−1|S|
P
kSji(Sij)−1|S| , (4.12)
=X
k
∇iχk(rnewi )(Skinew)−1 (4.13) . The implementation for this is found in: QuantumForce.cpp and LocalEn- ergyOpt.cpp.
4.4. OPTIMIZING THE∇2I|S|/|S| RATIO. 29
4.4 Optimizing the ∇
2i|S|/|S| ratio.
We will now derive the ∇2i|S|/|S| ratio using the inverse Slater matrix,
∇2i|S|
|S| = ∇2i P
kSjiCji P
kSjiCji , (4.14)
= ∇2i P
kSji(Sij)−1|S|
P
kSji(Sij)−1|S| , (4.15)
=X
k
∇2iχk(rnewi )(Skinew)−1. (4.16) These expressions speeds up the algorithm. The implementaion of this is found in LocalEnergyOpt.cpp.
4.5 Updating the inverse Slater determinant.
We now want to nd the inverse of the Slater determinant without using the CPU intensive inversion algorithm. For updating the inverse we have [7] to rst we calculate a matrix I˜ij used in the calculation.
I˜ij =X
l
Silnew(Sljold)−1. (4.17) Now we nd all values where j 6=i
(Skjnew)−1 = (Skjold)−1 − 1
RS(Sjiold)−1I˜ijj 6=i. (4.18) Then we nd all values where i=j
(Skinew)−1 = 1
RS(Skiold)−1else. (4.19) Here RS is the Slater ratio found earlier.
The implementation of this is found in WaveFunction.cpp.
4.6 Optimizing the Jastrow ratio
We set
gkj = akjrkj
1 +βrkj. (4.20)
30 CHAPTER 4. OPTIMIZATIONS We can express the Jastrow ratio as.
logJnew Jold =
N
X
k<j=1
h akjrkjnew
1 +βrnewkj − akjrkjold 1 +βroldkj
i
, (4.21)
≡
N
X
k<j=1
[gkjnew−gkjold]. (4.22) Changing ri only changesrij
rkjnew=roldkj k 6=i, (4.23)
logJnew Jold =
N
X
k<j=1
[goldkj −gkjold] +
N
X
j=1
[gnewij −gijold], (4.24)
logJnew Jold =
N
X
j=1
h aijrijnew
1 +βrijnew − aijrijold 1 +βrijold
i
. (4.25)
Taking the exponent on both sides gives Jnew
Jold =expXN
j=1
aijh rnewij
1 +βrnewij − roldij 1 +βroldij
i
. (4.26)
Herei is the moved fermion.
The implementation of this is found in WaveFunction.cpp.
4.7 Optimizing the
∇JiJRatio.
The x component of the Jastrow gradient ratio is then:
1 J
∂J
∂xi = 1 Q
i<jexp(gij)
∂
∂xi Y
i<j
exp(gij). (4.27) Using the product rule we transform the expression to a sum
1 J
∂J
∂xi
=X
i6=j
1 exp(gij)
∂
∂xi
exp(gij), (4.28)
=X
i6=j
1 exp(gij)
∂gij
∂xiexp(gij), (4.29)
4.8. OPTIMIZING THE ∇J2IJ RATIO 31
=X
i6=j
∂gij
∂xi, (4.30)
=X
i6=j
∂gij
∂rij
∂rij
∂xi. (4.31)
We look at each part separately. First
∂gij
∂rij = ∂
∂rij
aijrij 1 +βrij
, (4.32)
= aij
(1 +βrij)2. (4.33)
then ∂rij
∂xi = ∂
∂xi q
(xi −xj)2+ (yi−yj)2+ (zi−zj)2, (4.34)
= 1
22(xi−xj)/
q
(xi−xj)2+ (yi−yj)2+ (zi−zj)2, (4.35)
= xi −xj
rij . (4.36)
This combines to 1 J
∂J
∂xi =X
i6=j
aij rij
xi−xj
(1 +βrij)2. (4.37) The expression for the gradient becomes
∇iJ
J =X
i<j
aij rij
ri−rj
(1 +βrij)2. (4.38) The implementation of this is found in QuantumForce.cpp and LocalEn- ergyOpt.cpp.
4.8 Optimizing the
∇J2iJRatio
We can use similar techniques to nd the Laplaican. This is done in [7]
∇2iJ J =
∇iJ J
2
+X
i6=j
2 rij
∂gij
∂rij + ∂2gij
∂r2ij
. (4.39)
32 CHAPTER 4. OPTIMIZATIONS We nd
∂2gij
∂rij2 =− 2aijβ
(1 +βrij)3. (4.40)
Put together this gives
∇2iJ J =
∇iJ J
2
+X
i6=j
2 rij
aij
(1 +βrij)2 − 2ajiβ (1 +βrij)3
, (4.41)
=
∇iJ J
2
+X
i6=j
aij 2
rij(1 +βrij)3. (4.42) The implementation of this is found in LocalEnergyOpt.cpp.
Chapter 5 Orbitals
We will here look at two dierent types of orbitals, Hydrogenic ones and Gaussian orbitals derived by Hartree-Fock calculations.
The hydrogenic have a exp(−αr)dependency while the Gaussian orbitals have a exp(−αr2)dependency.
So with the gaussian we do not need a square root operation, which is a slow operation. We will later see how this saves some computational time.
5.1 Hydrogen orbitals
We will rst use hydrogen orbitals derived from: [11]
Eψ =−1
2∇2ψ+1
rψ. (5.1)
We use here the quantum numbers n, l, m.
• n is the principal quantum number. It can have values n= 1,2,3, ...
• l is the orbital momentum. It can have values l= 0,1,2, . . .
• m is the projection of the orbital momentum. It can have values
−l,−l+ 1, ...,0,1,2, .., l−1, l.
We have in spherical coordinates the wavefunction
ψ(r, θ, φ) = R(r)P(θ)F(φ). (5.2) For theR(r)function we have a tool in python: Sympy.physics.hydrogen.R_nl.
33
34 CHAPTER 5. ORBITALS Listing 5.1: Radial part of the hydrogen equation.
1 R_nl(n , l , r , Z=1):
• n is the main quantum number.
• l is the orbital momentum quantum number.
• r is the radial coordinate.
• Z is the atomic number.
This gives the radial part of the wavefunction with quantum number n and l.
We have for the spherical harmonics: [5]
P(θ)F(φ) = s
(2l+ 1)(l−m)!
4π(l+m)! Plm(cos(θ))exp(imφ). (5.3) HerePlm is the Legendre polynomial, and is given by the Python function sympy.assoc_legendre. It takes as input quantum numbersn and m.
Listing 5.2: Associated Legendre polynomial.
1 assoc_legendre (n ,m, x )
• n is the main quantum number.
• m is the projection of the orbital momentum quantum number.
• xis the coordinate used.
We then convert it all to Cartesian coordinates. The rst few hydrogen orbitals are
exp(−αr), (5.4)
(αr−2)exp(−αr/2), (5.5)
x∗exp(−αr/2), (5.6)
y∗exp(−αr/2), (5.7)
z∗exp(−αr/2). (5.8)
The algorithm used here can be found in: orbitalGenerator.py.
5.2. GAUSSIAN ORBITALS 35
5.2 Gaussian orbitals
A Gaussian orbital is given as: [8]
χn(x, y, z) =xiyjzkcne−αnr2. (5.9) Here x,y and z are Cartesian coordinates and r2 =x2+y2+z2
Where we have:
i+j +k =l. (5.10)
Here l is the total angular momentum
We use a sum of these orbitals as in equation (5.15). Here we have the constants cn and αn which we get from EMSL Basis set exchange.
One of the simplest form of GTO (there are many) is STO-3G, (Slater type orbitals) which we will use in this thesis.
In EMSL we rst select the orbital type (here STO-G3), then the format (here Turbomole format), and then the type of atom from the periodic table.
Then we just press the "Get Basis Set" button, and we get a table as in gure 5.2. See the interface for Basis Set Exchange in gure 5.1.
Letter Ang mom Nr Orb
S 0 1
P 1 3
D 2 6
F 3 10
G 4 15
H 5 21
Table 5.1: This table gives us the name of and the number of orbitals for a given angular momentum used in Gaussian orbitals.
The general formula for number of orbitals is seen in equation (5.11).
N rOrbitlas= (l+ 1)(l+ 2)
2 . (5.11)
36 CHAPTER 5. ORBITALS
i j k 2 0 0 0 2 0 0 0 2 1 1 0 1 0 1 0 1 1
Table 5.2: Here the angular momentum l = 2. This table gives us the dierent values of i,j and k for a D orbital.
Figure 5.1: The interface to Basis set exchange. One can choose which atom one wants, the type of orbital and the format wanted. We use here STO (Slater type orbitals) in Turbomole format.
5.2. GAUSSIAN ORBITALS 37
Figure 5.2: We see here the output for a Ne atom. We see we get two s orbitals and one p orbial. The rst number is theαnvalue and the second is the cn value.
38 CHAPTER 5. ORBITALS
0 0.1 0.2 0.3 0.4 0.5 0.6
-1 -0.5 0 0.5 1
Probability amplitude
Position
chi_1(x,y,z) chi_2(x,y,z) chi_3(x,y,z)
Figure 5.3: Here is a plot of equations (5.12), (5.13) and (5.14).The position axis is in hartree length units and the other axis is a probability amplitude
As an example we look at a S orbital where we have 3 contracted GTOs.
since l = 0 we have x0y0z0 = 1. We have a plot of these functions in gure 5.3.
χ1(x, y, z) = 0.15432897∗exp(−207.0156100∗r2), (5.12) χ2(x, y, z) = 0.53532814∗exp(−37.7081510∗r2), (5.13) and
χ3(x, y, z) = 0.44463454∗exp(−10.2052970∗r2). (5.14) The orbital function becomes:
φ(x, y, z) =X
n
Nnχn(x, y, z). (5.15) This function must be normalized
|hφn|φni|2 = 1. (5.16)
5.3. THE GRADIENT AND LAPLACIAN OF THE ORBITALS. 39 From [9] we have the expression for the normalization constant Nn
Nn=2αn π
3/4"
(8αn)i+j+ki!j!k!
(2i)!(2j)!(2k)!
#1/2
. (5.17)
The code to do this is found in: parsebasisset.py
5.3 The gradient and laplacian of the orbitals.
We need to nd the gradient function and the laplacian of the orbital func- tions. To do this we use a python script which does all derivations for us.
In python this is very simple. The command dif f in Sympy symbolically dierentiates an expression for a given variable. We then generate a c++ le with functions for the wavefunction, the gradient and the Laplacian for the dierent orbitals. We use basically the same algorithm for hydrogenic and Gaussian orbitals.
The code that does this for hydrogenic is found in the le: generateD- erivatesHydrogenic.py The code that does this for Gaussains is found in the le: generateDerivatesGaussians.py
40 CHAPTER 5. ORBITALS
Chapter 6
Calculation of Molecules, Blocking and Optimized Variational Parameters
In this chapter we present some additional theoretical ingredients needed in our calculations. We start with molecules, and move on to Blocking as a technique to compute the standard deviation and nally how to nd the optimal variational parameters.
6.1 Homonuclear Diatomic Molecules
We will now look at the Hamiltonian of Homonuclear Diatomic molecules
Hˆ =−1 2
N
X
i=1
∇2i +
N
X
i=1
Z
|R/2 +ri| + Z
|R/2−ri|
+Z2 R + 1
2
n
X
i6=j
1
|ri−rj|. (6.1) The wave functions are here a super position of two wavefunctions:
ψ+(ri, R) =ψ(r+R/2) +ψ(ri−R/2), (6.2) ψ−(ri, R) = ψ(r+R/2)−ψ(ri−R/2). (6.3) For the gradient we use a similar expression:
∇ψ+(ri, R) = ∇ψ(r+R/2) +∇ψ(ri−R/2), (6.4) 41
42CHAPTER 6. CALCULATION OF MOLECULES, BLOCKING AND OPTIMIZED VARIATIONAL PARAMETERS
Figure 6.1: A diatomic molecule with one of the electrons. Here R and r are vectors.
∇ψ−(ri, R) = ∇ψ(r+R/2)− ∇.ψ(ri−R/2). (6.5) For the Laplacian we have
∇2ψ+(ri, R) = ∇2ψ(r+R/2) +∇2ψ(ri−R/2), (6.6)
∇2ψ−(ri, R) = ∇2ψ(r+R/2)− ∇2ψ(ri−R/2). (6.7) The code that does this can be found in: Diatomic.cpp.
6.2 Random numbers
Random numbers are a bit tricky on a computer since all algorithms for random numbers are deterministic, but we can make a pretty good approxi- mation with pseudo-random numbers. The random function used in the code delivers values between 0 and 1 derived from a starting seed. The numbers should have little or no correlation between them, meaning a number should not aect the probability for the next number. Also the algorithm should be
6.3. BLOCKING 43 fast. The most common type is Linear the congruential algorithm
Ni = (aNi−1+c)M OD(M) (6.8) Here a, c and M are constants. The variable M should be as large as possible. This gives a random number between 0 and 1 with the equation
xi =Ni/M (6.9)
The code with random functions are found in: lib.cpp
6.3 Blocking
We wish here to estimate the covariance in order to nd a proper error estimate for ours results.
The problem here is that a brute force method will produce N2 calculation, and when N is big this will take too long time on an ordinary computer. To do this we use the method of blocking where we save all local energies from a single Monte Carlo simulation and divide it in blocks of size nb =N/n
mrn ≡ 1 nb
nb
X
k=1
mrk (6.10)
,
σ2(m) =D m2E
−D mE2
'm2n− mn2
. (6.11)
We make this calculation with increasing block sizes and plot it in a graph.
We can from this graph nd approximately the covariance, as the graph will go towards the real value. Example of plot is seen in Figure 6.2.
The code that does this is found in: blockingmain.cpp.
6.4 Gradient descent
We will here develop a method for nding the minimum value. If the mini- mum is atx=xm we have:
∇f(xm) = 0, (6.12)
∇f(xm−dx)<0, (6.13)
44CHAPTER 6. CALCULATION OF MOLECULES, BLOCKING AND OPTIMIZED VARIATIONAL PARAMETERS Table 6.1: delta values
•Brute force I δi =δ|∇f1(x
i)|
•Brute force II δi =δ
•Monotone Decreasing δi =δ/iN
•Newton's Method δi = ∇2f(x1 i)
∇f(xm+dx)>0. (6.14)
Heredx is an innite decimal displacement. The method used is
xi+1=xi−δi∇f(xi). (6.15) Newtons methods is an iterative way of nding the zero point of a function f. We choose a random point xi and draw a straight line to the x axis. The formula for this is:
0 =f0(xn)(xn+1−xn) +f(xn). (6.16) We rewrite this as
xi+1 =xi −f(xi)/∇f(xi). (6.17) We use in this thesis Newton's method. We must use numeric approxi- mations for the derivatives
∇f(xm) = ((f(xm+h)−f(xm−h))/(2h). (6.18)
∇2f(xm) = ((f(xm+h)−2f(xm) +f(xm−h))/(h2). (6.19) The values for h must here be picked carefully. Finding the minimum value for alpha beta we must nd the zero point for the derivative
xi+1 =xi − ∇f(xi)/∇2f(xi). (6.20) The code that does this (with MPI) is found in mpimain.cpp.
6.5 Parallelization
VMC is extremely easy to parallelize with MPI. One has to make sure all the processes start with dierent seed to the random number generator. So one just runs VMC in parallel and sum the results and divide by the number of nodes.
The Mpi function MPI_Reduce does the job nicely. This function collects and sums or multiplies all results from the dierent nodes. In this case we sum
6.6. ERRORS 45 Listing 6.1: MPI_Reduce
1 i n t MPI_Reduce(const void ∗sendbuf , void ∗recvbuf , 2 i n t count , MPI_Datatype datatype ,
3 MPI_Op op , i n t root , MPI_Comm comm) We look at the inputs and outputs of M P I_Reduce:
• sendbuf is a pointer to an array we wish to reduce.
• recvbuf is where the result is stored after calculation.
• count is the number of elements in the sendbuf array.
• M P I_Datatype is the type of variable used. Here M P I_Double.
• M P I_Op is the type of operation used. Here we sum and therefore use M P I_SU M.
• rootis the node where the result is sent. (Into recvbuf.)
• M P I_Comm is here just M P I_COM M_W ORLD.
• The returned integer is an errorcode.
There was some trouble making Armadillo work on the computer cluster Abel, but after some tweaking it now compiles and runs there.
6.6 Errors
Some few times the start positions give errors.
The simple solution is to run the rst timestep of the simulation and check for Nan (Not a number) and reselect if this show up.
Listing 6.2: Check for Nan 12
3 bool not_done = true;
45 //Loop u n t i l working values are found 6 while ( not_done ) {
78 not_done = f a l s e ; 9
46CHAPTER 6. CALCULATION OF MOLECULES, BLOCKING AND OPTIMIZED VARIATIONAL PARAMETERS 10 // Pick new random poi nts
11 f o r(i n t i = 0 ; i < n P a r t i c l e s ; i++) { 12 f o r(i n t j = 0 ; j < nDimensions ; j++) {
13 rOld ( i , j ) = gaussianDeviate (&idum )∗s q r t ( timestep ) ;
14 }
15 }
1617 //Remember the s t a r t i n g point 18 rCurr = rOld ;
19 rNew = rOld ; 2021 oldidum = idum ;
2223 //Get the i n v e r s e S l a t e r matrix 24 wf−>set_inverse ( rOld ) ;
2526 // Find the quatumforce
27 qforce_old = qf−>quantumforceOpt ( rOld ) ; 2829
30 //Loop trough a l l p a r t i c l e s
31 f o r (i n t i = 0 ; i < n P a r t i c l e s ; i++) { 3233
34 //Check f o r e r r o r s 35 i f ( ! Cycle (0 , i ) )
36 not_done = true;
3738 } 39 }
Finds new starter points which does not give singular inverse.
6.6. ERRORS 47
Figure 6.2: Example of blocking plot. The blocks axis shows number of blocks used in calculating the covariance which is plotted here in dimensionless units.
48CHAPTER 6. CALCULATION OF MOLECULES, BLOCKING AND OPTIMIZED VARIATIONAL PARAMETERS
Chapter 7
How to code VMC
We will here examine some of the code used in this thesis. Not all code will be listed, but the most important is listed and explained. The code for this thesis can be found at https://github.com/rogerkj/master
Included are codes for the generation of orbitals. Hydrogenic and Gaus- sian.
7.1 The C++ les
Let us look at the c++ les in this project:
• main.cpp contains the mpi stu and calls the main algorithm.
• mcintegrator.cpp contains the main VMC algorithm.
• LocalEnergyOpt.cpp contains the functions for nding the local energy.
• WaveFunction.cpp contains dierent tools as the algorithm for nding the inverse slater determinant and slater tools. Cause of legacy the le is called WaveFunction tough the wavefunctions are not in this le.
• Hydrogenic.cpp contains the hydrogenic wavefunctions, the gradient of that and the Laplacian.
• Gaussians.cpp contains the Gaussian wavefuncions, the gradient of that and the Laplacian. This le must be swapped manually according to the type of atom used.
• Diatomic.cpp contains functions for the wavefunctions, gradient and laplacian for diatomic molecules.
49
50 CHAPTER 7. HOW TO CODE VMC
• QuantumForce.cpp contains the algorithm for nding the Quatum force.
• lib.cpp contains the random function used.
• blockingmain.cpp contains code for the blocking algorithm.
• mpimain.cpp contains the minimum-nding MPI algorithm.
7.2 The Python les
We have some Python scripts for generating hydrogenic and Gaussian or- bitals.
• generateHydrogenic.py contains code that runs the main algorithm for hydrogenic orbitals
• generateDerivatesHydrogenic.py contains code for nding the hydro- genic gradient and Laplacian and printing to le.
• orbitalGenerator.py contains code for the generation of hydrogenic or- bitals.
• generateGaussians.py contains code that runs the main algorithm for Gaussian orbitals
• generateDerivatesGaussians.py contains code for nding the Gaussian gradient and Laplacian and printing to le.
• orbitalGenerator.py contains code for the generation of Gaussian or- bitals.
7.3 C++ code
We will here look at some of the code used in this thesis.
Here we have:
• dr−> waveF unction is the used wavefunction.
• dr−> gradient is the used gradient
• dr−> laplacian is the used Laplacian.
• inv_up is the inverse up Slater derterminant.
7.3. C++ CODE 51
• inv_down is the inverse down Slater determinant.
• nDimensions is the number of dimensions (here 3)
• nParticles is the number of particles.
• beta is theβ value used in the Jastrow factor.
• timestep is a set value who seems to work ne:(0.005).
• idum is the random seed.
7.3.1 Main MVC algorithm
Following is the main VMC algorithm inner loop. Here i is the current par- ticle,rN ew andrOldare new and old positions of the particles, respectively.
The function gaussianDeviate returns a random Gaussian distributed value.
This code is clipped from the le mcintegrator.cpp Listing 7.1: Main VMC algorithm 12 //Make next move
3 f o r(i n t j = 0 ; j < nDimensions ; j++) {
4 rNew( i , j ) = rOld ( i , j ) + gaussianDeviate (&idum ) ∗ s q r t ( timestep ) + qforce_old ( i , j ) ∗ timestep ∗D;
5 }
67 // Find S l a t e r determinant
8 double Rs = wf−>slaterOpt (rNew , rOld , i ) ; 109
11 // Store current s l a t e r d e t e r m i n a n t 12 old_inv_up = wf−>inv_up ;
13 old_inv_down = wf−>inv_down ; 1415 wf−>update_inverse (Rs , rNew , i ) ; 1617 // Find quantum f o r c e
18 qforce_new = qf−>quantumforceOpt ( rNew ) ; 1920 // get Greensfunction
52 CHAPTER 7. HOW TO CODE VMC 21 double g r e e n s f u n c t i o n = getGreensFunctionRatio (rNew
, rOld , qforce_new , qforce_old ) ;
22 The f o l l o w i n g code i s the quantum f o r c e . See s e c t i o n 17 2324
25 //Check f o r Jastrow f a c t o r 26 #i f d e f JASTROW
2728 // Find Jastrow f a c t o r
29 double jastrow = wf−>jastrowOpt (rNew , rOld , i ) ; 3031 #e l s e
3233 //No jastrow f a c t o r 34 double jastrow = 1 . 0 ; 3536 #e n d i f
3738
39 // Metropolis t e s t
40 i f ( ran2(&idum ) <= g r e e n s f u n c t i o n∗Rs∗Rs∗jastrow ) {
41 {
4243 // Step accepted , . . s t o r e r e s u l t
4445 f o r(i n t j = 0 ; j < nDimensions ; j++) { 46 rOld ( i , j ) = rNew( i , j ) ;
4748 }
4950 qforce_old = qforce_new ; 5152 i f ( c y c l e > nThermalize )
53 accetpted++;
5455 } e l s e {
5657 // Step not accepted . . .
5859 f o r(i n t j = 0 ; j < nDimensions ; j++) { 60 rNew( i , j ) = rOld ( i , j ) ;
7.3. C++ CODE 53
61 }
6263 qforce_new = qforce_old ; 6465 wf−>inv_up = old_inv_up ; 66 wf−>inv_down = old_inv_down ; 6768 }
6970 7172 73 }
7.3.2 Local energy code
We now look at the Local energy code.
We wish to calculate equation (3.30) We rst look at the kinetic energy in equation (3.32).
Local energy. Jastrow part.
We st calculate the two equations:
1
J∇2J (7.1)
1
J∇J (7.2)
The optimized formulas for this we nd in (4.38) and (4.42) Here r is here the current position of the particles.
This code is clipped from LocalEnergyOpt.cpp Listing 7.2: Jastrow factor 12 double j l a p l a c i a n = 0 . 0 ;
34 rowvec3 r i j V e c ; 5
54 CHAPTER 7. HOW TO CODE VMC 6 mat j g r a d i e n t = z e r o s ( n P a r t i c l e s , dimention ) ;
78 f o r(i n t i = 0 ; i < n P a r t i c l e s ; i++) { 9 f o r(i n t j = 0 ; j < n P a r t i c l e s ; j++) { 10 i f( i != j ) {
11 r i j V e c = r . row ( i ) − r . row ( j ) ; 12 double r i j = norm( rijVec , 2 ) ;
13 j g r a d i e n t . row ( i ) += r i j V e c∗dfdr ( r i j , i , j ) / r i j ;
14 j l a p l a c i a n += 2∗dfdr ( r i j , i , j ) / r i j + d2fdr2 ( r i j , i , j )
15 };
16 }
17 }
1819 double gradient2 = 0 . 0 ;
20 f o r (i n t i = 0 ; i < n P a r t i c l e s ; i++) {
21 gradient2 += dot ( j g r a d i e n t . row ( i ) , j g r a d i e n t . row ( i ) ) 22 } ;
2324 j l a p l a c i a n += gradient2 ; 2526
2728 // Derivate of the Jastrow f u n c t i o n
29 double LocalEnergyOpt : : dfdr (const double &r12 , const i n t &particleNum1 , const i n t &particleNum2 ) {
30 return wf−>amat ( particleNum1 , particleNum2 ) /((1 + beta∗r12 )∗(1 + beta∗r12 ) ) ;
31 }32
3334 // Second d e r i v a t e of the Jastrow f u n c t i o n
35 double LocalEnergyOpt : : d2fdr2 (const double &r12 , const i n t &particleNum1 , const i n t &particleNum2 ) {
36 return −2∗wf−>amat ( particleNum1 , particleNum2 )∗beta /((1 + beta∗r12 )∗(1 + beta∗r12 )∗(1 + beta∗r12 ) ) ; 37 }