Cours_2 [Compatibility Mode]

µ(gas, ideal) = µ0(gas) + kBT ln(P). µVT. PVT - .... taken from D. A. Kofke's lectures on Molecular Simulation, SUNY Buffalo ..... Probability distribution law:.
4MB taille 3 téléchargements 295 vues
Computer modeling methods Monte Carlo and Molecular Dynamics

http://allos.up.univ-mrs.fr/simulations.html

Bogdan Kuchta Laboratoire Chimie Provence (LCP) Université de Provence, Marseille

Brief Account of MC, MD N ~ 100 – 10,000 Periodic boundaries Prescribed intermolecular potential

Monte Carlo Molecular Dynamics

Importance sampling Metropolis algorithm for Canonical Ensemble Specify N, V, T

 

equations of motion integration schemes Specify N, V, E

Generate random moves

Solve Newton’s equations Fi = mi ai

Sample with P ∼exp(-E/kT)

Calculate ri(t), vi(t)

Take averages

Take averages

Obtain equilibrium properties

Obtain equilibrium and nonequilibrium properties

Features Common to MC and MD • We will get accurate results for our model system, provided: - N is large enough - run is long enough - we avoid metastability trapping - unwanted boundary effects are minimized • Runs typically involve N up to 100,000 and real times up to 10-50 ns. However, with current machines it is possible to study N up to several million, and times up to 1 μs.

Features Common to MC and MD For many problems the boundary effects can be minimized by the use of periodic boundary conditions (PBC). The sample of interest is surrounded by replicas of itself. To avoid spurious correlations between molecules with their images in neighboring boxes, N must be sufficiently large so that the interaction range is less than ½ of the box length.

Schematic representation of periodic boundary conditions for a two-dimensional system. The dashed circle shows the cutoff radius (L/2) and the minimum image convention. taken from Gubbins and Quirke.

Monte Carlo

A system of N molecules, described by their positions r = (r1, r2, ..., rN) The consecutive configurations are generated in a random way on the potential energy surface.

pk = C exp(−

Ek ) k BT

1.ri(n+1) = ri(n) + ∆r

Initial data:

2.∆E = E(n+1) – E(n)

Force fields Initial configuration

3.If ∆E < 0 , new configuration (n+1) is accepted (always) If ∆E > 0, new configuration is accepted with a probability p=exp(-∆E/kT)

Advantages: More frequent generation of more probable states (with lower energy) Possible simulations in different ensembles

Grand Canonical Monte Carlo

µVT- constant µ(gas) = µ(adsorbate) µ(gas, ideal) = µ0(gas) + kBT ln(P) µVT

PVT - constant

External ideal gas pressure P

Molecular Dynamics Molecular dynamics Exploration of the hyper-energy surface in a dynamic way, by solving the Newton equation of motion

r&i =

∂H pi = ∂pi mi

p& i = −

Choice of ∆t: it has be relatively small in comparison with the typical oscillation time of the studied phenomenon

ri(t+∆t) = ri(t) + vi(t) ∆t

∂H ∂U =− = Fi (ri ,..., rN ) ∂ri ∂ri

vi(t+∆t) = vi(t) + fi(t) ∆t/mi

Initial data:

Advantages:

Force fields

Due to the fact that temperature effects are included, the system may overcome energy barriers

Initial configuration Initial velocities

Differences Between MC and MD

• MD gives information about dynamical behavior, as well as equilibrium, thermodynamic properties. Thus, transport properties can be calculated. MC can only give static, equilibrium properties • MC can be more easily adapted to other ensembles: - µ, V, T (grand canonical) - N, V, T (canonical) - N, P, T (isobaric-isothermic) • In MC motions are artificial - in MD they are natural • In MC we can use special techniques to achieve equilibrium. For example, can ‘observe’ formation of micelles, slow phase transitions.

Newtonian Formulation Cartesian spatial coordinates ri = (xi,yi,zi) are primary variables 

for N atoms, system of N 2nd2nd-order differential equations

d 2ri m 2 ≡ m&& ri = Fi dt Assume conservative forces

r r F = −∇U

Gradient of a scalar potential energy

Integration Algorithms Equations of motion in cartesian coordinates dr j dt dp j dt

=

pj

r = ( rx , ry )

m

p = ( px , p y )

= Fj

2-dimensional space (for example)

N

F j = ∑ Fij

pairwise additive forces

i =1 i≠ j

F Desirable features of an integrator  minimal need to compute forces (a very expensive calculation)  good stability for large time steps  good accuracy  conserves energy and momentum  time--reversible time

Verlet Algorithm 1. Equations Very simple, very good, very popular algorithm Consider expansion of coordinate forward and backward in time 1 &&& r (t + δ t ) = r (t ) + m1 p(t )δ t + 21m F(t )δ t 2 + 3! r (t )δ t 3 + O (δ t 4 ) 1 &&& r (t − δ t ) = r (t ) − m1 p(t )δ t + 21m F(t )δ t 2 − 3! r (t )δ t 3 + O (δ t 4 )

Add these together r (t + δ t ) + r (t − δ t ) = 2r (t ) + m1 F (t )δ t 2 + O (δ t 4 )

Rearrange r (t + δ t ) = 2r (t ) − r (t − δ t ) + m1 F (t )δ t 2 + O (δ t 4 ) 

update without ever consulting velocities!

taken from D. A. Kofke’s lectures on Molecular Simulation, SUNY Buffalo http://www.eng.buffalo.edu/~kofke/ce530/index.html

