我正在尝试使用scipy.fmin(docs here),我无法弄清楚它为什么不起作用。我的代码:
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'对象不可迭代。 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))
但我不明白为什么。任何帮助将不胜感激!