View
213
Download
1
Embed Size (px)
Citation preview
CE 400 Honors SeminarMolecular Simulation
Prof. Kofke
Department of Chemical EngineeringUniversity at Buffalo, State University
of New York
Class 4
2
Statistical Mechanics
• Theoretical basis for derivation of macroscopic behaviors from microscopic origins
• Two fundamental postulates of equilibrium statistical mechanics– microstates of equal energy are equally likely– time average is equivalent to ensemble average
• Formalism extends postulates to more useful situations– thermal, mechanical, and/or chemical equilibrium with reservoirs
• systems at constant T, P, and/or m
– yields new formulas for probabilities of microstates• derivation invokes thermodynamic limit of very large system
• Macroscopic observables given as a weighted sum over microstates– dynamic properties require additional formalism
3
Ensembles
• Definition of an ensemble– Collection of microstates subject to at least one extensive constraint
• “microstate” is specification of all atom positions and momenta
• fixed total energy, total volume, and/or total number of molecules
• unconstrained extensive quantities are represented by full range of possible values
– Probability distribution p describing the likelihood of observing each state, or the weight that each state has in ensemble average
• Example: Some members of ensemble of fixed N– isothermal-isobaric (TPN)
• all energies and volumes represented
Low-probability state
4
Commonly Encountered Ensembles
N a m e A l l s t a t e s o f : P r o b a b i l i t y d i s t r i b u t i o n S c h e m a t i c
M i c r o c a n o n i c a l( E V N )
g i v e n E V N 1i
C a n o n i c a l( T V N )
a l l e n e r g i e s 1( ) iEi Q
E e
I s o t h e r m a l - i s o b a r i c( T P N )
a l l e n e r g i e s a n dv o l u m e s
( )1( , ) i iE P Vi iE V e
G r a n d - c a n o n i c a l( T V )
a l l e n e r g i e s a n dm o l e c u l e n u m b e r s
( )1( , ) i iE Ni iE N e
Note: 1/ kT
5
Markov Processes 1.
• Stochastic process– movement through a series of well-defined states in a way that
involves some element of randomness– for our purposes,“states” are microstates in the governing ensemble
• Markov process– stochastic process that has no memory– selection of next state depends only on current state, and not on
prior states– process is fully defined by a set of transition probabilities pij
• ij = probability of selecting state j next, given that presently in state i.
• Transition-probability matrix collects all ij
• Application– we can visit the states of a system in proportion to their probability
by application of a Markov process
6
Transition-Probability Matrix
• Example– system with three states
• Requirements of transition-probability matrix– all probabilities non-negative, and not greater than unity
– sum of each row is unity
– probability of staying in present state may be non-zero
11 12 13
21 22 23
31 32 33
0.1 0.5 0.4
0.9 0.1 0.0
0.3 0.3 0.4
If in state 1, will move to state 3 with probability 0.4
If in state 1, will stay in state 1 with probability 0.1
Never go to state 3 from state 2
7
Example
• Here’s a transition-probability matrix for an eight-state system
• Let’s do a walk based on it…
Group 1 2 3 4 5 6 7 8
1 0.000 0.143 0.143 0.143 0.143 0.143 0.143 0.143 1.000
2 0.019 0.381 0.143 0.048 0.124 0.095 0.048 0.143 1.000
3 0.010 0.071 0.667 0.024 0.062 0.048 0.024 0.095 1.000
4 0.057 0.143 0.143 0.086 0.143 0.143 0.143 0.143 1.000
5 0.022 0.143 0.143 0.055 0.330 0.110 0.055 0.143 1.000
6 0.029 0.143 0.143 0.071 0.143 0.257 0.071 0.143 1.000
7 0.057 0.143 0.143 0.143 0.143 0.143 0.086 0.143 1.000
8 0.014 0.107 0.143 0.036 0.093 0.071 0.036 0.500 1.000
Transition probabilities
8
Distribution of State Occupancies
• Consider process of repeatedly moving from one state to the next, choosing each subsequent state according to – 122132233123
etc.
• Histogram the occupancy number for each state– n1 = 3 1 = 0.33
– n2 = 5 2 = 0.42
– n3 = 4 3 = 0.25
• After very many steps, a limiting distribution emerges
• Click here for an applet that demonstrates a Markov process and its approach to a limiting distribution
1 2 3
9
Microscopic Reversibility
• The limiting distribution and the transition probabilities obey the principle of microscopic reversibility, a.k.a., detailed balance
– Loosely: “net flow from state i to state j equals net flow from state j to state i”
• Consider the example– Limiting distribution:
i ij j ji
Group 1 2 3 4 5 6 7 8
1 0.000 0.143 0.143 0.143 0.143 0.143 0.143 0.143 1.000
2 0.019 0.381 0.143 0.048 0.124 0.095 0.048 0.143 1.000
3 0.010 0.071 0.667 0.024 0.062 0.048 0.024 0.095 1.000
4 0.057 0.143 0.143 0.086 0.143 0.143 0.143 0.143 1.000
5 0.022 0.143 0.143 0.055 0.330 0.110 0.055 0.143 1.000
6 0.029 0.143 0.143 0.071 0.143 0.257 0.071 0.143 1.000
7 0.057 0.143 0.143 0.143 0.143 0.143 0.086 0.143 1.000
8 0.014 0.107 0.143 0.036 0.093 0.071 0.036 0.500 1.000
Transition probabilities
1 2 3 4 5 6 7 80.02 0.15 0.3 0.05 0.13 0.1 0.05 0.2
1 12 2 21
2 25 5 52
4 48 8 84
0.02 0.143 0.15 0.019
0.15 0.124 0.13 0.143
0.05 0.143 0.20 0.036
.etc
10
Application?
• How does this apply to molecular simulation?
• Statistical mechanics provides the limiting distribution– Canonical ensemble
• The Markov process relates the limiting distribution and the transition probabilities
• What is needed to tie these together?
• How can it be done?
1( ) exp( / )i iE E kT
Q
i ij j ji
11
Metropolis Algorithm
• Standard method to form Markov process in molecular simulation– Metropolis, Rosenbluth, Rosenbluth, Teller and Teller, Journal of
Chemical Physics, 21, 1087 (1953).
• Transition probabilities formulated to yield desired limiting distribution
• Each Markov transition is a two-step process– From state i select a trial state j with probability Tij
– Accept trial with probability • Generate a uniform random deviate r on (0,1)• If r < , accept, otherwise reject and use previous state as next one
– With this recipe
– Show that this obeys detailed balance
ji j
ij i
T
T
min(1, )
min(1,1/ )
ij ij
ji ji
T
T
12
Monte Carlo Simulation
• MC techniques applied to molecular simulation
• Almost always involves a Markov process– move to a new configuration from an existing one
according to a well-defined transition probability
• Simulation procedure– generate a new “trial” configuration by making a
perturbation to the present configuration
– accept the new configuration based on the ratio of the probabilities for the new and old configurations, according to the Metropolis algorithm
– if the trial is rejected, the present configuration is taken as the next one in the Markov chain
– repeat this many times, accumulating sums for averages
new
old
U
U
e
e
State k
State k+1
13
Trial Moves
• A great variety of trial moves can be made
• Basic selection of trial moves is dictated by choice of ensemble– almost all MC is performed at constant T
• no need to ensure trial holds energy fixed
– must ensure relevant elements of ensemble are sampled• all ensembles have molecule displacement, rotation; atom displacement• isobaric ensembles have trials that change the volume• grand-canonical ensembles have trials that insert/delete a molecule
• Significant increase in efficiency of algorithm can be achieved by the introduction of clever trial moves– reptation, crankshaft moves for polymers
– multi-molecule movements of associating molecules
– many more
14
General Form of Algorithm
Move each atom once (on average) 100’s or 1000’s
of cycles
Independent “measurement”
New configurationInitialization
Reset block sums
Compute block average
Compute final results
“cycle” or “sweep”
“block”moves per cycle
cycles per block
Add to block sum
blocks per simulation
New configuration
Entire SimulationMonte Carlo Move
Select type of trial moveeach type of move has fixed probability of being selected
Perform selected trial move
Decide to accept trial configuration, or keep
original
15
Displacement Trial Move 1. Specification
• Gives new configuration of same volume and number of molecules
• Basic trial:–
16
• Gives new configuration of same volume and number of molecules
• Basic trial:– displace a randomly selected atom to a point chosen with uniform
probability inside a cubic volume of edge 2d centered on the current position of the atom
Select an atom at random
Displacement Trial Move 1. Specification
17
Displacement Trial Move 1. Specification
• Gives new configuration of same volume and number of molecules
• Basic trial:– displace a randomly selected atom to a point chosen with uniform
probability inside a cubic volume of edge 2d centered on the current position of the atom
2
Consider a region about it
18
• Gives new configuration of same volume and number of molecules
• Basic trial:– displace a randomly selected atom to a point chosen with uniform
probability inside a cubic volume of edge 2d centered on the current position of the atom
Consider a region about it
Displacement Trial Move 1. Specification
19
• Gives new configuration of same volume and number of molecules
• Basic trial:– displace a randomly selected atom to a point chosen with uniform
probability inside a cubic volume of edge 2d centered on the current position of the atom
Move atom to point chosen uniformly in region
Displacement Trial Move 1. Specification
20
• Gives new configuration of same volume and number of molecules
• Basic trial:– displace a randomly selected atom to a point chosen with uniform
probability inside a cubic volume of edge 2d centered on the current position of the atom
Consider acceptance of new configuration
?
Displacement Trial Move 1. Specification
21
• Gives new configuration of same volume and number of molecules
• Basic trial:– displace a randomly selected atom to a point chosen with uniform
probability inside a cubic volume of edge 2d centered on the current position of the atom
• Limiting probability distribution– canonical ensemble
– for this trial move, probability ratios are the same in other common ensembles, so the algorithm described here pertains to them as well
( )1( )
NN N U N
Nd e d
Z rr r r
Examine underlying transition probabilities to formulate acceptance criterion
?
Displacement Trial Move 1. Specification
22
2. Analysis of Trial Probabilities
• Detailed specification of trial moves and probabilities
Event[reverse event]
Probability[reverse probability]
Select molecule k[select molecule k]
1/N[1/N]
Move to rnew
[move back to rold]1/v
[1/v]
Accept move[accept move]
min(1,)[min(1,1/)]
Forward-step trial probability
v = (2d
1 1min(1, )
N v
Reverse-step trial probability
11 1min(1, )
N v
is formulated to satisfy detailed balance
23
3. Analysis of Detailed Balance
Detailed balance
Forward-step trial probability
1 1min(1, )
N v
Reverse-step trial probability
11 1min(1, )
N v
i ij j ji=
Limiting distribution
( )1( )
NN N U N
Nd e d
Z rr r r
24
3. Analysis of Detailed Balance
Detailed balance
11 1 1 1min(1, ) min(1, )
old newU N U N
N N
e d e d
Z N v Z N v
r r
Forward-step trial probability
1 1min(1, )
N v
Reverse-step trial probability
11 1min(1, )
N v
i ij j ji=
Limiting distribution
( )1( )
NN N U N
Nd e d
Z rr r r
25
3. Analysis of Detailed Balance
Detailed balance
Forward-step trial probability
1 1min(1, )
N v
Reverse-step trial probability
11 1min(1, )
N v
i ij j ji
old newU Ue e
=
( )new oldU Ue Acceptance probability
11 1 1 1min(1, ) min(1, )
old newU N U N
N N
e d e d
Z N v Z N v
r r
26
4a. Examination of Java Code
public void thisTrial(Phase phase) { double uOld, uNew; if(phase.atomCount==0) {return;} //no atoms to move
int i = (int)(rand.nextDouble()*phase.atomCount); //pick a random number from 0 to N-1 Atom a = phase.firstAtom(); for(int j=i; --j>=0; ) {a = a.nextAtom();} //get ith atom in list
uOld = phase.potentialEnergy.currentValue(a); //calculate its contribution to the energy a.displaceWithin(stepSize); //move it within a local volume phase.boundary().centralImage(a.coordinate.position()); //apply PBC uNew = phase.potentialEnergy.currentValue(a); //calculate its new contribution to energy
if(uNew < uOld) { //accept if energy decreased nAccept++; return; } if(uNew >= Double.MAX_VALUE || //reject if energy is huge or doesn’t pass test Math.exp(-(uNew-uOld)/parentIntegrator.temperature) < rand.nextDouble()) { a.replace(); //...put it back in its original position return; } nAccept++; //if reached here, move is accepted }
Have a look at a simple MC simulation applet
27
4b. Examination of Java Code
• Atom methods
• Space.Vector methods public void setRandomCube() { x = random.nextDouble() - 0.5; y = random.nextDouble() - 0.5; }
public void PEa1Tv1(double a1, Vector u) { x += a1*u.x; y += a1*u.y;}
public void E(Vector u) {x = u.x; y = u.y;}
public final void displaceWithin(double d) {workVector.setRandomCube(); displaceBy(d,workVector);}
public final void displaceBy(double d, Space.Vector u) {rLast.E(r); translateBy(d,u);}
public final void translateBy(double d, Space.Vector u) {r.PEa1Tv1(d,u);} public final void replace() {r.E(rLast);}
28
5. Tuning
• Size of step is adjusted to reach a target rate of acceptance of displacement trials– typical target is 50%
– for hard potentials target may be lower (rejection is efficient)
Large step leads to less acceptance but
bigger moves
Small step leads to less movement but more acceptance
29
Assignments Summary
• 0. Send me an email– completed
• 1. Construct and deploy a simple molecular simulation applet– completed
• 2. Find and review an article from the literature that applies molecular simulation– 10/9: Notify me of paper to examine– 10/16: Present 15-minute oral summary to class
• 3. Design, construct, test and deploy a molecular simulation– Must demonstrate a non-trivial collective behavior– Incorporation of game-like features is encouraged– 10/23: Specification of simulation project due; prepare one design and an
alternate in case of project duplication. In-class discussion of needed components by each group to complete their project.
– 12/4: Present and explain applets in class
30
In-class Exercise
• Construct a NPT Monte Carlo simulation– Lennard-Jones potential
– Slider to adjust pressure
– Meter and box display to show density
– Measure density for several pressures
– Use Lennard-Jones system of units
• Construct a NVT Monte Carlo simulation– NSelector to select density
– MeterPressureSoft and box display to show density• www.cheme.buffalo.edu/courses/ce400/MeterPressureSoft.class
– Measure pressure for several densities
• Compare results. Do pressure/density data agree?