Verlet Algorithm 2. Flow diagram One MD Cycle

Configuration r(t) Previous configuration r(t-dt) One force evaluation per time step

Entire Simulation Initialization

Compute forces F(t) on all atoms using r(t)

Reset block sums

New configuration 1 move per cycle

Advance all positions according to r(t+dt) = 2r(t)-r(t-dt)+F(t)/m dt2

Add to block sum cycles per block

Compute block average blocks per simulation

Add to block sum

Compute final results

Yes

No End of block?

Block averages

Verlet Algorithm 2. Flow Diagram

t-dt

t

t+dt

r

Given current position and position at end of previous time step

v F

Schematic from Allen & Tildesley, Computer Simulation of Liquids

Verlet Algorithm 2. Flow Diagram

t-dt r v

t

t+dt Compute the force at the current position

F

Schematic from Allen & Tildesley, Computer Simulation of Liquids

Verlet Algorithm 2. Flow Diagram

t-dt

t

t+dt

r

Compute new position from present and previous positions, and present force

v F

Schematic from Allen & Tildesley, Computer Simulation of Liquids

Verlet Algorithm 2. Flow Diagram

t-2dt r v

t-dt

t

t+dt Advance to next time step, repeat

F

Schematic from Allen & Tildesley, Computer Simulation of Liquids

Verlet Algorithm. 3. Loose Ends Initialization  how to get position at “previous time step” when starting out?  simple approximation

r (t0 − δ t ) = r (t0 ) − v (t0 )δ t Obtaining the velocities  not evaluated during normal course of algorithm  needed to compute some properties, e.g. temperature diffusion constant  finite difference

v (t ) =

1 [r (t + δ t ) − r (t − δ t )] + O(δ t 2 ) 2δ t

taken from D. A. Kofke’s lectures on Molecular Simulation, SUNY Buffalo http://www.eng.buffalo.edu/~kofke/ce530/index.html

