Monte Carlo method: Basic ideas. deterministic vs. stochastic In deterministic models, the output of...
-
Upload
patrick-marsh -
Category
Documents
-
view
216 -
download
0
Transcript of Monte Carlo method: Basic ideas. deterministic vs. stochastic In deterministic models, the output of...
Monte Carlo method:
Basic ideas
deterministic vs. stochastic
• In deterministic models, the output of the model is fully determined by the parameter values and the initial conditions
• Stochastic models possess some inherent randomness. The same set of parameter values and initial conditions will lead to an ensemble of different outputs
2
Molecular Dynamics and Monte Carlo
Molecular dynamics (MD) is a deterministic method that solves the equations of motion to predict positions and velocities of all particles of a system. The statistical treatment of the information gained in this way allows predictions of thermodynamic and transport properties
Monte Carlo is a stochastic method in which the configurations of a system are sampled, in non-chronological order. The statistical treatment of the information gained in this way allows predictions of thermodynamic properties but not of transport properties
3
A crude approach to Monte CarloSuppose we begin with an empty simulation box of fixed volume and then randomly choose a position for each molecule in the box until achieving the desired density. We then “measure” the instantaneous values of the properties of interest.
The experiment is repeated many times.
If the temperature is constant , the probability of each state is:
all configurations
C
C
U
kT
U
kT
e
e
4
A crude approach to Monte Carlo
In high-density systems, it is very likely this simple way of placing molecules will cause overlaps.
In the hard core (e.g., hard spheres) intermolecular potential, overlaps lead to infinite configuration energy. Therefore, the probability of observing a microscopic state with overlap is zero.
all configurations
C
C
U
kT
U
kT
e
e
5
A crude approach to Monte Carlo
In high-density systems, it is very likely this simple way of placing molecules will cause overlaps.
In soft core intermolecular potentials (e.g., Lennard-Jones), overlaps lead to very high configuration energy. Therefore, the probability of observing a microscopic state with overlap is nearly zero.
all configurations
C
C
U
kT
U
kT
e
e
6
A crude approach to Monte Carlo
In summary:
Many of the generated configurations have extremely low (or zero) probability of occurrence and, therefore, contribute little to computing the average.
Such sampling approach is inefficient for computing average thermodynamic properties.
Another problem: how to compute the denominator, as it requires adding the Boltzmann factor of all configurations?
7
Importance sampling
Alternative:
Devise procedures that sample more frequently the states that matter most to the average properties.
This is called importance sampling.
8
Importance sampling
Importance sampling in the canonical ensemble:
In a box of fixed volume, place the desired number of molecules in an arrangement without overlaps, for example, according to a lattice (crystal) structure.
Develop other configurations with a bias towards lower energy states to try avoid highly unlikely configurations. Note: configurations with higher energy will be possible – but there will be a bias towards lower energy.
This introduces a bias in the sampling procedure. When computing averages, it is necessary to account for this bias.
9
Importance sampling
Importance sampling in the canonical ensemble:
There are several ways to devise schemes to introduce biases and accounting for them when computing average thermodynamic properties.
The most widely used is the Metropolis scheme originally published in 1953 – in the early stage of the development of electronic computers.
N. Metropolis, A.W. Rosenbluth, M.N. Rosenbluth, A.H. Teller, E. Teller, J. Chem. Phys. 21, 1087 (1953)
10
Markov chains
The Metropolis procedure uses a Markov chain of states.
In a Markov chain:
•There is a finite (or countable) set of states of the system;
•The probability of transition from one state to another depends on the properties of these two states and not on those of other states.
11
Markov chains
To illustrate the features of a Markov chain, consider a system with four possible states, with the probability of transition between any two of them given by the values above the arrows:
0,4
0,2
0,4
0,5 0,4 0,6
0,20,30,5
0,5 1 2 3 4
12
Markov chains
Let us organize these probabilities in a matrix, called transition matrix (columns and rows switched with respect to the book, but the discussion is equivalent):
0,4
0,2
0,4
0,5 0,4 0,6
0,20,30,5
0,5 1 2 3 4
1 1 2 1 3 1 4 1
1 2 2 2 3 2 4 2
1 3 2 3 3 3 4 3
1 4 2 4 3 4 4 4
T T T T
T T T T
T T T T
T T T T
P
13
Markov chains
Let us organize these probabilities in a matrix, called transition matrix (columns and rows switched with respect to the book, but the discussion is equivalent):
0,4
0,2
0,4
0,5 0,4 0,6
0,20,30,5
0,5 1 2 3 4
0.5 0.5 0.4 0
0.5 0 0.4 0
0 0.3 0 0.6
0 0.2 0.2 0.4
P
1 1 2 1 3 1 4 1
1 2 2 2 3 2 4 2
1 3 2 3 3 3 4 3
1 4 2 4 3 4 4 4
T T T T
T T T T
T T T T
T T T T
P
14
Markov chains
Why is the summation of the elements of each column equal to 1?
0,4
0,2
0,4
0,5 0,4 0,6
0,20,30,5
0,5 1 2 3 4
0.5 0.5 0.4 0
0.5 0 0.4 0
0 0.3 0 0.6
0 0.2 0.2 0.4
P
15
Markov chains
Note: until now, we have probabilities for the transitions but we do not have probabilities for the states. Let us make an initial guess that all four states are equally likely:
0,4
0,2
0,4
0,5 0,4 0,6
0,20,30,5
0,5 1 2 3 4
1
0.25
0.25
0.25
0.25
16
Markov chains
Let us assume an event takes place in the Markov chain. The new probability for the states is obtained by multiplying the transition matrix by the probability vector:
0,4
0,2
0,4
0,5 0,4 0,6
0,20,30,5
0,5 1 2 3 4
2 1
0.350
0.225
0.225
0.200
P
17
Markov chains
The probability vector after each subsequent event takes place is calculated in similar fashion:
0,4
0,2
0,4
0,5 0,4 0,6
0,20,30,5
0,5 1 2 3 4
1t1tt1t PPPP
It is possible to show (Perron-Frobenius theorem) that there is a single limiting distribution, independent of the initial value, for any Markovian matrix that represents an ergodic system.
18
Markov chains
In our problem, successive transitions leads to the following vector for the state probabilities:
0,4
0,2
0,4
0,5 0,4 0,6
0,20,30,5
0,5 1 2 3 4
0.4091
0.2727
0.1705
0.1477
19
Markov chains
In our problem, successive transitions leads to the following vector for the state probabilities:
0,4
0,2
0,4
0,5 0,4 0,6
0,20,30,5
0,5 1 2 3 4
0.4091
0.2727
0.1705
0.1477
At the beginning, we only knew transition probabilities.
Using the Markov chain, we found the state probabilities.
20
Metropolis method
We note that:
1n mm
T
nn m n mm
T
1 1 2 1 3 1 4 1
1 2 2 2 3 2 4 2
1 3 2 3 3 3 4 3
1 4 2 4 3 4 4 4
T T T T
T T T T
T T T T
T T T T
P
21
Metropolis method
In an ergodic* system in equilibrium, the average number of transitions that take to a state is equal to the number of transitions that leave this state. (If the number of transitions into the state were, for example, bigger, then the system would get stuck in such a state after some time).
A way to satisfy this condition is to impose what is called “microscopic reversibility”: the number of transitions that take the system from one state to another is equal to the number of transitions in the opposite direction:
m nT m n m nT
22
*ergodic: average over time is equal to average over states (phase space)
Metropolis method
Let us add over index m:
m nT 1m n m n n n m n nm m m
T T
To sample in the canonical ensemble:
m NVT m
23
Monte Carlo method in the canonical ensemble
All these details can be put to work in an algorithm for Monte Carlo simulations whose basic structure is relatively simple.
With the N particles of a system initially placed in a box of fixed volume kept at constant temperature:
1) Make small perturbation to the system, e.g., by trying to move one of its particles;
2) Accept or reject the move according to the transition probability of the Markovian matrix.
26
Monte Carlo method in the canonical ensemble
1) Make small perturbation to the system, e.g., by trying to move one of its molecules;
In the Metropolis formulation, this is governed by matrix
nm, mnnm
α
nm Probability of moving the system from state m to state n.
A solution:• Randomly pick a molecule;• Randomly pick a new position for it.
27
Monte Carlo method in the canonical ensemble
1) Make small perturbation to the system, e.g., by trying to move one of its molecules;
A solution:• Randomly pick a molecule – let us say, molecule i;• Randomly pick a new position for it.
max
max
max
2 1
2 1
2 1
n mi i x
n mi i y
n mi i z
x x rand r
y y rand r
z z rand r
rand Uniformly distributed random number between 0 & 1
maxr Maximum allowed displacement 28
Monte Carlo method in the canonical ensemble
max
max
max
2 1
2 1
2 1
n mi i x
n mi i y
n mi i z
x x rand r
y y rand r
z z rand r
The new position of molecule i is within a small box centered in its position in configuration m with sides equal to max2 r
29
Monte Carlo method in the canonical ensemble
2) Accept or reject the move according to the transition probability of the Markovian matrix.
m n
, m n
, m n
nm n m
nnm n m
m
T
n mU U
n kT
m
e
, 0 m n
, 0 m n
n m n m n mU U
n kT
mn m n m
U U
e
U U
30
Monte Carlo method in the canonical ensemble
2) Accept or reject the move according to the transition probability of the Markovian matrix.
m n
, 0 m n
, 0 m n
nm n m
nnm n m
m
U U
T
U U
31
Monte Carlo method in the canonical ensemble
What is the practical meaning of these conditions?
m n
, 0 m n
, 0 m n
nm n m
nnm n m
m
U U
T
U U
32
Monte Carlo method in the canonical ensemble
What is the practical meaning of these conditions?
is the probability of selecting a particle and randomly displacing it to a new position. Once this is done, if the energy of the system remains equal or decreases, the move is accepted.
What if the energy increases?
m n
, 0 m n
, 0 m n
nm n m
nnm n m
m
U U
T
U U
nm
33
Monte Carlo method in the canonical ensemble
What if the energy increases?
The probability of accepting the move depends on the ratio:
m n
, 0 m n
, 0 m n
nm n m
nnm n m
m
U U
T
U U
n mU U
n kT
m
e
Draw a random number uniformly distributed between 0 and 1. If its equal to or smaller than this ratio, accept the move. Otherwise, reject it.
34
Monte Carlo method in the canonical ensembleSummary:
From an initial configuration, repeat:
1randNinti p
Compute miU
max
mi
ni
maxmi
ni
maxmi
ni
r 1rand2zz
r 1rand2yy
r 1rand2xx
Compute niU
mi
ninm UUU
If
kT
Uexprand nm then
Accept the move
Update position of molecule “i”
Otherwise
Reject the move
35
Monte Carlo method: details
As in molecular dynamics, efficient implementation is very important. There are many “tricks”.
maxr
Maximum allowed displacement:
A large value means molecules can make big moves, but these are unlikely to succeed in a dense system. Most will result in overlaps and be rejected.
The consequence is that the sampling is inadequate.
36
Monte Carlo method: details
As in molecular dynamics, efficient implementation is very important. There are many “tricks”.
maxr
Maximum allowed displacement:
A small value means molecules can make small moves, likely to be accepted. But with small moves, a good sampling takes a lot of time.
The consequence is that the sampling is inadequate.
37
Monte Carlo method: details
As in molecular dynamics, efficient implementation is very important. There are many “tricks”.
maxr
Maximum allowed displacement:
Solution:
Periodically, during the equilibration part of the simulation, the maximum allowed displacement is adjusted in such a way that about 50% of the attempted moves are accepted. During the production part, it should be kept fixed.
38
Monte Carlo method: details
As in molecular dynamics, efficient implementation is very important. There are many “tricks”.
Random numbers play a crucial role in the method – no wonder it is called Monte Carlo method.
Computers do not really generate random numbers. They have deterministic functions that result in numbers that appear to be random (even though, they are not).
39
Monte Carlo method: details
As in molecular dynamics, efficient implementation is very important. There are many “tricks”.
Unlike molecular dynamics, there is no need to compute forces. Only energies matter to sample the states. Implementation tends to be simpler.
40
Monte Carlo method: details
As in molecular dynamics, efficient implementation is very important. There are many “tricks”.
Computing the total energy of the system is very time consuming because many pairs of particles need to be considered.
In the canonical ensemble, this does not need to be done in every attempted move. When a move is attempted, all molecules remain in their positions, except for one (molecule i). The energy change is the energy change of molecule i.
n m in imU U U U 41
Monte Carlo method: details
As in molecular dynamics, efficient implementation is very important. There are many “tricks”.
Cut-off distance
Intermolecular interactions fade away very quickly with distance unless there are electrostatic interactions. Therefore, after a few molecular radii, the interaction is very small. To save time, it is usual to define a cut-off distance beyond which interactions are neglected.
42
Monte Carlo method: details
As in molecular dynamics, efficient implementation is very important. There are many “tricks”.
Neighbor list
Also, it is useful to keep a list of neighbors, i.e., the particles that are inside the cut-off distance or nearby.
43
Periodic boundary conditions
What to do if a particle leaves the box as it moves?
44
Periodic boundary conditions
To avoid the effect of borders on simulation results, surround the system by replicas of itself.
45
Periodic boundary conditions
If a molecule leaves the system, another enters from the opposite side.
46
Periodic boundary conditions
Each particle interacts with the nearest replica of its neighbors.
47
Radial distribution function
Molecular simulations provide a lot of information that we will uncover as we discuss more of the fundamentals of statistical thermodynamics.
One type of information – the radial distribution function – has to do with the structure of the substance being simulated.
Formal definitions apart, the radial distribution function gives information about the average population of neighboring molecules as function of the intermolecular distance to a central molecule.
48
Radial distribution function
To evaluate it via molecular simulation, one splits the space around each central molecule in spherical concentric shells and counts how many neighboring particles have their center there.
Image source: http://rheneas.eng.buffalo.edu/w/images/e/e0/LJ_Rdf_shell_t.GIF49
Radial distribution function
The radial distribution function is the probability of finding the center of a neighboring molecule at a certain distance from the central molecule divided by the same probability for an ideal gas of same density.
50
Radial distribution function
Lennard-Jones fluid. Image source: Wikipedia
0.71Bk TT
3 0.844 51
Dimensionless quantities
Dimensionless quantities are defined as follows:
tt t m t
m
UU U U
rr r r
TT
k
UU U
kTT kT
52
Average properties from canonical MC simulations
MC simulations provide the average radial distribution function in numerical form. From it, thermodynamic properties can be evaluated using formulas from Chapter 11. For spherically symmetrical molecules:
2 3
0
2
3
du rP kT g r r dr
dr
22 , ,CU N u r g r T r dr
53
Instantaneous properties in canonical molecular simulations
The instantaneous values of the configuration energy are calculated as part of the procedure – they are readily available.
Let us examine how to compute the instantaneous pressure.
The force that acts on a particle i in the x-direction and the acceleration in that direction are related as follows:
2, ,
,2
i x i xi x
dv d rm m Fdt dt
54
Instantaneous properties in canonical molecular simulations
2,
, , ,2
1 1
2 2i x
i x i x i x
d rr m r F
dt
22 22,, ,
, 2 2
2 2, 2
, , ,2
1 1 1
2 4 2
1 1 1
4 2 2
i xi x i xi x
i x
i x i x i x
d mrd r drr m m
dt dt dt
d mrmv r F
dt
55
Instantaneous properties in canonical molecular simulations
2 2, 2
,20 0
2 2, , 2
, , ,
0
1 1
4 2
1 1
4 2 2
i x
i x
i x i x
i x i x i x
t t
d mrdt m v dt
dt
d mr d mr mv r F
dt dt
Now, integrate both sides of the equation over a certain period of time and divide by this time interval to obtain time averages:
56
Instantaneous properties in canonical molecular simulations
2 2, , 2
, , ,1 1 1
0
1 1 1
2 2 2 2
N N Ni x i x
i x i x i xi i i
t t
d mr d mr mv r F
dt dt
Summing all molecules:
The left-hand side has time derivatives of the total kinetic energy direction in the x-direction, which are zero for a system in equilibrium. Then:
2, , ,
1 1
1
2 2
N N
i x i x i xi i
mv r F
57
Instantaneous properties in canonical molecular simulations
Considering all three directions x, y, z:
Using the relationship between average kinetic energy and temperature:
2 2 2, , , , , , , , ,
1 1
1
1
2 2
1.
2
N N
i x i y i z i x i x i y i y i z i zi i
N
i ii
mv v v r F r F r F
r F
2 2 2, , ,
1 1
3 1.
2 2 2
N N
i ii x i y i zi i
mv v v NkT r F
58
Instantaneous properties in canonical molecular simulations
Then:
In an ideal gas, there are no intermolecular forces. The only forces acting on the system are interactions of molecules with the wall that confines the fluid in a reservoir. In this case:
1
. 3N
i ii
r F NkT
1
. 3 3N
moleculei iwalli
r F NkT PV
59
Instantaneous properties in canonical molecular simulations
In a real fluid:
1 1
1
. .
3 .
3
N N
molecule moleculei i i iwall moleculei i
N
moleculei imoleculei
r F r F
PV r F
NkT
1
1.
3
N
moleculei imoleculei
NkTP r F
V V
60
Instantaneous properties in canonical molecular simulations
In a real fluid:
1
1.
3
N
moleculei imoleculei
NkTP r F
V V
1
, , ,1 , , ,
1.
3
1
3
N Nij
ii j i i
N Nij ij ij
i x i y i zi j i i x i y i z
du rNkTP r
V V dr
du r du r du rNkTr r r
V V r r r
61
Instantaneous properties in canonical molecular simulations
Using that:
2 2 2
, , , , , ,ij i x j x i y j y i z j zr r r r r r r
1
1
1.
3
1
3
N Nij
ii j i i
N Nij
iji j i ij
du rNkTP r
V V dr
du rNkTr
V V r
it can be shown that:
62
Instantaneous properties in canonical molecular simulations
1
1
3
N Nij
iji j i ij
du rNkTP r
V V r
The last term appears as an average, but can be applied to a single configuration to obtain an instantaneous pressure:
63
valid for MC or MD