How to set a dihedral in PyMOL? I propose the set_dihedral command working incorrectly

168 Views Asked by At

I want to change the phi/psi/omega angles. But when I use set_dihedral, it doesn't change the angle. Instead, it moves (rotates?) the following chain. (I have a homotrimer, if it matters). What's wrong with my PyMOL, and how can I adjust dihedrals? Thank you.

1

There are 1 best solutions below

0
pippo1980 On

not sure about your question, to me it does seem to work, code:

#!/usr/bin/env python3

import pymol

from pymol import (
                    
                    cmd ,
                    stored 
                    )

print('########## PYMOL VERSION ##########################################')
print('         ',  cmd.get_version() )
print('###################################################################')

pymol.finish_launching()


cmd.fab('AFGA', 'peptide')

cmd.save('peptide_AFGA.pdb' , 'peptide')

# cmd.hide('sticks' , 'peptide')

cmd.hide('everything' , 'peptide')

cmd.show('lines' , 'peptide')

a = cmd.select('selected' , 'peptide and resi 2-3 and name CA')

stored.dict = {}


cmd.iterate('selected' , "stored.dict[int(resi)] = [model, segi, chain, resn, int(resi)]")

print('\n stored.dict -------> ', stored.dict,'\n\n')

for i in stored.dict.keys() :
    
    print( i , type(i))
    

print('stored.dict.keys ', stored.dict.keys() , type(stored.dict.keys()))


def get_dihedral_psi( res_id , selected):
    
    if int(res_id) + 1 in [i for i in selected.keys()] :
        
        print(selected[res_id][3], '   can calculate psi', '   ____________' , res_id , int(res_id))
        
        i = selected[res_id ]
        
        # print(i)
        
        s1 = "/{}/{}/{}/{}`{}/N".format(i[0] , i[1] , i [2] , i[3] , i[4])
        
        # print(s1)

        s2 = "/{}/{}/{}/{}`{}/CA".format(i[0] , i[1] , i [2] , i[3] , i[4])
        
        s3 = "/{}/{}/{}/{}`{}/C".format(i[0] , i[1] , i [2] , i[3] , i[4])
        
        i = selected[res_id + 1]
        
        s4 = "/{}/{}/{}/{}`{}/N".format(i[0] , i[1] , i [2] , i[3] , i[4])
        
       
        cmd.select('dihedral_psi_'+str(res_id) ,  s1 +' '+  s2 +' '+  s3 +' '+ s4)
        
        try:
            
            dihedral_val_psi = cmd.get_dihedral(s1, s2, s3, s4, state=0)
                
        except:
            
            dihedral_val_psi = None
            
    else : 
        
        print(selected[res_id][3], '   cannot calculate psi' , '____________' , res_id , int(res_id))
        
        dihedral_val_psi = None    
            
    return dihedral_val_psi

print(' psi for resi 2 ---> ' , get_dihedral_psi(2, stored.dict))


def set_dihedral_psi( res_id , selected, value):
    
    if int(res_id) + 1 in [i for i in selected.keys()] :
        
        print(selected[res_id][3], '   can set psi', '   ____________' , res_id , int(res_id))
        
        i = selected[res_id ]
        
        # print(i)
        
        s1 = "/{}/{}/{}/{}`{}/N".format(i[0] , i[1] , i [2] , i[3] , i[4])
        
        # print(s1)

        s2 = "/{}/{}/{}/{}`{}/CA".format(i[0] , i[1] , i [2] , i[3] , i[4])
        
        s3 = "/{}/{}/{}/{}`{}/C".format(i[0] , i[1] , i [2] , i[3] , i[4])
        
        i = selected[res_id + 1]
        
        s4 = "/{}/{}/{}/{}`{}/N".format(i[0] , i[1] , i [2] , i[3] , i[4])
        
       
        cmd.select('set_dihedral_psi_'+str(res_id) ,  s1 +' '+  s2 +' '+  s3 +' '+ s4)
        
        try:
            
            cmd.set_dihedral(s1, s2, s3, s4, value , state=0 , quiet = 0 )
            
            return True
                
        except:
            
            return False
            
    else : 
        
        print(selected[res_id][3], '   cannot set psi' , '____________' , res_id , int(res_id))

            
        return False


print('set psi for resi 2 ---> ' , set_dihedral_psi(2, stored.dict , 90))

cmd.save('peptide_AFGA_set_2_90.pdb' , 'peptide')

stored.dict = {}


cmd.iterate('selected' , "stored.dict[int(resi)] = [model, segi, chain, resn, int(resi)]")

print(' psi for resi 2 ---> ' , get_dihedral_psi(2, stored.dict))

output printed:

...
PYMOL VERSION '2.3'
...

stored.dict ------->  {2: ['peptide', '', '', 'PHE', 2], 3: ['peptide', '', '', 'GLY', 3]} 


2 <class 'int'>
3 <class 'int'>
stored.dict.keys  dict_keys([2, 3]) <class 'dict_keys'>
PHE    can calculate psi    ____________ 2 2
 psi for resi 2 --->  180.0
PHE    can set psi    ____________ 2 2
 SetDihedral: adjusted to 90.000
set psi for resi 2 --->  True
PHE    can calculate psi    ____________ 2 2
 psi for resi 2 --->  89.99998474121094

peptide created by cmd.fab('AFGA', 'peptide') resi 2 psi = 180°

enter image description here

peptide changed resi 2 psi to 90°

enter image description here

both of them

enter image description here

According to : http://www.mlb.co.jp/linux/science/garlic/doc/commands/dihedrals.html

MAIN CHAIN DIHEDRAL ANGLES The main chain dihedral angles are defined as follows:

(1) The phi angle is the angle of right-handed rotation around N-CA bond, the value being zero if CA-C bond is cis to C-N bond. Range: from -180 to 180 degrees.

(2) The psi angle is the angle of right-handed rotation around CA-C bond, the value being zero if C-N bond is cis to N-CA bond. Range: from -180 to 180 degrees.

(3) The omega angle is the angle of right-handed rotation about C-N bond, the value being zero if CA-C bond of the preceding residue is cis to N-CA bond. Most residues in a typical protein are involved in the formation of two peptide bonds. The peptide bond formed by the residues I and I + 1 is assigned to the residue I + 1. The same applies to the omega angle. For that reason no omega angle is assigned to the first residue.

So if I am not wrong, Pymol behaves as it should, at least when setting psi , I doubt phy and omega would work differently comman is always set_dihedral described in Set Dihedral PyMOL Wiki!