-1

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.

  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Oct 26 '22 at 22:35
  • By assuming we know what a DIHAEDRAL calculation is, you are limiting the number of people who can respond. Tell us the logic of what you are trying to accomplish and show us your attempt along with what is wrong with your result and we are happy to help – itprorh66 Oct 26 '22 at 23:24

1 Answers1

0

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.
FlaFlam
  • 81
  • 1
  • 4
  • Yes that look exaclty what I need. Thank you for the explaination (as precius as the code). Still I do have a problem, when I run the code it gives me the error "name 'dihedral_res' is not defined". How this can be possible? The function look defined... For sure I'm missing something banal. – Riccardo Fusco Oct 29 '22 at 14:53
  • Executing raw python scripts directly in the PyMOL terminal can be sometimes tricky. Try to encapsulate it in around [`python`/`python end`](https://pymolwiki.org/index.php/Python) statements or use the [`run`](https://pymolwiki.org/index.php/Run) command. – FlaFlam Oct 30 '22 at 09:53
  • Oh nono, I'm using jupyter notebook to write the code, generally it works just fine. Thank you Again. – Riccardo Fusco Oct 30 '22 at 15:43
  • Maybe is an issue with the scope of the name space. I edited the answer to include the 'space' argument in the function call. – FlaFlam Nov 01 '22 at 09:47
  • YESS. It works perfect. So I also learn how the scope behave in this case. Thank you! – Riccardo Fusco Nov 01 '22 at 10:44