Remember: don't be afraid to use your ultimate spell SUMMON RAY


The force function

Define the function using keyword def and name it "get_force", like this:
def get_force():

Don't forget the ":"!
Since this function takes in one arguement which is the positions. However, in LJ's case, only separation between interacting atoms matter. Since we are only modeling two atoms here, we will use the variable name "r". So now the first line of this function would look like:
def get_force(r):

Then define the "force" variable, and assign the force calculated with r and the equation given above in the list to the force variable.
Now that what this function needs to return is calculated, we simply return its value with
return force



The acceleration function

Define a function with name "get_acceleration", and take in one arguement: force.
Define a variable "acceleration". Assign force devided by mass (1 in this case) to it.
Return the variable "acceleration".


The move calculator function

Define a function with name "get_delta_r_v". It takes in two arguments: velocity, acceleration
We will hard code time increment to be 0.01 by creating a variable called "delta_t" and set it to be 0.01.
Define a variable "delta_r" and assign to it the value calculated using the equation provided previously.
Assign to the variable velocity, the new velocity calculated using the equation provided previously.
Return both delta_r and velocity by returning a tuple like this:
return delta_r , velocity



The damper function

Define a function with name "damp_delta_r_v". It takes in two arguments: velocity, position change delta_r
Hard code the threshold by creating a variable called "threshold_r" and assign to it value 0.1.
Use the if condition. If delta_r is greater than theshold_r, assign threshold_r to delta_r. Assign 0 to velocity.
Else, assign velocity * 0.9 to velocity.
Outside of the if condition block, return delta_r and velocity.


The updater function

Define a function with name "update_r". It takes in two arguments: r and delta_r.
It assines the sum of r and delta_r to variable r.
Then it returns r.

The main function

Here is the part of code that uses the above functions and find the optimal bond length.
First initialize variables by setting r to 0.3, velocity to 0, delta_r to 0 and acceleration to 0.
Initialize force to be 100.
Use while loop, with condition of the absolute value of force greater than 0.01. In side the while loop:
  1. Assign get_force return value to force.
  2. Assign get_acceleration return value to acceleration.
  3. Assign get_delta_r_v return values to delta_r, velocity.
  4. Assign damp_delta_r_v return values to delta_r, velocity.
  5. Assign update_r return value to r.
You could add a print statement inside the loop to keep track of changes and values of r and force like this:
print("The value of r and force are now ", r,force)