I'm wondering how the built-in function of Pymol actually work. When I define a function like "take some atom names" , "calculate some propriety (e.g. dihaedral)". Then the function "Iterate" should Iterate this function trought an atom selection.
I haven't understood how I can manipulate the output...
Here there is some code (actually this piece of code was solved by another user: FlamFlam).
This is a function that (as I understood) shoud take some atoms name (s1,s2,s3,s4), calculate a propriety (dihaedral). Then it just return a tuple with the atom identifiers and the angle properties (that's exaclty what I want).
def dihedral_res(model, segi, chain, resn, resi):
sele = []
s1 = "/{}/{}/{}/{}`{}/P".format(model, segi, chain, resn, resi)
s2 = "/{}/{}/{}/{}`{}/C4'".format(model, segi, chain, resn, resi)
s3 = "/{}/{}/{}/{}`{}/P".format(model, segi, chain, resn, resi)
s4 = "/{}/{}/{}/{}`{}/C4'".format(model, segi, chain, resn, resi)
try:
dihedral_val = cmd.get_dihedral(s1, s2, s3, s4, state=0)
except:
dihedral_val = None
return model, segi, chain, resn, resi, dihedral_val
dihedral_res = {'dihedral_res': dihedral_res}
cmd.iterate("name P", "dihedral_res(model, segi, chain, resn, resi)", space=dihedral_res)
This is the output:
('mir23', 'RNAA', '', 'C', '2', 180.0)
('mir23', 'RNAA', '', 'A', '3', 180.0)
('mir23', 'RNAA', '', 'A', '4', 180.0)
('mir23', 'RNAA', '', 'U', '5', 180.0)
Now my question is: how I can start to manipulate this output? I'd like to make a list with all this tuples (so that indexing this list of tuples I can do whatever i want). I'd like also to generate a csv that look like this (the empty space is important, since only in this case i don't have the chain ID) (I don't really care if the csv will be printed with the string identifier "")
model, segi, chain, resn, resi, angle
'mir23', 'RNAA', '', 'C', '2', 180.0
'mir23', 'RNAA', '', 'A', '3', 180.0
I also haven't understood why pymol obligate me to make a dictionary and how it works.
(I know that s1/s3 and s2/s4 are the same atom, I didn't care, yet, about the scientific part)
Using as input
1bna.pdb:and code :
output
test_name_P.csv:I changed your
dihedral_res()function and purged the list fromNones, it won't be a problem to get them back.See here for explanations: Iterate PimolWiki
Examples are available too.
I am pretty sure that applying your
dihedral_resto my input selectingname Pisn't what you were trying to accomplish, but without a proper input I focused on the algorithm.