Добавить результат итерации pymol в переменнуюPython

Программы на Python
Гость
Добавить результат итерации pymol в переменную

Сообщение Гость »


I have the following code:

Код: Выделить всё

def grab(resi):
s1 = f"resi {resi} & name P"
s2 = f"resi {resi} & name C4'"
s3 = f"resi {int(resi) + 1} & name P"
s4 = f"resi {int(resi) +1 } & name C4'"

try:
dih = round(cmd.get_dihedral(s1,s2,s3,s4),2)
except:
dih = None

return s1,s2,s3,s4,dih

Код: Выделить всё

myspace = {"grab": grab}
cmd.iterate("(name P)","grab(resi)",space=myspace)
This function basically grab some specific atoms and returns the dihaedral tuple. And that's exacly what I want.
The code return the following:

Код: Выделить всё

('resi 2 & name P',
"resi 2 & name C4'",
'resi 3 & name P',
"resi 3 & name C4'",
172.29)

('resi 3 & name P',
"resi 3 & name C4'",
'resi 4 & name P',
"resi 4 & name C4'",
-139.65)
...
So, the code just print me the returned content of the function, I'd like to add this to a variable so that I can manipulate it.
In other words, I want a list of tuple connected to a variable:

Код: Выделить всё

my_final_list
> [('resi 2 & name P',
"resi 2 & name C4'",
'resi 3 & name P',
"resi 3 & name C4'",
172.29),('resi 3 & name P',
"resi 3 & name C4'",
'resi 4 & name P',
"resi 4 & name C4'",
-139.65) ..]
Probably its easier than I think but I just can't arrive to the solution.


Источник: https://stackoverflow.com/questions/749 ... a-variable

Вернуться в «Python»