a6097a43c8677363e2ee01472b1a33385adeff41
[unres.git] / source / pymol / show_UNRES.py
1 # -*- coding: utf-8 -*-
2 '''
3 -------------------------------------------------------------------------------
4   show_UNRES.py - UNRES model viewer v 1.0
5 -------------------------------------------------------------------------------
6  
7   Written by Dawid JagieÅ‚a (lightnir@chem.univ.gda.pl)  Feb 2013 
8  
9 '''
10
11 from chempy import cpv
12 from pymol import cmd
13 import cmd
14 from pymol.cgo import *
15
16 from pymol.menu import *
17 import pymol.menu
18
19 def __init__(self):
20         # Add unres to known represtentations 
21         from pymol import constants
22         constants.repres_sc.append('unres')
23
24
25 def show_UNRES(sl='(all)'):
26         # basic settings
27         p_radius = 0.6
28         e_size = 1.0
29         # residue dictionary
30         # resn = [color_Red, color_Green, color_Blue, elipsoid_side_width ]
31         resdb = {       'CYS': [1.000, 1.000, 0.000, 2.96868],
32                                 'MET': [0.000, 1.000, 0.000, 3.08863],
33                                 'PHE': [0.000, 0.392, 0.000, 3.04238],
34                                 'ILE': [0.000, 1.000, 0.000, 3.17389],
35                                 'LEU': [0.000, 1.000, 0.000, 2.52078],
36                                 'VAL': [0.000, 1.000, 0.000, 2.68924],
37                                 'TRP': [0.000, 0.392, 0.000, 3.47403],
38                                 'TYR': [0.596, 0.984, 0.596, 3.35434],
39                                 'ALA': [0.000, 1.000, 0.000, 1.72686],
40                                 'GLY': [1.000, 1.000, 1.000, 1.11383],
41                                 'THR': [1.000, 0.000, 1.000, 2.59210],
42                                 'SER': [1.000, 0.000, 1.000, 1.68800],
43                                 'GLN': [1.000, 0.000, 1.000, 2.22201],
44                                 'ASN': [1.000, 0.000, 1.000, 2.24946],
45                                 'GLU': [1.000, 0.000, 0.000, 2.05551],
46                                 'ASP': [1.000, 0.000, 0.000, 1.77556],
47                                 'HIS': [1.000, 0.000, 1.000, 3.02627],
48                                 'ARG': [0.000, 0.000, 1.000, 3.25143],
49                                 'LYS': [0.000, 0.000, 1.000, 4.50054],
50                                 'PRO': [0.000, 1.000, 1.000, 2.20525]
51                         }
52
53
54         # Get pseudo-peptide group positions
55         atoms=cmd.get_model(sl+" & n. CA").atom
56         p=[]
57         for i in range(0,len(atoms)-1):
58                 p.append( [atoms[i].coord[0]+(atoms[i+1].coord[0]-atoms[i].coord[0])/2, atoms[i].coord[1]+(atoms[i+1].coord[1]-atoms[i].coord[1])/2, atoms[i].coord[2]+(atoms[i+1].coord[2]-atoms[i].coord[2])/2 ] )
59         obj=[]
60         for i in range(0,len(p)):
61                 obj.extend( [ COLOR, 0.643, 0.933, 0.960 ] )
62                 obj.extend( [ SPHERE, p[i][0], p[i][1], p[i][2], p_radius ] )
63
64         # Get Sidechain elipsoids positions
65         atoms=cmd.get_model(sl+" & n. CB").atom
66         e=[]
67         for i in range(0,len(atoms)):
68                 ca=cmd.get_model(sl+" & n. CA & resn "+atoms[i].resn+" & resi "+atoms[i].resi).atom
69                 e.append( [ atoms[i].resn, atoms[i].coord[0], atoms[i].coord[1], atoms[i].coord[2], atoms[i].coord[0]-ca[0].coord[0], atoms[i].coord[1]-ca[0].coord[1], atoms[i].coord[2]-ca[0].coord[2] ] )
70
71         # This is from pymol devel example cgo07.py form http://pymol.sourcearchive.com/documentation/1.2r1/cgo07_8py-source.html
72     #
73         # [ ELLIPSOID, x_pos, y_pos, z_pos, size, x0, y0, z0, x1, y1, z2, x2, y2, z2 ]
74         # where the xyz vectors are orthogonal and of length 1.0 or less.
75         for i in range(0,len(e)):
76                 # vactor CB->CA
77                 tmp0=[e[i][4], e[i][5], e[i][6]]
78                 l=cpv.length(tmp0)
79                 # random vector
80                 tmp1 = cpv.random_vector()
81                 # orthogonal vector to tmp0 and tmp1 
82                 tmp2 = cpv.cross_product(tmp1, tmp0)
83                 tmp3 = cpv.cross_product(tmp0, tmp2)
84                 tmp2 = cpv.normalize(tmp2)
85                 tmp3 = cpv.normalize(tmp3)
86                 tmp2 = cpv.scale(tmp2,0.9*resdb[e[i][0]][3])
87                 tmp3 = cpv.scale(tmp3,0.9*resdb[e[i][0]][3])
88                                 
89                 obj.extend( [ COLOR, resdb[e[i][0]][0], resdb[e[i][0]][1], resdb[e[i][0]][2] ] )
90                 obj.extend( [ ELLIPSOID, e[i][1], e[i][2], e[i][3], e_size, ] + tmp0 + tmp2 + tmp3 )
91
92         cmd.set('cgo_ellipsoid_quality', 2)
93         cmd.load_cgo(obj,'UNRES_'+sl)
94
95
96 # Hook up to PyMols show command
97
98 def myshow(representation="",selection="",_self=cmd):
99         '''
100 DESCRIPTION
101          
102     "show" turns on representations for objects and selections.
103          
104 USAGE
105  
106     show [ representation [, selection ]]
107  
108 ARGUMENTS
109  
110     representation = lines, spheres, mesh, ribbon, cartoon, sticks,
111     dots, surface, labels, extent, nonbonded, nb_spheres, slice,
112     extent, slice, dashes, angles, dihedrals, cgo, cell, callback,
113     unres or everything
114  
115     selection = string: a selection-expression or name-pattern
116  
117 NOTES
118  
119     With no arguments, "show" alone turns on lines for all bonds and
120     nonbonded for all atoms in all molecular objects.
121  
122 EXAMPLES
123  
124     show
125     show ribbon
126     show lines, (name ca or name c or name n)
127
128 SEE ALSO
129  
130     hide, enable, disable
131  
132 '''
133
134         if representation=='unres':
135                 if selection=="":
136                         show_UNRES('all')
137                 else:
138                         show_UNRES(selection)
139         else:
140                 cmd.show(representation, selection,_self)
141
142
143 cmd.extend('show',myshow)