
MSE 492/627: Introduction to Atomistic Simulations, Leonid Zhigilei
Homework #1 (page 1 of 2)
Simple MD code with Velocity Verlet algorithm
Write the simplest possible one-dimensional “molecular dynamics code” for two particles
connected by a spring (Force = k(x2-x1-x0)) where Δx=x2-x1is the distance between particles,
x0 is the equilibrium length of the spring.
Your code can have the following structure:
• Define the parameters of the system (k, x0, m1, m2), initial coordinates and velocities of the
particles in the system (x10, x20, v10, v20), initial time = 0, time of the simulation, and timestep
of integration, Δt.
• Calculate initial force Finit = k(x20-x
10-x
0)
•F
old = Finit, x1old= x10, x2old= x20, v1old= v10, v2old= v20
• Time loop:
1. Calculate position at the current time
x1new = x1old + Δt v1old + Δt2Fold/2m1
x2new = x2old + Δt v2old -Δt2Fold/2m2
2. Calculate new forces
Fnew = k(x2new -x
1new -x
0)
3. Calculate new velocities
v1new = v1old + Δt(Fold + Fnew)/2m1
v2new = v2old -Δt(Fold + Fnew)/2m2
4. Copy new variables to old ones (actually, you do not need to store the values
of x and v at two different times, you can use the same variables
and write new values over the old ones at steps 1 and 3). Write
coordinates and velocities to disc for further analysis.
5. Update time (New time = old time + Δt). If the current time is less than the
time of the simulation, go to the time loop and repeat.
• End of the time loop and end of code