Python Lab 1 Part B
This page is under construction.
Part A: Damped molecular dynamics
This is a practice that introduces you to iterative algorithms.
To get started, inside your directory for lab1, create a new script named lab1_part_b.py.
add the shebang to the topline of this script.
The shebang is #!/usr/bin/env python.
Save and exit the script. Then make the script an executable with the command chmod like this:
chmod +x lab1_part_b.py
This algorithm will simulate two atoms separated at a certain distance and find the optimum bond length.
For simplicity's sake, we'll fix one of the atom so that only one atom can move during the simulation.
We will also set the mass of the atoms to 1 in this practice. Set initial position/separation r to 0.3, and velocity to 0. We will choose the convergence criteria to be force smaller than 0.01.
To complete the algorithm, you will need the following functions:
- The force function that takes in positions and returns force. The LJ potential is
VLJ(r) = 4 ε [ (σ / r)12 - (σ / r)6 ].
Use 1 for ε and σ. The resulting force(slope, or 1-D gradient) for LJ is
FLJ(r) = - 4 * 1 [ -12 * (1 / r)13 + 6 * (1 / r)7 ] (1 pt) - The acceleration function that takes in forces and masses and returns acceleration.
F = m * a (1 pt) - The move calculator function that takes in velocity, acceleration. We will choose a fixed time increment "delta_t = 0.1" . It returns the position change and new velocity. The position change over time period delta_t is
delta_r = v * delta_t + 1/2 * acceleration * delta_t ** 2
The velocity changes by acceleration * delta_t(1 pt) - The damper function that takes in position change and velocity. If the position change is larger than a threshold, the position change is set to the threshold and velocity is set to zero. Otherwise, the velocity is reduced by 10%. We will choose the threshold to be 0.1. (1 pt)
- The updater function that takes in the current position, position change and returns new position. (1 pt)
Variable initialization
Loop start
calculate force
calculate acceleration
calculate movement
dampen movement and update velocity
update position
It's perfectly fine to write your own code in whatever way you like as long as it works (decently well). (1 pt) If your code is running properly, it should stop when r gets around 1.12
However, if you are new to coding and aren't sure if you can do this, you could use the cheat provided here.
To enable cheat, simply shout "I've really tried and I really need some experience to start things off!" and click the link.