Initial Velocities Random direction  randomize each component independently  randomize direction by choosing point on spherical surface Magnitude consistent with desired temperature. Choices: prob(vx ) ∝ exp − 12 mvx2 / kT  Maxwell--Boltzmann: Maxwell 1 v 2 = kT / m  Uniform over ((-1/2,+1/2), then scale so that N ∑ i,x vx = ± kT / m  Constant at  Same for y, z components Be sure to shift so centercenter-ofof-mass momentum is zero

(

Px ≡ N1 ∑ pi, x pi, x → pi, x − Px

taken from D. A. Kofke’s lectures on Molecular Simulation, SUNY Buffalo http://www.eng.buffalo.edu/~kofke/ce530/index.html

)

Velocity Verlet Algorithm Round-off advantage of leapfrog, but better treatment of velocities RoundAlgorithm r (t + δ t ) = r (t ) + v (t )δ t + 21m F(t )δ t 2 v (t + δ t ) = v (t ) + 21m [ F(t ) + F(t + δ t ) ]δ t

Implemented in stages  evaluate current force  compute r at new time  add currentcurrent-force term to velocity (gives v at halfhalf-time step)  compute new force  add newnew-force term to velocity Also mathematically equivalent to Verlet algorithm (in giving values of r)

taken from D. A. Kofke’s lectures on Molecular Simulation, SUNY Buffalo http://www.eng.buffalo.edu/~kofke/ce530/index.html

Monte Carlo: basis Overwhelming number of configurations in which U is repulsive (particularly for dense systems), so that exp[–U(j)/kT] ≅ 0 and there is a little contribution to the average. There is only a small fraction of phase space that contributes appreciably to the average.

• Importance sampling: If configurations can be sampled with probability proportional to exp[–U(xN)/kT], we expect these configurations will be the ones contributing most to the average. Then

1 nc A = ∑ A( j ) nc j =1 where nc = total number of configurations. Metropolis et al. showed how to implement importance sampling: (N. Metropolis, A. W. Rosenbluth, M. N. Rosenbluth, A. H. Teller and E. Teller, J. Chem. Phys. 21, 1087 (1953))

Monte Carlo: basis

(taken from D. Frenkel and B. Smit, Understanding Molecular Simulation, 2nd ed. (2002) )

Monte Carlo: basis • Markov chain: The Metropolis method generates a Markov chain, which satisfies 2 conditions: 1. The outcome of each trial depends only on the preceding trial, and not on any prior trials 2. Each trial belongs to a finite set of possible states.

Thus the first condition makes a clear distinction between MC and MD. In MD, which is deterministic, all states are connected in time • References: – A. R. Leach, Molecular Modelling, Longman, London (1996) pp. 414-418 – D. Frenkel and B. Smit, Understanding Molecular Simulation, 2nd ed., Academic Press (2002) pp. 24-27 – M. P. Allen and D. J. Tildesley, Computer Simulation of Liquids, Clarendon Press, Oxford (1987) pp. 114-123 taken from K. E. Gubbins lectures on Multi-Scale Modeling of Matter http://chumba.che.ncsu.edu/

Theory behind the importance sampling • Transition Matrix (TM): Suppose the system is in state m, (xN)m. The probability of a transition to state n with (xN)n is πmn (xN)m

(xN)n

πmn = probability of moving from m to n

Let M be the total number of possible states. Then the elements pmn form a M x M matrix, called the transition matrix :

 π11 π12 K π1M    π π π K  22 2M  π =  21 M M M    π π π K  M1 M2 MM 

∑ πmn = 1 n

for m=1,2,….M

(Each row must sum to 1, i.e n must be one of the possible states)

Theory behind the importance sampling The probability that the system is in a particular state is given by the row matrix ρ

ρ = ( ρ1 ρ 2 K ρ m K ρ n K ρ M ) Thus ρi = probability that the system is in state i with energy Ei and configuration (xN)i . (Note: these states do not have to be equilibrium ones – they are not equilibrium, usually).

Let ρ (1) represent the initial, randomly chosen configuration. Then the probability of the second state is :

ρ(2 ) = ρ(1) π

And the third state is:

ρ(3) = ρ(2 ) π = ρ(1)π π

, etc.

Theory behind the importance sampling The equilibrium distribution of the system is found by applying π an infinite number of times. Markov chain gives this limiting distribution:

ρ limit = lim ρ(1) π

M

M →∞

In our situation :

ρlimit must obey the Boltzmann distribution law, i.e. it must be proportional to exp[–E(xN)/kT].

• Example: Consider a system that can only exist in two states, E1 and E2, which have values such that exp(–E1/kT) : exp(–E2/kT) = 2:1. The following transition matrix provides this ρlimit:

 0.5 0.5  π =  1 0  

e− βU

new

e− βU

old

π12= exp(–E2/kT) /exp(–E1/kT) = 1/2 ; π11 = 1 - π12 = 1/2 π21=1 ⇒ exp(–E1/kT) /exp(–E2/kT) = 2 ; π22 = 1 - π21 = 0 WHY ???? ⇒

Theory behind the importance sampling Suppose the initial state is in E1, i.e. ρ (1) = (ρ1 ρ2) = (1 0). Then the second state is

 0.5 0.5  ρ(2) = ρ(1) π = (1 0 )  = (0.5 0.5) 1 0   and

 0.5 0.5  ρ(3) = (0.5 0.5)  = (0.75 0.25) 1 0    0.5 0.5  ρ(4 ) = (0.75 0.25)  = (0.625 0.375) 1 0  

Successive applications of π leads to

 2 1 ρ limit =    3 3

Theory behind the importance sampling When the limiting distribution is reached, application of π simply gives the limiting distribution back,

ρ limit π = ρ limit Thus, in the above example

 2 1  0.5 0.5 =  2 1  =  exp(− E / kT ) , exp(− E       Z Z  3 3 1 0   3 3 1

2

/ kT )   

Z = exp(− E1 / kT ) + exp(− E2 / kT )

Theory behind the importance sampling • Stochastic Matrix (SM): The stochastic matrix, with elements αmn, gives the probability of choosing the two states m and n, between which the move is made. It is also called the underlying matrix of the Markov π) and SM (α α) are related by chain. The TM (π

π mn = αmn pmn Probability of a transition from m to n

= Probability of choosing states m, n

α is assumed to be symmetrical, αmn = αnm.

X

Probability of accepting a trial move from m to n

In general, this can be violated !!!!!!!

The probability of choosing states m and n must be the same whether the move is from m to n or n to m.

Theory behind the importance sampling •

Microscopic reversibility: The condition of microscopic reversibility states that, at equilibrium, the transition from m to n must equal the rate of transition from n to m.

rate of

The rate of transition from m to n is the product of the probability from m to n, πmn, times the probability density of the initial state m, ρm. It requires

π mn ρ m = π nm ρ n

(6)

This is necessary to maintain the equilibrium distribution once it is reached.

Equation:

ρnπnm = ρmπmn is sometimes called the detailed balance condition or microscopic reversibility.

Theory behind the importance sampling This becomes, generally

ρm αmn pmn = ρn αnm pnm - Since α is symmetric, αmn = αnm, this becomes

ρm pmn = ρn pnm

pmn ρ n = pnm ρ m

So, if ρn ~ exp(-βU)

{

}

pmn ρ n = = exp − β  U ( x N ) − U ( x N )  n m  pnm ρ m Turn the problem around... …given a desired ρ, what transition probabilities will yield this as a limiting distribution? Construct transition probabilities to satisfy detailed balance

Theory behind the importance sampling • The Metropolis scheme: - We need an acceptance probability scheme for pmn that obeys detailed balance condition - Also, pmn cannot be greater than 1, since it is a probability - Metropolis et al. chose to use pmn

=1 ρ = n ρm

if ρn ≥ ρm, i.e. if E(xN)n ≤ E (xN)m if ρn < ρm , i.e. if E(xN)n > E(xN)m

Other choices are possible (see Allen & Tildesley), but the Metropolis scheme seems more efficient than others.

πmn From the above the transition probability is :

= αmn

if ρn ≥ ρm, n ≠ m

= αmn

ρn ρm

= 1−

∑ π m 'n '

if ρn < ρm , n ≠ m if n = m

m '≠ n '

The Metropolis Method -The usual scheme for putting Metropolis into practice is 1) A randomly chosen molecule i is made to undergo a random displacement ∆r from its initial position to a new position within a cube of length l, centered on the original position of i. Usually l is chosen so that ~50% of trial moves are accepted. If l is too small we get a higher acceptance rate, but this may not sample all configurations efficiently. If l is too large most trials are rejected 2) Calculate E(xN)n and ∆E = E(xN)n – E(xN)m 3) If ∆E is negative, i.e. ρn /ρm > 1, the move is accepted 4) If ∆E is positive, i.e. pn /pm < 1, the move is accepted with probability pn /pm = exp[–∆E /kT]. The decision to accept or reject the move is made by generating a random number z with a value between 0 and 1. If z ≤ exp[–∆E /kT] the move is accepted, otherwise it is rejected. If it is rejected the old state m is again counted as the new configuration in the chain.

