1
$\begingroup$

I am trying to make a figure in which the protein structures are colored by the distance between the calphas in the overlayed structures.

I am comparing our cryoEM structure to that of a previous crystal structure and trying to show the major distance shifts in an easy to look at manner. I can get the RMSD using some online servers but it doesn't give me a good visual way of looking at the data.

$\endgroup$
2
  • $\begingroup$ 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. $\endgroup$
    – Community Bot
    Aug 21, 2022 at 13:46
  • 2
    $\begingroup$ Not an expert here, but you could try to create a pdb with only c-alpha where B factor column has value according to bond lenght (proportional to it) and then color by b factor spectrum, I am sure there is some command about this : pymolwiki.org/index.php/Spectrum $\endgroup$
    – pippo1980
    Aug 21, 2022 at 15:57

1 Answer 1

1
$\begingroup$

Ok, quite late.... my code stolen from https://pymolwiki.org/index.php/Spectrum as per in my comment:

Not an expert here, but you could try to create a pdb with only c-alpha where B factor column has value according to bond lenght (proportional to it) and then color by b factor spectrum, I am sure there is some command about this : pymolwiki.org/index.php/Spectrum –

code using a fake peptide created with cmd.fab('AFGVAL', 'peptide_1') :

peptide_1.pdb :

ATOM      1  N   ALA     1      19.613   5.728  -6.281  1.00  0.00           N  
ATOM      2  CA  ALA     1      20.289   7.022  -6.281  1.00  0.00           C  
ATOM      3  C   ALA     1      21.789   6.848  -6.281  1.00  0.00           C  
ATOM      4  O   ALA     1      22.320   5.731  -6.292  1.00  0.00           O  
ATOM      5  CB  ALA     1      19.781   7.814  -5.064  1.00  0.00           C  
ATOM      6  H   ALA     1      20.159   4.796  -6.281  1.00  0.00           H  
ATOM      7  HA  ALA     1      20.021   7.561  -7.209  1.00  0.00           H  
ATOM      8 1HB  ALA     1      18.685   7.964  -5.100  1.00  0.00           H  
ATOM      9 2HB  ALA     1      20.005   7.300  -4.109  1.00  0.00           H  
ATOM     10 3HB  ALA     1      20.237   8.819  -5.007  1.00  0.00           H  
ATOM     11  N   PHE     2      22.540   7.897  -6.270  1.00  0.00           N  
ATOM     12  CA  PHE     2      23.990   7.730  -6.270  1.00  0.00           C  
ATOM     13  C   PHE     2      24.690   9.068  -6.255  1.00  0.00           C  
ATOM     14  O   PHE     2      24.050  10.156  -6.244  1.00  0.00           O  
ATOM     15  CB  PHE     2      24.437   6.942  -7.538  1.00  0.00           C  
ATOM     16  CG  PHE     2      23.824   5.546  -7.729  1.00  0.00           C  
ATOM     17  CD1 PHE     2      22.610   5.411  -8.413  1.00  0.00           C  
ATOM     18  CD2 PHE     2      24.430   4.416  -7.174  1.00  0.00           C  
ATOM     19  CE1 PHE     2      22.002   4.165  -8.523  1.00  0.00           C  
ATOM     20  CE2 PHE     2      23.826   3.167  -7.294  1.00  0.00           C  
ATOM     21  CZ  PHE     2      22.611   3.043  -7.966  1.00  0.00           C  
ATOM     22  H   PHE     2      22.130   8.821  -6.260  1.00  0.00           H  
ATOM     23  HA  PHE     2      24.287   7.177  -5.358  1.00  0.00           H  
ATOM     24 2HB  PHE     2      25.541   6.842  -7.539  1.00  0.00           H  
ATOM     25 3HB  PHE     2      24.233   7.549  -8.444  1.00  0.00           H  
ATOM     26 1HD  PHE     2      22.116   6.283  -8.820  1.00  0.00           H  
ATOM     27 2HD  PHE     2      25.362   4.509  -6.633  1.00  0.00           H  
ATOM     28 1HE  PHE     2      21.050   4.077  -9.026  1.00  0.00           H  
ATOM     29 2HE  PHE     2      24.295   2.298  -6.857  1.00  0.00           H  
ATOM     30  HZ  PHE     2      22.134   2.079  -8.049  1.00  0.00           H  
ATOM     31  N   GLY     3      25.980   9.099  -6.253  1.00  0.00           N  
ATOM     32  CA  GLY     3      26.656  10.393  -6.239  1.00  0.00           C  
ATOM     33  C   GLY     3      28.155  10.220  -6.239  1.00  0.00           C  
ATOM     34  O   GLY     3      28.685   9.105  -6.251  1.00  0.00           O  
ATOM     35  H   GLY     3      26.513   8.242  -6.261  1.00  0.00           H  
ATOM     36 3HA  GLY     3      26.365  10.908  -5.371  0.00  0.00           H  
ATOM     37  HA  GLY     3      26.378  10.953  -7.151  1.00  0.00           H  
ATOM     38  N   VAL     4      28.906  11.269  -6.227  1.00  0.00           N  
ATOM     39  CA  VAL     4      30.356  11.101  -6.228  1.00  0.00           C  
ATOM     40  C   VAL     4      31.055  12.440  -6.212  1.00  0.00           C  
ATOM     41  O   VAL     4      30.429  13.507  -6.201  1.00  0.00           O  
ATOM     42  CB  VAL     4      30.798  10.251  -7.484  1.00  0.00           C  
ATOM     43  CG1 VAL     4      32.326  10.136  -7.737  1.00  0.00           C  
ATOM     44  CG2 VAL     4      30.276   8.794  -7.470  1.00  0.00           C  
ATOM     45  H   VAL     4      28.497  12.192  -6.217  1.00  0.00           H  
ATOM     46  HA  VAL     4      30.654  10.571  -5.305  1.00  0.00           H  
ATOM     47  HB  VAL     4      30.366  10.744  -8.381  1.00  0.00           H  
ATOM     48 1HG1 VAL     4      32.862   9.673  -6.888  1.00  0.00           H  
ATOM     49 2HG1 VAL     4      32.559   9.537  -8.638  1.00  0.00           H  
ATOM     50 3HG1 VAL     4      32.799  11.120  -7.921  1.00  0.00           H  
ATOM     51 1HG2 VAL     4      29.177   8.752  -7.361  1.00  0.00           H  
ATOM     52 2HG2 VAL     4      30.510   8.264  -8.413  1.00  0.00           H  
ATOM     53 3HG2 VAL     4      30.710   8.201  -6.643  1.00  0.00           H  
ATOM     54  N   ALA     5      32.345  12.471  -6.211  1.00  0.00           N  
ATOM     55  CA  ALA     5      33.021  13.765  -6.196  1.00  0.00           C  
ATOM     56  C   ALA     5      34.521  13.592  -6.197  1.00  0.00           C  
ATOM     57  O   ALA     5      35.052  12.475  -6.219  1.00  0.00           O  
ATOM     58  CB  ALA     5      32.511  14.544  -4.971  1.00  0.00           C  
ATOM     59  H   ALA     5      32.879  11.614  -6.220  1.00  0.00           H  
ATOM     60  HA  ALA     5      32.753  14.314  -7.119  1.00  0.00           H  
ATOM     61 1HB  ALA     5      31.415  14.694  -5.007  1.00  0.00           H  
ATOM     62 2HB  ALA     5      32.734  14.020  -4.022  1.00  0.00           H  
ATOM     63 3HB  ALA     5      32.967  15.549  -4.903  1.00  0.00           H  
ATOM     64  N   LEU     6      35.271  14.641  -6.173  1.00  0.00           N  
ATOM     65  CA  LEU     6      36.722  14.473  -6.173  1.00  0.00           C  
ATOM     66  C   LEU     6      37.420  15.811  -6.143  1.00  0.00           C  
ATOM     67  O   LEU     6      36.792  16.881  -6.122  1.00  0.00           O  
ATOM     68  CB  LEU     6      37.174  13.638  -7.404  1.00  0.00           C  
ATOM     69  CG  LEU     6      36.580  12.214  -7.580  1.00  0.00           C  
ATOM     70  CD1 LEU     6      37.231  11.514  -8.782  1.00  0.00           C  
ATOM     71  CD2 LEU     6      36.743  11.343  -6.323  1.00  0.00           C  
ATOM     72  H   LEU     6      34.862  15.564  -6.154  1.00  0.00           H  
ATOM     73  HA  LEU     6      37.013  13.950  -5.245  1.00  0.00           H  
ATOM     74 2HB  LEU     6      38.279  13.552  -7.384  1.00  0.00           H  
ATOM     75 3HB  LEU     6      36.958  14.216  -8.325  1.00  0.00           H  
ATOM     76  HG  LEU     6      35.495  12.316  -7.792  1.00  0.00           H  
ATOM     77 1HD1 LEU     6      37.097  12.092  -9.716  1.00  0.00           H  
ATOM     78 2HD1 LEU     6      38.318  11.367  -8.642  1.00  0.00           H  
ATOM     79 3HD1 LEU     6      36.787  10.518  -8.962  1.00  0.00           H  
ATOM     80 1HD2 LEU     6      37.799  11.259  -6.005  1.00  0.00           H  
ATOM     81 2HD2 LEU     6      36.175  11.759  -5.470  1.00  0.00           H  
ATOM     82 3HD2 LEU     6      36.357  10.318  -6.476  1.00  0.00           H  
TER   
END

