21
12/7/2011 1 Titus Beu 2011 Titus Beu University “Babes-Bolyai” Department of Theoretical and Computational Physics Cluj-Napoca, Romania 5. Basics of molecular dynamics 5. Basics of molecular dynamics Titus Beu 2011 Bibliography Equations of motion for MD simulations Non-bonded and bonding potentials Potential derivatives and forces Van der Waals potentials Bonded potentials Force parameters in heterogeneous systems Time integration methods Simple application – Oblique throw

5. Basics of molecular dynamicsphys.ubbcluj.ro/~tbeu/MD/C5.pdf · 12/7/2011 2 Titus Beu 2011 Leach, A. R., Molecular Modelling . Principles and applications, Second edition (Prentice

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: 5. Basics of molecular dynamicsphys.ubbcluj.ro/~tbeu/MD/C5.pdf · 12/7/2011 2 Titus Beu 2011 Leach, A. R., Molecular Modelling . Principles and applications, Second edition (Prentice

12/7/2011

1

Titus Beu 2011

Titus BeuUniversity “Babes-Bolyai”Department of Theoretical and Computational PhysicsCluj-Napoca, Romania

5. Basics of molecular dynamics5. Basics of molecular dynamics

Titus Beu 2011

Bibliography

Equations of motion for MD simulations

Non-bonded and bonding potentials

Potential derivatives and forces

Van der Waals potentials

Bonded potentials

Force parameters in heterogeneous systems

Time integration methods

Simple application – Oblique throw

Page 2: 5. Basics of molecular dynamicsphys.ubbcluj.ro/~tbeu/MD/C5.pdf · 12/7/2011 2 Titus Beu 2011 Leach, A. R., Molecular Modelling . Principles and applications, Second edition (Prentice

12/7/2011

2

Titus Beu 2011

Leach, A. R., Molecular Modelling. Principles and applications, Second edition (Prentice Hall, 2001) .

Frenkel , D., Smit, B., Understanding Molecular Simulation. From Algorithms to Applications (Academic Press, 2002).

Rapaport, D.C., The Art of Molecular Dynamics Simulation. Second Edition (Cambridge University Press, 2004).

Allen, M. P., Tildesley, D. J., Computer Simulation of Liquids (Clarendon Press, Oxford, 1991).

Titus Beu 2011

Classical MD --- numerical integration of Newton's equations of motion:

ri – position of particle i

Fi – force acting upon particle i

Forces – typically derive from potential functions:

Conservation of total energy:

2

1 22( , , ), 1,2, ,i

i N

dm i N

dt= =

rF r r r… …

1 2 1 2( , , , ) ( , , , )ii N NU= −∇

rF r r r r r r… …

kinE E U= +

Page 3: 5. Basics of molecular dynamicsphys.ubbcluj.ro/~tbeu/MD/C5.pdf · 12/7/2011 2 Titus Beu 2011 Leach, A. R., Molecular Modelling . Principles and applications, Second edition (Prentice

12/7/2011

3

Titus Beu 2011

Simplest potential – pairwise interactions (absence of external forces):

rij = ri − rj distance vector between particles i and j (rij = |rij|)

j > i prevents double counting of particle pairs

Forces on individual particles:

Newton's third law, fji = − fij, reduces calculations

Most time-consuming component of MD – evaluation of forces – effort ~N2

Tractable calculations – forces expressed analytically

Potential cut off – reduction of computational effort: u(rij) = 0 for rij > Rcut

1

( )N N

ij

i j i

U u r= >

=∑∑

N

i ij

j i≠

=∑F f

Titus Beu 2011

Non-bonded potentials – closed-shell weakly-bonded van der Waals systemsEx. inert gases (Ar, Kr,...), hydrogen-bonded systems (water, DNA, proteins,...),...

v(ri) – applied field or effect of container – dropped for periodic bulk systems

3-body and higher order terms are usually neglected

Bonding potentials – strongly bonded systems (covalent bond, ionic bond,...)Ex. hydrocarbons, fullerenes, DNA, proteins, ...

Most of the established force fields sum up harmonic contributions

Force constants weight the deviations from the equilibrium values of the bond

lengths rij, bond angles θijk, etc.

non-bonded( ) ( ) ( , ) ( , , )N

i i j i j k

i i j i i j i k j

U v u w> > >

= + + +∑ ∑∑ ∑∑∑r r r r r r r …

( ) ( ) ( )2 2

0

bonded

bonds angles torsions

( ) 1 cos2 2 2

r n

ij ijk ijklN eq eq

ij ij ijk ijl ijkl ijkl

k k kU r r n

θ

θ θ φ φ = − + − + + − + ∑ ∑ ∑r …

Page 4: 5. Basics of molecular dynamicsphys.ubbcluj.ro/~tbeu/MD/C5.pdf · 12/7/2011 2 Titus Beu 2011 Leach, A. R., Molecular Modelling . Principles and applications, Second edition (Prentice

12/7/2011

4

Titus Beu 2011

AMBER (Assisted Model Building with Energy Refinement) – family of force fieldsfor molecular dynamics of biomolecules

AMBER – software package for MD simulations

Bonded energy between covalently bonded atoms – harmonic approximation

Non-bonded energy between all atom pairs = van der Waals + electrostatic

Reference:D.A. Case, T.A. Darden, T.E. Cheatham, III, C.L. Simmerling, J. Wang, R.E. Duke, R. Luo, R.C. Walker, W. Zhang, K.M. Merz, B. Roberts, B. Wang, S. Hayik, A. Roitberg, G. Seabra, I. Kolossváry, K.F. Wong, F. Paesani, J. Vanicek, J. Liu, X. Wu, S.R. Brozell, T. Steinbrecher, H. Gohlke, Q. Cai, X. Ye, J. Wang, M.-J. Hsieh, G. Cui, D.R. Roe, D.H. Mathews, M.G. Seetin, C. Sagui, V. Babin, T. Luchko, S. Gusarov, A. Kovalenko, and P.A. Kollman (2010), AMBER 11, University of California, San Francisco

( ) ( )

( )

2 2

bonds angles

0

torsions

6 61

0 0

1 1 0

( )2 2

1 cos2

24

r

ij ijkN eq eq

ij ij ijk ijl

n

ijkl

ijkl ijkl

N Nij ij i j

ij

i j i ij ij ij

k kU r r

kn

r r q q

r r r

θ

θ θ

φ φ

επε

= = +

= − + −

+ + −

+ − +

∑ ∑

∑∑

r

Titus Beu 2011

Inter-atomic distance in Cartesian coordinates:

Gradient of inter-atomic distance:

Pair-wise forces caused by displacement of atom i:

( ) ( ) ( )

( ) ( ) ( )2 2 2

ij x i j y i j z i j

ij i j i j i j

x x y y z z

r x x y y z z

= − + − + −

= − + − + −

r e e e

ij ij ij ij

x y z

i i i i

ij i j i j i j ij

x y z

i ij ij ij ij

r r r r

x y z

r x x y y z z

r r r r

∂ ∂ ∂ ∂= + +

∂ ∂ ∂ ∂

∂ − − −= + + =

e e er

re e e

r

( ) ( ) ( )

( ) ( ) ( )

ij ij ij ij ij

i

i ij i ij ij

ij ij ij ij ij

j i

j ij j ij ij

u r u r r u r

r r r

u r u r r u r

r r r

∂ ∂ ∂ ∂= − = − = −

∂ ∂ ∂ ∂

∂ ∂ ∂ ∂= − = − = = −

∂ ∂ ∂ ∂

rf

r r

rf f

r r

Page 5: 5. Basics of molecular dynamicsphys.ubbcluj.ro/~tbeu/MD/C5.pdf · 12/7/2011 2 Titus Beu 2011 Leach, A. R., Molecular Modelling . Principles and applications, Second edition (Prentice

12/7/2011

5

Titus Beu 2011

Cosine of angle between two bonds (j is the vertex):

Gradient of angle cosine in Cartesian coordinates :

( )( ) ( )( ) ( )( )

( ) ( ) ( ) ( ) ( ) ( )2 2 2 2 2 2

cosi j k j i j k j i j k jij kj

ijk

ij kji j i j i j k j k j k j

x x x x y y y y z x z x

r rx x y y z z x x y y z z

θ− − + − − + − −⋅

= =⋅ − + − + − − + − + −

r r

( ) ( )1cos cos

1cos cos

1cos cos

cos cos cos

k j i j

ijk ijk

i ij kj ij

kj ij

ijk ijk

i ij kj ij

ij kj

ijk ijk

k kj ij kj

ijk ijk ijk

j i k

x x x x

x r r r

r r r

r r r

θ θ

θ θ

θ θ

θ θ θ

− −∂= − ∂

∂= − ∂

∂= − ∂

∂ ∂ ∂= − −

∂ ∂ ∂

r r

r

r r

r

r r r

Titus Beu 2011

Three-body interaction depending on angle between bonds:

Forces on atoms i and k:

Force on vertex atom j:

( , , ) (cos )i j k ijku u θ=r r r

( )j i k= − +f f f

(cos ) (cos ) cos (cos )1cos

cos cos

(cos ) (cos ) cos (cos )1cos

cos c

ijk ijk ijk kj ij ijk

i ijk

i ijk i ij kj ij ijk

ijk ijk ijk ij kj ijk

k ijk

k ijk k kj ij kj

u u u

r r r

u u u

r r r

θ θ θ θθ

θ θ

θ θ θ θθ

θ

∂ ∂ ∂ ∂= − = − = − − ∂ ∂ ∂ ∂

∂ ∂ ∂ ∂= − = − = − − ∂ ∂ ∂ ∂

r rf

r r

r rf

r r os ijkθ

Page 6: 5. Basics of molecular dynamicsphys.ubbcluj.ro/~tbeu/MD/C5.pdf · 12/7/2011 2 Titus Beu 2011 Leach, A. R., Molecular Modelling . Principles and applications, Second edition (Prentice

12/7/2011

6

Titus Beu 2011

Lennard-Jones potential – the most common pair potential for non-bonded (van der Waals) systems (1924):

σ – collision diameter (uLJ(σ) = 0)

ε – well depth (interaction strength)

(σ /rij)12 – strong repulsion at small rij (non-bonded overlap of electronic orbitals)

−(σ /rij)6 – weak attraction at large rij – long-range attractive van der Waals

dispersion forces (dipole-dipole interactions due to fluctuating dipoles)

12 6

LJ

6 6

( ) 4

48 1

2

ij

ij ij

ij

ij

ij ij ij ij

u rr r

r r r r

σ σε

ε σ σ

= −

= − ⋅

rf

Titus Beu 2011

Lennard-Jones potential – the most common pair potential for non-bonded (van der Waals) systems (1924):

req = 21/6σ – minimum (uLJ(req) = −ε)

ε – well depth (interaction strength)

(req /rij)12 – strong repulsion at small rij (non-bonded overlap of electronic orbitals)

−(req /rij)6 – weak attraction at large rij – long-range attractive van der Waals

dispersion forces (dipole-dipole interactions due to fluctuating dipoles)

12 6

LJ

6 6

( ) 2

121

eq eq

ij

ij ij

eq eq ij

ij

ij ij ij ij

r ru r

r r

r r

r r r r

ε

ε

= −

= − ⋅

rf

Page 7: 5. Basics of molecular dynamicsphys.ubbcluj.ro/~tbeu/MD/C5.pdf · 12/7/2011 2 Titus Beu 2011 Leach, A. R., Molecular Modelling . Principles and applications, Second edition (Prentice

12/7/2011

7

Titus Beu 2011

//===========================================================================

void ForcesL_0(float epsilon, float sigma, float rcut,float x[], float y[], float z[],

float Fx[], float Fy[], float Fz[], int natm, float &Epot)//---------------------------------------------------------------------------

// Returns forces for the Lennard-Jones 12-6 potential// Energies in eV, forces in eV/Angs, distances in Angs

{float factE, factF, rcut2, sigma2;

float dx, dy, dz, sr2, sr6, fpr, fxi, fyi, fzi, r2;int iatm, jatm;

factE = 4.e0 * epsilon; factF = 48.e0 * epsilon;

sigma2 = sigma * sigma; rcut2 = rcut * rcut;Epot = 0.e0;

for (iatm=1; iatm<=natm; iatm++) Fx[iatm] = Fy[iatm] = Fz[iatm] = 0.e0;

for (iatm=1; iatm<=natm-1; iatm++) {for (jatm=iatm+1; jatm<=natm; jatm++) {

dx = x[iatm] - x[jatm];dy = y[iatm] - y[jatm];

dz = z[iatm] - z[jatm];

r2 = dx*dx + dy*dy + dz*dz;if (r2 < rcut2) {

sr2 = sigma2 / r2;sr6 = sr2 * sr2 * sr2;

fpr = factF * sr6 * (sr6 - 0.5e0) / r2; // f/r

fxi = fpr * dx;fyi = fpr * dy;

fzi = fpr * dz;Fx[iatm] += fxi; Fx[jatm] -= fxi;

Fy[iatm] += fyi; Fy[jatm] -= fyi;Fz[iatm] += fzi; Fz[jatm] -= fzi;

Epot += factE * sr6 * (sr6 - 1.e0);

}}

}}

//===========================================================================

void ForcesL_0(float epsilon, float sigma, float rcut,float x[], float y[], float z[],

float Fx[], float Fy[], float Fz[], int natm, float &Epot)//---------------------------------------------------------------------------

// Returns forces for the Lennard-Jones 12-6 potential// Energies in eV, forces in eV/Angs, distances in Angs

{float factE, factF, rcut2, sigma2;

float dx, dy, dz, sr2, sr6, fpr, fxi, fyi, fzi, r2;int iatm, jatm;

factE = 4.e0 * epsilon; factF = 48.e0 * epsilon;

sigma2 = sigma * sigma; rcut2 = rcut * rcut;Epot = 0.e0;

for (iatm=1; iatm<=natm; iatm++) Fx[iatm] = Fy[iatm] = Fz[iatm] = 0.e0;

for (iatm=1; iatm<=natm-1; iatm++) {for (jatm=iatm+1; jatm<=natm; jatm++) {

dx = x[iatm] - x[jatm];dy = y[iatm] - y[jatm];

dz = z[iatm] - z[jatm];

r2 = dx*dx + dy*dy + dz*dz;if (r2 < rcut2) {

sr2 = sigma2 / r2;sr6 = sr2 * sr2 * sr2;

fpr = factF * sr6 * (sr6 - 0.5e0) / r2; // f/r

fxi = fpr * dx;fyi = fpr * dy;

fzi = fpr * dz;Fx[iatm] += fxi; Fx[jatm] -= fxi;

Fy[iatm] += fyi; Fy[jatm] -= fyi;Fz[iatm] += fzi; Fz[jatm] -= fzi;

Epot += factE * sr6 * (sr6 - 1.e0);

}}

}}

Titus Beu 2011

General Lennard-Jones potential (1924, John Lennard-Jones):

n = 12, m = 6 Lennard-Jones potential

Buckingham exp-6 potential (1938):

r−12 replaced by a more realistic exp

3 adjustable parameters (ε, rm, α)

Negative singularity (strongly attractive) in the origin!

/( )

LJ ( )

n mm n m

ij

ij ij

n nu r

n m m r r

σ σε

− = − −

6

B

6( ) exp 1

6 6

mij

m

rru r

r r

αε α

α α

= − − −

− −

Page 8: 5. Basics of molecular dynamicsphys.ubbcluj.ro/~tbeu/MD/C5.pdf · 12/7/2011 2 Titus Beu 2011 Leach, A. R., Molecular Modelling . Principles and applications, Second edition (Prentice

12/7/2011

8

Titus Beu 2011

Hill potential (1948):

Parameters – determined by fitting to data for the rare gases

Assumed to be applicable to non-polar gases

Halgren potential (1992):

rij* – depends on the atomic polarizability rii* = Aαi1/4

n = 12, m = 6, δ = γ = 0 → Lennard-Jones potential

n = 14, m = 7, δ = 0.07, γ = 0.12 → buffered 14-7 potential

( ) ( )

( )

H * *

1 1( ) 2

/ /

n m

ij

ij ij ij ij

u rr r r r

δ γε

δ γ

− + + = −

+ +

( ) ( )6

Hill ( ) expij ij m m iju r A B r r C r r= − −

Titus Beu 2011

Many-body effects can significantly affect the dispersion interaction – account for approximately 10% of the lattice energy of crystalline argon

Axilrod-Teller three-body dispersion potential (1943) – triple-dipole correction:

Linear arrangement of atoms – negative contribution – enhances interaction(high correlation of the motions of the electrons)

Equilateral arrangement of atoms – positive contribution – weakens interaction(low correlations)

( ) ( )( )

AT 3 3 3

2 2 2

5 5 5

1 3cos cos cos( , , )

3

ijk jki kij

i j k

ij jk ki

ij jk ki ij jk jk ki ki ij

ij jk ki

u Ar r r

r r rA

r r r

θ θ θ+=

+ ⋅ ⋅ ⋅=

r r r

r r r r r r

Page 9: 5. Basics of molecular dynamicsphys.ubbcluj.ro/~tbeu/MD/C5.pdf · 12/7/2011 2 Titus Beu 2011 Leach, A. R., Molecular Modelling . Principles and applications, Second edition (Prentice

12/7/2011

9

Titus Beu 2011

Finnis-Sinclair potential (1984) – pairwise contributions + many-body term:

u(rij) – pairwise potential (can include electrostatic and repulsive contributions)

Many-body term ~ electron density (decays exponentially from the nuclei)

Tersoff potential (1988) – “empirical bond-order potential”:

bij – bond order between atom i and atom j – the bond strength decreases as the number of bonds to atom i increases

( ) ( )1/2

( ) ( )

( ) exp exp

N

FS ij i

i j i

N

FS ij ij

i j i j i

U u r B

U A r B r

ρ

α β

>

> ≠

= −

= − − −

∑ ∑

∑ ∑ ∑

r

r

( ) ( )

( )1/2

,

( ) exp exp

1 exp

N

T ij ij ij

i j i j i

ij ik ij

k i k j

U A r B b r

b r r

α β

β

> ≠

≠ ≠

= − − −

= + − −

∑ ∑ ∑

r

Titus Beu 2011

The most common potential for bonded interactions – covalent bonds:

k – force constant for bond stretching

req – equilibrium bond length

rcut – cut-off distance

u'bond – shifted bonding potential – asymptotically 0 (discontinuous forces in rcut)

( )

( )

( )

2

bond eq

2

bond eq bond cut

eq

( )2

( ) ( )2

ij ij

ij ij

ij

ij ij

ij

ku r r r

ku r r r u r

k r rr

= −

′ = − −

= − − ⋅r

f

Page 10: 5. Basics of molecular dynamicsphys.ubbcluj.ro/~tbeu/MD/C5.pdf · 12/7/2011 2 Titus Beu 2011 Leach, A. R., Molecular Modelling . Principles and applications, Second edition (Prentice

12/7/2011

10

Titus Beu 2011

//===========================================================================

void ForcesB_0(float kfor, float req, float rcut,float x[], float y[], float z[],

float Fx[], float Fy[], float Fz[], int natm, float &Epot)//---------------------------------------------------------------------------

// Returns harmonic forces for bonded interactions// Energies in eV, forces in eV/Angs, distances in Angs

{float factE, factF, Ecut;

float dr, dx, dy, dz, fpr, fxi, fyi, fzi, r;int iatm, jatm;

factE = 0.5e0 * kfor;

factF = -kfor;dr = rcut - req;

Ecut = factE * dr * dr;Epot = 0.e0;

for (iatm=1; iatm<=natm; iatm++) Fx[iatm] = Fy[iatm] = Fz[iatm] = 0.e0;

for (iatm=1; iatm<=natm-1; iatm++) {for (jatm=iatm+1; jatm<=natm; jatm++) {

dx = x[iatm] - x[jatm];dy = y[iatm] - y[jatm];

dz = z[iatm] - z[jatm];

r = sqrt(dx*dx + dy*dy + dz*dz);if (r <= rcut) {

dr = r - req;fpr = factF * dr / r; // f/r

fxi = fpr * dx;fyi = fpr * dy;

fzi = fpr * dz;Fx[iatm] += fxi; Fx[jatm] -= fxi;

Fy[iatm] += fyi; Fy[jatm] -= fyi;Fz[iatm] += fzi; Fz[jatm] -= fzi;

Epot += factE * dr * dr - Ecut;

}}

}}

//===========================================================================

void ForcesB_0(float kfor, float req, float rcut,float x[], float y[], float z[],

float Fx[], float Fy[], float Fz[], int natm, float &Epot)//---------------------------------------------------------------------------

// Returns harmonic forces for bonded interactions// Energies in eV, forces in eV/Angs, distances in Angs

{float factE, factF, Ecut;

float dr, dx, dy, dz, fpr, fxi, fyi, fzi, r;int iatm, jatm;

factE = 0.5e0 * kfor;

factF = -kfor;dr = rcut - req;

Ecut = factE * dr * dr;Epot = 0.e0;

for (iatm=1; iatm<=natm; iatm++) Fx[iatm] = Fy[iatm] = Fz[iatm] = 0.e0;

for (iatm=1; iatm<=natm-1; iatm++) {for (jatm=iatm+1; jatm<=natm; jatm++) {

dx = x[iatm] - x[jatm];dy = y[iatm] - y[jatm];

dz = z[iatm] - z[jatm];

r = sqrt(dx*dx + dy*dy + dz*dz);if (r <= rcut) {

dr = r - req;fpr = factF * dr / r; // f/r

fxi = fpr * dx;fyi = fpr * dy;

fzi = fpr * dz;Fx[iatm] += fxi; Fx[jatm] -= fxi;

Fy[iatm] += fyi; Fy[jatm] -= fyi;Fz[iatm] += fzi; Fz[jatm] -= fzi;

Epot += factE * dr * dr - Ecut;

}}

}}

Titus Beu 2011

Three-body interaction depending harmonically on angle between bonds:

Forces on atoms i and k:

Force on vertex atom j:

( )2

( , , ) (cos ) cos cos2

ijk eq

i j k ijk ijk ijk

ku u

θ

θ θ θ= = −r r r

( )

( )

cos cos(cos )1cos cos

cos

cos cos(cos )1cos c

cos

eq

ijk ijk ijkkj ij ijk kj ij

i ijk ijk

ij kj ij ijk ij kj ij

eq

ijk ijk ijkkj ij ijk ij

k ijk

ij kj ij ijk kj ij

ku

r r r r r r

ku

r r r r r

θ

θ

θ θθθ θ

θ

θ θθθ

θ

− ∂= − − = − − ∂

− ∂= − − = − − ∂

r r r rf

r r rf os

kj

ijk

kjrθ

r

( )j i k= − +f f f

Page 11: 5. Basics of molecular dynamicsphys.ubbcluj.ro/~tbeu/MD/C5.pdf · 12/7/2011 2 Titus Beu 2011 Leach, A. R., Molecular Modelling . Principles and applications, Second edition (Prentice

12/7/2011

11

Titus Beu 2011

Lorentz-Berthelot mixing rules – standard approach for deriving parameters for mixtures from atomic parameters

Lennard-Jones interaction:collision diameter – arithmetic mean, well depth – geometric mean:

Most successful when applied to similar species

Failure for dissimilar species due to overestimation of the well depth

van der Waals parameters derived from:

crystal packing analysis

liquid simulations optimized to reproduce thermodynamic properties (densities, enthalpies of vaporisation,...)

( ) ( )1 1,

2 2

eq eq eq

AB A B AB AA BB

AB AA BB

r r rσ σ σ

ε ε ε

= + = +

=

Titus Beu 2011

Standard method for solving ODEs – finite difference approach

All finite difference integrators assume that trajectories are continuous and the positions and velocities can be represented as Taylor series expansions:

Solution on a step-by-step basis – propagated solution becomes initial condition for next step

δt is significantly smaller (femtoseconds) than the trajectory extent (nanoseconds)

Order of integrator – power of δt in the last term retained in the Taylor series

MD integrators:

Low-order methods – leapfrog, Verlet – easy implementation, stability

High-order (predictor-corrector) methods – high accuracy for large time-steps

( )

( )

2 3 4

2 3

1 1( ) ( ) ( ) ( ) ( )

2 6

1( ) ( ) ( ) ( )

2

t t t t t t t t t O t

t t t t t t t O t

δ δ δ δ δ

δ δ δ δ

+ = + + + +

+ = + + +

r r v a b

v v a b

Page 12: 5. Basics of molecular dynamicsphys.ubbcluj.ro/~tbeu/MD/C5.pdf · 12/7/2011 2 Titus Beu 2011 Leach, A. R., Molecular Modelling . Principles and applications, Second edition (Prentice

12/7/2011

12

Titus Beu 2011

Euler algorithm

Approximation – quadratic in positions and linear in velocities:

Advantage: simplicity

Disadvantages:

lowest order algorithm – O(δt3)

significant total energy drift (propagation of round-off errors)

not time-reversible

Not recommended!

( )

( )

2 3

2

1( ) ( ) ( ) ( )

2

( ) ( ) ( )

t t t t t t t O t

t t t t t O t

δ δ δ δ

δ δ δ

+ = + + +

+ = + +

r r v a

v v a

Titus Beu 2011

Verlet algorithm (Verlet, 1967)

Connects positions at times t − δt, t, and t + δt:

Propagation relation (by summation) – implies only positions and accelerations:

Velocities are not intrinsic quantities – necessary for kinetic energy & temperature:

Advantages: O(δt4) algorithm, small storage requirements, energy conservation

Disadvantages:

propagates round-off errors – difference of large (δt)0 terms + small (δt)2 term

non-synchronized velocities – lag of 1 or ½ step behind positions

not self-starting – besides r(t), also r(t−δt) is needed

( )

( )

2 3 4

2 3 4

1 1( ) ( ) ( ) ( ) ( )

2 6

1 1( ) ( ) ( ) ( ) ( )

2 6

t t t t t t t t t O t

t t t t t t t t t O t

δ δ δ δ δ

δ δ δ δ δ

+ = + + + +

− = − + − +

r r v a b

r r v a b

( )2 4( ) 2 ( ) ( ) ( )t t t t t t t O tδ δ δ δ+ = − − + +r r r a

[ ] ( ) ( )2( ) ( ) ( ) 2t t t t t t O tδ δ δ δ= + − − +v r r

Page 13: 5. Basics of molecular dynamicsphys.ubbcluj.ro/~tbeu/MD/C5.pdf · 12/7/2011 2 Titus Beu 2011 Leach, A. R., Molecular Modelling . Principles and applications, Second edition (Prentice

12/7/2011

13

Titus Beu 2011

Leap Frog algorithm (Hockney & Eastwood, 1970)

Mid-interval velocities:

Propagation relations – subtract and replace first one up to O(δt2) in r(t+δt/2):

Velocities and positions are staggered – velocity at time t:

Advantages: O(δt3) algorithm, small storage requirements, energy conservation

Disadvantages:

non-synchronized velocities – lag of ½ step behind positions

not self-starting – besides r(t), also v(t−δt/2) is needed

( )

( )

2 3

2 3

( 2) ( ) ( ) 2 ( ) 8

( 2) ( ) ( ) 2 ( ) 8

t t t t t t t O t

t t t t t t t O t

δ δ δ δ

δ δ δ δ

+ = + + +

− = − + +

v v a b

v v a b

( )

( )

3

3

( 2) ( 2) ( )

( ) ( ) ( 2)

t t t t t t O t

t t t t t t O t

δ δ δ δ

δ δ δ δ

+ = − + +

+ = + + +

v v a

r r v

[ ] ( )31( ) ( 2) ( 2)

2t t t t t O tδ δ δ= − + + +v v v

Titus Beu 2011

Velocity Verlet algorithm (Swope et al., 1982)

Positions, velocities and accelerations at the same time

Algebraically equivalent to Verlet and Leap Frog algorithms

1. Predictor step – advance velocity to mid-interval and propagate position:

2. Corrector step – update force (acceleration) and propagate velocity:

Advantages:

O(δt3) algorithm

small storage requirements

good energy conservation

( )( ) ( )

( ) ( 2) ( ) 2

t t t t m

t t t t t t t

δ δ

δ δ δ δ

+ = +

+ = + + +

a F r

v v a

( )

( )

2

3

( 2) ( ) ( ) 2

( ) ( ) ( 2)

t t t t t O t

t t t t t t O t

δ δ δ

δ δ δ δ

+ = + +

+ = + + +

v v a

r r v

Page 14: 5. Basics of molecular dynamicsphys.ubbcluj.ro/~tbeu/MD/C5.pdf · 12/7/2011 2 Titus Beu 2011 Leach, A. R., Molecular Modelling . Principles and applications, Second edition (Prentice

12/7/2011

14

Titus Beu 2011

//===========================================================================

void Verlet0(float amass, float fpar, float rpar, float rcut, float dt,float x[], float y[], float z[],

float vx[], float vy[], float vz[],float ax[], float ay[], float az[], int natm,

float &Ekin, float &Epot, int fopt)//---------------------------------------------------------------------------

// Energies in eV, forces in eV/A, distances in A, velocities in A/psec,// accelerations in A/psec^2

//---------------------------------------------------------------------------{

float dt2;int iatm;

dt2 = 0.5e0 * dt;

for (iatm=1; iatm<=natm; iatm++) {vx[iatm] += ax[iatm] * dt2; // v(t+dt/2)

vy[iatm] += ay[iatm] * dt2;vz[iatm] += az[iatm] * dt2;

x[iatm] += vx[iatm] * dt; // r(t+dt)y[iatm] += vy[iatm] * dt;

z[iatm] += vz[iatm] * dt;}

switch(fopt) { // F(t+dt)

case 0: ForcesL_0(fpar,rpar,rcut,x,y,z,ax,ay,az,natm,Epot); break;case 1: ForcesB_0(fpar,rpar,rcut,x,y,z,ax,ay,az,natm,Epot); }

Ekin = 0.e0;

for (iatm=1; iatm<=natm; iatm++) {ax[iatm] /= amass; // a(t+dt)

ay[iatm] /= amass;az[iatm] /= amass;

vx[iatm] += ax[iatm] * dt2; // v(t+dt)vy[iatm] += ay[iatm] * dt2;

vz[iatm] += az[iatm] * dt2;Ekin += vx[iatm]*vx[iatm] + vy[iatm]*vy[iatm] + vz[iatm]*vz[iatm];

}Ekin *= 0.5e0 * amass;

}

//===========================================================================

void Verlet0(float amass, float fpar, float rpar, float rcut, float dt,float x[], float y[], float z[],

float vx[], float vy[], float vz[],float ax[], float ay[], float az[], int natm,

float &Ekin, float &Epot, int fopt)//---------------------------------------------------------------------------

// Energies in eV, forces in eV/A, distances in A, velocities in A/psec,// accelerations in A/psec^2

//---------------------------------------------------------------------------{

float dt2;int iatm;

dt2 = 0.5e0 * dt;

for (iatm=1; iatm<=natm; iatm++) {vx[iatm] += ax[iatm] * dt2; // v(t+dt/2)

vy[iatm] += ay[iatm] * dt2;vz[iatm] += az[iatm] * dt2;

x[iatm] += vx[iatm] * dt; // r(t+dt)y[iatm] += vy[iatm] * dt;

z[iatm] += vz[iatm] * dt;}

switch(fopt) { // F(t+dt)

case 0: ForcesL_0(fpar,rpar,rcut,x,y,z,ax,ay,az,natm,Epot); break;case 1: ForcesB_0(fpar,rpar,rcut,x,y,z,ax,ay,az,natm,Epot); }

Ekin = 0.e0;

for (iatm=1; iatm<=natm; iatm++) {ax[iatm] /= amass; // a(t+dt)

ay[iatm] /= amass;az[iatm] /= amass;

vx[iatm] += ax[iatm] * dt2; // v(t+dt)vy[iatm] += ay[iatm] * dt2;

vz[iatm] += az[iatm] * dt2;Ekin += vx[iatm]*vx[iatm] + vy[iatm]*vy[iatm] + vz[iatm]*vz[iatm];

}Ekin *= 0.5e0 * amass;

}

Titus Beu 2011

Pedictor-corrector methods

Higher order than the Verlet method – require extra computations and storage

Multiple-value methods:

multistep methods – accelerations from several earlier time steps –Adams approach

higher derivatives methods – higher accelerations at current time step –Nordsieck method

We consider multistep methods – stepsize h cannot be changed easily

The method implies two steps:

predictor step providing an initial approximation to the propagated solution

corrector step yielding a refined approximation.

Page 15: 5. Basics of molecular dynamicsphys.ubbcluj.ro/~tbeu/MD/C5.pdf · 12/7/2011 2 Titus Beu 2011 Leach, A. R., Molecular Modelling . Principles and applications, Second edition (Prentice

12/7/2011

15

Titus Beu 2011

Predictor step – extrapolation to time t+δt of values from earlier time steps:

Adams-Bashforth method (O(δtk+1))

Provides exact results for x(t) = tq with q ≤ k if the (rational) coefficients αi satisfy the k−1 equations:

[ ]

[ ]

12

1

1

1

( ) : ( ) ( ) ( ) ( ) (1 )

( ) ( )( ) : ( ) (1 )

k

i

i

k

i

i

P x x t t x t v t t t a t i t

x t t x tP v v t t t a t i t

t

δ δ δ α δ

δδ δ α δ

δ

=

=

+ = + + + −

+ −′+ = + + −

1

1

1

1

1(1 ) ,

( 1)( 2)

1(1 ) , 0,1, , 2

2

kq

i

i

kq

i

i

iq q

i q kq

α

α

=

=

− =+ +

′− = = −+

∑ …

Titus Beu 2011

Corrector step – uses the predicted values to update f(t+δt):

the predicted values do not appear explicitly in the corrector formulae, except for the evaluation f:

Adams-Moulton method (O(δtk+1))

[ ]

[ ]

12

1

1

1

( ) : ( ) ( ) ( ) ( ) (2 )

( ) ( )( ) : ( ) (2 )

k

i

i

k

i

i

C x x t t x t v t t t a t i t

x t t x tC v v t t t a t i t

t

δ δ δ β δ

δδ δ β δ

δ

=

=

+ = + + + −

+ −′+ = + + −

1

1

1

1

1(2 ) ,

( 1)( 2)

1(2 ) , 0,1, , 2

2

kq

i

i

kq

i

i

iq q

i q kq

β

β

=

=

− =+ +

′− = = −+

∑ …

Page 16: 5. Basics of molecular dynamicsphys.ubbcluj.ro/~tbeu/MD/C5.pdf · 12/7/2011 2 Titus Beu 2011 Leach, A. R., Molecular Modelling . Principles and applications, Second edition (Prentice

12/7/2011

16

Titus Beu 2011

Gear-type predictor-corrector algorithm (k = 4):

1. Predictor step

2. Update forces

3. Corrector step

[ ]

[ ]

2

( ) ( ) ( ) 19 ( ) 10 ( ) 3 ( 2 )24

( ) ( )( ) 27 ( ) 22 ( ) 7 ( 2 )

24

tt t t t t t t t t t

t t t tt t t t t t t

t

δδ δ δ δ

δ δδ δ δ

δ

+ = + + − − + −

+ −+ = + − − + −

r r v a a a

r rv a a a

[ ]

[ ]

2

( ) ( ) ( ) 3 ( ) 10 ( ) ( )24

( ) ( )( ) 7 ( ) 6 ( ) ( )

24

tt t t t t t t t t t

t t t tt t t t t t t

t

δδ δ δ δ

δ δδ δ δ

δ

+ = + + + + − −

+ −+ = + + + − −

r r v a a a

r rv a a a

( ) ( , ( ), ( )) /t t t t t t t t mδ δ δ δ+ = + + +a F r v

Titus Beu 2011

//===========================================================================

void PredCorr0(float amass, float fpar, float rpar, float rcut, float dt,float x[], float y[], float z[],

float vx[], float vy[], float vz[],float ax[], float ay[], float az[],

float ax1[], float ay1[], float az1[],float ax2[], float ay2[], float az2[], int natm,

float &Ekin, float &Epot, int iopt, int fopt)//---------------------------------------------------------------------------

// x[Angs], v[Angs/psec], a[Angs/psec*psec]{

const float pr0 = 19.e0/24.e0, pr1 =-10.e0/24.e0, pr2 = 3.e0/24.e0;const float pv0 = 27.e0/24.e0, pv1 =-22.e0/24.e0, pv2 = 7.e0/24.e0;

const float cr0 = 3.e0/24.e0, cr1 = 10.e0/24.e0, cr2 =-1.e0/24.e0;const float cv0 = 7.e0/24.e0, cv1 = 6.e0/24.e0, cv2 =-1.e0/24.e0;

float *x0, *y0, *z0, *vx0, *vy0, *vz0;

float fact, dt1, dt2;int iatm;

if (iopt == 0) {

x0 = Vector(1,natm); vx0 = Vector(1,natm);y0 = Vector(1,natm); vy0 = Vector(1,natm);

z0 = Vector(1,natm); vz0 = Vector(1,natm);}

dt2 = dt * dt;

//===========================================================================

void PredCorr0(float amass, float fpar, float rpar, float rcut, float dt,float x[], float y[], float z[],

float vx[], float vy[], float vz[],float ax[], float ay[], float az[],

float ax1[], float ay1[], float az1[],float ax2[], float ay2[], float az2[], int natm,

float &Ekin, float &Epot, int iopt, int fopt)//---------------------------------------------------------------------------

// x[Angs], v[Angs/psec], a[Angs/psec*psec]{

const float pr0 = 19.e0/24.e0, pr1 =-10.e0/24.e0, pr2 = 3.e0/24.e0;const float pv0 = 27.e0/24.e0, pv1 =-22.e0/24.e0, pv2 = 7.e0/24.e0;

const float cr0 = 3.e0/24.e0, cr1 = 10.e0/24.e0, cr2 =-1.e0/24.e0;const float cv0 = 7.e0/24.e0, cv1 = 6.e0/24.e0, cv2 =-1.e0/24.e0;

float *x0, *y0, *z0, *vx0, *vy0, *vz0;

float fact, dt1, dt2;int iatm;

if (iopt == 0) {

x0 = Vector(1,natm); vx0 = Vector(1,natm);y0 = Vector(1,natm); vy0 = Vector(1,natm);

z0 = Vector(1,natm); vz0 = Vector(1,natm);}

dt2 = dt * dt;

Page 17: 5. Basics of molecular dynamicsphys.ubbcluj.ro/~tbeu/MD/C5.pdf · 12/7/2011 2 Titus Beu 2011 Leach, A. R., Molecular Modelling . Principles and applications, Second edition (Prentice

12/7/2011

17

Titus Beu 2011

// PREDICTOR

for (iatm=1; iatm<=natm; iatm++) {x0[iatm] = x[iatm]; vx0[iatm] = vx[iatm];

y0[iatm] = y[iatm]; vy0[iatm] = vy[iatm];z0[iatm] = z[iatm]; vz0[iatm] = vz[iatm];

x[iatm] = x0[iatm] + vx0[iatm] * dt

+ (pr0*ax[iatm] + pr1*ax1[iatm] + pr2*ax2[iatm]) * dt2;y[iatm] = y0[iatm] + vy0[iatm] * dt

+ (pr0*ay[iatm] + pr1*ay1[iatm] + pr2*ay2[iatm]) * dt2;z[iatm] = z0[iatm] + vz0[iatm] * dt

+ (pr0*az[iatm] + pr1*az1[iatm] + pr2*az2[iatm]) * dt2;

vx[iatm] = (x[iatm] - x0[iatm]) / dt+ (pv0*ax[iatm] + pv1*ax1[iatm] + pv2*ax2[iatm]) * dt;

vy[iatm] = (y[iatm] - y0[iatm]) / dt+ (pv0*ay[iatm] + pv1*ay1[iatm] + pv2*ay2[iatm]) * dt;

vz[iatm] = (z[iatm] - z0[iatm]) / dt+ (pv0*az[iatm] + pv1*az1[iatm] + pv2*az2[iatm]) * dt;

ax2[iatm] = ax1[iatm]; ax1[iatm] = ax[iatm];

ay2[iatm] = ay1[iatm]; ay1[iatm] = ay[iatm];az2[iatm] = az1[iatm]; az1[iatm] = az[iatm];

}

switch(fopt) { // F(t+dt)case 0: ForcesL_0(fpar,rpar,rcut,x,y,z,ax,ay,az,natm,Epot); break;

case 1: ForcesB_0(fpar,rpar,rcut,x,y,z,ax,ay,az,natm,Epot); }

// PREDICTOR

for (iatm=1; iatm<=natm; iatm++) {x0[iatm] = x[iatm]; vx0[iatm] = vx[iatm];

y0[iatm] = y[iatm]; vy0[iatm] = vy[iatm];z0[iatm] = z[iatm]; vz0[iatm] = vz[iatm];

x[iatm] = x0[iatm] + vx0[iatm] * dt

+ (pr0*ax[iatm] + pr1*ax1[iatm] + pr2*ax2[iatm]) * dt2;y[iatm] = y0[iatm] + vy0[iatm] * dt

+ (pr0*ay[iatm] + pr1*ay1[iatm] + pr2*ay2[iatm]) * dt2;z[iatm] = z0[iatm] + vz0[iatm] * dt

+ (pr0*az[iatm] + pr1*az1[iatm] + pr2*az2[iatm]) * dt2;

vx[iatm] = (x[iatm] - x0[iatm]) / dt+ (pv0*ax[iatm] + pv1*ax1[iatm] + pv2*ax2[iatm]) * dt;

vy[iatm] = (y[iatm] - y0[iatm]) / dt+ (pv0*ay[iatm] + pv1*ay1[iatm] + pv2*ay2[iatm]) * dt;

vz[iatm] = (z[iatm] - z0[iatm]) / dt+ (pv0*az[iatm] + pv1*az1[iatm] + pv2*az2[iatm]) * dt;

ax2[iatm] = ax1[iatm]; ax1[iatm] = ax[iatm];

ay2[iatm] = ay1[iatm]; ay1[iatm] = ay[iatm];az2[iatm] = az1[iatm]; az1[iatm] = az[iatm];

}

switch(fopt) { // F(t+dt)case 0: ForcesL_0(fpar,rpar,rcut,x,y,z,ax,ay,az,natm,Epot); break;

case 1: ForcesB_0(fpar,rpar,rcut,x,y,z,ax,ay,az,natm,Epot); }

Titus Beu 2011

Ekin = 0.e0;

for (iatm=1; iatm<=natm; iatm++) {ax[iatm] /= amass; // a(t+dt)

ay[iatm] /= amass;az[iatm] /= amass;

x[iatm] = x0[iatm] + vx0[iatm] * dt

+ (cr0*ax[iatm] + cr1*ax1[iatm] + cr2*ax2[iatm]) * dt2;y[iatm] = y0[iatm] + vy0[iatm] * dt

+ (cr0*ay[iatm] + cr1*ay1[iatm] + cr2*ay2[iatm]) * dt2;z[iatm] = z0[iatm] + vz0[iatm] * dt

+ (cr0*az[iatm] + cr1*az1[iatm] + cr2*az2[iatm]) * dt2;

vx[iatm] = (x[iatm] - x0[iatm]) / dt+ (cv0*ax[iatm] + cv1*ax1[iatm] + cv2*ax2[iatm]) * dt;

vy[iatm] = (y[iatm] - y0[iatm]) / dt+ (cv0*ay[iatm] + cv1*ay1[iatm] + cv2*ay2[iatm]) * dt;

vz[iatm] = (z[iatm] - z0[iatm]) / dt+ (cv0*az[iatm] + cv1*az1[iatm] + cv2*az2[iatm]) * dt;

Ekin += vx[iatm]*vx[iatm] + vy[iatm]*vy[iatm] + vz[iatm]*vz[iatm];

}Ekin *= 0.5e0 * amass;

if (iopt < 0) {

FreeVector(x0,1);FreeVector(y0,1);

FreeVector(z0,1);}

}

Ekin = 0.e0;

for (iatm=1; iatm<=natm; iatm++) {ax[iatm] /= amass; // a(t+dt)

ay[iatm] /= amass;az[iatm] /= amass;

x[iatm] = x0[iatm] + vx0[iatm] * dt

+ (cr0*ax[iatm] + cr1*ax1[iatm] + cr2*ax2[iatm]) * dt2;y[iatm] = y0[iatm] + vy0[iatm] * dt

+ (cr0*ay[iatm] + cr1*ay1[iatm] + cr2*ay2[iatm]) * dt2;z[iatm] = z0[iatm] + vz0[iatm] * dt

+ (cr0*az[iatm] + cr1*az1[iatm] + cr2*az2[iatm]) * dt2;

vx[iatm] = (x[iatm] - x0[iatm]) / dt+ (cv0*ax[iatm] + cv1*ax1[iatm] + cv2*ax2[iatm]) * dt;

vy[iatm] = (y[iatm] - y0[iatm]) / dt+ (cv0*ay[iatm] + cv1*ay1[iatm] + cv2*ay2[iatm]) * dt;

vz[iatm] = (z[iatm] - z0[iatm]) / dt+ (cv0*az[iatm] + cv1*az1[iatm] + cv2*az2[iatm]) * dt;

Ekin += vx[iatm]*vx[iatm] + vy[iatm]*vy[iatm] + vz[iatm]*vz[iatm];

}Ekin *= 0.5e0 * amass;

if (iopt < 0) {

FreeVector(x0,1);FreeVector(y0,1);

FreeVector(z0,1);}

}

Page 18: 5. Basics of molecular dynamicsphys.ubbcluj.ro/~tbeu/MD/C5.pdf · 12/7/2011 2 Titus Beu 2011 Leach, A. R., Molecular Modelling . Principles and applications, Second edition (Prentice

12/7/2011

18

Titus Beu 2011

#include <math.h>

#include <stdio.h>#include <conio.h>

#include "Memalloc.h"#include <Graphlib.h>

//===========================================================================

void Forces(float m, float x, float y, float z, float vx, float vy, float vz,float &Fx, float &Fy, float &Fz, float &Epot)

//---------------------------------------------------------------------------{

const float g = 9.81;const float k = 1.0;

Fx = - k*vx;

Fy = - k*vy;Fz = -m*g - k*vz;

Epot = m * g * z;

}

#include <math.h>

#include <stdio.h>#include <conio.h>

#include "Memalloc.h"#include <Graphlib.h>

//===========================================================================

void Forces(float m, float x, float y, float z, float vx, float vy, float vz,float &Fx, float &Fy, float &Fz, float &Epot)

//---------------------------------------------------------------------------{

const float g = 9.81;const float k = 1.0;

Fx = - k*vx;

Fy = - k*vy;Fz = -m*g - k*vz;

Epot = m * g * z;

}

Titus Beu 2011

//===========================================================================

void Propag(float m, float &x, float &y, float &z,float &vx, float &vy, float &vz,

float &ax, float &ay, float &az,float &Ekin, float &Epot, float dt)

//---------------------------------------------------------------------------{

float dt2;

dt2 = 0.5 * dt;vx += ax * dt2; x += vx * dt;

vy += ay * dt2; y += vy * dt;vz += az * dt2; z += vz * dt;

Forces(m,x,y,z,vx,vy,vz,ax,ay,az,Epot);

ax /= m; ay /= m; az /= m;

vx += ax * dt2;vy += ay * dt2;

vz += az * dt2;

Ekin = 0.5*m*(vx*vx + vy*vy + vz*vz); }

//===========================================================================

void Propag(float m, float &x, float &y, float &z,float &vx, float &vy, float &vz,

float &ax, float &ay, float &az,float &Ekin, float &Epot, float dt)

//---------------------------------------------------------------------------{

float dt2;

dt2 = 0.5 * dt;vx += ax * dt2; x += vx * dt;

vy += ay * dt2; y += vy * dt;vz += az * dt2; z += vz * dt;

Forces(m,x,y,z,vx,vy,vz,ax,ay,az,Epot);

ax /= m; ay /= m; az /= m;

vx += ax * dt2;vy += ay * dt2;

vz += az * dt2;

Ekin = 0.5*m*(vx*vx + vy*vy + vz*vz); }

Page 19: 5. Basics of molecular dynamicsphys.ubbcluj.ro/~tbeu/MD/C5.pdf · 12/7/2011 2 Titus Beu 2011 Leach, A. R., Molecular Modelling . Principles and applications, Second edition (Prentice

12/7/2011

19

Titus Beu 2011

//===========================================================================

void Display(float x[],float y[],float z[],float vx[],float vy[],float vz[],float Ekin[],float Epot[],float Etot[],int i)

//---------------------------------------------------------------------------{

int icont;float *step;

cleardevice(); step = Vector(1,i);

for(icont=1; icont <= i; icont++) {step[icont]=icont;}

Plot(step,x,i,1, 0.1,0.4,0.7,0.9,"istep","x","");Plot(step,y,i,1, 0.1,0.4,0.4,0.6,"istep","y","");

Plot(step,z,i,1, 0.1,0.4,0.1,0.3,"istep","z","");Plot(step,Ekin,i,1, 0.5,0.9,0.7,0.9,"istep","Ekin","");

Plot(step,Epot,i,1, 0.5,0.9,0.4,0.6,"istep","Epot","");Plot(step,Etot,i,1, 0.5,0.9,0.1,0.3,"istep","Etot","");

FreeVector(step,1); }

//===========================================================================

void Display(float x[],float y[],float z[],float vx[],float vy[],float vz[],float Ekin[],float Epot[],float Etot[],int i)

//---------------------------------------------------------------------------{

int icont;float *step;

cleardevice(); step = Vector(1,i);

for(icont=1; icont <= i; icont++) {step[icont]=icont;}

Plot(step,x,i,1, 0.1,0.4,0.7,0.9,"istep","x","");Plot(step,y,i,1, 0.1,0.4,0.4,0.6,"istep","y","");

Plot(step,z,i,1, 0.1,0.4,0.1,0.3,"istep","z","");Plot(step,Ekin,i,1, 0.5,0.9,0.7,0.9,"istep","Ekin","");

Plot(step,Epot,i,1, 0.5,0.9,0.4,0.6,"istep","Epot","");Plot(step,Etot,i,1, 0.5,0.9,0.1,0.3,"istep","Etot","");

FreeVector(step,1); }

Titus Beu 2011

//===========================================================================

int main(){

const float pi = 3.1415926;int maxstep = 10000;

float *x,*vx,*ax;

float *y,*vy,*ay;float *z,*vz,*az;

float *Ekin,*Epot,*Etot;float Ekini,Epoti,Etoti;

float m,xi,yi,zi,vxi,vyi,vzi,axi,ayi,azi;float v,alfa,beta,dt;

float x0,y0,z0,vx0,vy0,vz0;int i,n;

// xmax =

// tmax = // nstep = tmax / dt;

x = Vector(1,maxstep); vx = Vector(1,maxstep); ax = Vector(1,maxstep);

y = Vector(1,maxstep); vy = Vector(1,maxstep); ay = Vector(1,maxstep);z = Vector(1,maxstep); vz = Vector(1,maxstep); az = Vector(1,maxstep);

Ekin = Vector(1,maxstep);

Epot = Vector(1,maxstep);Etot = Vector(1,maxstep);

//===========================================================================

int main(){

const float pi = 3.1415926;int maxstep = 10000;

float *x,*vx,*ax;

float *y,*vy,*ay;float *z,*vz,*az;

float *Ekin,*Epot,*Etot;float Ekini,Epoti,Etoti;

float m,xi,yi,zi,vxi,vyi,vzi,axi,ayi,azi;float v,alfa,beta,dt;

float x0,y0,z0,vx0,vy0,vz0;int i,n;

// xmax =

// tmax = // nstep = tmax / dt;

x = Vector(1,maxstep); vx = Vector(1,maxstep); ax = Vector(1,maxstep);

y = Vector(1,maxstep); vy = Vector(1,maxstep); ay = Vector(1,maxstep);z = Vector(1,maxstep); vz = Vector(1,maxstep); az = Vector(1,maxstep);

Ekin = Vector(1,maxstep);

Epot = Vector(1,maxstep);Etot = Vector(1,maxstep);

Page 20: 5. Basics of molecular dynamicsphys.ubbcluj.ro/~tbeu/MD/C5.pdf · 12/7/2011 2 Titus Beu 2011 Leach, A. R., Molecular Modelling . Principles and applications, Second edition (Prentice

12/7/2011

20

Titus Beu 2011

// Inits

m = 1.0;x0 = 0.0;

y0 = 0.0;z0 = 10.0;

v = 10;alfa = 0.0; alfa = alfa/180.0 * pi;

beta = 30.0; beta = beta/180.0 * pi;vx0 = v * sin(beta) * cos(alfa);

vy0 = v * sin(beta) * sin(alfa);vz0 = v * cos(beta);

dt = 0.01;

initwindow(1000,750);

i = 1;

xi = x0; vxi = vx0;yi = y0; vyi = vy0;

zi = z0; vzi = vz0;Forces(m,xi,yi,zi,vxi,vyi,vzi,axi,ayi,azi,Epoti);

x[1] = xi; vx[1] = vxi; ax[1] = axi/m;

y[1] = yi; vy[1] = vyi; ay[1] = ayi/m;z[1] = zi; vz[1] = vzi; az[1] = azi/m;

Ekin[1] = 0.5*m*(vxi*vxi + vyi*vyi + vzi*vzi);Epot[1] = Epoti;

Etot[1] = Ekini + Epoti;

// Inits

m = 1.0;x0 = 0.0;

y0 = 0.0;z0 = 10.0;

v = 10;alfa = 0.0; alfa = alfa/180.0 * pi;

beta = 30.0; beta = beta/180.0 * pi;vx0 = v * sin(beta) * cos(alfa);

vy0 = v * sin(beta) * sin(alfa);vz0 = v * cos(beta);

dt = 0.01;

initwindow(1000,750);

i = 1;

xi = x0; vxi = vx0;yi = y0; vyi = vy0;

zi = z0; vzi = vz0;Forces(m,xi,yi,zi,vxi,vyi,vzi,axi,ayi,azi,Epoti);

x[1] = xi; vx[1] = vxi; ax[1] = axi/m;

y[1] = yi; vy[1] = vyi; ay[1] = ayi/m;z[1] = zi; vz[1] = vzi; az[1] = azi/m;

Ekin[1] = 0.5*m*(vxi*vxi + vyi*vyi + vzi*vzi);Epot[1] = Epoti;

Etot[1] = Ekini + Epoti;

Titus Beu 2011

while (zi >= 0.0) {

Propag(m,xi,yi,zi,vxi,vyi,vzi,axi,ayi,azi,Ekini,Epoti,dt);printf("%f %f %f\n",xi,yi,zi);

i++;x[i] = xi; vx[i] = vxi; ax[i] = axi/m;

y[i] = yi; vy[i] = vyi; ay[i] = ayi/m;z[i] = zi; vz[i] = vzi; az[i] = azi/m;

Ekin[i] = Ekini;Epot[i] = Epoti;

Etot[i] = Ekini + Epoti;

Display(x,y,z, vx,vy,vz, Ekin,Epot,Etot,i);}

n = i;

Display(x,y,z, vx,vy,vz, Ekin,Epot,Etot,n);getch();

closegraph();

FreeVector(x,1); FreeVector(vx,1); FreeVector(ax,1);FreeVector(y,1); FreeVector(vy,1); FreeVector(ay,1);

FreeVector(z,1); FreeVector(vz,1); FreeVector(az,1);FreeVector(Ekin,1);

FreeVector(Epot,1);FreeVector(Etot,1);

return 0;}

while (zi >= 0.0) {

Propag(m,xi,yi,zi,vxi,vyi,vzi,axi,ayi,azi,Ekini,Epoti,dt);printf("%f %f %f\n",xi,yi,zi);

i++;x[i] = xi; vx[i] = vxi; ax[i] = axi/m;

y[i] = yi; vy[i] = vyi; ay[i] = ayi/m;z[i] = zi; vz[i] = vzi; az[i] = azi/m;

Ekin[i] = Ekini;Epot[i] = Epoti;

Etot[i] = Ekini + Epoti;

Display(x,y,z, vx,vy,vz, Ekin,Epot,Etot,i);}

n = i;

Display(x,y,z, vx,vy,vz, Ekin,Epot,Etot,n);getch();

closegraph();

FreeVector(x,1); FreeVector(vx,1); FreeVector(ax,1);FreeVector(y,1); FreeVector(vy,1); FreeVector(ay,1);

FreeVector(z,1); FreeVector(vz,1); FreeVector(az,1);FreeVector(Ekin,1);

FreeVector(Epot,1);FreeVector(Etot,1);

return 0;}

Page 21: 5. Basics of molecular dynamicsphys.ubbcluj.ro/~tbeu/MD/C5.pdf · 12/7/2011 2 Titus Beu 2011 Leach, A. R., Molecular Modelling . Principles and applications, Second edition (Prentice

12/7/2011

21

Titus Beu 2011