【问题标题】:Minimum distance between atoms原子之间的最小距离
【发布时间】:2021-03-19 17:09:04
【问题描述】:

我想通过 Lennard Jones 势计算两个原子之间的最小距离。 我要使用的公式是:

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

已经给出了包含变量的函数的以下构造,此示例的解决方案应为 0.764724。

我的想法是使用“最小”功能,但我完全不知道如何使用它。即使在阅读了 SciPy 手册之后也没有。 我应该如何开始?

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

def get_minimum_energy_distance(C12, C6):
   my code

【问题讨论】:

    标签: python scipy scipy-optimize


    【解决方案1】:

    您需要做的第一件事是定义要优化的函数:

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

    最后,我们调用 scipy 的minimze,传入我们定义的函数。我们还需要传入对最小 y 对应的 r 位置的猜测,我选择了 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])
    

    这就是你的结果。我建议阅读scipy minimize documentation 以熟悉一些优化参数,然后与它们一起玩,看看该方法如何响应 x0 的不同初始猜测(r 值对应于 min y)。

    【讨论】: