I'm trying to use scipy.fmin (docs here) and I can't figure out why it isn't working. My code:
def moveMolecule(array):
x0 = [0, 0, 0]
minV = fmin(calculateV,x0)
Where calculateV is:
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
I keep getting the error TypeError: 'numpy.float64' object is not iterable. CalculateV runs fine by itself. I thought the error was that I wasn't returning a function, so I tried doing:
# Calculate potential for NNs
for r in radius:
val = ((4 * _e) * (((_d / r) ** 12) - ((_d / r) ** 6)))
V.append(val)
return val
But I'm still getting the same error. Seems the issues is with:
points = tuple(map(tuple, array))
But I don't understand why. Any help would be greatly appreciated!