Difference between revisions of "CompSciHW10"
From Predictive Chemistry
(Created page with "Intro. Scientific Computing, HW10 - Due Friday, April 22. <pre> 1) Write a complete code to simulate the Lennard-Jones gas in a 2D periodic box with box length L = 14 and ...") |
m |
||
Line 8: | Line 8: | ||
where u_ij = |x_i - x_j|**-6 |
where u_ij = |x_i - x_j|**-6 |
||
The force on each particle, i, is therefore |
The force on each particle, i, is therefore |
||
− | F_i = sum_{j != i} 6 (x_i - x_j) / |x_i - x_j| ( 2 u_ij^2 - u_ij ) |
+ | F_i = sum_{j != i} 6 (x_i - x_j) / |x_i - x_j|^2 ( 2 u_ij^2 - u_ij ) |
2) Run the simulation for 100 steps, and create a plot showing the locations of the atoms |
2) Run the simulation for 100 steps, and create a plot showing the locations of the atoms |
Revision as of 11:15, 18 April 2016
Intro. Scientific Computing, HW10 - Due Friday, April 22.
1) Write a complete code to simulate the Lennard-Jones gas in a 2D periodic box with box length L = 14 and n=100 particles. Start them off on a 10x10 grid with Gaussian distributed velocities. Ignore units and assume beta = m = 1. The Hamiltonian is given by H = sum_j m v_j^2/2 + 1/2 sum_{i != j} u_ij^2 - u_ij where u_ij = |x_i - x_j|**-6 The force on each particle, i, is therefore F_i = sum_{j != i} 6 (x_i - x_j) / |x_i - x_j|^2 ( 2 u_ij^2 - u_ij ) 2) Run the simulation for 100 steps, and create a plot showing the locations of the atoms every 10 steps. 3) For every timestep, calculate the kinetic and potential energies. What do you observe about the behavior of the potential energy? 4) Make a plot of the total energy vs. time for your 100 step simulation. Overlay these plots for several different values of the numerical timestep, dt.
Hints: <source lang="python">
- Wrap all coordinates in an array to the range [0,L)
print x - L*floor(x/L)
- Find the closest distance between two points, r_ij
y = x[i] - x[j] print y - L*floor(y/L + 0.5)
- Calculate the LJ force on an atom at point z
r = closest_distance(z, x) # matrix of closest distances (n x 3) r2 = sum(r*r, 1) # vector of squared distances (n) u = r2**-3 print 6 * sum(r * ((2*u*u - u)/sqrt(r2))[:,newaxis], 0) # sum over other atoms </source>