Minimum distance between atoms

Viewed 104

I want to calculate the minimum distance between two atoms by means of the Lennard Jones potential. The formula I want to use is:

V(r) = C12/r^12 - C6/r^6 where C12 = 1 and C6 = 10

The following construct of the function including variables was already given and the solutions for this example should be 0.764724.

My idea is to use the "minimum"-function but I have absolutely no clue how to use it. Not even after reading the SciPy manual. How should I start?

import numpy as np
from scipy.optimize import minimize, leastsq, least_squares, curve_fit

def get_minimum_energy_distance(C12, C6):
   my code
1 Answers

The first thing you'll need to do is define your function to optimise:

def f(r, C12=1, C6=10):
    return (C12/r**12) - (C6/r**6)

Finally, we call scipy's minimze, passing in our function we defined. We also need to pass in a guess of the r-location corresponding to the minimum y, and I've chosen r=1.5:

from scipy.optimize import minimize

res = minimize(f,1.5)

#      fun: -24.999999999999936
#  hess_inv: array([[0.00032439]])
#       jac: array([2.38418579e-06])
#   message: 'Optimization terminated successfully.'
#      nfev: 36
#       nit: 4
#      njev: 12
#    status: 0
#   success: True
#         x: array([0.76472448])

res['x']

# array([0.76472448])

And there's your result. I would recommend reading the scipy minimize documentation to become familiar with some of the optimisation parameters and then have a play with them to see how the method responds to different initial guesses of x0 (r-value corresponding to min y).

Related