The Metropolis Method - This can be summarized by writing the acceptance probability, Pacc ≡ pmn as:

Pacc = min 1, exp ( − ∆U kT ) 

(10)

1

0 ≤ rnd ≤ 1

exp(-∆U/kT)

If rnd ≤ exp(-∆U/kT) - move accepted Otherwise - no ∆U

IF (EDIF.le.0.0) then XR = RNDM() RTEST = TEMP * LOG(XR) IF (EDIF.LT.RTEST) RETURN IACT = IACT + 1 endif

EDIF = -∆U ln(rnd) ≤ -∆U/kT

Grand Canonical Ensemble: Statistical Approach •

• • • •

We must first choose a set of independent variables (ensemble), and then derive the distribution law for the probability the system is in a certain (quantum or classical) state. The most commonly used ensembles are: N,V,E Microcanonical ensemble • Probability distribution law: N,V,T Canonical ensemble µ,V,T Grand canonical ensemble − β E −µ N e ( k ) N,P,T Isothermal-isobaric ensemble

PNk =

Ξ = ∑ e βµ N ∑ e − β Ek = ∑ e βµ N QN N ≥0

where

β = 1/kT

µ = chemical potential per molecule = Ek = energy of system in q.s. k

Ξ=

probability system is in quantum state k and has N molecules

N ≥0

k

grand partition function

Ξ

=

 ∂G     ∂N T , P

= Ξ( µ,V , T )

Grand Canonical Ensemble: Statistical Approach •Derivation of the limiting distribution: The grand partition function :

Ξ = Ξ ( µ , V , T ) = ∑ e βµ N ∑ e − β UK = ∑ e βµ N QN N ≥0

N ≥0

K

Let us assume that we are dealing with a classical system of N identical particles contained in a cubic box of length L = V1/3. Replacing the expression for the classical partition function in the canonical ensemble, QN:

Ξ = ∑e N ≥0

βµ N

QN = ∑ e

1

L

( )

L

K ∫ d r exp  − β U r 3N ∫  Λ N!

βµ N

N ≥0

N

0

0

N

12

where

 h2  Λ=  = thermal de Broglie wavelength 2 π mkT   Therefore, the corresponding probability density is :

(

1 exp − β U (r N ) + βµN 3N ΞΛ

ρ (r N ) =

)

Grand Canonical Ensemble: classical Approach • Gibbs-Duhem equation:

For an open phase

dU = TdS − PdV + ∑ µi dni i

From the definition G = H –TS = U + PV –TS and G = Σµini, so

U = TS − PV + ∑ µi ni (8.8)

i

Differentiating this equation,

dU = TdS + SdT − PdV − VdP + ∑ µi dni + ∑ ni dµi i

i

(8.9)

Grand Canonical Ensemble: classical Approach From (8.7) and (8.9)

SdT − VdP + ∑ ni dµi = 0

Gibbs-Duhem equation

(8.10)

i

• Grand Potential (or Grand Free Energy): For the grand canonical ensemble, the thermodynamic potential is

Ω = A − ∑ N α µα = A − G = − PV

(bulk system)

α

d ( PV ) = PdV + VdP = PdV + SdT + ∑ N α dµα α

For change at fixed T, Ω = − PV

V, µα : dΩ ≤ 0

is minimum at equilibrium

Grand Canonical Ensemble: classical Approach Thus

 ∂ ( PV )   ∂Ω  P=  = −   ∂V T , µ  ∂V T , µ

(8.12)

 ∂ ( PV )   ∂Ω  S =  = −   ∂T V , µ  ∂T V , µ

(8.13)

 ∂ ( PV )   ∂Ω  N =  = −   ∂µ V ,T  ∂µ V ,T

(8.14)

(8.11)

Grand Canonical Ensemble: statistical Approach • Thermodynamic properties in terms of

Ξ

1) Average number of molecules

N = ∑∑ PNk N = N

or

N =

k

1 e βµ N e− β Ek N ∑ Ξ Nk

1  ∂ ln Ξ    β  ∂µ  βV

PV = kT ln Ξ = −Ω central equation for the grand canonical ensemble

2) The function PV A thermodynamic identity is (8.14)

 ∂ ( PV )  N =   ∂µ V ,T

Grand Canonical Ensemble: statistical Approach 3) The equation of state From (8.12):

∂ ( PV )   ∂ ln Ξ  P =   ⇒ P = kT    ∂V T , µ  ∂V T , µ qN , where q is the molecular partition function QN = For ideal gas: N! N e βµ q ln Ξ = ln ∑ = ln e λq = λq = βPV and λ ≡ e βµ N! N ≥0

(

N =

)

( )

1  ∂ ln Ξ  ∂ βµ  ∂ ( λq )  e q =   = kT   = kT β  ∂µ  βV ∂µ  ∂µ  βV

= e βµ q = λq = βPV

(

Thus:

)

1 PV kT ∴ PV = kT N = RT N = βPV =

Grand Canonical Monte Carlo Insertion/Deletion Trial Move 1. Limiting probability • Gives new configuration of the same volume but different number of molecules • Choose with equal probability: – insertion trial: add a molecule to a randomly selected position – deletion trial: remove a randomly selected molecule from the system • Limiting probability – grand-canonical ensemble:

