I am trying to calculate below summation

where f_j,f_j are functions of q calculated before and q=sin(theta) where theta varies[0,90], and r_ij is the respective distance bewteen each two elements I am doing this calculation for.
I used the sum() function at first but it didn't work proberly as it returns a float number, but as q is changing and there's no summation for it I'm expecting an array!Ergo I gave it up.
My second approach was recursive function for calculating this summation,but I get so many errors and have no idea what is wrong with my code as I thing all the syntaxes are correct and I have no idea why I get errors or wrong values one after another!
theta=arange(radians(0.5), radians(40.010), radians(0.03))
q=sin(theta)
f_q_1= 2*exp(-3*pow(q,2))+4*exp(-5*pow(q,2))+1.95
f_q_2=...
.
f_q_i(or j).
atom_positions= open('coordinates.txt','r')
lines = atom_positions.readlines()
for i in range(0, len(lines)):
line = lines[i]
values = line.split(" ")
for j in range(0,len(lines)):
if j<>i:
nextLine = lines[j]
nextLineValues = nextLine.split(" ")
r =sqrt((float(values[5])-float(nextLineValues[5]))**2 + (float(values[6])
-float(nextLineValues[6]))**2+(float(values[7])-float(nextLineValues[7]))**2)
line_len = len(lines)
def I_tot(line_len,i,f_i,f_j,r):
I=0
if i<line_len:
I=I+(f_i*f_j*sin(q*r)/(q*r))
return I + I_tot(line_len,i,f_i,f_j,r)
else:
return I
else:
plot(2*theta,I_tot)
show()
atom_positions.close()
error:
RuntimeError: maximum recursion depth exceeded while calling a Python object
+This question is not a duplicate of recursive summation questions asked here before, As I checked them and couldn't find a solution to my problem.
I have also tried the function
def I_tot():
I=0
for i in range(0,len(lines)):
I=I+(f_i*f_j*sin(q*r)/(q*r))
return I
But I have no idea whether it gives me the correct summation or not, because the graph I get in the end is far from my expectation and indicates that this summation should not be correct.
sum? returning a float for that expression seems fairly reasonable to me.sinwill give a float after all. If you don't want floats, you could just convert it to a int.