Calculate Psi/Phi and/or dihaedral Pymol - Pymol API

135 Views Asked by At

I'm struggling a bit tryng to calculate multiple dihedral through residues just giving the atom name. Basically I'd like to interate the dihaedral calcualtion all around a protein / RNA.

For now I'm arrived here:

def myfunc(model,chain,segi,resn,resi,name):
    s1 = "/%s/%s/%s/%s`%s/CB" % (model,chain,segi,resn,resi)
    s2 = "/%s/%s/%s/%s`%s/CA" % (model,chain,segi,resn,resi)
    s3 = "/%s/%s/%s/%s`%s/N" % (model,chain,segi,resn,resi)
    s4 = "/%s/%s/%s/%s`%s/C" % (model,chain,segi,resn,resi)
    cmd.get_dihedral(s1,s2,s3,s4,state=0)
    print(s1,s2,s3,s4)

myspace = {'myfunc': myfunc}
cmd.iterate('(all)', 'myfunc(model,chain,segi,resn,resi,name)', space=myspace)

The TOP would be a file that look like this:

NAME NAME NAME NAME DIHAEDRAL

NAME NAME NAME NAME DIHAEDRAL

Someone can help? Thanks in advance guys.

1

There are 1 best solutions below

5
FlaFlam On

If I understood you correctly, this should be close to what you are looking for:

def dihedral_res(model, segi, chain, resn, resi):
    s1 = "/{}/{}/{}/{}`{}/CB".format(model, segi, chain, resn, resi)
    s2 = "/{}/{}/{}/{}`{}/CA".format(model, segi, chain, resn, resi)
    s3 = "/{}/{}/{}/{}`{}/N".format(model, segi, chain, resn, resi)
    s4 = "/{}/{}/{}/{}`{}/C".format(model, segi, chain, resn, resi)
    try:
        dihedral_val = cmd.get_dihedral(s1, s2, s3, s4, state=0)
    except:
        dihedral_val = None
    print(s1, s2, s3, s4, dihedral_val)

cmd.iterate("name CA", "dihedral_res(model, segi, chain, resn, resi)", space={"dihedral_res":dihedral_res})

There were several errors in your script:

  • The cmd.iterate command loops from atom to atom over a selection. If you manually define the name of the atoms in your function, you only need to loop over the residues. The selection has to be restricted to avoid duplicate dihedrals.
  • Therefore, name argument was not used and can be omitted.
  • segi and chain arguments were swapped according to the selection macros
  • Not all residues have the specific names that you chose. A try-except should catch the cases where not found.
  • You were calculating the dihedral value but you were doing nothing with it!! Print it to the screen or save it to a file.