p(r N ) = ρ (r N )dr N =

(

)

1 exp − β U (r N ) + βµN dr N 3N ΞΛ 1/ 2

 where Λ =  h   2πmk T  2

is thermal de Broglie wavelength

B

Grand Canonical Monte Carlo Insertion/Deletion Trial Move 2. Analysis of Trial Probabilities •

Event [reverse event] Select insertion trial [select deletion trial] Place molecule at rN+1 [delete molecule N+1] Accept move [accept move]

Transition matrix

Probability [reverse probability] ½ [½ ] dr/V [1/(N+1)] min(1,χ) [min(1,1/χ)]

Convention insert: (N+1) = Nold+1 delete: (N+1) = Nold

Forward-step 1 dr × × min(1, χ ) trial 2 V probability Reverse-step 1 1 × × min(1, χ1 ) trial 2 N +1 probability

χ is formulated to satisfy detailed balance

adapted from D. A. Kofke’s lectures on Molecular Simulation, SUNY Buffalo http://www.eng.buffalo.edu/~kofke/ce530/index.html

Grand Canonical Monte Carlo Insertion/Deletion Trial Move 3. Analysis of Detailed Balance •

Detailed specification of trial moves and and probabilities

Forward-step 1 dr trial × × min(1, χ ) 2 V probability

Reverse-step 1 1 trial × × min(1, χ1 ) 2 N + 1 probability

Detailed balance

pi

πij

=

pj

πji

Limiting p(r N ) = 1 exp(− βU (r N ) + βµN )dr N ΞΛdN distribution

adapted from D. A. Kofke’s lectures on Molecular Simulation, SUNY Buffalo http://www.eng.buffalo.edu/~kofke/ce530/index.html

Grand Canonical Monte Carlo Insertion/Deletion Trial Move 3. Analysis of Detailed Balance

Forward-step 1 dr trial × × min(1, χ ) probability 2 V

Reverse-step 1 1 trial × × min(1, χ1 ) probability 2 N + 1

Detailed balance

pi e− βU

old

+ βµ N

ΞΛ dN

πij

=

pj

πji

