0

我正在尝试使用 scipy.fmin (此处的文档),但我无法弄清楚它为什么不起作用。我的代码:

def moveMolecule(array):
    x0 = [0, 0, 0]
    minV = fmin(calculateV,x0)

其中calculateV 是:

def calculateV(array):
# Calculation of LJ potential using possible radii
# Returns potential in kJ/mol as an list with closest neighbor(s)
points = tuple(map(tuple, array))
radius = []
V = []

# Query tree for nearest neighbors using KD tree
# Returns indices of NN
for n in points:
    output = [i for i in points if i != n]
    tree = spatial.KDTree(output)
    index = tree.query_ball_point(x=n, r=3)
    for i in index:
        radius.append(euclideanDist(tree.data[i], n))

# Calculate potential for NNs
for r in radius:
    V.append((4 * _e) * (((_d / r) ** 12) - ((_d / r) ** 6)))
return V

我不断收到错误 TypeError: 'numpy.float64' object is not iterable。CalculateV 本身运行良好。我认为错误是我没有返回函数,所以我尝试这样做:

# Calculate potential for NNs
for r in radius:
    val = ((4 * _e) * (((_d / r) ** 12) - ((_d / r) ** 6)))
    V.append(val)
return val

但我仍然遇到同样的错误。似乎问题在于:

points = tuple(map(tuple, array))

但我不明白为什么。任何帮助将不胜感激!

4

0 回答 0