peptide_2_moved.pdb , same pdb with some just carbon alpha moved by hand :

ATOM      1  N   ALA     1      19.613   5.728  -6.281  1.00  0.00           N  
ATOM      2  CA  ALA     1      20.289   7.022  -6.281  1.00  0.00           C  
ATOM      3  C   ALA     1      21.789   6.848  -6.281  1.00  0.00           C  
ATOM      4  O   ALA     1      22.320   5.731  -6.292  1.00  0.00           O  
ATOM      5  CB  ALA     1      19.781   7.814  -5.064  1.00  0.00           C  
ATOM      6  H   ALA     1      20.159   4.796  -6.281  1.00  0.00           H  
ATOM      7  HA  ALA     1      20.021   7.561  -7.209  1.00  0.00           H  
ATOM      8 1HB  ALA     1      18.685   7.964  -5.100  1.00  0.00           H  
ATOM      9 2HB  ALA     1      20.005   7.300  -4.109  1.00  0.00           H  
ATOM     10 3HB  ALA     1      20.237   8.819  -5.007  1.00  0.00           H  
ATOM     11  N   PHE     2      22.540   7.897  -6.270  1.00  0.00           N  
ATOM     12  CA  PHE     2      24.369   7.337  -6.515  1.00  0.00           C  
ATOM     13  C   PHE     2      24.690   9.068  -6.255  1.00  0.00           C  
ATOM     14  O   PHE     2      24.050  10.156  -6.244  1.00  0.00           O  
ATOM     15  CB  PHE     2      24.437   6.942  -7.538  1.00  0.00           C  
ATOM     16  CG  PHE     2      23.824   5.546  -7.729  1.00  0.00           C  
ATOM     17  CD1 PHE     2      22.610   5.411  -8.413  1.00  0.00           C  
ATOM     18  CD2 PHE     2      24.430   4.416  -7.174  1.00  0.00           C  
ATOM     19  CE1 PHE     2      22.002   4.165  -8.523  1.00  0.00           C  
ATOM     20  CE2 PHE     2      23.826   3.167  -7.294  1.00  0.00           C  
ATOM     21  CZ  PHE     2      22.611   3.043  -7.966  1.00  0.00           C  
ATOM     22  H   PHE     2      22.130   8.821  -6.260  1.00  0.00           H  
ATOM     23  HA  PHE     2      24.287   7.177  -5.358  1.00  0.00           H  
ATOM     24 2HB  PHE     2      25.541   6.842  -7.539  1.00  0.00           H  
ATOM     25 3HB  PHE     2      24.233   7.549  -8.444  1.00  0.00           H  
ATOM     26 1HD  PHE     2      22.116   6.283  -8.820  1.00  0.00           H  
ATOM     27 2HD  PHE     2      25.362   4.509  -6.633  1.00  0.00           H  
ATOM     28 1HE  PHE     2      21.050   4.077  -9.026  1.00  0.00           H  
ATOM     29 2HE  PHE     2      24.295   2.298  -6.857  1.00  0.00           H  
ATOM     30  HZ  PHE     2      22.134   2.079  -8.049  1.00  0.00           H  
ATOM     31  N   GLY     3      25.980   9.099  -6.253  1.00  0.00           N  
ATOM     32  CA  GLY     3      26.656  10.393  -6.239  1.00  0.00           C  
ATOM     33  C   GLY     3      28.155  10.220  -6.239  1.00  0.00           C  
ATOM     34  O   GLY     3      28.685   9.105  -6.251  1.00  0.00           O  
ATOM     35  H   GLY     3      26.513   8.242  -6.261  1.00  0.00           H  
ATOM     36 3HA  GLY     3      26.365  10.908  -5.371  0.00  0.00           H  
ATOM     37  HA  GLY     3      26.378  10.953  -7.151  1.00  0.00           H  
ATOM     38  N   VAL     4      28.906  11.269  -6.227  1.00  0.00           N  
ATOM     39  CA  VAL     4      30.719  10.841  -6.509  1.00  0.00           C  
ATOM     40  C   VAL     4      31.055  12.440  -6.212  1.00  0.00           C  
ATOM     41  O   VAL     4      30.429  13.507  -6.201  1.00  0.00           O  
ATOM     42  CB  VAL     4      30.798  10.251  -7.484  1.00  0.00           C  
ATOM     43  CG1 VAL     4      32.326  10.136  -7.737  1.00  0.00           C  
ATOM     44  CG2 VAL     4      30.276   8.794  -7.470  1.00  0.00           C  
ATOM     45  H   VAL     4      28.497  12.192  -6.217  1.00  0.00           H  
ATOM     46  HA  VAL     4      30.654  10.571  -5.305  1.00  0.00           H  
ATOM     47  HB  VAL     4      30.366  10.744  -8.381  1.00  0.00           H  
ATOM     48 1HG1 VAL     4      32.862   9.673  -6.888  1.00  0.00           H  
ATOM     49 2HG1 VAL     4      32.559   9.537  -8.638  1.00  0.00           H  
ATOM     50 3HG1 VAL     4      32.799  11.120  -7.921  1.00  0.00           H  
ATOM     51 1HG2 VAL     4      29.177   8.752  -7.361  1.00  0.00           H  
ATOM     52 2HG2 VAL     4      30.510   8.264  -8.413  1.00  0.00           H  
ATOM     53 3HG2 VAL     4      30.710   8.201  -6.643  1.00  0.00           H  
ATOM     54  N   ALA     5      32.345  12.471  -6.211  1.00  0.00           N  
ATOM     55  CA  ALA     5      32.965  13.942  -6.049  1.00  0.00           C  
ATOM     56  C   ALA     5      34.521  13.592  -6.197  1.00  0.00           C  
ATOM     57  O   ALA     5      35.052  12.475  -6.219  1.00  0.00           O  
ATOM     58  CB  ALA     5      32.511  14.544  -4.971  1.00  0.00           C  
ATOM     59  H   ALA     5      32.879  11.614  -6.220  1.00  0.00           H  
ATOM     60  HA  ALA     5      32.753  14.314  -7.119  1.00  0.00           H  
ATOM     61 1HB  ALA     5      31.415  14.694  -5.007  1.00  0.00           H  
ATOM     62 2HB  ALA     5      32.734  14.020  -4.022  1.00  0.00           H  
ATOM     63 3HB  ALA     5      32.967  15.549  -4.903  1.00  0.00           H  
ATOM     64  N   LEU     6      35.271  14.641  -6.173  1.00  0.00           N  
ATOM     65  CA  LEU     6      37.139  14.337  -6.385  1.00  0.00           C  
ATOM     66  C   LEU     6      37.420  15.811  -6.143  1.00  0.00           C  
ATOM     67  O   LEU     6      36.792  16.881  -6.122  1.00  0.00           O  
ATOM     68  CB  LEU     6      37.174  13.638  -7.404  1.00  0.00           C  
ATOM     69  CG  LEU     6      36.580  12.214  -7.580  1.00  0.00           C  
ATOM     70  CD1 LEU     6      37.231  11.514  -8.782  1.00  0.00           C  
ATOM     71  CD2 LEU     6      36.743  11.343  -6.323  1.00  0.00           C  
ATOM     72  H   LEU     6      34.862  15.564  -6.154  1.00  0.00           H  
ATOM     73  HA  LEU     6      37.013  13.950  -5.245  1.00  0.00           H  
ATOM     74 2HB  LEU     6      38.279  13.552  -7.384  1.00  0.00           H  
ATOM     75 3HB  LEU     6      36.958  14.216  -8.325  1.00  0.00           H  
ATOM     76  HG  LEU     6      35.495  12.316  -7.792  1.00  0.00           H  
ATOM     77 1HD1 LEU     6      37.097  12.092  -9.716  1.00  0.00           H  
ATOM     78 2HD1 LEU     6      38.318  11.367  -8.642  1.00  0.00           H  
ATOM     79 3HD1 LEU     6      36.787  10.518  -8.962  1.00  0.00           H  
ATOM     80 1HD2 LEU     6      37.799  11.259  -6.005  1.00  0.00           H  
ATOM     81 2HD2 LEU     6      36.175  11.759  -5.470  1.00  0.00           H  
ATOM     82 3HD2 LEU     6      36.357  10.318  -6.476  1.00  0.00           H  
TER   
END