− βU + βµ ( N +1) N +1 dr N  1 dr dr 1  e 1 1 ) × × min(1, χ ) = × × min(1, ( 1) χ d N +  2 V   2 N + 1  ΞΛ new

Limitingp(r N ) = 1 exp(− β U (r N ) + βµN )dr N ΞΛdN distribution

Grand Canonical Monte Carlo Insertion/Deletion Trial Move 3. Analysis of Detailed Balance Forward-step 1 dr trial × × min(1, χ ) 2 V probability

Reverse-step 1 1 trial × × min(1, χ1 ) 2 N + 1 probability

Detailed balance

πij

pi e− βU

old

+ βµ N

ΞΛ dN

=

πji

pj

− βU + βµ ( N +1) N +1 dr N  1 dr dr 1  e 1  × × min(1, χ ) = × × min(1, χ1 )  d ( N +1)  2 V   2 N +1  ΞΛ new

Remember insert: (N+1) = Nold+1 delete: (N+1) = Nold

new 1 − βU old 1 e χ= d e − βU + βµ V Λ ( N + 1)

χ=

V − β (U new −U old ) + βµ e Λd ( N + 1)

Acceptance probability

Grand Canonical Monte Carlo 1 ΞΛ

limit (N=const): (− β U )= exp (r ) + βµN )dr ρ (r Canonical N

N

N

3N

Acceptable trial moves are: – Particle move: a particle is selected at random and given a new conformation (e.g., for atoms, a random displacement). The detailed balance condition gives:

pold →new ρ new exp(− βU new ) = = = exp(− β (U new − U old )) pnew→old ρ new exp(− βU old )

Therefore, the acceptance criteria for this trial move is given by:

{

Pa cc = m in 1, ex p  − β ( U n ew − U o ld ) 

}

Grand Canonical Monte Carlo – Insertion trial: a particle is inserted at a random position. The old configuration has N particles and the new has N+1 particles. The detailed balance condition gives:

Pacc = min(1,χ)

χ=

V − β (U new −U old ) + βµ e Λ3 ( N + 1)

Remember insert: (N+1) = Nold+1 delete: (N+1) = Nold

Therefore, the acceptance criteria for this trial move is given by:

  V Pacc = min 1, 3 exp β  µ − Unew ( N + 1) + Uold ( N )    Λ ( N + 1) 

{

}

Grand Canonical Monte Carlo Chemical potential for un ideal gas:

   µ  µ   q q q exp exp     µ  kT   kT  q       = exp Ξ = ∑e  = exp   N!     Λ Λ         pV  µ V = ln Ξ = exp   q kT  kT  Λ p 1 µ  Λ exp   = exp[βµ ] = kT q  kT  n



n

tr

kT

3

n =0

3

3

rot

3

rot

When the gas is atomic (qrot=1):

p µ  exp   = exp[βµ ] = Λ kT  kT 

3

rot

Grand Canonical Monte Carlo “Insert” algorithm call pos_gen(xct,yct,zct,rpore,ypore,zpore) call ener0(xct,yct,zct,enn) call potgr(xct,yct,zct,EG)

For an atomic ideal gas adsorption:

ent = enn + EG

P Λ = exp[βµ ] kT

coefi = zz*vol/(npart+1) rtest = temp*log(rndm()) etest = -ent + temp*log(coefi) if (rtest.lt.etest) then

3

B

VP   exp[− β (U ( N + 1) − U ( N ) )] P = min 1, β N +1  

IAA = IAA +1 xc(npart+1) = xct yc(npart+1) = yct zc(npart+1) = zct

acc

call update_add endif

Grand Canonical Monte Carlo – Deletion trial: a randomly selected particle is removed from the system. The old configuration has N particles and the new has N – 1 particles. The detailed balance condition gives:

Pacc = min(1,1/χ)

χ=

Remember insert: (N+1) = Nold+1 delete: (N+1) = Nold

V − β (U new −U old ) + βµ e Λ3 ( N + 1)

Therefore, the acceptance criteria for this trial move is given by:

 Λ3 N  Pacc = min 1, exp − β  µ + Unew ( N − 1) − Uold ( N )    V 

{

}

Grand Canonical Monte Carlo “Remove” algorithm

ip=INT(npart*rndm())+1 eno = ENmol(ip) coef = npart/(zz*vol) rtest = temp*log(rndm()) etest = eno + temp*log(coef)

For an atomic ideal gas adsorption:

P Λ = exp[− βµ ] kT 3

if (rtest.lt.etest) then IAR = IAR + 1 call update_remove(ip) endif

B

 1 N  exp [− β (U ( N ) − U ( N − 1) )] Pacc = min  1,  β VPid 

MC in the Grand Canonical (µVT) Ensemble • •



GCMC works best if the acceptance of trial moves by which particles are added or removed is not too low. For atomic fluids, this condition effectively limits the maximum density at which the method can be used to about twice the critical density Special tricks are needed to extend the GCMC method to higher densities (see, e.g., M. Mezei, Mol. Phys. 40, 901 (1980))



GCMC is easily implemented for mixtures and inhomogeneous systems, such as fluids near interfaces

Summary Markov process is a stochastic process with no memory Full specification of process is given by a matrix of transition probabilities π A distribution of states are generated by repeatedly stepping from one state to another according to π A desired limiting distribution can be used to construct transition probabilities using detailed balance  Many different P matrices can be constructed to satisfy detailed balance  Metropolis algorithm is one such choice, widely used in MC simulation Markov Monte Carlo is good for evaluating averages, but not absolute integrals

Examples of calculated properties

Simple Thermodynamic properties in MCMC-NVT Internal Energy: The average potential (configurational) energy is easily obtained as the ensemble average of the energies of the states that are examined during the course of a simulation:

1 M

U= U =

M

∑U i =1

where M is the number of states visited

i

Note that what we calculate in a MC simulation is the configurational contribution to the measured properties. ---------------------------------------------------After obtaining the simulation averages, we can add the kinetic energy 3RT/2 (ideal gas) and intramolecular contributions (e.g., electronic, rotation, vibration, internal rotation) to the measured properties.

-700

Simple Thermodynamic properties in MCMC-NVT

-800

-900

-900

-1000

0

200

400

600

800

1000

2000

4000

6000

8000

1 M

M

∑U i =1

i

10000

MC steps -400 1800

-600

1600 1400 1200

Distribution

Energy (K)

1200

1400

0

Distribution

1600

-1100 1800

U= U =

-1000

-800

-1100

Energy (K)

-700

-800

-1000

1000 800 600 400 200

-1200 0

5000

10000

15000

20000

25000 3

Monte Carlo steps / 10

30000

0

-1100

-1000

-900

-800

-700

Simple Thermodynamic properties in MCMC-NVT

Heat Capacity: Capacity: The heat capacity is defined as:

 ∂U  CV =    ∂T V Therefore, this quantity can be calculated by performing a series of simulations at different temperatures, and then differentiating the energy with respect to the temperature. The differentiation can be done numerically of by fitting a polynomial to the data and then analytically differentiating the fitted function.

Simple Thermodynamic properties in MCMC-NVT Heat Capacity. The heat capacity can also be calculated from a single simulation by considering the instantaneous fluctuations in the energy:

U − U 2

CV =

kT 2

2

=

(U −

U

kT 2

)

2

proof: appendix 6.2 Leach, Allen & Tildesley pp. 51-54

The previous equations give the potential (configurational) contribution to the heat capacity. We will need to compute the kinetic part separately. For example, for a system of N atoms, the kinetic part can be calculated easily giving the following wellwellknown result:

3 CVid = Nk 2

ideal gas part of the specific heat

Can calculate many other properties from variable fluctuations in simulations (see, e.g. Allen & Tildesley, pp. 5151-54)

Simple Thermodynamic properties in MCMC-NVT -1050

1 U= U = M

-1100

Energy (K)

-1150

N constant P(T) path

-1200

M

∑U

i

i =1

∂U  CV =    ∂T V

-1250 -1300 -1350 -1400 40

50

60

70

80

90

100

110

120

130

20 Total energy fluctuations

Temperature (K)

CV =

U

2

− U kT

2

2

=

(U −

U

kT

)

2

18 16 14 12 10 8

N const P(T) path

6 4 40

50

60

70

80

90

100

110

120

130

Temperature (K)

2

Simple Thermodynamic properties Pressure: The pressure is usually calculated in a simulation via the virial theorem of Clausius. The virial is defined as the expectation value of the sum of the products of the coordinates of the particles and the forces acting on them. It can be shown that:

NkT 1 P= − V 3V where

w(r ) = r

N

N

∑ ∑ r ij ⋅ F ij i =1 j =i +1

NkT 1 = − V 3V

∑ ∑ w(rij ) N

N

i =1 j =i +1

du (r ) , the derivative of the pair potential used in the dr simulation

For a proof of this, see Leach, pp. 309, or Allen & Tildesley, pp. 4646-49

Structural Properties in MCMC-NVT Radial distribution function: function: This gives the probability of finding an atom (or molecule) a distance r from another atom (or molecule), as compared to the ideal gas distribution

If I have one atom at some central position, how many atoms can I expect to find at a distance between r and r+dr away from it?

figure taken from S. C. Glotzer’s lectures on Computational Nanoscience of Soft Materials, University of Michigan; http://www.engin.umich.edu/dept/cheme/people/glotzertch.html

Radial distribution function • Distribution and correlation functions are useful because they tell us the molecular structure of the material The radial distribution function, g(r), measures the probability of finding 2 molecules a distance r apart.

(Figure taken from Tester and Modell, Thermodynamics and its applications, 3rd edition, Prentice Hall, New Jersey (1997)

Radial distribution function: fluids • Example: homogeneous, isotropic fluid

(from Tester and Modell, Thermodynamics and its applications, 3rd edition, Prentice Hall, New Jersey (1997)

Radial distribution functions for gas and liquid phases of water, and their relationship to molecular-level visualizations

Radial distribution function: crystals • Example: crystalline solid

(from Tester and Modell, Thermodynamics and its applications, 3rd edition, Prentice Hall, New Jersey (1997)

Radial distribution function for a solid phase of water, and its relationship to molecular-level visualizations

Structural Properties in MCMC-NVT Radial distribution function: Consider a spherical shell of thickness dr at a distance r from a chosen atom. The volume of the shell is:

4 4 4 V = π (r + dr )3 − πr 3 = 4πr 2 dr + 4πrdr 2 + πdr 3 3 3 3 ∴V ≈ 4πr 2 dr In 22-d:

A = π (r + dr ) − πr 2 = 2πrdr + πdr 2 ∴ A ≈ 2πrdr 2

If the number of atoms per unit volume is the number density ρ, then if the atoms were randomly distributed, the total number in the shell would be 4πρ πρrr2dr (2πρ πρrdr rdr in 22-d), since ρ= N/V. taken from S. C. Glotzer’s lectures on Computational Nanoscience of Soft Materials, University of Michigan http://www.engin.umich.edu/dept/cheme/people/glotzertch.html

Structural Properties in MCMC-NVT

Divide by # of atoms summed over in outer sum of dn(r)

Divide by # of atoms in the shell of width dr at r if atoms distributed randomly (like an ideal gas)

1 dn(r ) g (r ) = N 4πr 2 drρ dn(r ) = ∑∑ δ (r − rij ) N

N

i =1 j >i

Actual # of atoms in a shell of width dr at r

Sum over atoms

g(r) gives the probability of finding an atom a scalar distance r from another atom compared to the ideal gas probability.

For each atom, count the number of atoms a distance r away

taken from S. C. Glotzer’s lectures on Computational Nanoscience of Soft Materials, University of Michigan http://www.engin.umich.edu/dept/cheme/people/glotzertch.html

Structural Properties in MCMC-NVT Radial distribution function:

taken from S. C. Glotzer’s lectures on Computational Nanoscience of Soft Materials, University of Michigan http://www.engin.umich.edu/dept/cheme/people/glotzertch.html

Grand Canonical Ensemble (TP) Fixing µ, T for the reservoir determines the equilibrium concentration inside the adsorbent Adsorbent in contact with a reservoir that imposes constant chemical potential and temperature, by exchanging particles and energy. (From D. Frenkel and B. Smit, “Understanding Molecular Simulation” 2nd Edition, Academic Press, San Diego (2002))

Grand Canonical Ensemble -200 -400

mc_ene.dat Energy

-600 -800 -1000 -1200

1 2 3 4 5 6 7 8 9 10 11 12 13 14

N

Energy_wall

Energy_total

154 -.7704136000E+03 159 -.7655882000E+03 160 -.7707390000E+03 163 -.7535974000E+03 166 -.7421404000E+03 163 -.7624775000E+03 161 -.7582797000E+03 164 -.7566785000E+03 169 -.7399601000E+03 162 -.7740249000E+03 164 -.7633221000E+03 165 -.7596610000E+03 166 -.7547378000E+03 168 -.7503984000E+03 ……… …….

-.1162552000E+04 -.1162659000E+04 -.1165556000E+04 -.1157627000E+04 -.1146248000E+04 -.1171144000E+04 -.1152653000E+04 -.1159382000E+04 -.1153505000E+04 -.1180890000E+04 -.1166162000E+04 -.1173743000E+04 -.1164632000E+04 -.1165403000E+04

-1400 -1600 0

500

1000

1500

2000

Nbin

600 500 400

N

Nbin

300 200 100 0 0

500

1000

1500

2000

Nbin

Non-equilibrium situation

Grand Canonical Ensemble mc.pos 20 15

N y

10

z

1 154 10.886520 -14.887360 9.244424 10.898990 14.983010 21.000650 14.028510 11.913710 2.990251 -14.459990 11.605350 .722188 1.908520 18.285780 22.916110 1.256716 -18.238170 4.253842 13.606980 -12.499060 7.607756 -15.536920 -9.600965 16.492660 -15.764630 -9.760927 24.275380 -4.318254 -17.841070 23.939530 15.933630 -9.115001 17.567660 …………. ……..

Nbin = 1 N = 154

Y Axis Title

Nbin x

5 0 -5 -10 -15 -20 -20 -15 -10 -5

0

5

10 15 20

X Axis Title

20 15 10

Y Axis Title

20 15

Nbin = 2000 N = 615

Y Axis Title

10 5

5

-10

0

-15

-5

-20

-10

Nbin = 1000 N = 258

0 -5

-20 -15 -10 -5

0

5

X Axis Title

-15 -20 -20 -15 -10 -5

0

5

X Axis Title

10 15 20

10 15 20

Grand Canonical Ensemble Equilibrium situation

-200 1400

-400 1200

T = const

-600

Energy

1000

σ 16.2 7.6 5.8 6.9 9.7 13.2 31.6 26.7 8.3

234.7 362.8 385.8 401.9 421.2 448.3 558.3 691.6 1259.1

600

-800 -1000

400

-1200

200

-1400

0 0.0

0.2

0.4

0.6

0.8

1.0

-1600 0

2000

Pressure

4000

6000

8000

10000

6

MC steps/10

500

Mean values

Variation

-337.7 -1160.2 -1497.9

13.5 15.3 10.2

400

300

N

p 0.05 0.1 0.2 0.3 0.4 0.5 0.7 0.8 0.9



800

200

100

234.7

16.2

0 0

2000

4000

6000

8000 6

MC steps/10

Grand Canonical Ensemble • Some examples: T=290 K

Reduced local density ρ *

8

T=252 K T=228 K T=192 K

6

T=290 K

4

2

0 0

1

2

3

4

5

T=192 K

Reduced radial position r *

(a)

(b)

Freezing of CCl4 in a multi-walled carbon nanotube with D = 5 nm (a) Density profile; (b) snapshots of typical configurations of the adsorbed phase. The carbon nanotube walls are not shown for clarity (taken from F. R. Hung et al., Mol. Phys., (2004))

10000

MC in the Isobaric-Isothermal (NPT) Ensemble •

NPT ensemble widely used in MC simulations



Most laboratory experiments are carried out under conditions of controlled pressure and temperature



NPT simulations can be used to measure the equation of state of a model system, even if the virial expression for the pressure cannot be readily evaluated (e.g. nonspherical hardcore molecules, models where the non-pairwise additive potential energy function is computed numerically for each new configuration)



Convenient to simulate systems in the vicinity of a first-order transition, since at constant pressure the system is free to transform completely into the state of lowest Gibbs free energy



In addition to particle displacement (and rotation for the case of polyatomic molecules), isobaric ensembles have trials moves that change the volume •

The constant-pressure MC method widely used nowadays was originally proposed by McDonald (I. R. McDonald, Mol. Phys. 23, 41 (1972))

Volume-Change Trial Moves •

Gives new configuration of different volume and same N • Basic trial – increase or decrease the total system volume by some amount within ±dV, scaling all molecule centers-of-mass in proportion to the linear scaling of the volume

+dV

+

Perturb the total system volume

Scale all positions in proportion

adapted from D. A. Kofke’s lectures on Molecular Simulation, SUNY Buffalo http://www.eng.buffalo.edu/~kofke/ce530/index.html

Volume-Change Trial Moves •

It is possible to show that the Metropolis scheme is implemented for this trial move by generating a Markov chain of states which has a limiting distribution proportional to



(



)

ρ NPT (V ) ∝ exp − β  U s N , V + PV −

 ln V   β 

N

proof: Frenkel & Smit, pp. 115-119 (13.12)   We have written U(sN, V) to indicate that Υ depends on the real coordinates of the particles in a box of volume V. sN are scaled coordinates, defined as ri = Lsi, for i = 1, 2, … N. We use such coordinates because we need to scale all molecule centers-of-mass in proportion to the linear scaling of the volume. We have assumed that the system is contained in a cubic box with length L=V1/3 . • We can now carry out the Metropolis sampling on the reduced coordinates sN and the volume V.

Volume-Change Trial Moves •

An attempt to change the volume from V to V’ = V + dV, where dV is a random number uniformly distributed over the interval [–dVmax, +dVmax], will give the following detailed balance condition:

pold →new ρ new = pnew→old ρ old

   N N exp − β  U s , V ' + PV '− ln V '  β    =    N N exp − β  U s ,V + PV − ln V   β   

(

)

(

)

  N  V '   N N = exp − β  U s ,V ' − U s , V + P (V '− V ) − ln     β  V    

(

)

(

)

Volume-Change Trial Moves •

Therefore, the acceptance criteria for this volume change attempt is given by

(

{

(

)

(

)

Pacc = min 1, exp − β  U s , V ' − U s , V +  N

N

})

+ P (V '− V ) − N β −1 ln (V ' V )  •

Instead of attempting random changes in the volume, one might construct trial moves in the box length L.

Volume-Change Trial Moves C....

THIS IS THE CODE FOR THE BOX MOVE C.... do I = 1,3 do J = I,3 BOXT(I,J) = BOX(I,J) + DB - DB2 * RAND() enddo CALL ENERGY (Enew,Vnew)

EDIF = Enew - Eold + P*(Vnew-Vold)- RB * N * LOG( Vnew / Vold ) IF (EDIF.GT.0.0) then XR = RAND() RTEST = RB * LOG(XR) IF (EDIF.LT.RTEST) then RETURN

!(not accepted) ELSEIF

………

!THE MOVE HAS BEEN ACCEPTED, need to be updated ENDIF