added UNRES visualization plugin for PyMOL
authorDawid Jagiela <lightnir@chem.univ.gda.pl>
Sun, 10 Feb 2013 23:44:52 +0000 (00:44 +0100)
committerDawid Jagiela <lightnir@chem.univ.gda.pl>
Sun, 10 Feb 2013 23:44:52 +0000 (00:44 +0100)
source/pymol/show_UNRES.py [new file with mode: 0644]

diff --git a/source/pymol/show_UNRES.py b/source/pymol/show_UNRES.py
new file mode 100644 (file)
index 0000000..a6097a4
--- /dev/null
@@ -0,0 +1,143 @@
+# -*- coding: utf-8 -*-
+'''
+-------------------------------------------------------------------------------
+  show_UNRES.py - UNRES model viewer v 1.0
+-------------------------------------------------------------------------------
+  Written by Dawid JagieÅ‚a (lightnir@chem.univ.gda.pl)  Feb 2013 
+'''
+
+from chempy import cpv
+from pymol import cmd
+import cmd
+from pymol.cgo import *
+
+from pymol.menu import *
+import pymol.menu
+
+def __init__(self):
+       # Add unres to known represtentations 
+       from pymol import constants
+       constants.repres_sc.append('unres')
+
+
+def show_UNRES(sl='(all)'):
+       # basic settings
+       p_radius = 0.6
+       e_size = 1.0
+       # residue dictionary
+       # resn = [color_Red, color_Green, color_Blue, elipsoid_side_width ]
+       resdb = {       'CYS': [1.000, 1.000, 0.000, 2.96868],
+                               'MET': [0.000, 1.000, 0.000, 3.08863],
+                               'PHE': [0.000, 0.392, 0.000, 3.04238],
+                               'ILE': [0.000, 1.000, 0.000, 3.17389],
+                               'LEU': [0.000, 1.000, 0.000, 2.52078],
+                               'VAL': [0.000, 1.000, 0.000, 2.68924],
+                               'TRP': [0.000, 0.392, 0.000, 3.47403],
+                               'TYR': [0.596, 0.984, 0.596, 3.35434],
+                               'ALA': [0.000, 1.000, 0.000, 1.72686],
+                               'GLY': [1.000, 1.000, 1.000, 1.11383],
+                               'THR': [1.000, 0.000, 1.000, 2.59210],
+                               'SER': [1.000, 0.000, 1.000, 1.68800],
+                               'GLN': [1.000, 0.000, 1.000, 2.22201],
+                               'ASN': [1.000, 0.000, 1.000, 2.24946],
+                               'GLU': [1.000, 0.000, 0.000, 2.05551],
+                               'ASP': [1.000, 0.000, 0.000, 1.77556],
+                               'HIS': [1.000, 0.000, 1.000, 3.02627],
+                               'ARG': [0.000, 0.000, 1.000, 3.25143],
+                               'LYS': [0.000, 0.000, 1.000, 4.50054],
+                               'PRO': [0.000, 1.000, 1.000, 2.20525]
+                       }
+
+
+       # Get pseudo-peptide group positions
+       atoms=cmd.get_model(sl+" & n. CA").atom
+       p=[]
+       for i in range(0,len(atoms)-1):
+               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 ] )
+       obj=[]
+       for i in range(0,len(p)):
+               obj.extend( [ COLOR, 0.643, 0.933, 0.960 ] )
+               obj.extend( [ SPHERE, p[i][0], p[i][1], p[i][2], p_radius ] )
+
+       # Get Sidechain elipsoids positions
+       atoms=cmd.get_model(sl+" & n. CB").atom
+       e=[]
+       for i in range(0,len(atoms)):
+               ca=cmd.get_model(sl+" & n. CA & resn "+atoms[i].resn+" & resi "+atoms[i].resi).atom
+               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] ] )
+
+       # This is from pymol devel example cgo07.py form http://pymol.sourcearchive.com/documentation/1.2r1/cgo07_8py-source.html
+    #
+       # [ ELLIPSOID, x_pos, y_pos, z_pos, size, x0, y0, z0, x1, y1, z2, x2, y2, z2 ]
+       # where the xyz vectors are orthogonal and of length 1.0 or less.
+       for i in range(0,len(e)):
+               # vactor CB->CA
+               tmp0=[e[i][4], e[i][5], e[i][6]]
+               l=cpv.length(tmp0)
+               # random vector
+               tmp1 = cpv.random_vector()
+               # orthogonal vector to tmp0 and tmp1 
+               tmp2 = cpv.cross_product(tmp1, tmp0)
+               tmp3 = cpv.cross_product(tmp0, tmp2)
+               tmp2 = cpv.normalize(tmp2)
+               tmp3 = cpv.normalize(tmp3)
+               tmp2 = cpv.scale(tmp2,0.9*resdb[e[i][0]][3])
+               tmp3 = cpv.scale(tmp3,0.9*resdb[e[i][0]][3])
+                               
+               obj.extend( [ COLOR, resdb[e[i][0]][0], resdb[e[i][0]][1], resdb[e[i][0]][2] ] )
+               obj.extend( [ ELLIPSOID, e[i][1], e[i][2], e[i][3], e_size, ] + tmp0 + tmp2 + tmp3 )
+
+       cmd.set('cgo_ellipsoid_quality', 2)
+       cmd.load_cgo(obj,'UNRES_'+sl)
+
+
+# Hook up to PyMols show command
+
+def myshow(representation="",selection="",_self=cmd):
+       '''
+DESCRIPTION
+        
+    "show" turns on representations for objects and selections.
+        
+USAGE
+    show [ representation [, selection ]]
+ARGUMENTS
+    representation = lines, spheres, mesh, ribbon, cartoon, sticks,
+    dots, surface, labels, extent, nonbonded, nb_spheres, slice,
+    extent, slice, dashes, angles, dihedrals, cgo, cell, callback,
+    unres or everything
+    selection = string: a selection-expression or name-pattern
+NOTES
+    With no arguments, "show" alone turns on lines for all bonds and
+    nonbonded for all atoms in all molecular objects.
+EXAMPLES
+    show
+    show ribbon
+    show lines, (name ca or name c or name n)
+
+SEE ALSO
+    hide, enable, disable
+'''
+
+       if representation=='unres':
+               if selection=="":
+                       show_UNRES('all')
+               else:
+                       show_UNRES(selection)
+       else:
+               cmd.show(representation, selection,_self)
+
+
+cmd.extend('show',myshow)