code :

import pymol

import math

from pymol import (
                    
                    cmd ,
                    stored 
                    )

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

pymol.finish_launching()


cmd.set('internal_gui_width' ,  '500')

cmd.load('peptide_1.pdb' , 'peptide_1')

cmd.load('peptide_2_moved.pdb' , 'peptide_2_moved')

diff_len = lambda x,y : math.sqrt((x[0]-y[0])*(x[0]-y[0]) + (x[1]-y[1])*(x[1]-y[1]) + (x[2]-y[2])*(x[2]-y[2]))



cmd.select('peptide_1_CA' ,'peptide_1 and name CA')

cmd.select('peptide_2_moved_CA' ,'peptide_2_moved and name CA')

stored.peptide_1_CA_coord = []

stored.peptide_2_moved_CA_coord = []

cmd.iterate_state('1' , 'peptide_1_CA' , 'stored.peptide_1_CA_coord.append((x,y,z))')
            
cmd.iterate_state('1' , 'peptide_2_moved_CA' , 'stored.peptide_2_moved_CA_coord.append((x,y,z))')


print('stored.peptide_1_CA_coord : ' , stored.peptide_1_CA_coord)

print('stored.peptide_2_moved_CA_coord : ' , stored.peptide_2_moved_CA_coord)

stored.newB = list(map(lambda x,y: diff_len(x,y), stored.peptide_2_moved_CA_coord, stored.peptide_1_CA_coord))

print('\nstorednewB to be passed : ', stored.newB , '\n')

cmd.alter('peptide_2_moved_CA', 'b=stored.newB.pop(0)')


cmd.save('peptide_2_moved_CA.pdb' , 'peptide_2_moved_CA')

cmd.spectrum('b', 'rainbow_rev' , 'peptide_2_moved_CA' , '0' , '1')


cmd.color('lightblue' , 'peptide_1' )

cmd.set('cartoon_transparency' , '0.5', 'peptide_1')

cmd.alphatoall('peptide_2_moved')


cmd.save('peptide_2_moved_CA_alphatoall.pdb' , 'peptide_2_moved')


cmd.load('peptide_2_moved_CA_alphatoall.pdb' , 'peptide_2_moved_CA_alphatoall')

cmd.spectrum('b', 'rainbow_rev' , 'peptide_2_moved_CA_alphatoall' , '0' , '1')

output:

########## PYMOL VERSION ##########################################
          ('2.3.0'
...
stored.peptide_1_CA_coord :  [(20.288999557495117, 7.021999835968018, -6.281000137329102), (23.989999771118164, 7.730000019073486, -6.269999980926514), (26.6560001373291, 10.392999649047852, -6.238999843597412), (30.356000900268555, 11.10099983215332, -6.228000164031982), (33.020999908447266, 13.765000343322754, -6.196000099182129), (36.72200012207031, 14.472999572753906, -6.172999858856201)]
stored.peptide_2_moved_CA_coord :  [(20.288999557495117, 7.021999835968018, -6.281000137329102), (24.368999481201172, 7.336999893188477, -6.514999866485596), (26.6560001373291, 10.392999649047852, -6.238999843597412), (30.7189998626709, 10.840999603271484, -6.508999824523926), (32.96500015258789, 13.942000389099121, -6.048999786376953), (37.138999938964844, 14.336999893188477, -6.385000228881836)]

storednewB to be passed :  [0.0, 0.5984269572074781, 0.0, 0.5275691186189471, 0.23679966390593804, 0.48716415818795433] 

showing in pymol window:

enter image description here

that is the CAs trace of moved (rainbow colored) vs original (lightblue [lightgray out of ray to png]) according to Palette https://pymolwiki.org/index.php/Palette_Colorbars rainbow_rev :

enter image description here

that goes from red = 0 to BLUE = 1 as set out in

cmd.spectrum('b', 'rainbow_rev' , 'peptide_2_moved_CA' , '0' , '1')

againg transferred calculated CAs to all atom using AlphaToAll :

cmd.alphatoall('peptide_2_moved') (check it into code) enter image description here

To use spectrum from min to max of the actual distance differences use in code above:

.....

stored.min = min(stored.newB)

stored.max = max(stored.newB)

print('\nmin of storednewB : ' , stored.min)

print('\nmax of storednewB : ' , stored.max)

print('\n')


cmd.alter('peptide_2_moved_CA', 'b=stored.newB.pop(0)')

cmd.save('peptide_2_moved_CA.pdb' , 'peptide_2_moved_CA')


cmd.spectrum('b', 'rainbow_rev' , 'peptide_2_moved_CA' , stored.min , stored.max)
....

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.