├── .gitignore ├── README ├── __init__.py ├── pymolrc └── scripts ├── CavityView.py ├── Cycler.py ├── DNAselections.py ├── FindSeq.py ├── GenUtils.py ├── Geometry.py ├── InterfaceUtils-network.py ├── InterfaceUtils.py ├── InterfaceUtils_ori.py ├── InterfaceUtils_try.py ├── LigandView.py ├── MoleculeUtils.py ├── Mutations.py ├── Native-network.py ├── Native.py ├── PDBBrowser.py ├── PDBinfo.py ├── PackingMeasureUtils.py ├── ShowContacts.py ├── __init__.py ├── aaindex.py ├── aaindex ├── aaindex1 ├── aaindex2 └── aaindex3 ├── align_sg.py ├── axes.py ├── axes_cyl.py ├── gensymm.py ├── pdb_hb_uns.py ├── rawAsBfact.py ├── roeAsBfact.py ├── rosetta_tools.py ├── rosetta_vdw.py ├── sample_pymolrc ├── showaxes.py ├── spectrumbar.py ├── test.py ├── tmalign.py ├── util.py └── vecmat.py /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | 3 | /.DS_Store 4 | .DS_Store 5 | 6 | *~ 7 | ._* 8 | 9 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | If you want to gain the people's ovation and fame forever, document your stuff here! 2 | List the files you've added and way briefly what kind of stuff is in them and their 3 | status (mostly, if they're for public consumption or not). I'll start: 4 | 5 | 6 | PackingMeasureUtils.py 7 | 8 | contains stuff for viewing "*_packing.pdb" files. Should mostly work, 9 | so use these without fear (be careful what you use as radii though...). 10 | 11 | loadPackingPDB , [] 12 | 13 | loads a foo_packing.pdb file and colors it all pretty-like 14 | creates two selections along with the loaded object called 15 | NAMEcavities and NAMEprotein which are the heteratoms representing 16 | holes and everything else, respectively. Names can get pretty long, 17 | by pymol lets you do good stuff like "select NA*cav*", which will 18 | match a selection called NAMEISREALLYLONGcavities. 19 | 20 | expandRadii byamount, selection 21 | contractRadii byamount, selection 22 | These do just what they say. A rebuild is triggered, so they're not instantaneous 23 | 24 | useOccRadii selection 25 | useTempRadii selection 26 | will take VDW radii from PDB occ/bfac cols and use them as radii 27 | 28 | useTempColors selection 29 | useOccColors selection 30 | Colors by occ/bfac from pdb 31 | 32 | useRosettaRadii 33 | changes standard radii to match rosetta 34 | 35 | 36 | PDBBrowser.py 37 | 38 | contains some quick and dirty functions for browsing a bunch of PDBs 39 | Experimental! My not work right for you. 40 | 41 | loadFromGlob pattern, name=None, native=None, delete=True, pickrandom=F 42 | 43 | This takes a shell style pattern like ~/mypdbs/foobar_*_packing.pdb and 44 | loads one of the files. If the file ends with _packing.pdb[.gz] it uses 45 | loadPackingPdb. If pattern is just a directory, it'll browse the .pdb/.pdb.gz 46 | files in that dir 47 | pickrand = True, it'll pick a random one. 48 | name = optional name for loaded objcet 49 | native arg provides a native for reference, although I don't think 50 | does anything as yet. 51 | 52 | loadPrev / loadNext 53 | go back and fourth in the structures you've browsed. this will actually 54 | load and delete them, so they don't have to stay in pymol. uses the globals 55 | LOADLIST and POINTER. 56 | 57 | browseReset 58 | resets browsing history (LOADLIST and POINTER) 59 | 60 | 61 | rosetta_tools.py 62 | 63 | This is a PyMOL plugin which can be used to highlight certain features on proteins. 64 | Currently there are two functions implemented: 65 | 66 | Hydrogen bond visualization 67 | This function displays hydrogen bonds to help with evaluating de novo designed 68 | structures and designed interfaces. The bonds are created as CGO objects (native 69 | to PyMOL) and are colored in gradient from yellow (for good, low-energy hydrogen 70 | bonds) to white (weak H-bonds). 71 | 72 | Surface hydrophobic patch visualization 73 | This function of the plugin identifies hydrophobic patches on the surface of 74 | all visible objects and colors them. 75 | 76 | The plugin requires the following things: 77 | - python, version >= 2.4 78 | Note: If you have old versions of python on your machine, make sure PyMOL uses version 79 | 2.4 or greater. The plugin will NOT work for python v2.3. It may be necessary to 80 | reinstall PyMOL or completely remove older version of python to get this to work. 81 | 82 | - The X11 version of PyMOL 83 | MAC users: Only the X11 version of PyMOL is capable of running plugins. You will 84 | need to obtain the PyMOLX11Hybrid version of PyMOL from the PyMOL Web site if 85 | you are running MacPyMOL. 86 | 87 | Hydrogen bond visualization only: 88 | - A compiled copy of Rosetta and the Rosetta database somewhere on your machine. 89 | 90 | Hydrophobic patch visualization only: 91 | - A compiled copy of the QUILT patch identification algorithm (available for download 92 | from ftp://ftp.ebi.ac.uk/pub/contrib/lijnzaad/) 93 | 94 | 95 | To install the plugin, follow these instructions: 96 | 1) Locate the PyMOL plugins folder and create a symbolic link to the file 'rosetta_tools.py' 97 | in this folder. The commands for this will look something like below: 98 | cd /path/to/pymol/modules/pmg_tk/startup 99 | ln -s /path/to/rosetta_tools.py rosetta_tools.py 100 | 101 | For hydrogen bond visualization: 102 | 2a) Locate the src/pilot_apps.src.settings.all file in your Rosetta directory and add in 103 | compilation of the executable 'report_hbonds_for_plugin' by adding the following lines: 104 | 105 | "pilot/ronj" : [ 106 | "report_hbonds_for_plugin", 107 | ], 108 | 109 | Then compile it: 110 | scons mode=release bin/report_hbonds_for_plugin.{linux|macos}gccrelease 111 | 112 | 3) In your HOME directory (check your environment by typing 'env'), create a file named 113 | ".rosettatoolsplugin" and put the following two lines in it: 114 | 115 | rosetta_executable /path/to/mini/bin/report_hbonds_for_plugin.linuxgccrelease 116 | rosetta_database /path/to/minirosetta_database/ 117 | 118 | This file is necessary so that the PyMOL plugin knows how to find Rosetta and the database. 119 | 120 | 4) Run PyMOL 121 | 122 | 5) With a structure loaded, click on "Plugins -> Rosetta Tools -> display hydrogen bonds". 123 | Note: PyMOL must be started from the same directory as the loaded PDB file so that the plugin 124 | can find it. Hydrogen bonds across chains only can be drawn using the menu item 125 | "Plugins -> Rosetta Tools -> display hydrogen bonds, interface only" 126 | 127 | The bonds are colored by a gradient: 128 | Yellow ====> good score 129 | White ====> bad score 130 | 131 | Energies are displayed for bonds across chains. 132 | 133 | For hydrophobic patch visualization: 134 | 2a) Compile QUILT according to the instruction provided in the README. 135 | 136 | 3) In your HOME directory, create or append to a file named ".rosettatoolsplugin" the following 137 | line in it: 138 | 139 | quilt_executable /path/to/quilt/src/quilt 140 | 141 | 4) Copy the files 'ATOMS' and 'RESIDUES' distributed with the quilt src to your HOME directory. 142 | 143 | cp /path/to/quilt/ATOMS ~/.atoms 144 | cp /path/to/quilt/RESIDUES ~/.residues 145 | 146 | 5) Run PyMOL 147 | 148 | 6) With a structure loaded, click on "Plugins -> Rosetta Tools -> display hydrophobic patches". 149 | The plugin will change the protein to spherical represenation and will color the three largest 150 | hydrophobic patches dark green (largest), palegreen, and gray (3rd largest). 151 | 152 | 153 | -------------------------------------------------------------------------------- /__init__.py: -------------------------------------------------------------------------------- 1 | """Bakerlab macromolecular modeling tools for Python. 2 | 3 | pymol -- Tools which directly interact with PyMOL 4 | Note: these all use "import pymol" 5 | 6 | """ 7 | 8 | 9 | __all__ = ["pymol_scripts"] 10 | 11 | # When being checked-out without options, this has the form 12 | # "Revision: x.y " 13 | # When exported using -kv, it is "x.y". 14 | __version__ = "$Revision: 0.1 $".split()[-2:][0] 15 | 16 | -------------------------------------------------------------------------------- /pymolrc: -------------------------------------------------------------------------------- 1 | 2 | #_ feedback push 3 | #_ feedback disable,all,everything 4 | 5 | #from pymol import cmd 6 | 7 | import sys 8 | 9 | set cylinder_shader_ff_workaround, 1 10 | 11 | 12 | sys.path.append("/home/longxing/pymol_scripts/") 13 | sys.path.append("/home/longxing/pymol_scripts/scripts") 14 | 15 | from scripts import * 16 | 17 | ########################################################### 18 | ## Custom commands 19 | set cartoon_flat_sheets, 0 20 | ########################################################### 21 | 22 | #run /home/longxing/pymol_scripts/scripts/all_commands.py 23 | 24 | run /home/longxing/pymol_scripts/scripts/tmalign.py 25 | 26 | run /home/longxing/pymol_scripts/scripts/rawAsBfact.py 27 | run /home/longxing/pymol_scripts/scripts/roeAsBfact.py 28 | 29 | run /home/longxing/pymol_scripts/scripts/PDBinfo.py 30 | 31 | aaindex.init("/home/longxing/pymol_scripts/scripts/aaindex") 32 | 33 | # END COMMANDS 34 | _ feedback pop 35 | 36 | alias pbi, color gray80, chainA; color white, chainB; aaindex2b DVLA000001; spectrum b, red_green, chainB; util.cnc; 37 | alias ipbi, color gray80, chainA; color white, chainB; aaindex2b DVLA000001; spectrum b, red_green, chainB and interface; util.cnc; 38 | 39 | alias npbi, color gray80, chainA; color white, chainB; aaindex2b DVLA000002; spectrum b, red_green, chainB; util.cnc; 40 | alias inpbi, color gray80, chainA; color white, chainB; aaindex2b DVLA000002; spectrum b, red_green, chainB and interfaceB; util.cnc; 41 | 42 | alias dl, color gray80, chainA; color white, chainB; aaindex2b DVLA000003; spectrum b, green_red, chainB; util.cnc; 43 | alias idl, color gray80, chainA; color white, chainB; aaindex2b DVLA000003; spectrum b, green_red, chainB and interfaceB; util.cnc; 44 | 45 | alias hydro, color gray80, chainA; color white, chainB; aaindex2b NADH010101; spectrum b, green_white_yellow, chainB; util.cnc; 46 | alias ihydro, color gray80, chainA; color white, chainB; aaindex2b NADH010101; spectrum b, green_white_yellow, chainB and interfaceB; util.cnc; 47 | 48 | alias alpha, color gray80, chainA; color white, chainB; aaindex2b CHOP780201; spectrum b, red_green, chainB; util.cnc; 49 | alias ialpha, color gray80, chainA; color white, chainB; aaindex2b CHOP780201; spectrum b, red_green, chainB and interfaceB; util.cnc; 50 | 51 | alias beta, color gray80, chainA; color white, chainB; aaindex2b CHOP780202; spectrum b, red_green, chainB; util.cnc; 52 | alias ibeta, color gray80, chainA; color white, chainB; aaindex2b CHOP780202; spectrum b, red_green, chainB and interfaceB; util.cnc; 53 | 54 | alias stik, hide all; cmd.show("cartoon"); cmd.show("sticks","not hydro"); 55 | alias cbc, hide all; cmd.show("cartoon"); util.cbc; 56 | alias cnc, hide all; cmd.show("cartoon"); cmd.show("sticks","not hydro"); cmd.util.cbc("all"); cmd.util.cnc("all"); 57 | alias cg, object=cmd.get_names()[0]; cmd.view('v', 'store'); util.protein_vacuum_esp(object, mode=2, quiet=0); cmd.disable(object + "_e_pot"); cmd.enable(object); cmd.view('v', 'recall'); 58 | alias surf, cmd.extract('target', 'chainA'); cmd.view('v', 'store'); util.protein_vacuum_esp('target', mode=2, quiet=0); cmd.disable('target' + "_e_pot"); cmd.enable('target'); cmd.view('v', 'recall'); cmd.zoom('interface'); cmd.create('inter_bawls','interfaceB'); cmd.show('spheres','inter_bawls'); cmd.disable('inter_bawls'); cmd.create('inter_cage',"interfaceB"); cmd.show('mesh','inter_cage'); cmd.color('magenta','inter_cage'); cmd.util.cnc('inter_cage'); cmd.disable('inter_cage'); 59 | 60 | alias bam, pdbdircyclerlite; set_cycler_command 'stix; show cartoon'; 61 | 62 | alias bbo, hide all; show sticks, name Ca+C+O+N+CA 63 | alias hetsee, hide all; show cartoon; alignto asym*; zoom; select interfaceA, asym and chain A within 10 of (asym and chain B); select interfaceB, asym and chain B within 10 of (asym and chain A); select interfaceAA, not hydro within 3 of interfaceA; select interfaceBB, not hydro within 3 of interfaceB; show lines, interfaceAA; show lines, interfaceBB; select interfaceOri, resi and asym and interfaceAA or asym and interfaceBB; show sticks, interfaceOri; disable interface*; disable *_2_S* or *_3_S* or *_4_S* or or *_5_S* 64 | 65 | 66 | # calculate the phi psi angle of the selected residue. 67 | alias pp, (phi,psi)=cmd.phi_psi("sele").values()[0];abego = {phi>0 and -100<=psi<100:'G',phi<0 and psi>=100:'E',phi>0 and psi<-100:'E',phi<=0 and -75<=psi<50:'A',phi<=0 and psi<-75:'B',phi<=0 and psi>=50:'B'}[1]; print "\\n"; print "phi: %s"%(phi); print "psi: %s"%(psi); print "AGEGO: %s" % abego; print "\\n"; 68 | alias seq, one_letter ={'VAL':'V', 'ILE':'I', 'LEU':'L', 'GLU':'E', 'GLN':'Q','ASP':'D', 'ASN':'N', 'HIS':'H', 'TRP':'W', 'PHE':'F', 'TYR':'Y','ARG':'R', 'LYS':'K', 'SER':'S', 'THR':'T', 'MET':'M', 'ALA':'A','GLY':'G', 'PRO':'P', 'CYS':'C'}; pyMOLSeq = []; cmd.iterate("sele and n. CA", "pyMOLSeq.append( one_letter[resn] )"); pyMOLSeq = ''.join( pyMOLSeq ); print "\\nSequence:\\n%s" % (pyMOLSeq) 69 | 70 | #custom commands by longxing 71 | alias sphere, show spheres,sele; useRosettaRadii 72 | -------------------------------------------------------------------------------- /scripts/CavityView.py: -------------------------------------------------------------------------------- 1 | 2 | import pymol 3 | from pymol import * 4 | 5 | from rosetta_vdw import useRosettaRadii 6 | from PackingMeasureUtils import useTempRadii 7 | from GenUtils import zload 8 | 9 | def viewCav(prot = 'all' , lig = 'hetatm', niram = 'cbas'): 10 | cmd.hide('everything') 11 | cmd.show('stick', prot) 12 | cmd.hide('everything', 'elem h') 13 | cmd.show('spheres', 'resn cav') 14 | cmd.hide('sticks', 'resn cav') 15 | useTempRadii() 16 | cmd.center('resn cav') 17 | 18 | def loadCavPDB(fname,name=None): 19 | 20 | if name is None: 21 | name = name = os.path.basename(fname) 22 | if name.endswith('.gz'): 23 | name = name[:-3] 24 | if name.endswith('.pdb'): 25 | name = name[:-4] 26 | if name.endswith('.'): 27 | name = name[:-1] 28 | 29 | zload(fname,name) 30 | viewCav() 31 | 32 | cmd.extend('viewCav',viewCav) 33 | cmd.extend('loadCavPDB',loadCavPDB) 34 | -------------------------------------------------------------------------------- /scripts/Cycler.py: -------------------------------------------------------------------------------- 1 | """Utility commands to cycle active objects in pymol. 2 | 3 | Adds cycler types to pymol: 4 | pdbdircycler - Cycles through all pdbs in a given directory. 5 | pdbdircyclerlite - Cycles through all pdbs in a given directory, loading one object at a time. 6 | pdblistfilecycler - Cycles through all pdbs listed in a file. 7 | pdblistfilecyclerlite - Cycles through all pdbs listed in a file, loading one object at a time. 8 | objcycler - Cycles though all objects. 9 | 10 | Adds cycler commands: 11 | set_cycler_command - Sets command run on each cycler iteration. Use to init object representation in lite cyclers. 12 | """ 13 | 14 | import logging 15 | logger = logging.getLogger("Cycler") 16 | 17 | from pymol import cmd,viewing 18 | import os,re 19 | 20 | from glob import glob 21 | from os import path 22 | 23 | # ashworth 24 | # minimal general classes to support convenient "list mode" behavior in pymol (left/right arrows cycle through list) 25 | # the 'Lite' classes use the LoadDeleteCycler instead of the EnableCycler, in order that only a single pdb from the list is loaded into memory at any given time. These 'Lite' versions are preferable for large numbers of pdbs that would exceed system memory if loaded all at once. 26 | 27 | #################################################################################################### 28 | # relates paths to object names in a way that matches the result of cmd.load 29 | def objname(objpath): 30 | return re.sub( r'(\.pdb|\.pdb.gz)$', '', path.basename(objpath)) 31 | 32 | # base class cycler for enable/disable behavior, with all objects (pdbs) preloaded 33 | class EnableCycler(object): 34 | def __init__(self): 35 | self.current_index = 0 36 | self.auto_zoom = False 37 | self.onload_command = None 38 | 39 | def iter(self,by=1): 40 | #enabled = cmd.get_names('objects',enabled_only=1)[0] 41 | 42 | choices = self.choices() 43 | l = len(choices) 44 | 45 | assert self.current_index < l 46 | next_object = (self.current_index + by) % l 47 | 48 | cmd.disable(objname(choices[self.current_index])) 49 | 50 | self.current_index = next_object 51 | cmd.enable(objname(choices[self.current_index])) 52 | if self.auto_zoom: 53 | cmd.zoom(objname(choices[self.current_index])) 54 | 55 | if self.onload_command: 56 | logging.debug("onload_command: %s", self.onload_command) 57 | cmd.do(self.onload_command) 58 | 59 | cmd.replace_wizard('message',choices[self.current_index]) 60 | 61 | def choices(self): 62 | raise NotImplementedError("EnableCycler.choices") 63 | 64 | # base class cycler for load/delete behavior (to be employed when there are too many pdbs to hold in memory all at once) 65 | class LoadDeleteCycler(object): 66 | def __init__(self): 67 | self.auto_zoom = False 68 | self.onload_command = None 69 | 70 | def iter(self,by=1): 71 | loaded = cmd.get_names('objects')[0] 72 | choices = self.choices() 73 | l = len(choices) 74 | next_file = 0 75 | next_file_index = 0 76 | for i in range(l): 77 | if objname(choices[i]) == loaded: 78 | next_file_index = (i+by) % l 79 | next_file = choices[ (i+by) % l ] 80 | break 81 | cmd.delete('all') 82 | if not os.path.exists(next_file): 83 | raise ValueError("Can not locate file: %s" % next) 84 | cmd.load(next_file) 85 | if self.auto_zoom: 86 | cmd.zoom() 87 | 88 | if self.onload_command: 89 | logging.debug("onload_command: %s", self.onload_command) 90 | cmd.do(self.onload_command) 91 | 92 | #cmd.replace_wizard('message',next_file) 93 | # to display current pdb index, start at 1 94 | cmd.replace_wizard('message',next_file + ", %d/%d" % (next_file_index+1,l) ) # +1, so the cycler starts at 1 95 | 96 | def choices(self): 97 | raise NotImplementedError("EnableCycler.choices") 98 | 99 | #################################################################################################### 100 | # cycler over all pdbs in directory 101 | class PDBDirCycler(EnableCycler): 102 | def __init__(self,target_dir='.'): 103 | super(PDBDirCycler, self).__init__() 104 | self.pdbs = glob(path.join(target_dir, "*.pdb*")) 105 | self.loadpdbs() 106 | def loadpdbs(self): 107 | for pdb in self.pdbs: 108 | cmd.load(pdb) 109 | cmd.disable(objname(pdb)) 110 | cmd.enable(objname(self.pdbs[0])) 111 | def choices(self): 112 | return self.pdbs 113 | 114 | class PDBDirCyclerLite(LoadDeleteCycler): 115 | def __init__(self,target_dir='.'): 116 | super(PDBDirCyclerLite, self).__init__() 117 | self.pdbs = [ f for f in os.listdir(target_dir) if re.search('.pdb.*$',f) ] 118 | pdb = self.pdbs[0] 119 | cmd.load(pdb) 120 | def choices(self): 121 | return self.pdbs 122 | 123 | #################################################################################################### 124 | # cycler over pdbs in list file 125 | class PDBListFileCycler(EnableCycler): 126 | def __init__(self,list_file): 127 | super(PDBListFileCycler, self).__init__() 128 | self.pdbs = [ l.strip() for l in open(list_file) ] 129 | self.loadpdbs() 130 | def loadpdbs(self): 131 | for pdb in self.pdbs: 132 | cmd.load(pdb) 133 | cmd.disable(objname(pdb)) 134 | cmd.enable(objname(self.pdbs[0])) 135 | def choices(self): 136 | return self.pdbs 137 | 138 | class PDBListFileCyclerLite(LoadDeleteCycler): 139 | def __init__(self,list_file): 140 | super(PDBListFileCyclerLite, self).__init__() 141 | self.pdbs = [ l.strip() for l in open(list_file) ] 142 | pdb = self.pdbs[0] 143 | cmd.load(pdb) 144 | def choices(self): 145 | return self.pdbs 146 | 147 | #################################################################################################### 148 | # cycler over all PyMOL objects (including new ones) 149 | class ObjectCycler(EnableCycler): 150 | def __init__(self): 151 | super(ObjectCycler, self).__init__() 152 | cmd.disable('all') 153 | cmd.enable( cmd.get_names('objects')[0] ) 154 | def choices(self): 155 | return cmd.get_names('objects') 156 | 157 | #################################################################################################### 158 | def prev_pdb(): 159 | viewing.cycler.iter(-1) 160 | def next_pdb(): 161 | viewing.cycler.iter(1) 162 | 163 | def spawnPDBDirCycler(target_dir='.',lite=False): 164 | if lite: viewing.cycler = PDBDirCyclerLite(target_dir) 165 | else: viewing.cycler = PDBDirCycler(target_dir) 166 | cmd.set_key('left',prev_pdb) 167 | cmd.set_key('right',next_pdb) 168 | 169 | def spawnPDBListFileCycler(list_file,lite=False): 170 | if lite: viewing.cycler = PDBListFileCyclerLite(list_file) 171 | else: viewing.cycler = PDBListFileCycler(list_file) 172 | cmd.set_key('left',prev_pdb) 173 | cmd.set_key('right',next_pdb) 174 | 175 | def spawnObjectCycler(): 176 | viewing.cycler = ObjectCycler() 177 | cmd.set_key('left',prev_pdb) 178 | cmd.set_key('right',next_pdb) 179 | 180 | def setCyclerOnloadCommand(command_string): 181 | if command_string[0] == '"' or command_string[0] == "'": 182 | command_string = command_string[1:-1] 183 | if viewing.cycler: 184 | logging.debug("Setting cycler onload_command: %s", command_string) 185 | viewing.cycler.onload_command = command_string 186 | 187 | cmd.extend( 'pdbdircycler', lambda dir='.': spawnPDBDirCycler('.',False) ) 188 | cmd.extend( 'pdbdircyclerlite', lambda dir='.': spawnPDBDirCycler('.',True) ) 189 | cmd.extend( 'pdblistfilecycler', lambda file: spawnPDBListFileCycler(file,False) ) 190 | cmd.extend( 'pdblistfilecyclerlite', lambda file: spawnPDBListFileCycler(file,True) ) 191 | 192 | cmd.extend( 'objcycler', spawnObjectCycler ) 193 | cmd.extend( 'set_cycler_command', setCyclerOnloadCommand ) 194 | 195 | # vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 196 | -------------------------------------------------------------------------------- /scripts/DNAselections.py: -------------------------------------------------------------------------------- 1 | # ashworth 2 | # useful selection groups for protein-DNA interfaces 3 | 4 | from pymol import cmd,util 5 | 6 | # shortcut command for pymol's "color by chains (e. c)" 7 | def color_by_chains(): 8 | for obj in cmd.get_names('objects'): 9 | util.color_chains('%s and e. c' %obj) 10 | cmd.extend('cbce',color_by_chains) 11 | 12 | #class DNA_selections: 13 | # def __init__(self,display=True): 14 | def DNA_selections(display='all'): 15 | bbatoms = 'name C2\*+C3\*+C4\*+C5\*+P+O3\*+O4\*+O5\*+O1P+O2P+H1\*+1H2\*+2H2\*+H3\*+H4\*+1H5\*+2H5\*+c2\'+c3\'+c4\'+c5\'+o3\'+o4\'+o5\'+op2+op1+h1\'+1h2\'+2h2\'+h3\'+h4\'+1h5\'+2h5\'' 16 | waters = 'n. wo6+wn7+wn6+wn4+wo4 or r. hoh' 17 | cmd.select('DNA', 'r. g+a+c+t+gua+ade+cyt+thy+da+dc+dg+dt+5mc',enable=0) 18 | cmd.select('notDNA','not DNA',enable=0) 19 | cmd.select('DNAbases','DNA and not %s' % bbatoms ,enable=0) 20 | cmd.select('DNAbb','DNA and %s' % bbatoms ,enable=0) 21 | cmd.select('sc_base','byres notDNA w. 7 of DNAbases',enable=0) 22 | cmd.select('sc_base','sc_base and not n. c+n+o',enable=0) 23 | cmd.select('dna_h2o','%s w. 3.6 of DNAbases' %waters ,enable=0) 24 | cmd.set('sphere_transparency','0.5'); cmd.color('marine','dna_h2o') 25 | cmd.do('selectPolarProtons') 26 | # color_by_chains() 27 | cmd.color('gray','e. c') 28 | 29 | cmd.select('pbb','notDNA and n. c+n+ca',enable=0) 30 | 31 | if display != 'none': 32 | cmd.label('n. c1\*+c1\' and DNA','\'%s%s(%s)\' % (chain,resi,resn)') 33 | cmd.set('label_color','white') 34 | 35 | if display == 'all': 36 | # display things 37 | cmd.show('sticks','DNAbases or sc_base') 38 | cmd.show('ribbon','DNAbb') 39 | cmd.show('cartoon','notDNA') 40 | cmd.show('spheres','dna_h2o') 41 | cmd.hide('everything','e. h and not polar_protons') 42 | 43 | cmd.extend('DNAselections', DNA_selections ) 44 | cmd.extend('DNAselections_nodisplay', lambda: DNA_selections('none') ) 45 | cmd.extend('DNAselections_labelsonly', lambda: DNA_selections('labels') ) 46 | -------------------------------------------------------------------------------- /scripts/FindSeq.py: -------------------------------------------------------------------------------- 1 | """ 2 | DESCRIPTION: 3 | Given a sequence/regex to find, select those 4 | matching amino acids in the protein. 5 | 6 | USAGE: 7 | findseq needle, haystack[, selName[, het[, firstOnly]]] 8 | 9 | PARAMS: 10 | needle (string) 11 | the sequence of amino acids to match and select 12 | in the haystack. This can be a sequence of amino 13 | acids, or a string-style regular expression. See 14 | examples. 15 | 16 | hastack (string or PyMOL selection) 17 | name of the PyMOL object/selection in which 18 | to find the needle. 19 | 20 | selName (string; defaults to None) 21 | This is the name of the selection to return. If selName 22 | is left blank (None), then the selection name will be 23 | foundSeqXYZ where XYZ is some random number; if selName is 24 | "sele" the usual PyMOL "(sele)" will be used; and, lastly, 25 | if selName is anything else, that name will be used verbatim. 26 | 27 | het (0 or 1; defaults to 0) 28 | This boolean flag allows (1) or disallows (0) heteroatoms 29 | from being considered. 30 | 31 | firstOnly (0 or 1; defaults to 0) 32 | Subsequences or motifs might be repeated, this controls how we 33 | consider multiple matches. If firstOnly is False (0) then we return 34 | all found subsequences; if firstOnly is True (1), then we just return 35 | the first found sequence. 36 | 37 | RETURNS: 38 | a newly created selection with the atoms you sought. If there are 39 | more than two contiguous regions, then a newly created group is 40 | returned with each contiguous segment its own selection. 41 | 42 | EXAMPLE: 43 | # find SPVI in 1h12, foundSeqXYZ as return name 44 | findseq SPVI, 1h12 45 | 46 | # find FATEW and make it (sele). 47 | findseq FATEW, 1g01, sele 48 | 49 | # find the regular expression GMS.*QWY in 1a3h 50 | # and put the return value in (sele). 51 | fetch 1a3h 52 | # this ends up finding the sequence, GMSSHGLQWY 53 | findseq GMS.*QWY, 1a3h, sele 54 | 55 | NOTES: 56 | Assumes we're using the ONE LETTER amino acid abbreviations. 57 | 58 | AUTHOR: 59 | Jason Vertrees, 2009. 60 | """ 61 | 62 | from pymol import cmd 63 | import re 64 | import string 65 | import types 66 | import random 67 | 68 | 69 | def findseq(needle, haystack, selName=None, het=0, firstOnly=0): 70 | # set the name of the selection to return. 71 | if selName == None: 72 | rSelName = "foundSeq" + str(random.randint(0, 32000)) 73 | selName = rSelName 74 | elif selName == "sele": 75 | rSelName = "sele" 76 | else: 77 | rSelName = selName 78 | 79 | # input checking 80 | if not checkParams(needle, haystack, selName, het, firstOnly): 81 | print("There was an error with a parameter. Please see") 82 | print("the above error message for how to fix it.") 83 | return None 84 | 85 | one_letter = { 86 | '00C': 'C', '01W': 'X', '0A0': 'D', '0A1': 'Y', '0A2': 'K', 87 | '0A8': 'C', '0AA': 'V', '0AB': 'V', '0AC': 'G', '0AD': 'G', 88 | '0AF': 'W', '0AG': 'L', '0AH': 'S', '0AK': 'D', '0AM': 'A', 89 | '0AP': 'C', '0AU': 'U', '0AV': 'A', '0AZ': 'P', '0BN': 'F', 90 | '0C ': 'C', '0CS': 'A', '0DC': 'C', '0DG': 'G', '0DT': 'T', 91 | '0G ': 'G', '0NC': 'A', '0SP': 'A', '0U ': 'U', '0YG': 'YG', 92 | '10C': 'C', '125': 'U', '126': 'U', '127': 'U', '128': 'N', 93 | '12A': 'A', '143': 'C', '175': 'ASG', '193': 'X', '1AP': 'A', 94 | '1MA': 'A', '1MG': 'G', '1PA': 'F', '1PI': 'A', '1PR': 'N', 95 | '1SC': 'C', '1TQ': 'W', '1TY': 'Y', '200': 'F', '23F': 'F', 96 | '23S': 'X', '26B': 'T', '2AD': 'X', '2AG': 'G', '2AO': 'X', 97 | '2AR': 'A', '2AS': 'X', '2AT': 'T', '2AU': 'U', '2BD': 'I', 98 | '2BT': 'T', '2BU': 'A', '2CO': 'C', '2DA': 'A', '2DF': 'N', 99 | '2DM': 'N', '2DO': 'X', '2DT': 'T', '2EG': 'G', '2FE': 'N', 100 | '2FI': 'N', '2FM': 'M', '2GT': 'T', '2HF': 'H', '2LU': 'L', 101 | '2MA': 'A', '2MG': 'G', '2ML': 'L', '2MR': 'R', '2MT': 'P', 102 | '2MU': 'U', '2NT': 'T', '2OM': 'U', '2OT': 'T', '2PI': 'X', 103 | '2PR': 'G', '2SA': 'N', '2SI': 'X', '2ST': 'T', '2TL': 'T', 104 | '2TY': 'Y', '2VA': 'V', '32S': 'X', '32T': 'X', '3AH': 'H', 105 | '3AR': 'X', '3CF': 'F', '3DA': 'A', '3DR': 'N', '3GA': 'A', 106 | '3MD': 'D', '3ME': 'U', '3NF': 'Y', '3TY': 'X', '3XH': 'G', 107 | '4AC': 'N', '4BF': 'Y', '4CF': 'F', '4CY': 'M', '4DP': 'W', 108 | '4F3': 'GYG', '4FB': 'P', '4FW': 'W', '4HT': 'W', '4IN': 'X', 109 | '4MF': 'N', '4MM': 'X', '4OC': 'C', '4PC': 'C', '4PD': 'C', 110 | '4PE': 'C', '4PH': 'F', '4SC': 'C', '4SU': 'U', '4TA': 'N', 111 | '5AA': 'A', '5AT': 'T', '5BU': 'U', '5CG': 'G', '5CM': 'C', 112 | '5CS': 'C', '5FA': 'A', '5FC': 'C', '5FU': 'U', '5HP': 'E', 113 | '5HT': 'T', '5HU': 'U', '5IC': 'C', '5IT': 'T', '5IU': 'U', 114 | '5MC': 'C', '5MD': 'N', '5MU': 'U', '5NC': 'C', '5PC': 'C', 115 | '5PY': 'T', '5SE': 'U', '5ZA': 'TWG', '64T': 'T', '6CL': 'K', 116 | '6CT': 'T', '6CW': 'W', '6HA': 'A', '6HC': 'C', '6HG': 'G', 117 | '6HN': 'K', '6HT': 'T', '6IA': 'A', '6MA': 'A', '6MC': 'A', 118 | '6MI': 'N', '6MT': 'A', '6MZ': 'N', '6OG': 'G', '70U': 'U', 119 | '7DA': 'A', '7GU': 'G', '7JA': 'I', '7MG': 'G', '8AN': 'A', 120 | '8FG': 'G', '8MG': 'G', '8OG': 'G', '9NE': 'E', '9NF': 'F', 121 | '9NR': 'R', '9NV': 'V', 'A ': 'A', 'A1P': 'N', 'A23': 'A', 122 | 'A2L': 'A', 'A2M': 'A', 'A34': 'A', 'A35': 'A', 'A38': 'A', 123 | 'A39': 'A', 'A3A': 'A', 'A3P': 'A', 'A40': 'A', 'A43': 'A', 124 | 'A44': 'A', 'A47': 'A', 'A5L': 'A', 'A5M': 'C', 'A5O': 'A', 125 | 'A66': 'X', 'AA3': 'A', 'AA4': 'A', 'AAR': 'R', 'AB7': 'X', 126 | 'ABA': 'A', 'ABR': 'A', 'ABS': 'A', 'ABT': 'N', 'ACB': 'D', 127 | 'ACL': 'R', 'AD2': 'A', 'ADD': 'X', 'ADX': 'N', 'AEA': 'X', 128 | 'AEI': 'D', 'AET': 'A', 'AFA': 'N', 'AFF': 'N', 'AFG': 'G', 129 | 'AGM': 'R', 'AGT': 'X', 'AHB': 'N', 'AHH': 'X', 'AHO': 'A', 130 | 'AHP': 'A', 'AHS': 'X', 'AHT': 'X', 'AIB': 'A', 'AKL': 'D', 131 | 'ALA': 'A', 'ALC': 'A', 'ALG': 'R', 'ALM': 'A', 'ALN': 'A', 132 | 'ALO': 'T', 'ALQ': 'X', 'ALS': 'A', 'ALT': 'A', 'ALY': 'K', 133 | 'AP7': 'A', 'APE': 'X', 'APH': 'A', 'API': 'K', 'APK': 'K', 134 | 'APM': 'X', 'APP': 'X', 'AR2': 'R', 'AR4': 'E', 'ARG': 'R', 135 | 'ARM': 'R', 'ARO': 'R', 'ARV': 'X', 'AS ': 'A', 'AS2': 'D', 136 | 'AS9': 'X', 'ASA': 'D', 'ASB': 'D', 'ASI': 'D', 'ASK': 'D', 137 | 'ASL': 'D', 'ASM': 'X', 'ASN': 'N', 'ASP': 'D', 'ASQ': 'D', 138 | 'ASU': 'N', 'ASX': 'B', 'ATD': 'T', 'ATL': 'T', 'ATM': 'T', 139 | 'AVC': 'A', 'AVN': 'X', 'AYA': 'A', 'AYG': 'AYG', 'AZK': 'K', 140 | 'AZS': 'S', 'AZY': 'Y', 'B1F': 'F', 'B1P': 'N', 'B2A': 'A', 141 | 'B2F': 'F', 'B2I': 'I', 'B2V': 'V', 'B3A': 'A', 'B3D': 'D', 142 | 'B3E': 'E', 'B3K': 'K', 'B3L': 'X', 'B3M': 'X', 'B3Q': 'X', 143 | 'B3S': 'S', 'B3T': 'X', 'B3U': 'H', 'B3X': 'N', 'B3Y': 'Y', 144 | 'BB6': 'C', 'BB7': 'C', 'BB9': 'C', 'BBC': 'C', 'BCS': 'C', 145 | 'BCX': 'C', 'BE2': 'X', 'BFD': 'D', 'BG1': 'S', 'BGM': 'G', 146 | 'BHD': 'D', 'BIF': 'F', 'BIL': 'X', 'BIU': 'I', 'BJH': 'X', 147 | 'BLE': 'L', 'BLY': 'K', 'BMP': 'N', 'BMT': 'T', 'BNN': 'A', 148 | 'BNO': 'X', 'BOE': 'T', 'BOR': 'R', 'BPE': 'C', 'BRU': 'U', 149 | 'BSE': 'S', 'BT5': 'N', 'BTA': 'L', 'BTC': 'C', 'BTR': 'W', 150 | 'BUC': 'C', 'BUG': 'V', 'BVP': 'U', 'BZG': 'N', 'C ': 'C', 151 | 'C12': 'TYG', 'C1X': 'K', 'C25': 'C', 'C2L': 'C', 'C2S': 'C', 152 | 'C31': 'C', 'C32': 'C', 'C34': 'C', 'C36': 'C', 'C37': 'C', 153 | 'C38': 'C', 'C3Y': 'C', 'C42': 'C', 'C43': 'C', 'C45': 'C', 154 | 'C46': 'C', 'C49': 'C', 'C4R': 'C', 'C4S': 'C', 'C5C': 'C', 155 | 'C66': 'X', 'C6C': 'C', 'C99': 'TFG', 'CAF': 'C', 'CAL': 'X', 156 | 'CAR': 'C', 'CAS': 'C', 'CAV': 'X', 'CAY': 'C', 'CB2': 'C', 157 | 'CBR': 'C', 'CBV': 'C', 'CCC': 'C', 'CCL': 'K', 'CCS': 'C', 158 | 'CCY': 'CYG', 'CDE': 'X', 'CDV': 'X', 'CDW': 'C', 'CEA': 'C', 159 | 'CFL': 'C', 'CFY': 'FCYG', 'CG1': 'G', 'CGA': 'E', 'CGU': 'E', 160 | 'CH ': 'C', 'CH6': 'MYG', 'CH7': 'KYG', 'CHF': 'X', 'CHG': 'X', 161 | 'CHP': 'G', 'CHS': 'X', 'CIR': 'R', 'CJO': 'GYG', 'CLE': 'L', 162 | 'CLG': 'K', 'CLH': 'K', 'CLV': 'AFG', 'CM0': 'N', 'CME': 'C', 163 | 'CMH': 'C', 'CML': 'C', 'CMR': 'C', 'CMT': 'C', 'CNU': 'U', 164 | 'CP1': 'C', 'CPC': 'X', 'CPI': 'X', 'CQR': 'GYG', 'CR0': 'TLG', 165 | 'CR2': 'GYG', 'CR5': 'G', 'CR7': 'KYG', 'CR8': 'HYG', 'CRF': 'TWG', 166 | 'CRG': 'THG', 'CRK': 'MYG', 'CRO': 'GYG', 'CRQ': 'QYG', 'CRU': 'E', 167 | 'CRW': 'ASG', 'CRX': 'ASG', 'CS0': 'C', 'CS1': 'C', 'CS3': 'C', 168 | 'CS4': 'C', 'CS8': 'N', 'CSA': 'C', 'CSB': 'C', 'CSD': 'C', 169 | 'CSE': 'C', 'CSF': 'C', 'CSH': 'SHG', 'CSI': 'G', 'CSJ': 'C', 170 | 'CSL': 'C', 'CSO': 'C', 'CSP': 'C', 'CSR': 'C', 'CSS': 'C', 171 | 'CSU': 'C', 'CSW': 'C', 'CSX': 'C', 'CSY': 'SYG', 'CSZ': 'C', 172 | 'CTE': 'W', 'CTG': 'T', 'CTH': 'T', 'CUC': 'X', 'CWR': 'S', 173 | 'CXM': 'M', 'CY0': 'C', 'CY1': 'C', 'CY3': 'C', 'CY4': 'C', 174 | 'CYA': 'C', 'CYD': 'C', 'CYF': 'C', 'CYG': 'C', 'CYJ': 'X', 175 | 'CYM': 'C', 'CYQ': 'C', 'CYR': 'C', 'CYS': 'C', 'CZ2': 'C', 176 | 'CZO': 'GYG', 'CZZ': 'C', 'D11': 'T', 'D1P': 'N', 'D3 ': 'N', 177 | 'D33': 'N', 'D3P': 'G', 'D3T': 'T', 'D4M': 'T', 'D4P': 'X', 178 | 'DA ': 'A', 'DA2': 'X', 'DAB': 'A', 'DAH': 'F', 'DAL': 'A', 179 | 'DAR': 'R', 'DAS': 'D', 'DBB': 'T', 'DBM': 'N', 'DBS': 'S', 180 | 'DBU': 'T', 'DBY': 'Y', 'DBZ': 'A', 'DC ': 'C', 'DC2': 'C', 181 | 'DCG': 'G', 'DCI': 'X', 'DCL': 'X', 'DCT': 'C', 'DCY': 'C', 182 | 'DDE': 'H', 'DDG': 'G', 'DDN': 'U', 'DDX': 'N', 'DFC': 'C', 183 | 'DFG': 'G', 'DFI': 'X', 'DFO': 'X', 'DFT': 'N', 'DG ': 'G', 184 | 'DGH': 'G', 'DGI': 'G', 'DGL': 'E', 'DGN': 'Q', 'DHA': 'A', 185 | 'DHI': 'H', 'DHL': 'X', 'DHN': 'V', 'DHP': 'X', 'DHU': 'U', 186 | 'DHV': 'V', 'DI ': 'I', 'DIL': 'I', 'DIR': 'R', 'DIV': 'V', 187 | 'DLE': 'L', 'DLS': 'K', 'DLY': 'K', 'DM0': 'K', 'DMH': 'N', 188 | 'DMK': 'D', 'DMT': 'X', 'DN ': 'N', 'DNE': 'L', 'DNG': 'L', 189 | 'DNL': 'K', 'DNM': 'L', 'DNP': 'A', 'DNR': 'C', 'DNS': 'K', 190 | 'DOA': 'X', 'DOC': 'C', 'DOH': 'D', 'DON': 'L', 'DPB': 'T', 191 | 'DPH': 'F', 'DPL': 'P', 'DPP': 'A', 'DPQ': 'Y', 'DPR': 'P', 192 | 'DPY': 'N', 'DRM': 'U', 'DRP': 'N', 'DRT': 'T', 'DRZ': 'N', 193 | 'DSE': 'S', 'DSG': 'N', 'DSN': 'S', 'DSP': 'D', 'DT ': 'T', 194 | 'DTH': 'T', 'DTR': 'W', 'DTY': 'Y', 'DU ': 'U', 'DVA': 'V', 195 | 'DXD': 'N', 'DXN': 'N', 'DYG': 'DYG', 'DYS': 'C', 'DZM': 'A', 196 | 'E ': 'A', 'E1X': 'A', 'EDA': 'A', 'EDC': 'G', 'EFC': 'C', 197 | 'EHP': 'F', 'EIT': 'T', 'ENP': 'N', 'ESB': 'Y', 'ESC': 'M', 198 | 'EXY': 'L', 'EY5': 'N', 'EYS': 'X', 'F2F': 'F', 'FA2': 'A', 199 | 'FA5': 'N', 'FAG': 'N', 'FAI': 'N', 'FCL': 'F', 'FFD': 'N', 200 | 'FGL': 'G', 'FGP': 'S', 'FHL': 'X', 'FHO': 'K', 'FHU': 'U', 201 | 'FLA': 'A', 'FLE': 'L', 'FLT': 'Y', 'FME': 'M', 'FMG': 'G', 202 | 'FMU': 'N', 'FOE': 'C', 'FOX': 'G', 'FP9': 'P', 'FPA': 'F', 203 | 'FRD': 'X', 'FT6': 'W', 'FTR': 'W', 'FTY': 'Y', 'FZN': 'K', 204 | 'G ': 'G', 'G25': 'G', 'G2L': 'G', 'G2S': 'G', 'G31': 'G', 205 | 'G32': 'G', 'G33': 'G', 'G36': 'G', 'G38': 'G', 'G42': 'G', 206 | 'G46': 'G', 'G47': 'G', 'G48': 'G', 'G49': 'G', 'G4P': 'N', 207 | 'G7M': 'G', 'GAO': 'G', 'GAU': 'E', 'GCK': 'C', 'GCM': 'X', 208 | 'GDP': 'G', 'GDR': 'G', 'GFL': 'G', 'GGL': 'E', 'GH3': 'G', 209 | 'GHG': 'Q', 'GHP': 'G', 'GL3': 'G', 'GLH': 'Q', 'GLM': 'X', 210 | 'GLN': 'Q', 'GLQ': 'E', 'GLU': 'E', 'GLX': 'Z', 'GLY': 'G', 211 | 'GLZ': 'G', 'GMA': 'E', 'GMS': 'G', 'GMU': 'U', 'GN7': 'G', 212 | 'GND': 'X', 'GNE': 'N', 'GOM': 'G', 'GPL': 'K', 'GS ': 'G', 213 | 'GSC': 'G', 'GSR': 'G', 'GSS': 'G', 'GSU': 'E', 'GT9': 'C', 214 | 'GTP': 'G', 'GVL': 'X', 'GYC': 'CYG', 'GYS': 'SYG', 'H2U': 'U', 215 | 'H5M': 'P', 'HAC': 'A', 'HAR': 'R', 'HBN': 'H', 'HCS': 'X', 216 | 'HDP': 'U', 'HEU': 'U', 'HFA': 'X', 'HGL': 'X', 'HHI': 'H', 217 | 'HHK': 'AK', 'HIA': 'H', 'HIC': 'H', 'HIP': 'H', 'HIQ': 'H', 218 | 'HIS': 'H', 'HL2': 'L', 'HLU': 'L', 'HMF': 'A', 'HMR': 'R', 219 | 'HOL': 'N', 'HPC': 'F', 'HPE': 'F', 'HPQ': 'F', 'HQA': 'A', 220 | 'HRG': 'R', 'HRP': 'W', 'HS8': 'H', 'HS9': 'H', 'HSE': 'S', 221 | 'HSL': 'S', 'HSO': 'H', 'HTI': 'C', 'HTN': 'N', 'HTR': 'W', 222 | 'HV5': 'A', 'HVA': 'V', 'HY3': 'P', 'HYP': 'P', 'HZP': 'P', 223 | 'I ': 'I', 'I2M': 'I', 'I58': 'K', 'I5C': 'C', 'IAM': 'A', 224 | 'IAR': 'R', 'IAS': 'D', 'IC ': 'C', 'IEL': 'K', 'IEY': 'HYG', 225 | 'IG ': 'G', 'IGL': 'G', 'IGU': 'G', 'IIC': 'SHG', 'IIL': 'I', 226 | 'ILE': 'I', 'ILG': 'E', 'ILX': 'I', 'IMC': 'C', 'IML': 'I', 227 | 'IOY': 'F', 'IPG': 'G', 'IPN': 'N', 'IRN': 'N', 'IT1': 'K', 228 | 'IU ': 'U', 'IYR': 'Y', 'IYT': 'T', 'JJJ': 'C', 'JJK': 'C', 229 | 'JJL': 'C', 'JW5': 'N', 'K1R': 'C', 'KAG': 'G', 'KCX': 'K', 230 | 'KGC': 'K', 'KOR': 'M', 'KPI': 'K', 'KST': 'K', 'KYQ': 'K', 231 | 'L2A': 'X', 'LA2': 'K', 'LAA': 'D', 'LAL': 'A', 'LBY': 'K', 232 | 'LC ': 'C', 'LCA': 'A', 'LCC': 'N', 'LCG': 'G', 'LCH': 'N', 233 | 'LCK': 'K', 'LCX': 'K', 'LDH': 'K', 'LED': 'L', 'LEF': 'L', 234 | 'LEH': 'L', 'LEI': 'V', 'LEM': 'L', 'LEN': 'L', 'LET': 'X', 235 | 'LEU': 'L', 'LG ': 'G', 'LGP': 'G', 'LHC': 'X', 'LHU': 'U', 236 | 'LKC': 'N', 'LLP': 'K', 'LLY': 'K', 'LME': 'E', 'LMQ': 'Q', 237 | 'LMS': 'N', 'LP6': 'K', 'LPD': 'P', 'LPG': 'G', 'LPL': 'X', 238 | 'LPS': 'S', 'LSO': 'X', 'LTA': 'X', 'LTR': 'W', 'LVG': 'G', 239 | 'LVN': 'V', 'LYM': 'K', 'LYN': 'K', 'LYR': 'K', 'LYS': 'K', 240 | 'LYX': 'K', 'LYZ': 'K', 'M0H': 'C', 'M1G': 'G', 'M2G': 'G', 241 | 'M2L': 'K', 'M2S': 'M', 'M3L': 'K', 'M5M': 'C', 'MA ': 'A', 242 | 'MA6': 'A', 'MA7': 'A', 'MAA': 'A', 'MAD': 'A', 'MAI': 'R', 243 | 'MBQ': 'Y', 'MBZ': 'N', 'MC1': 'S', 'MCG': 'X', 'MCL': 'K', 244 | 'MCS': 'C', 'MCY': 'C', 'MDH': 'X', 'MDO': 'ASG', 'MDR': 'N', 245 | 'MEA': 'F', 'MED': 'M', 'MEG': 'E', 'MEN': 'N', 'MEP': 'U', 246 | 'MEQ': 'Q', 'MET': 'M', 'MEU': 'G', 'MF3': 'X', 'MFC': 'GYG', 247 | 'MG1': 'G', 'MGG': 'R', 'MGN': 'Q', 'MGQ': 'A', 'MGV': 'G', 248 | 'MGY': 'G', 'MHL': 'L', 'MHO': 'M', 'MHS': 'H', 'MIA': 'A', 249 | 'MIS': 'S', 'MK8': 'L', 'ML3': 'K', 'MLE': 'L', 'MLL': 'L', 250 | 'MLY': 'K', 'MLZ': 'K', 'MME': 'M', 'MMT': 'T', 'MND': 'N', 251 | 'MNL': 'L', 'MNU': 'U', 'MNV': 'V', 'MOD': 'X', 'MP8': 'P', 252 | 'MPH': 'X', 'MPJ': 'X', 'MPQ': 'G', 'MRG': 'G', 'MSA': 'G', 253 | 'MSE': 'M', 'MSL': 'M', 'MSO': 'M', 'MSP': 'X', 'MT2': 'M', 254 | 'MTR': 'T', 'MTU': 'A', 'MTY': 'Y', 'MVA': 'V', 'N ': 'N', 255 | 'N10': 'S', 'N2C': 'X', 'N5I': 'N', 'N5M': 'C', 'N6G': 'G', 256 | 'N7P': 'P', 'NA8': 'A', 'NAL': 'A', 'NAM': 'A', 'NB8': 'N', 257 | 'NBQ': 'Y', 'NC1': 'S', 'NCB': 'A', 'NCX': 'N', 'NCY': 'X', 258 | 'NDF': 'F', 'NDN': 'U', 'NEM': 'H', 'NEP': 'H', 'NF2': 'N', 259 | 'NFA': 'F', 'NHL': 'E', 'NIT': 'X', 'NIY': 'Y', 'NLE': 'L', 260 | 'NLN': 'L', 'NLO': 'L', 'NLP': 'L', 'NLQ': 'Q', 'NMC': 'G', 261 | 'NMM': 'R', 'NMS': 'T', 'NMT': 'T', 'NNH': 'R', 'NP3': 'N', 262 | 'NPH': 'C', 'NRP': 'LYG', 'NRQ': 'MYG', 'NSK': 'X', 'NTY': 'Y', 263 | 'NVA': 'V', 'NYC': 'TWG', 'NYG': 'NYG', 'NYM': 'N', 'NYS': 'C', 264 | 'NZH': 'H', 'O12': 'X', 'O2C': 'N', 'O2G': 'G', 'OAD': 'N', 265 | 'OAS': 'S', 'OBF': 'X', 'OBS': 'X', 'OCS': 'C', 'OCY': 'C', 266 | 'ODP': 'N', 'OHI': 'H', 'OHS': 'D', 'OIC': 'X', 'OIP': 'I', 267 | 'OLE': 'X', 'OLT': 'T', 'OLZ': 'S', 'OMC': 'C', 'OMG': 'G', 268 | 'OMT': 'M', 'OMU': 'U', 'ONE': 'U', 'ONL': 'X', 'OPR': 'R', 269 | 'ORN': 'A', 'ORQ': 'R', 'OSE': 'S', 'OTB': 'X', 'OTH': 'T', 270 | 'OTY': 'Y', 'OXX': 'D', 'P ': 'G', 'P1L': 'C', 'P1P': 'N', 271 | 'P2T': 'T', 'P2U': 'U', 'P2Y': 'P', 'P5P': 'A', 'PAQ': 'Y', 272 | 'PAS': 'D', 'PAT': 'W', 'PAU': 'A', 'PBB': 'C', 'PBF': 'F', 273 | 'PBT': 'N', 'PCA': 'E', 'PCC': 'P', 'PCE': 'X', 'PCS': 'F', 274 | 'PDL': 'X', 'PDU': 'U', 'PEC': 'C', 'PF5': 'F', 'PFF': 'F', 275 | 'PFX': 'X', 'PG1': 'S', 'PG7': 'G', 'PG9': 'G', 'PGL': 'X', 276 | 'PGN': 'G', 'PGP': 'G', 'PGY': 'G', 'PHA': 'F', 'PHD': 'D', 277 | 'PHE': 'F', 'PHI': 'F', 'PHL': 'F', 'PHM': 'F', 'PIV': 'X', 278 | 'PLE': 'L', 'PM3': 'F', 'PMT': 'C', 'POM': 'P', 'PPN': 'F', 279 | 'PPU': 'A', 'PPW': 'G', 'PQ1': 'N', 'PR3': 'C', 'PR5': 'A', 280 | 'PR9': 'P', 'PRN': 'A', 'PRO': 'P', 'PRS': 'P', 'PSA': 'F', 281 | 'PSH': 'H', 'PST': 'T', 'PSU': 'U', 'PSW': 'C', 'PTA': 'X', 282 | 'PTH': 'Y', 'PTM': 'Y', 'PTR': 'Y', 'PU ': 'A', 'PUY': 'N', 283 | 'PVH': 'H', 'PVL': 'X', 'PYA': 'A', 'PYO': 'U', 'PYX': 'C', 284 | 'PYY': 'N', 'QLG': 'QLG', 'QUO': 'G', 'R ': 'A', 'R1A': 'C', 285 | 'R1B': 'C', 'R1F': 'C', 'R7A': 'C', 'RC7': 'HYG', 'RCY': 'C', 286 | 'RIA': 'A', 'RMP': 'A', 'RON': 'X', 'RT ': 'T', 'RTP': 'N', 287 | 'S1H': 'S', 'S2C': 'C', 'S2D': 'A', 'S2M': 'T', 'S2P': 'A', 288 | 'S4A': 'A', 'S4C': 'C', 'S4G': 'G', 'S4U': 'U', 'S6G': 'G', 289 | 'SAC': 'S', 'SAH': 'C', 'SAR': 'G', 'SBL': 'S', 'SC ': 'C', 290 | 'SCH': 'C', 'SCS': 'C', 'SCY': 'C', 'SD2': 'X', 'SDG': 'G', 291 | 'SDP': 'S', 'SEB': 'S', 'SEC': 'A', 'SEG': 'A', 'SEL': 'S', 292 | 'SEM': 'X', 'SEN': 'S', 'SEP': 'S', 'SER': 'S', 'SET': 'S', 293 | 'SGB': 'S', 'SHC': 'C', 'SHP': 'G', 'SHR': 'K', 'SIB': 'C', 294 | 'SIC': 'DC', 'SLA': 'P', 'SLR': 'P', 'SLZ': 'K', 'SMC': 'C', 295 | 'SME': 'M', 'SMF': 'F', 'SMP': 'A', 'SMT': 'T', 'SNC': 'C', 296 | 'SNN': 'N', 'SOC': 'C', 'SOS': 'N', 'SOY': 'S', 'SPT': 'T', 297 | 'SRA': 'A', 'SSU': 'U', 'STY': 'Y', 'SUB': 'X', 'SUI': 'DG', 298 | 'SUN': 'S', 'SUR': 'U', 'SVA': 'S', 'SVX': 'S', 'SVZ': 'X', 299 | 'SYS': 'C', 'T ': 'T', 'T11': 'F', 'T23': 'T', 'T2S': 'T', 300 | 'T2T': 'N', 'T31': 'U', 'T32': 'T', 'T36': 'T', 'T37': 'T', 301 | 'T38': 'T', 'T39': 'T', 'T3P': 'T', 'T41': 'T', 'T48': 'T', 302 | 'T49': 'T', 'T4S': 'T', 'T5O': 'U', 'T5S': 'T', 'T66': 'X', 303 | 'T6A': 'A', 'TA3': 'T', 'TA4': 'X', 'TAF': 'T', 'TAL': 'N', 304 | 'TAV': 'D', 'TBG': 'V', 'TBM': 'T', 'TC1': 'C', 'TCP': 'T', 305 | 'TCQ': 'X', 'TCR': 'W', 'TCY': 'A', 'TDD': 'L', 'TDY': 'T', 306 | 'TFE': 'T', 'TFO': 'A', 'TFQ': 'F', 'TFT': 'T', 'TGP': 'G', 307 | 'TH6': 'T', 'THC': 'T', 'THO': 'X', 'THR': 'T', 'THX': 'N', 308 | 'THZ': 'R', 'TIH': 'A', 'TLB': 'N', 'TLC': 'T', 'TLN': 'U', 309 | 'TMB': 'T', 'TMD': 'T', 'TNB': 'C', 'TNR': 'S', 'TOX': 'W', 310 | 'TP1': 'T', 'TPC': 'C', 'TPG': 'G', 'TPH': 'X', 'TPL': 'W', 311 | 'TPO': 'T', 'TPQ': 'Y', 'TQQ': 'W', 'TRF': 'W', 'TRG': 'K', 312 | 'TRN': 'W', 'TRO': 'W', 'TRP': 'W', 'TRQ': 'W', 'TRW': 'W', 313 | 'TRX': 'W', 'TS ': 'N', 'TST': 'X', 'TT ': 'N', 'TTD': 'T', 314 | 'TTI': 'U', 'TTM': 'T', 'TTQ': 'W', 'TTS': 'Y', 'TY2': 'Y', 315 | 'TY3': 'Y', 'TYB': 'Y', 'TYI': 'Y', 'TYN': 'Y', 'TYO': 'Y', 316 | 'TYQ': 'Y', 'TYR': 'Y', 'TYS': 'Y', 'TYT': 'Y', 'TYU': 'N', 317 | 'TYX': 'X', 'TYY': 'Y', 'TZB': 'X', 'TZO': 'X', 'U ': 'U', 318 | 'U25': 'U', 'U2L': 'U', 'U2N': 'U', 'U2P': 'U', 'U31': 'U', 319 | 'U33': 'U', 'U34': 'U', 'U36': 'U', 'U37': 'U', 'U8U': 'U', 320 | 'UAR': 'U', 'UCL': 'U', 'UD5': 'U', 'UDP': 'N', 'UFP': 'N', 321 | 'UFR': 'U', 'UFT': 'U', 'UMA': 'A', 'UMP': 'U', 'UMS': 'U', 322 | 'UN1': 'X', 'UN2': 'X', 'UNK': 'X', 'UR3': 'U', 'URD': 'U', 323 | 'US1': 'U', 'US2': 'U', 'US3': 'T', 'US5': 'U', 'USM': 'U', 324 | 'V1A': 'C', 'VAD': 'V', 'VAF': 'V', 'VAL': 'V', 'VB1': 'K', 325 | 'VDL': 'X', 'VLL': 'X', 'VLM': 'X', 'VMS': 'X', 'VOL': 'X', 326 | 'X ': 'G', 'X2W': 'E', 'X4A': 'N', 'X9Q': 'AFG', 'XAD': 'A', 327 | 'XAE': 'N', 'XAL': 'A', 'XAR': 'N', 'XCL': 'C', 'XCP': 'X', 328 | 'XCR': 'C', 'XCS': 'N', 'XCT': 'C', 'XCY': 'C', 'XGA': 'N', 329 | 'XGL': 'G', 'XGR': 'G', 'XGU': 'G', 'XTH': 'T', 'XTL': 'T', 330 | 'XTR': 'T', 'XTS': 'G', 'XTY': 'N', 'XUA': 'A', 'XUG': 'G', 331 | 'XX1': 'K', 'XXY': 'THG', 'XYG': 'DYG', 'Y ': 'A', 'YCM': 'C', 332 | 'YG ': 'G', 'YOF': 'Y', 'YRR': 'N', 'YYG': 'G', 'Z ': 'C', 333 | 'ZAD': 'A', 'ZAL': 'A', 'ZBC': 'C', 'ZCY': 'C', 'ZDU': 'U', 334 | 'ZFB': 'X', 'ZGU': 'G', 'ZHP': 'N', 'ZTH': 'T', 'ZZJ': 'A'} 335 | 336 | # remove hetero atoms (waters/ligands/etc) from consideration? 337 | if het: 338 | cmd.select("__h", "br. " + haystack) 339 | else: 340 | cmd.select("__h", "br. " + haystack + " and not het") 341 | 342 | # get the AAs in the haystack 343 | aaDict = {'aaList': []} 344 | cmd.iterate("(name ca) and __h", "aaList.append((resi,resn,chain))", space=aaDict) 345 | 346 | # remove redundant residues, Longxing 2019-01-26 347 | curr_res = None 348 | for index, v in enumerate(aaDict['aaList']): 349 | if v == curr_res: 350 | aaDict['aaList'].pop(index) 351 | curr_res = v 352 | # 2019-01-26, Longxing, some pdbs contain non number residue index 353 | # just add a filter before converting that to a number. 354 | #IDs = [int(x[0]) for x in aaDict['aaList']] 355 | IDs = [int(filter( lambda ch: ch in '0123456789', x[0]) ) for x in aaDict['aaList']] 356 | AAs = ''.join([one_letter[x[1]] for x in aaDict['aaList']]) 357 | chains = [x[2] for x in aaDict['aaList']] 358 | 359 | reNeedle = re.compile(needle.upper()) 360 | it = reNeedle.finditer(AAs) 361 | 362 | # make an empty selection to which we add residues 363 | cmd.select(rSelName, 'None') 364 | 365 | for i in it: 366 | (start, stop) = i.span() 367 | # we found some residues, which chains are they from? 368 | i_chains = chains[start:stop] 369 | # are all residues from one chain? 370 | if len(set(i_chains)) != 1: 371 | # now they are not, this match is not really a match, skip it 372 | continue 373 | chain = i_chains[0] 374 | cmd.select(rSelName, rSelName + " or (__h and i. " + str(IDs[start]) + "-" + str(IDs[stop - 1]) + " and c. " + chain + " )") 375 | if int(firstOnly): 376 | break 377 | cmd.delete("__h") 378 | return rSelName 379 | cmd.extend("findseq", findseq) 380 | 381 | 382 | def checkParams(needle, haystack, selName, het, firstOnly): 383 | """ 384 | This is just a helper function for checking the user input 385 | """ 386 | # check Needle 387 | if len(needle) == 0 or not cmd.is_string(needle): 388 | print("Error: Please provide a string 'needle' to search for.") 389 | print("Error: For help type 'help motifFinder'.") 390 | return False 391 | 392 | # check Haystack 393 | if len(haystack) == 0 or not cmd.is_string(haystack): 394 | print("Error: Please provide valid PyMOL object or selection name") 395 | print("Error: in which to search.") 396 | print("Error: For help type 'help motifFinder'.") 397 | return False 398 | 399 | # check het 400 | try: 401 | het = bool(int(het)) 402 | except ValueError: 403 | print("Error: The 'het' parameter was not 0 or 1.") 404 | return False 405 | 406 | # check first Only 407 | try: 408 | firstOnly = bool(int(het)) 409 | except ValueError: 410 | print("Error: The 'firstOnly' parameter was not 0 or 1.") 411 | return False 412 | 413 | # check selName 414 | if not cmd.is_string(selName): 415 | print("Error: selName was not a string.") 416 | return False 417 | return True -------------------------------------------------------------------------------- /scripts/GenUtils.py: -------------------------------------------------------------------------------- 1 | import os 2 | import pymol 3 | from pymol import cmd 4 | 5 | import sys 6 | import zlib 7 | import glob 8 | import urllib 9 | import gzip 10 | import re 11 | 12 | 13 | # JK DEBUG - Load a BAFF PDB 14 | #def baff_load(fname,name=None): 15 | # 16 | # cmd.load(fname) 17 | # cmd.hide("lines") 18 | # cmd.show( "cartoon" ) 19 | # cmd.show( "sticks", "not element h and chain c and resi 65" ) 20 | # cmd.show( "sticks", "not element h and chain i and byres ( resi 65 around 6.0 )" ) 21 | # cmd.center("chain c and resi 65") 22 | # 23 | #cmd.extend("baff_load",baff_load) 24 | 25 | 26 | # Load a PDB, with support for gzipped PDBs 27 | def zload(fname,name=None): 28 | 29 | if name is None: 30 | name = name = os.path.basename(fname) 31 | if name.endswith('.gz'): 32 | name = name[:-3] 33 | if name.endswith('.pdb'): 34 | name = name[:-4] 35 | if name.endswith('.'): 36 | name = name[:-1] 37 | 38 | # Check if the file exists. If not 4 chars, give a warning and do nothing else 39 | if not os.path.isfile(fname): 40 | # If fname is not 4 chars and the file doesn't exist, print an error message 41 | if len(name) != 4: 42 | print "Error, file does not exist" 43 | return 44 | 45 | # Same error if the first char is not a number 46 | if not re.match('[0-9]', name): 47 | print "Error, file does not exist" 48 | return 49 | 50 | # If the length is 4 and the first char is a number, this is presumably a standard PDB ID 51 | print "Using PDB file "+name+" from repository..." 52 | 53 | # If the filename is 4 chars, goto the PDB homedir repository looking for it 54 | # Assemble the PDB name (with .gz) in the homedir repository 55 | pdbdir = os.path.expanduser("PDBs/") 56 | if not os.path.isdir(pdbdir): os.mkdir(pdbdir) 57 | fname = pdbdir + name.lower() + ".pdb.gz" 58 | 59 | # If it's not found there, download it and add it to the PDB homedir repository so we can continue 60 | if not os.path.isfile(fname): 61 | pdburl = "http://www.rcsb.org/pdb/files/"+name+".pdb" 62 | response = urllib.urlopen(pdburl) 63 | f = gzip.open(fname, 'wb') 64 | f.write( response.read() ) 65 | f.close() 66 | print "Downloaded PDB "+name 67 | 68 | pdbstr='' 69 | 70 | if fname.endswith('.gz'): 71 | FTEXT, FHCRC, FEXTRA, FNAME, FCOMMENT = 1, 2, 4, 8, 16 72 | 73 | input=open(fname) 74 | magic=input.read(2) 75 | if magic!='\037\213': 76 | print 'Not a gzipped file' 77 | if ord(input.read(1))!=8: 78 | print 'Unknown compression method' ; sys.exit(0) 79 | flag=ord(input.read(1)) 80 | input.read(4+1+1) # Discard modification time, extra flags, and OS byte. 81 | 82 | if flag & FEXTRA: 83 | # Read & discard the extra field, if present 84 | xlen=ord(input.read(1)) 85 | xlen=xlen+256*ord(input.read(1)) 86 | input.read(xlen) 87 | if flag & FNAME: 88 | # Read and discard a null-terminated string containing the filename 89 | while (1): 90 | s=input.read(1) 91 | if s=='\000': break 92 | if flag & FCOMMENT: 93 | # Read and discard a null-terminated string containing a comment 94 | while (1): 95 | s=input.read(1) 96 | if s=='\000': break 97 | if flag & FHCRC: 98 | input.read(2) # Read & discard the 16-bit header CRC 99 | 100 | decompobj=zlib.decompressobj(-zlib.MAX_WBITS) 101 | crcval=zlib.crc32("") 102 | length=0 103 | while (1): 104 | data=input.read(1024) 105 | if data=="": break 106 | pdbstr+=decompobj.decompress(data) 107 | crcval=zlib.crc32(pdbstr, crcval) 108 | pdbstr+=decompobj.flush() 109 | input.close() 110 | crcval=zlib.crc32(pdbstr, crcval) 111 | 112 | else: 113 | 114 | f=open(fname, 'r') 115 | pdbstr=f.read() 116 | f.close() 117 | 118 | cmd.read_pdbstr(pdbstr, name) 119 | 120 | # call useRosettaRadii to reset 121 | def hilightPolar(sel='all'): 122 | N = "elem N"# and (not name N)" 123 | O = "elem O"# and (not name O)" # want to inlude look BB atoms... 124 | S = "elem S" 125 | sel = sel + " and " + N+" or "+O+" or "+S 126 | cmd.alter(sel,"vdw=0.3") 127 | cmd.rebuild() 128 | cmd.show('spheres',sel) 129 | 130 | def unhilightPolar(sel='all'): 131 | N = "elem N"# and (not name N)" 132 | O = "elem O"# and (not name O)" # want to inlude look BB atoms... 133 | S = "elem S" 134 | sel = sel + " and " + N+" or "+O+" or "+S 135 | cmd.alter(sel,"vdw=1.0") 136 | cmd.rebuild() 137 | cmd.hide('spheres',sel) 138 | 139 | # Load all PDBs in the current directory 140 | def load_all_pdbs(): 141 | 142 | for fname in glob.glob('*.pdb'): 143 | cmd.load(fname) 144 | 145 | cmd.extend("load_all_pdbs",load_all_pdbs) 146 | 147 | 148 | cmd.extend("zload",zload) 149 | cmd.extend('hilightPolar',hilightPolar) 150 | cmd.extend('unhilightPolar',unhilightPolar) 151 | 152 | -------------------------------------------------------------------------------- /scripts/Geometry.py: -------------------------------------------------------------------------------- 1 | from pymol import cmd 2 | from math import asin,acos,atan,cos,sin,tan,sqrt 3 | 4 | 5 | 6 | def getAtomProjectionOnPlane(sel,a,b,c,d):# specify d as distance along norm from origin rather than -distance (ax+by+cz=d) 7 | """ 8 | returns a list of all projected balls ordered by signed distance along 9 | the normal to the plane ax + by + cz + d = 0 10 | """ 11 | p = Plane(float(a),float(b),float(c),-float(d)) 12 | slice = [s for s in p.getProjections(sel) if s is not None] 13 | slice.sort() 14 | return slice 15 | 16 | def getAtomProjectionAsR(sel='all',fname='points.R',a=1,b=0,c=0,d=0,varname='slice'): 17 | print "write projections to file",fname 18 | o = open(fname,'w') 19 | o.write( projectionAsRString(sel,a,b,c,d,varname) ) 20 | o.close() 21 | 22 | def projectionAsRString(sel='all',a=0,b=0,c=1,d=0,varname='slice'): 23 | slice = getAtomProjectionOnPlane(sel,a,b,c,d) 24 | Npoints = len(slice) 25 | s = '' 26 | s += "%(varname)s = array(NA,c(%(Npoints)i,9)) \n "%vars() 27 | s += "%(varname)s = as.data.frame(%(varname)s) \n "%vars() 28 | s += "names(%(varname)s) = c('x','y','z','r','xorig','yorig','zorig','rorig','signdis' ) \n"%vars() 29 | s += "%(varname)s$atype = rep('H',%(Npoints)i) \n "%vars() 30 | 31 | for ii in range(1,len(slice)+1): 32 | pa = slice[ii-1] 33 | #print pa 34 | x,y,z = pa.coordproj 35 | r = pa.radiusproj 36 | ox,oy,oz = pa.atom.coord 37 | origr = pa.atom.vdw 38 | signdis = pa.signeddis 39 | atype = pa.atom.symbol 40 | occ = pa.atom.q 41 | bfac = pa.atom.b 42 | s += "%(varname)s[%(ii)i,1] = "%vars() + `x` + '\n' 43 | s += "%(varname)s[%(ii)i,2] = "%vars() + `y` + '\n' 44 | s += "%(varname)s[%(ii)i,3] = "%vars() + `z` + '\n' 45 | s += "%(varname)s[%(ii)i,4] = "%vars() + `r` + '\n' 46 | s += "%(varname)s[%(ii)i,5] = "%vars() + `ox` + '\n' 47 | s += "%(varname)s[%(ii)i,6] = "%vars() + `oy` + '\n' 48 | s += "%(varname)s[%(ii)i,7] = "%vars() + `oz` + '\n' 49 | s += "%(varname)s[%(ii)i,8] = "%vars() + `origr` + '\n' 50 | s += "%(varname)s[%(ii)i,9] = "%vars() + `signdis` + '\n' 51 | s += "%(varname)s[%(ii)i,9] = "%vars() + `signdis` + '\n' 52 | s += "%(varname)s$atype[%(ii)i] = "%vars() + `atype` + '\n' 53 | s += "%(varname)s$occ[%(ii)i] = "%vars() + `occ` + '\n' 54 | s += "%(varname)s$bfac[%(ii)i] = "%vars() + `bfac` + '\n' 55 | return s 56 | 57 | def multiSliceAsR(sel='all',fname='/tmp/points.R',a=0,b=0,c=1,interval=1,varname='slice'): 58 | origin = Plane(float(a),float(b),float(c),0) 59 | mn = 99999999 60 | mx = -99999999 61 | for atom in cmd.get_model(sel).atom: 62 | d = origin.signedDisTo(atom) 63 | if mn > d: 64 | mn = d 65 | if mx < d: 66 | mx = d 67 | 68 | o = open(fname,'w') 69 | o.write( "%(varname)s = list() \n"%vars() ) 70 | for ii,d in enumerate(range(mn,mx,interval)): 71 | print 'slice',ii,d 72 | variter = varname+"[[%i]]"%(ii+1) 73 | o.write( projectionAsRString(sel,a,b,c,d,varname=variter) ) 74 | o.close() 75 | 76 | #cmd.extend('getAtomProjectionOnPlane',getAtomProjectionOnPlane) 77 | cmd.extend('getAtomProjectionAsR',getAtomProjectionAsR) 78 | cmd.extend('multiSliceAsR',multiSliceAsR) 79 | 80 | 81 | 82 | # argh! why can't I get this to work? 83 | def scaleCoords(amount=1.0,sel='all'): 84 | m = cmd.get_model(sel) 85 | for a in m.atom: 86 | if a.index == 80: 87 | delta = [float(k)*(amount-1) for k in a.coord] 88 | print amount, a.coord, delta 89 | cmd.translate( [ delta[0], delta[1], delta[2] ] , "index "+`a.index`) 90 | 91 | class ProjectedAtom(object): 92 | """The ProjectedAtom class.""" 93 | def __init__( self, atom, coordproj, radiusproj, signeddis ): 94 | self.atom = atom 95 | self.coordproj = coordproj 96 | self.radiusproj = radiusproj 97 | self.signeddis = signeddis 98 | def __cmp__(self,other): 99 | return cmp(self.signeddis,other.signeddis) 100 | def __repr__(self): 101 | return "TODO!!!" 102 | 103 | # lets try something more successful... 104 | class Plane(object): 105 | """The Plane class.""" 106 | 107 | def __init__(self, a=1,b=0,c=0,d=0): # (a,b,c).(x,y,z) + d == ax + by + cz + d == 0 108 | l = sqrt(a**2+b**2+c**2) 109 | self.a = a/l 110 | self.b = b/l 111 | self.c = c/l 112 | self.d = d/l 113 | 114 | def signedDisTo(self,atom): # just (x0,y0,z0).(a,b,c) + d (assumes a,b,c,d are normalized) 115 | return self.a*atom.coord[0] + self.b*atom.coord[1] + self.c*atom.coord[2] + self.d 116 | 117 | def disTo(self,atom): 118 | return abs( self.signedDisTo(atom) ) 119 | 120 | def getProjection(self,atom): 121 | d = self.signedDisTo(atom) 122 | r = atom.vdw 123 | if abs(d) >= r: # atom doesn't intersect plain 124 | None 125 | else: 126 | rproj = r * cos( asin( d/r ) ) 127 | xproj = atom.coord[0] - d * self.a # XYZ - dist_to_plain * Normal == projected point on plain 128 | yproj = atom.coord[1] - d * self.b 129 | zproj = atom.coord[2] - d * self.c 130 | pa = ProjectedAtom( atom, (xproj,yproj,zproj), rproj, d ) 131 | return pa 132 | 133 | def getProjections(self,sel='all'): 134 | return [ self.getProjection(a) for a in cmd.get_model(sel).atom ] 135 | 136 | 137 | -------------------------------------------------------------------------------- /scripts/InterfaceUtils-network.py: -------------------------------------------------------------------------------- 1 | 2 | import pymol 3 | from pymol import cmd 4 | 5 | import sys,os 6 | 7 | from MoleculeUtils import selectPolarProtons 8 | from MoleculeUtils import selectApolarProtons 9 | from MoleculeUtils import colorCPK 10 | from PackingMeasureUtils import loadPackingPDB 11 | 12 | def loadSurfaceInterfacePDB( file,name=None,native=None,wt=None): 13 | 14 | print " Loading interface PDB %s"%(file) 15 | 16 | if name is None: 17 | name = name = os.path.basename(file) 18 | if name.endswith('.pdb'): 19 | name = name[:-4] 20 | 21 | # Call Will's packing PDB loading function 22 | # Note: proteins will be cartoons, cavities will be spheres 23 | # Rosetta radii will be enabled 24 | name = loadPackingPDB(file,name,native) 25 | 26 | cavselname = name+"cavities" 27 | protselname = name+"protein" 28 | cmd.hide("lines",protselname) 29 | 30 | backbone_colorlist = [ 'forest','gold', 'violet', 'cyan', \ 31 | 'salmon', 'lime', 'slate', 'magenta', 'orange', 'marine', \ 32 | 'olive', 'forest', 'firebrick', 'chocolate' ] 33 | curr_bb_color = 0 34 | 35 | carbon_colorlist = ['titanium', 'wheat', 'grey', 'pink' ] 36 | curr_carbon_color = 0 37 | 38 | # Derive selections for the interface, color by chain 39 | cmd.select("interface", "none") 40 | cmd.select("heavy_interface", "none") 41 | selectPolarProtons("polar_protons") 42 | selectApolarProtons("apolar_protons") 43 | alphabet = list(('abcdefghijklmnopqrstuvwxyz').upper()) 44 | for letter in alphabet: 45 | chainname = "chain"+letter 46 | cmd.select( chainname, "chain %s and not hetatm and not symbol w"%(letter) ) 47 | 48 | # Check whether any protein atoms exist with this chain ID 49 | # JK Later, put in a special "non-interface" case for L/H antibody chains 50 | if cmd.count_atoms("chain%s"%(letter))>0: 51 | interfacename = "interface"+letter 52 | cmd.select("not_this_chain", "not hetatm and not symbol w and not %s"%(chainname) ) 53 | cmd.select(interfacename, "byres %s and (not_this_chain around 4.0)"%(chainname) ) 54 | cmd.select("heavy_%s"%(interfacename), "%s and not apolar_protons"%(interfacename)) 55 | cmd.select("interface", "interface or %s"%(interfacename) ) 56 | cmd.select("heavy_interface", "heavy_interface or heavy_%s"%(interfacename) ) 57 | cmd.delete("not_this_chain") 58 | 59 | cmd.color(backbone_colorlist[curr_bb_color], chainname) 60 | #changing.... 61 | colorCPK(interfacename,backbone_colorlist[curr_bb_color]) 62 | curr_bb_color = curr_bb_color+1 63 | if(curr_bb_color == len(backbone_colorlist)): 64 | curr_bb_color = 0 65 | 66 | #colorCPK(interfacename,carbon_colorlist[curr_carbon_color]) 67 | curr_carbon_color = curr_carbon_color+1 68 | if(curr_carbon_color == len(carbon_colorlist)): 69 | curr_carbon_color = 0 70 | cmd.color("white", "%s and polar_protons"%(interfacename)) 71 | 72 | else: 73 | cmd.delete(chainname) 74 | 75 | cmd.delete("apolar_protons") 76 | cmd.delete("polar_protons") 77 | 78 | # Show the interface in sticks, colored cpk 79 | #cmd.hide( "cartoon", "interface" ) 80 | cmd.show( "sticks", "heavy_interface" ) 81 | cmd.zoom("interface") 82 | 83 | cmd.create("design", "chain B") 84 | cmd.create("target", "chain A") 85 | cmd.show( "surface", "target" ) 86 | cmd.show( "surface", "design" ) 87 | cmd.set( "transparency", 0 ) 88 | 89 | #if loaded together with wt 90 | cmd.load( wt, "wt" ) 91 | cmd.create( "wt_A", "wt and chain A" ) 92 | cmd.create( "wt_B", "wt and chain B" ) 93 | cmd.select("none") 94 | cmd.create( "des_A", "not wt and chain A" ) 95 | cmd.show( "surface", "des_A" ) 96 | cmd.create( "des_B", "not wt and chain B") 97 | cmd.show( "surface", "des_B" ) 98 | cmd.align( "wt_A", "des_A" ) 99 | cmd.align( "wt_B", "des_B" ) 100 | # cmd.show( "lines", "wt_A" ) 101 | # cmd.show( "lines", "wt_B" ) 102 | 103 | cmd.show( "cartoon", "(not interface) or byres(neighbor(interface)) or byres(neighbor(byres(neighbor(interface))))" ) 104 | 105 | # Show interface waters as small purple spheres 106 | cmd.select( "interface_water", "(symbol w or resn HOH) and (interface around 8.0)") 107 | if cmd.count_atoms("interface_water")>0: 108 | # Put the waters in a separate object, so that we can scale their radii 109 | newwatername = name+"waters" 110 | cmd.create(newwatername, "interface_water") 111 | cmd.remove("interface_water") 112 | cmd.color("purple", newwatername) 113 | cmd.show( "spheres", newwatername ) 114 | cmd.set( "sphere_scale", 0.1, newwatername ) 115 | 116 | else: 117 | cmd.delete("interface_water") 118 | 119 | # Show interface ligands as pink sticks 120 | cmd.select( "interface_hetero", "(not symbol w and not resn HOH) and (hetatm and not symbol w and not resn WSS) and (interface around 4.5)") 121 | if cmd.count_atoms("interface_hetero")>0: 122 | cmd.color("pink", "interface_hetero") 123 | cmd.show( "sticks", "interface_hetero" ) 124 | else: 125 | cmd.delete("interface_hetero") 126 | 127 | cmd.select("none") 128 | return name 129 | 130 | cmd.extend("loadSurfaceInterfacePDB",loadSurfaceInterfacePDB) 131 | 132 | def surfaceInterfacePDB(): 133 | cmd.hide("lines") 134 | 135 | backbone_colorlist = [ 'forest','gold', 'violet', 'cyan', \ 136 | 'salmon', 'lime', 'slate', 'magenta', 'orange', 'marine', \ 137 | 'olive', 'forest', 'firebrick', 'chocolate' ] 138 | curr_bb_color = 0 139 | 140 | carbon_colorlist = ['titanium', 'wheat', 'grey', 'pink' ] 141 | curr_carbon_color = 0 142 | 143 | # Derive selections for the interface, color by chain 144 | cmd.select("interface", "none") 145 | cmd.select("heavy_interface", "none") 146 | selectPolarProtons("polar_protons") 147 | selectApolarProtons("apolar_protons") 148 | alphabet = list(('abcdefghijklmnopqrstuvwxyz').upper()) 149 | for letter in alphabet: 150 | chainname = "chain"+letter 151 | cmd.select( chainname, "chain %s and not hetatm and not symbol w"%(letter) ) 152 | 153 | # Check whether any protein atoms exist with this chain ID 154 | # JK Later, put in a special "non-interface" case for L/H antibody chains 155 | if cmd.count_atoms("chain%s"%(letter))>0: 156 | interfacename = "interface"+letter 157 | cmd.select("not_this_chain", "not hetatm and not symbol w and not %s"%(chainname) ) 158 | cmd.select(interfacename, "byres %s and (not_this_chain around 4.0)"%(chainname) ) 159 | cmd.select("heavy_%s"%(interfacename), "%s and not apolar_protons"%(interfacename)) 160 | cmd.select("interface", "interface or %s"%(interfacename) ) 161 | cmd.select("heavy_interface", "heavy_interface or heavy_%s"%(interfacename) ) 162 | cmd.delete("not_this_chain") 163 | 164 | cmd.color(backbone_colorlist[curr_bb_color], chainname) 165 | #changing.... 166 | colorCPK(interfacename,backbone_colorlist[curr_bb_color]) 167 | curr_bb_color = curr_bb_color+1 168 | if(curr_bb_color == len(backbone_colorlist)): 169 | curr_bb_color = 0 170 | 171 | #colorCPK(interfacename,carbon_colorlist[curr_carbon_color]) 172 | curr_carbon_color = curr_carbon_color+1 173 | if(curr_carbon_color == len(carbon_colorlist)): 174 | curr_carbon_color = 0 175 | cmd.color("white", "%s and polar_protons"%(interfacename)) 176 | 177 | else: 178 | cmd.delete(chainname) 179 | 180 | cmd.delete("apolar_protons") 181 | cmd.delete("polar_protons") 182 | 183 | # Show the interface in sticks, colored cpk 184 | #cmd.hide( "cartoon", "interface" ) 185 | cmd.show( "sticks", "heavy_interface" ) 186 | 187 | cmd.create("design", "chain B") 188 | cmd.create("target", "chain A") 189 | cmd.show( "surface", "target" ) 190 | cmd.show( "surface", "design" ) 191 | 192 | cmd.set( "transparency", 0 ) 193 | 194 | cmd.show( "cartoon", "(not interface) or byres(neighbor(interface)) or byres(neighbor(byres(neighbor(interface))))" ) 195 | 196 | # Show interface waters as small purple spheres 197 | cmd.select( "interface_water", "(symbol w or resn HOH) and (interface around 8.0)") 198 | if cmd.count_atoms("interface_water")>0: 199 | # Put the waters in a separate object, so that we can scale their radii 200 | newwatername = name+"waters" 201 | cmd.create(newwatername, "interface_water") 202 | cmd.remove("interface_water") 203 | cmd.color("purple", newwatername) 204 | cmd.show( "spheres", newwatername ) 205 | cmd.set( "sphere_scale", 0.1, newwatername ) 206 | 207 | else: 208 | cmd.delete("interface_water") 209 | 210 | # Show interface ligands as pink sticks 211 | cmd.select( "interface_hetero", "(not symbol w and not resn HOH) and (hetatm and not symbol w and not resn WSS) and (interface around 4.5)") 212 | if cmd.count_atoms("interface_hetero")>0: 213 | cmd.color("pink", "interface_hetero") 214 | cmd.show( "sticks", "interface_hetero" ) 215 | else: 216 | cmd.delete("interface_hetero") 217 | 218 | # Show polar contacts 219 | cmd.distance("hbonds","interfaceA","interfaceB",3.2,mode=2) 220 | cmd.hide("labels") 221 | 222 | # Show vacuum electrostatics 223 | cmd.util.protein_vacuum_esp("design", mode=2, quiet=0) 224 | cmd.util.protein_vacuum_esp("target", mode=2, quiet=0) 225 | 226 | cmd.disable("design_e_chg") 227 | cmd.disable("design_e_map") 228 | cmd.disable("design_e_pot") 229 | 230 | cmd.disable("target_e_chg") 231 | cmd.disable("target_e_map") 232 | cmd.disable("target_e_pot") 233 | 234 | cmd.disable("design") 235 | cmd.disable("target") 236 | 237 | cmd.zoom("interface") 238 | cmd.remove("sele") 239 | cmd.select("none") 240 | 241 | 242 | cmd.extend("surfaceInterfacePDB",surfaceInterfacePDB) 243 | 244 | 245 | def loadInterfacePDB(file,name=None,native=None,wt=None): 246 | 247 | print " Loading interface PDB %s"%(file) 248 | 249 | if name is None: 250 | name = name = os.path.basename(file) 251 | if name.endswith('.pdb'): 252 | name = name[:-4] 253 | 254 | # Call Will's packing PDB loading function 255 | # Note: proteins will be cartoons, cavities will be spheres 256 | # Rosetta radii will be enabled 257 | name = loadPackingPDB(file,name,native) 258 | 259 | cavselname = name+"cavities" 260 | protselname = name+"protein" 261 | cmd.hide("lines",protselname) 262 | 263 | backbone_colorlist = ['plutonium','wheat','green', 'yellow', 'violet', 'cyan', \ 264 | 'salmon', 'lime', 'slate', 'magenta', 'orange', 'marine', \ 265 | 'olive', 'forest', 'firebrick', 'chocolate' ] 266 | curr_bb_color = 0 267 | 268 | carbon_colorlist = ['teal', 'wheat', 'grey', 'pink' ] 269 | curr_carbon_color = 0 270 | 271 | # Derive selections for the interface, color by chain 272 | cmd.select("interface", "none") 273 | cmd.select("heavy_interface", "none") 274 | selectPolarProtons("polar_protons") 275 | selectApolarProtons("apolar_protons") 276 | alphabet = list(('abcdefghijklmnopqrstuvwxyz').upper()) 277 | for letter in alphabet: 278 | chainname = "chain"+letter 279 | cmd.select( chainname, "chain %s and not hetatm and not symbol w"%(letter) ) 280 | 281 | # Check whether any protein atoms exist with this chain ID 282 | # JK Later, put in a special "non-interface" case for L/H antibody chains 283 | if cmd.count_atoms("chain%s"%(letter))>0: 284 | interfacename = "interface"+letter 285 | cmd.select("not_this_chain", "not hetatm and not symbol w and not %s"%(chainname) ) 286 | cmd.select(interfacename, "byres %s and (not_this_chain around 4.0)"%(chainname) ) 287 | cmd.select("heavy_%s"%(interfacename), "%s and not apolar_protons"%(interfacename)) 288 | cmd.select("interface", "interface or %s"%(interfacename) ) 289 | cmd.select("heavy_interface", "heavy_interface or heavy_%s"%(interfacename) ) 290 | cmd.delete("not_this_chain") 291 | 292 | cmd.color(backbone_colorlist[curr_bb_color], chainname) 293 | colorCPK(interfacename,backbone_colorlist[curr_bb_color]) 294 | curr_bb_color = curr_bb_color+1 295 | if(curr_bb_color == len(backbone_colorlist)): 296 | curr_bb_color = 0 297 | 298 | #colorCPK(interfacename,carbon_colorlist[curr_carbon_color]) 299 | curr_carbon_color = curr_carbon_color+1 300 | if(curr_carbon_color == len(carbon_colorlist)): 301 | curr_carbon_color = 0 302 | cmd.color("white", "%s and polar_protons"%(interfacename)) 303 | 304 | else: 305 | cmd.delete(chainname) 306 | 307 | cmd.delete("apolar_protons") 308 | cmd.delete("polar_protons") 309 | 310 | # Show the interface in sticks, colored cpk 311 | #cmd.hide( "cartoon", "interface" ) 312 | cmd.show( "sticks", "heavy_interface" ) 313 | cmd.zoom("interface") 314 | 315 | cmd.show( "cartoon", "(not interface) or byres(neighbor(interface)) or byres(neighbor(byres(neighbor(interface))))" ) 316 | 317 | # Show interface waters as small purple spheres 318 | cmd.select( "interface_water", "(symbol w or resn HOH) and (interface around 8.0)") 319 | if cmd.count_atoms("interface_water")>0: 320 | # Put the waters in a separate object, so that we can scale their radii 321 | newwatername = name+"waters" 322 | cmd.create(newwatername, "interface_water") 323 | cmd.remove("interface_water") 324 | cmd.color("purple", newwatername) 325 | cmd.show( "spheres", newwatername ) 326 | cmd.set( "sphere_scale", 0.1, newwatername ) 327 | 328 | else: 329 | cmd.delete("interface_water") 330 | 331 | # Show interface ligands as pink sticks 332 | cmd.select( "interface_hetero", "(not symbol w and not resn HOH) and (hetatm and not symbol w and not resn WSS) and (interface around 4.5)") 333 | if cmd.count_atoms("interface_hetero")>0: 334 | cmd.color("pink", "interface_hetero") 335 | cmd.show( "sticks", "interface_hetero" ) 336 | else: 337 | cmd.delete("interface_hetero") 338 | 339 | cmd.select("none") 340 | return name 341 | 342 | cmd.extend("loadInterfacePDB",loadInterfacePDB) 343 | 344 | def interfacePDB(): 345 | 346 | backbone_colorlist = ['plutonium','wheat','green', 'yellow', 'violet', 'cyan', \ 347 | 'salmon', 'lime', 'slate', 'magenta', 'orange', 'marine', \ 348 | 'olive', 'forest', 'firebrick', 'chocolate' ] 349 | curr_bb_color = 0 350 | 351 | carbon_colorlist = ['teal', 'wheat', 'grey', 'pink' ] 352 | curr_carbon_color = 0 353 | 354 | # Derive selections for the interface, color by chain 355 | cmd.select("interface", "none") 356 | cmd.select("heavy_interface", "none") 357 | selectPolarProtons("polar_protons") 358 | selectApolarProtons("apolar_protons") 359 | alphabet = list(('abcdefghijklmnopqrstuvwxyz').upper()) 360 | for letter in alphabet: 361 | chainname = "chain"+letter 362 | cmd.select( chainname, "chain %s and not hetatm and not symbol w"%(letter) ) 363 | 364 | # Check whether any protein atoms exist with this chain ID 365 | # JK Later, put in a special "non-interface" case for L/H antibody chains 366 | if cmd.count_atoms("chain%s"%(letter))>0: 367 | interfacename = "interface"+letter 368 | cmd.select("not_this_chain", "not hetatm and not symbol w and not %s"%(chainname) ) 369 | cmd.select(interfacename, "byres %s and (not_this_chain around 4.0)"%(chainname) ) 370 | cmd.select("heavy_%s"%(interfacename), "%s and not apolar_protons"%(interfacename)) 371 | cmd.select("interface", "interface or %s"%(interfacename) ) 372 | cmd.select("heavy_interface", "heavy_interface or heavy_%s"%(interfacename) ) 373 | cmd.delete("not_this_chain") 374 | 375 | cmd.color(backbone_colorlist[curr_bb_color], chainname) 376 | colorCPK(interfacename,backbone_colorlist[curr_bb_color]) 377 | curr_bb_color = curr_bb_color+1 378 | if(curr_bb_color == len(backbone_colorlist)): 379 | curr_bb_color = 0 380 | 381 | #colorCPK(interfacename,carbon_colorlist[curr_carbon_color]) 382 | curr_carbon_color = curr_carbon_color+1 383 | if(curr_carbon_color == len(carbon_colorlist)): 384 | curr_carbon_color = 0 385 | cmd.color("white", "%s and polar_protons"%(interfacename)) 386 | 387 | else: 388 | cmd.delete(chainname) 389 | 390 | cmd.delete("apolar_protons") 391 | cmd.delete("polar_protons") 392 | 393 | # Show the interface in sticks, colored cpk 394 | #cmd.hide( "cartoon", "interface" ) 395 | cmd.show( "sticks", "heavy_interface and not hydro" ) 396 | cmd.zoom("interface") 397 | 398 | cmd.show( "cartoon", "(not interface) or byres(neighbor(interface)) or byres(neighbor(byres(neighbor(interface))))" ) 399 | 400 | # Show interface waters as small purple spheres 401 | cmd.select( "interface_water", "(symbol w or resn HOH) and (interface around 8.0)") 402 | if cmd.count_atoms("interface_water")>0: 403 | # Put the waters in a separate object, so that we can scale their radii 404 | newwatername = name+"waters" 405 | cmd.create(newwatername, "interface_water") 406 | cmd.remove("interface_water") 407 | cmd.color("purple", newwatername) 408 | cmd.show( "spheres", newwatername ) 409 | cmd.set( "sphere_scale", 0.1, newwatername ) 410 | 411 | else: 412 | cmd.delete("interface_water") 413 | 414 | # Show interface ligands as pink sticks 415 | cmd.select( "interface_hetero", "(not symbol w and not resn HOH) and (hetatm and not symbol w and not resn WSS) and (interface around 4.5)") 416 | if cmd.count_atoms("interface_hetero")>0: 417 | cmd.color("pink", "interface_hetero") 418 | cmd.show( "sticks", "interface_hetero" ) 419 | else: 420 | cmd.delete("interface_hetero") 421 | 422 | # Show polar contacts 423 | #cmd.distance("hbonds","interfaceA","interfaceB",3.2,mode=1) 424 | cmd.distance("hbonds","interfaceA","interfaceB",3.5,mode=2) 425 | #cmd.distance("hbonds","interfaceA","interfaceB",3.2,mode=3) 426 | 427 | 428 | cmd.hide("labels") 429 | cmd.hide("lines") 430 | cmd.select("none") 431 | 432 | cmd.extend("interfacePDB",interfacePDB) 433 | 434 | def stix(): 435 | 436 | backbone_colorlist = ['plutonium','wheat','green', 'yellow', 'violet', 'cyan', \ 437 | 'salmon', 'lime', 'slate', 'magenta', 'orange', 'marine', \ 438 | 'olive', 'forest', 'firebrick', 'chocolate' ] 439 | curr_bb_color = 0 440 | 441 | carbon_colorlist = ['teal', 'wheat', 'grey', 'pink' ] 442 | curr_carbon_color = 0 443 | 444 | # Derive selections for the interface, color by chain 445 | cmd.select("interface", "none") 446 | cmd.select("heavy_interface", "none") 447 | selectPolarProtons("polar_protons") 448 | selectApolarProtons("apolar_protons") 449 | alphabet = list(('abcdefghijklmnopqrstuvwxyz').upper()) 450 | for letter in alphabet: 451 | chainname = "chain"+letter 452 | cmd.select( chainname, "chain %s and not hetatm and not symbol w"%(letter) ) 453 | 454 | # Check whether any protein atoms exist with this chain ID 455 | # JK Later, put in a special "non-interface" case for L/H antibody chains 456 | if cmd.count_atoms("chain%s"%(letter))>0: 457 | interfacename = "interface"+letter 458 | cmd.select("not_this_chain", "not hetatm and not symbol w and not %s"%(chainname) ) 459 | cmd.select(interfacename, "byres %s and (not_this_chain around 4.0)"%(chainname) ) 460 | cmd.select("heavy_%s"%(interfacename), "%s and not apolar_protons"%(interfacename)) 461 | cmd.select("interface", "interface or %s"%(interfacename) ) 462 | cmd.select("heavy_interface", "heavy_interface or heavy_%s"%(interfacename) ) 463 | cmd.delete("not_this_chain") 464 | 465 | cmd.color(backbone_colorlist[curr_bb_color], chainname) 466 | colorCPK(chainname,backbone_colorlist[curr_bb_color]) 467 | curr_bb_color = curr_bb_color+1 468 | if(curr_bb_color == len(backbone_colorlist)): 469 | curr_bb_color = 0 470 | 471 | #colorCPK(interfacename,carbon_colorlist[curr_carbon_color]) 472 | curr_carbon_color = curr_carbon_color+1 473 | if(curr_carbon_color == len(carbon_colorlist)): 474 | curr_carbon_color = 0 475 | cmd.color("white", "%s and polar_protons"%(interfacename)) 476 | 477 | else: 478 | cmd.delete(chainname) 479 | 480 | cmd.delete("apolar_protons") 481 | cmd.delete("polar_protons") 482 | 483 | # Show the interface in sticks, colored cpk 484 | #cmd.hide( "cartoon", "interface" ) 485 | cmd.show( "sticks", "not hydro" ) 486 | cmd.zoom("interface") 487 | 488 | cmd.show( "cartoon", "(not interface) or byres(neighbor(interface)) or byres(neighbor(byres(neighbor(interface))))" ) 489 | 490 | # Show interface waters as small purple spheres 491 | cmd.select( "interface_water", "(symbol w or resn HOH) and (interface around 8.0)") 492 | if cmd.count_atoms("interface_water")>0: 493 | # Put the waters in a separate object, so that we can scale their radii 494 | newwatername = name+"waters" 495 | cmd.create(newwatername, "interface_water") 496 | cmd.remove("interface_water") 497 | cmd.color("purple", newwatername) 498 | cmd.show( "spheres", newwatername ) 499 | cmd.set( "sphere_scale", 0.1, newwatername ) 500 | 501 | else: 502 | cmd.delete("interface_water") 503 | 504 | # Show interface ligands as pink sticks 505 | cmd.select( "interface_hetero", "(not symbol w and not resn HOH) and (hetatm and not symbol w and not resn WSS) and (interface around 4.5)") 506 | if cmd.count_atoms("interface_hetero")>0: 507 | cmd.color("pink", "interface_hetero") 508 | cmd.show( "sticks", "interface_hetero" ) 509 | else: 510 | cmd.delete("interface_hetero") 511 | 512 | # Show polar contacts 513 | #cmd.distance("hbonds","interfaceA","interfaceB",3.2,mode=1) 514 | cmd.distance("hbonds","interfaceA","interfaceB",4.5,mode=2) 515 | #cmd.distance("hbonds","interfaceA","interfaceB",3.2,mode=3) 516 | 517 | 518 | cmd.hide("labels") 519 | cmd.hide("lines") 520 | cmd.select("none") 521 | 522 | cmd.extend("stix",stix) 523 | 524 | 525 | -------------------------------------------------------------------------------- /scripts/InterfaceUtils.py: -------------------------------------------------------------------------------- 1 | 2 | import pymol 3 | from pymol import cmd 4 | from pymol import stored 5 | 6 | import sys,os 7 | 8 | from MoleculeUtils import selectPolarProtons 9 | from MoleculeUtils import selectApolarProtons 10 | from MoleculeUtils import colorCPK 11 | from PackingMeasureUtils import loadPackingPDB 12 | 13 | def loadSurfaceInterfacePDB( file,name=None,native=None,wt=None): 14 | 15 | print " Loading interface PDB %s"%(file) 16 | 17 | if name is None: 18 | name = name = os.path.basename(file) 19 | if name.endswith('.pdb'): 20 | name = name[:-4] 21 | 22 | # Call Will's packing PDB loading function 23 | # Note: proteins will be cartoons, cavities will be spheres 24 | # Rosetta radii will be enabled 25 | name = loadPackingPDB(file,name,native) 26 | 27 | cavselname = name+"cavities" 28 | protselname = name+"protein" 29 | cmd.hide("lines",protselname) 30 | 31 | backbone_colorlist = [ 'forest','gold', 'violet', 'cyan', \ 32 | 'salmon', 'lime', 'slate', 'magenta', 'orange', 'marine', \ 33 | 'olive', 'forest', 'firebrick', 'chocolate' ] 34 | curr_bb_color = 0 35 | 36 | carbon_colorlist = ['titanium', 'wheat', 'grey', 'pink' ] 37 | curr_carbon_color = 0 38 | 39 | # Derive selections for the interface, color by chain 40 | cmd.select("interface", "none") 41 | cmd.select("heavy_interface", "none") 42 | selectPolarProtons("polar_protons") 43 | selectApolarProtons("apolar_protons") 44 | alphabet = list(('abcdefghijklmnopqrstuvwxyz').upper()) 45 | for letter in alphabet: 46 | chainname = "chain"+letter 47 | cmd.select( chainname, "chain %s and not hetatm and not symbol w"%(letter) ) 48 | 49 | # Check whether any protein atoms exist with this chain ID 50 | # JK Later, put in a special "non-interface" case for L/H antibody chains 51 | if cmd.count_atoms("chain%s"%(letter))>0: 52 | interfacename = "interface"+letter 53 | cmd.select("not_this_chain", "not hetatm and not symbol w and not %s"%(chainname) ) 54 | cmd.select(interfacename, "byres %s and (not_this_chain around 4.0)"%(chainname) ) 55 | cmd.select("heavy_%s"%(interfacename), "%s and not apolar_protons"%(interfacename)) 56 | cmd.select("interface", "interface or %s"%(interfacename) ) 57 | cmd.select("heavy_interface", "heavy_interface or heavy_%s"%(interfacename) ) 58 | cmd.delete("not_this_chain") 59 | 60 | cmd.color(backbone_colorlist[curr_bb_color], chainname) 61 | #changing.... 62 | colorCPK(interfacename,backbone_colorlist[curr_bb_color]) 63 | curr_bb_color = curr_bb_color+1 64 | if(curr_bb_color == len(backbone_colorlist)): 65 | curr_bb_color = 0 66 | 67 | #colorCPK(interfacename,carbon_colorlist[curr_carbon_color]) 68 | curr_carbon_color = curr_carbon_color+1 69 | if(curr_carbon_color == len(carbon_colorlist)): 70 | curr_carbon_color = 0 71 | cmd.color("white", "%s and polar_protons"%(interfacename)) 72 | 73 | else: 74 | cmd.delete(chainname) 75 | 76 | cmd.delete("apolar_protons") 77 | cmd.delete("polar_protons") 78 | 79 | # Show the interface in sticks, colored cpk 80 | #cmd.hide( "cartoon", "interface" ) 81 | cmd.show( "sticks", "heavy_interface" ) 82 | #cmd.zoom("interface") 83 | 84 | cmd.create("design", "chain B") 85 | cmd.create("target", "chain A") 86 | cmd.show( "surface", "target" ) 87 | cmd.show( "surface", "design" ) 88 | cmd.set( "transparency", 0 ) 89 | 90 | #if loaded together with wt 91 | cmd.load( wt, "wt" ) 92 | cmd.create( "wt_A", "wt and chain A" ) 93 | cmd.create( "wt_B", "wt and chain B" ) 94 | cmd.select("none") 95 | cmd.create( "des_A", "not wt and chain A" ) 96 | cmd.show( "surface", "des_A" ) 97 | cmd.create( "des_B", "not wt and chain B") 98 | cmd.show( "surface", "des_B" ) 99 | cmd.align( "wt_A", "des_A" ) 100 | cmd.align( "wt_B", "des_B" ) 101 | # cmd.show( "lines", "wt_A" ) 102 | # cmd.show( "lines", "wt_B" ) 103 | 104 | #cmd.show( "cartoon", "(interface) or byres(neighbor(interface)) or byres(neighbor(byres(neighbor(interface))))" ) 105 | cmd.show( "cartoon") 106 | 107 | # Show interface waters as small purple spheres 108 | cmd.select( "interface_water", "(symbol w or resn HOH) and (interface around 8.0)") 109 | if cmd.count_atoms("interface_water")>0: 110 | # Put the waters in a separate object, so that we can scale their radii 111 | newwatername = name+"waters" 112 | cmd.create(newwatername, "interface_water") 113 | cmd.remove("interface_water") 114 | cmd.color("purple", newwatername) 115 | cmd.show( "spheres", newwatername ) 116 | cmd.set( "sphere_scale", 0.1, newwatername ) 117 | 118 | else: 119 | cmd.delete("interface_water") 120 | 121 | # Show interface ligands as pink sticks 122 | cmd.select( "interface_hetero", "(not symbol w and not resn HOH) and (hetatm and not symbol w and not resn WSS) and (interface around 4.5)") 123 | if cmd.count_atoms("interface_hetero")>0: 124 | cmd.color("pink", "interface_hetero") 125 | cmd.show( "sticks", "interface_hetero" ) 126 | else: 127 | cmd.delete("interface_hetero") 128 | 129 | cmd.select("none") 130 | return name 131 | 132 | cmd.extend("loadSurfaceInterfacePDB",loadSurfaceInterfacePDB) 133 | 134 | def surfaceInterfacePDB(): 135 | cmd.hide("lines") 136 | 137 | backbone_colorlist = [ 'forest','gold', 'violet', 'cyan', \ 138 | 'salmon', 'lime', 'slate', 'magenta', 'orange', 'marine', \ 139 | 'olive', 'forest', 'firebrick', 'chocolate' ] 140 | curr_bb_color = 0 141 | 142 | carbon_colorlist = ['titanium', 'wheat', 'grey', 'pink' ] 143 | curr_carbon_color = 0 144 | 145 | # Derive selections for the interface, color by chain 146 | cmd.select("interface", "none") 147 | cmd.select("heavy_interface", "none") 148 | selectPolarProtons("polar_protons") 149 | selectApolarProtons("apolar_protons") 150 | alphabet = list(('abcdefghijklmnopqrstuvwxyz').upper()) 151 | for letter in alphabet: 152 | chainname = "chain"+letter 153 | cmd.select( chainname, "chain %s and not hetatm and not symbol w"%(letter) ) 154 | 155 | # Check whether any protein atoms exist with this chain ID 156 | # JK Later, put in a special "non-interface" case for L/H antibody chains 157 | if cmd.count_atoms("chain%s"%(letter))>0: 158 | interfacename = "interface"+letter 159 | cmd.select("not_this_chain", "not hetatm and not symbol w and not %s"%(chainname) ) 160 | cmd.select(interfacename, "byres %s and (not_this_chain around 4.0)"%(chainname) ) 161 | cmd.select("heavy_%s"%(interfacename), "%s and not apolar_protons"%(interfacename)) 162 | cmd.select("interface", "interface or %s"%(interfacename) ) 163 | cmd.select("heavy_interface", "heavy_interface or heavy_%s"%(interfacename) ) 164 | cmd.delete("not_this_chain") 165 | 166 | cmd.color(backbone_colorlist[curr_bb_color], chainname) 167 | #changing.... 168 | colorCPK(interfacename,backbone_colorlist[curr_bb_color]) 169 | curr_bb_color = curr_bb_color+1 170 | if(curr_bb_color == len(backbone_colorlist)): 171 | curr_bb_color = 0 172 | 173 | #colorCPK(interfacename,carbon_colorlist[curr_carbon_color]) 174 | curr_carbon_color = curr_carbon_color+1 175 | if(curr_carbon_color == len(carbon_colorlist)): 176 | curr_carbon_color = 0 177 | cmd.color("white", "%s and polar_protons"%(interfacename)) 178 | 179 | else: 180 | cmd.delete(chainname) 181 | 182 | cmd.delete("apolar_protons") 183 | cmd.delete("polar_protons") 184 | 185 | # Show the interface in sticks, colored cpk 186 | #cmd.hide( "cartoon", "interface" ) 187 | cmd.show( "sticks", "heavy_interface" ) 188 | 189 | cmd.create("design", "chain B") 190 | cmd.create("target", "chain A") 191 | cmd.show( "surface", "target" ) 192 | cmd.show( "surface", "design" ) 193 | 194 | cmd.set( "transparency", 0 ) 195 | 196 | cmd.show( "cartoon", "(not interface) or byres(neighbor(interface)) or byres(neighbor(byres(neighbor(interface))))" ) 197 | 198 | # Show interface waters as small purple spheres 199 | cmd.select( "interface_water", "(symbol w or resn HOH) and (interface around 8.0)") 200 | if cmd.count_atoms("interface_water")>0: 201 | # Put the waters in a separate object, so that we can scale their radii 202 | newwatername = name+"waters" 203 | cmd.create(newwatername, "interface_water") 204 | cmd.remove("interface_water") 205 | cmd.color("purple", newwatername) 206 | cmd.show( "spheres", newwatername ) 207 | cmd.set( "sphere_scale", 0.1, newwatername ) 208 | 209 | else: 210 | cmd.delete("interface_water") 211 | 212 | # Show interface ligands as pink sticks 213 | cmd.select( "interface_hetero", "(not symbol w and not resn HOH) and (hetatm and not symbol w and not resn WSS) and (interface around 4.5)") 214 | if cmd.count_atoms("interface_hetero")>0: 215 | cmd.color("pink", "interface_hetero") 216 | cmd.show( "sticks", "interface_hetero" ) 217 | else: 218 | cmd.delete("interface_hetero") 219 | 220 | # Show polar contacts 221 | cmd.distance("hbonds","interfaceA","interfaceB",3.2,mode=2) 222 | cmd.hide("labels") 223 | 224 | # Show vacuum electrostatics 225 | cmd.util.protein_vacuum_esp("design", mode=2, quiet=0) 226 | cmd.util.protein_vacuum_esp("target", mode=2, quiet=0) 227 | 228 | cmd.disable("design_e_chg") 229 | cmd.disable("design_e_map") 230 | cmd.disable("design_e_pot") 231 | 232 | cmd.disable("target_e_chg") 233 | cmd.disable("target_e_map") 234 | cmd.disable("target_e_pot") 235 | 236 | cmd.disable("design") 237 | cmd.disable("target") 238 | 239 | #cmd.zoom("interface") 240 | cmd.remove("sele") 241 | cmd.select("none") 242 | 243 | 244 | cmd.extend("surfaceInterfacePDB",surfaceInterfacePDB) 245 | 246 | 247 | def loadInterfacePDB(file,name=None,native=None,wt=None): 248 | 249 | print " Loading interface PDB %s"%(file) 250 | 251 | if name is None: 252 | name = name = os.path.basename(file) 253 | if name.endswith('.pdb'): 254 | name = name[:-4] 255 | 256 | # Call Will's packing PDB loading function 257 | # Note: proteins will be cartoons, cavities will be spheres 258 | # Rosetta radii will be enabled 259 | name = loadPackingPDB(file,name,native) 260 | 261 | cavselname = name+"cavities" 262 | protselname = name+"protein" 263 | cmd.hide("lines",protselname) 264 | 265 | backbone_colorlist = ['plutonium','wheat','green', 'yellow', 'violet', 'cyan', \ 266 | 'salmon', 'lime', 'slate', 'magenta', 'orange', 'marine', \ 267 | 'olive', 'forest', 'firebrick', 'chocolate' ] 268 | curr_bb_color = 0 269 | 270 | carbon_colorlist = ['teal', 'wheat', 'grey', 'pink' ] 271 | curr_carbon_color = 0 272 | 273 | # Derive selections for the interface, color by chain 274 | cmd.select("interface", "none") 275 | cmd.select("heavy_interface", "none") 276 | selectPolarProtons("polar_protons") 277 | selectApolarProtons("apolar_protons") 278 | alphabet = list(('abcdefghijklmnopqrstuvwxyz').upper()) 279 | for letter in alphabet: 280 | chainname = "chain"+letter 281 | cmd.select( chainname, "chain %s and not hetatm and not symbol w"%(letter) ) 282 | 283 | # Check whether any protein atoms exist with this chain ID 284 | # JK Later, put in a special "non-interface" case for L/H antibody chains 285 | if cmd.count_atoms("chain%s"%(letter))>0: 286 | interfacename = "interface"+letter 287 | cmd.select("not_this_chain", "not hetatm and not symbol w and not %s"%(chainname) ) 288 | cmd.select(interfacename, "byres %s and (not_this_chain around 4.0)"%(chainname) ) 289 | cmd.select("heavy_%s"%(interfacename), "%s and not apolar_protons"%(interfacename)) 290 | cmd.select("interface", "interface or %s"%(interfacename) ) 291 | cmd.select("heavy_interface", "heavy_interface or heavy_%s"%(interfacename) ) 292 | cmd.delete("not_this_chain") 293 | 294 | cmd.color(backbone_colorlist[curr_bb_color], chainname) 295 | colorCPK(interfacename,backbone_colorlist[curr_bb_color]) 296 | curr_bb_color = curr_bb_color+1 297 | if(curr_bb_color == len(backbone_colorlist)): 298 | curr_bb_color = 0 299 | 300 | #colorCPK(interfacename,carbon_colorlist[curr_carbon_color]) 301 | curr_carbon_color = curr_carbon_color+1 302 | if(curr_carbon_color == len(carbon_colorlist)): 303 | curr_carbon_color = 0 304 | cmd.color("white", "%s and polar_protons"%(interfacename)) 305 | 306 | else: 307 | cmd.delete(chainname) 308 | 309 | cmd.delete("apolar_protons") 310 | cmd.delete("polar_protons") 311 | 312 | # Show the interface in sticks, colored cpk 313 | #cmd.hide( "cartoon", "interface" ) 314 | cmd.show( "sticks", "heavy_interface" ) 315 | #cmd.zoom("interface") 316 | 317 | cmd.show( "cartoon", "(not interface) or byres(neighbor(interface)) or byres(neighbor(byres(neighbor(interface))))" ) 318 | 319 | # Show interface waters as small purple spheres 320 | cmd.select( "interface_water", "(symbol w or resn HOH) and (interface around 8.0)") 321 | if cmd.count_atoms("interface_water")>0: 322 | # Put the waters in a separate object, so that we can scale their radii 323 | newwatername = name+"waters" 324 | cmd.create(newwatername, "interface_water") 325 | cmd.remove("interface_water") 326 | cmd.color("purple", newwatername) 327 | cmd.show( "spheres", newwatername ) 328 | cmd.set( "sphere_scale", 0.1, newwatername ) 329 | 330 | else: 331 | cmd.delete("interface_water") 332 | 333 | # Show interface ligands as pink sticks 334 | cmd.select( "interface_hetero", "(not symbol w and not resn HOH) and (hetatm and not symbol w and not resn WSS) and (interface around 4.5)") 335 | if cmd.count_atoms("interface_hetero")>0: 336 | cmd.color("pink", "interface_hetero") 337 | cmd.show( "sticks", "interface_hetero" ) 338 | else: 339 | cmd.delete("interface_hetero") 340 | 341 | cmd.select("none") 342 | return name 343 | 344 | cmd.extend("loadInterfacePDB",loadInterfacePDB) 345 | 346 | def interfacePDB(): 347 | 348 | backbone_colorlist = ['plutonium','wheat','green', 'yellow', 'violet', 'cyan', \ 349 | 'salmon', 'lime', 'slate', 'magenta', 'orange', 'marine', \ 350 | 'olive', 'forest', 'firebrick', 'chocolate' ] 351 | curr_bb_color = 0 352 | 353 | carbon_colorlist = ['teal', 'wheat', 'grey', 'pink' ] 354 | curr_carbon_color = 0 355 | 356 | # Derive selections for the interface, color by chain 357 | cmd.select("interface", "none") 358 | cmd.select("heavy_interface", "none") 359 | selectPolarProtons("polar_protons") 360 | selectApolarProtons("apolar_protons") 361 | alphabet = list(('abcdefghijklmnopqrstuvwxyz').upper()) 362 | for letter in alphabet: 363 | chainname = "chain"+letter 364 | cmd.select( chainname, "chain %s and not hetatm and not symbol w"%(letter) ) 365 | 366 | # Check whether any protein atoms exist with this chain ID 367 | # JK Later, put in a special "non-interface" case for L/H antibody chains 368 | if cmd.count_atoms("chain%s"%(letter))>0: 369 | interfacename = "interface"+letter 370 | cmd.select("not_this_chain", "not hetatm and not symbol w and not %s"%(chainname) ) 371 | cmd.select(interfacename, "byres %s and (not_this_chain around 4.0)"%(chainname) ) 372 | cmd.select("heavy_%s"%(interfacename), "%s and not apolar_protons"%(interfacename)) 373 | cmd.select("interface", "interface or %s"%(interfacename) ) 374 | cmd.select("heavy_interface", "heavy_interface or heavy_%s"%(interfacename) ) 375 | cmd.delete("not_this_chain") 376 | 377 | cmd.color(backbone_colorlist[curr_bb_color], chainname) 378 | colorCPK(interfacename,backbone_colorlist[curr_bb_color]) 379 | curr_bb_color = curr_bb_color+1 380 | if(curr_bb_color == len(backbone_colorlist)): 381 | curr_bb_color = 0 382 | 383 | #colorCPK(interfacename,carbon_colorlist[curr_carbon_color]) 384 | curr_carbon_color = curr_carbon_color+1 385 | if(curr_carbon_color == len(carbon_colorlist)): 386 | curr_carbon_color = 0 387 | cmd.color("white", "%s and polar_protons"%(interfacename)) 388 | 389 | else: 390 | cmd.delete(chainname) 391 | 392 | cmd.delete("apolar_protons") 393 | cmd.delete("polar_protons") 394 | 395 | # Show the interface in sticks, colored cpk 396 | #cmd.hide( "cartoon", "interface" ) 397 | cmd.show( "sticks", "heavy_interface and not hydro" ) 398 | #cmd.zoom("interface") 399 | 400 | cmd.show( "cartoon", "(not interface) or byres(neighbor(interface)) or byres(neighbor(byres(neighbor(interface))))" ) 401 | 402 | # Show interface waters as small purple spheres 403 | cmd.select( "interface_water", "(symbol w or resn HOH) and (interface around 8.0)") 404 | if cmd.count_atoms("interface_water")>0: 405 | # Put the waters in a separate object, so that we can scale their radii 406 | newwatername = "interfacewater" 407 | cmd.create(newwatername, "interface_water") 408 | cmd.remove("interface_water") 409 | cmd.color("purple", newwatername) 410 | cmd.show( "spheres", newwatername ) 411 | cmd.set( "sphere_scale", 0.1, newwatername ) 412 | 413 | else: 414 | cmd.delete("interface_water") 415 | 416 | # Show interface ligands as pink sticks 417 | cmd.select( "interface_hetero", "(not symbol w and not resn HOH) and (hetatm and not symbol w and not resn WSS) and (interface around 4.5)") 418 | if cmd.count_atoms("interface_hetero")>0: 419 | cmd.color("pink", "interface_hetero") 420 | cmd.show( "sticks", "interface_hetero" ) 421 | else: 422 | cmd.delete("interface_hetero") 423 | 424 | # Show polar contacts 425 | #cmd.distance("hbonds","interfaceA","interfaceB",3.2,mode=1) 426 | cmd.distance("hbonds","interfaceA","interfaceB",3.5,mode=2) 427 | #cmd.distance("hbonds","interfaceA","interfaceB",3.2,mode=3) 428 | 429 | cmd.hide("labels") 430 | cmd.hide("lines") 431 | cmd.select("none") 432 | 433 | cmd.extend("interfacePDB",interfacePDB) 434 | 435 | 436 | 437 | def interfaceResidues(cmpx, cA='c. A', cB='c. B', cutoff=1.0, selName="interface"): 438 | """ 439 | interfaceResidues -- finds 'interface' residues between two chains in a complex. 440 | 441 | PARAMS 442 | cmpx 443 | The complex containing cA and cB 444 | 445 | cA 446 | The first chain in which we search for residues at an interface 447 | with cB 448 | 449 | cB 450 | The second chain in which we search for residues at an interface 451 | with cA 452 | 453 | cutoff 454 | The difference in area OVER which residues are considered 455 | interface residues. Residues whose dASA from the complex to 456 | a single chain is greater than this cutoff are kept. Zero 457 | keeps all residues. 458 | 459 | selName 460 | The name of the selection to return. 461 | 462 | RETURNS 463 | * A selection of interface residues is created and named 464 | depending on what you passed into selName 465 | * An array of values is returned where each value is: 466 | ( modelName, residueNumber, dASA ) 467 | 468 | NOTES 469 | If you have two chains that are not from the same PDB that you want 470 | to complex together, use the create command like: 471 | create myComplex, pdb1WithChainA or pdb2withChainX 472 | then pass myComplex to this script like: 473 | interfaceResidues myComlpex, c. A, c. X 474 | 475 | This script calculates the area of the complex as a whole. Then, 476 | it separates the two chains that you pass in through the arguments 477 | cA and cB, alone. Once it has this, it calculates the difference 478 | and any residues ABOVE the cutoff are called interface residues. 479 | 480 | AUTHOR: 481 | Jason Vertrees, 2009. 482 | """ 483 | # Save user's settings, before setting dot_solvent 484 | oldDS = cmd.get("dot_solvent") 485 | cmd.set("dot_solvent", 1) 486 | 487 | # set some string names for temporary objects/selections 488 | tempC, selName1 = "tempComplex", selName+"1" 489 | chA, chB = "chA", "chB" 490 | 491 | # operate on a new object & turn off the original 492 | cmd.create(tempC, cmpx) 493 | cmd.disable(cmpx) 494 | 495 | # remove cruft and inrrelevant chains 496 | cmd.remove(tempC + " and not (polymer and (%s or %s))" % (cA, cB)) 497 | 498 | # get the area of the complete complex 499 | cmd.get_area(tempC, load_b=1) 500 | # copy the areas from the loaded b to the q, field. 501 | cmd.alter(tempC, 'q=b') 502 | 503 | # extract the two chains and calc. the new area 504 | # note: the q fields are copied to the new objects 505 | # chA and chB 506 | cmd.extract(chA, tempC + " and (" + cA + ")") 507 | cmd.extract(chB, tempC + " and (" + cB + ")") 508 | cmd.get_area(chA, load_b=1) 509 | cmd.get_area(chB, load_b=1) 510 | 511 | # update the chain-only objects w/the difference 512 | cmd.alter( "%s or %s" % (chA,chB), "b=b-q" ) 513 | 514 | # The calculations are done. Now, all we need to 515 | # do is to determine which residues are over the cutoff 516 | # and save them. 517 | stored.r, rVal, seen = [], [], [] 518 | cmd.iterate('%s or %s' % (chA, chB), 'stored.r.append((model,resi,b))') 519 | 520 | cmd.enable(cmpx) 521 | cmd.select(selName1, 'none') 522 | for (model,resi,diff) in stored.r: 523 | key=resi+"-"+model 524 | if abs(diff)>=float(cutoff): 525 | if key in seen: continue 526 | else: seen.append(key) 527 | rVal.append( (model,resi,diff) ) 528 | # expand the selection here; I chose to iterate over stored.r instead of 529 | # creating one large selection b/c if there are too many residues PyMOL 530 | # might crash on a very large selection. This is pretty much guaranteed 531 | # not to kill PyMOL; but, it might take a little longer to run. 532 | cmd.select( selName1, selName1 + " or (%s and i. %s)" % (model,resi)) 533 | 534 | # this is how you transfer a selection to another object. 535 | cmd.select(selName, cmpx + " in " + selName1) 536 | # clean up after ourselves 537 | cmd.delete(selName1) 538 | cmd.delete(chA) 539 | cmd.delete(chB) 540 | cmd.delete(tempC) 541 | # show the selection 542 | cmd.enable(selName) 543 | 544 | # reset users settings 545 | cmd.set("dot_solvent", oldDS) 546 | 547 | return rVal 548 | 549 | cmd.extend("interfaceResidues", interfaceResidues) 550 | 551 | def stix(): 552 | 553 | backbone_colorlist = ['plutonium','wheat','green', 'yellow', 'violet', 'cyan', \ 554 | 'salmon', 'lime', 'slate', 'magenta', 'orange', 'marine', \ 555 | 'olive', 'forest', 'firebrick', 'chocolate' ] 556 | curr_bb_color = 0 557 | 558 | carbon_colorlist = ['teal', 'wheat', 'grey', 'pink' ] 559 | curr_carbon_color = 0 560 | 561 | # Derive selections for the interface, color by chain 562 | cmd.select("interface", "none") 563 | cmd.select("heavy_interface", "none") 564 | selectPolarProtons("polar_protons") 565 | selectApolarProtons("apolar_protons") 566 | alphabet = list(('abcdefghijklmnopqrstuvwxyz').upper()) 567 | for letter in alphabet: 568 | chainname = "chain"+letter 569 | cmd.select( chainname, "chain %s and not hetatm and not symbol w"%(letter) ) 570 | 571 | # Check whether any protein atoms exist with this chain ID 572 | # JK Later, put in a special "non-interface" case for L/H antibody chains 573 | if cmd.count_atoms("chain%s"%(letter))>0: 574 | interfacename = "interface"+letter 575 | cmd.select("not_this_chain", "not hetatm and not symbol w and not %s"%(chainname) ) 576 | cmd.select(interfacename, "byres %s and (not_this_chain around 6.0)"%(chainname) ) 577 | cmd.select("heavy_%s"%(interfacename), "%s and not apolar_protons"%(interfacename)) 578 | cmd.select("interface", "interface or %s"%(interfacename) ) 579 | cmd.select("heavy_interface", "heavy_interface or heavy_%s"%(interfacename) ) 580 | cmd.delete("not_this_chain") 581 | 582 | cmd.color(backbone_colorlist[curr_bb_color], chainname) 583 | colorCPK(chainname,backbone_colorlist[curr_bb_color]) 584 | curr_bb_color = curr_bb_color+1 585 | if(curr_bb_color == len(backbone_colorlist)): 586 | curr_bb_color = 0 587 | 588 | #colorCPK(interfacename,carbon_colorlist[curr_carbon_color]) 589 | curr_carbon_color = curr_carbon_color+1 590 | if(curr_carbon_color == len(carbon_colorlist)): 591 | curr_carbon_color = 0 592 | cmd.color("white", "%s and polar_protons"%(interfacename)) 593 | 594 | else: 595 | cmd.delete(chainname) 596 | 597 | cmd.delete("apolar_protons") 598 | cmd.delete("polar_protons") 599 | 600 | # Show the interface in sticks, colored cpk 601 | #cmd.hide( "cartoon", "interface" ) 602 | cmd.show( "sticks", "not hydro" ) 603 | #cmd.zoom("interface") 604 | 605 | cmd.show( "cartoon", "(not interface) or byres(neighbor(interface)) or byres(neighbor(byres(neighbor(interface))))" ) 606 | cmd.show( "cartoon" ) 607 | 608 | 609 | # Show interface waters as small purple spheres 610 | cmd.select( "interface_water", "(symbol w or resn HOH) and (interface around 8.0)") 611 | if cmd.count_atoms("interface_water")>0: 612 | # Put the waters in a separate object, so that we can scale their radii 613 | newwatername = name+"waters" 614 | cmd.create(newwatername, "interface_water") 615 | cmd.remove("interface_water") 616 | cmd.color("purple", newwatername) 617 | cmd.show( "spheres", newwatername ) 618 | cmd.set( "sphere_scale", 0.1, newwatername ) 619 | 620 | else: 621 | cmd.delete("interface_water") 622 | 623 | # Show interface ligands as pink sticks 624 | cmd.select( "interface_hetero", "(not symbol w and not resn HOH) and (hetatm and not symbol w and not resn WSS) and (interface around 4.5)") 625 | if cmd.count_atoms("interface_hetero")>0: 626 | cmd.color("pink", "interface_hetero") 627 | cmd.show( "sticks", "interface_hetero" ) 628 | else: 629 | cmd.delete("interface_hetero") 630 | 631 | # Show polar contacts 632 | #cmd.distance("hbonds","interfaceA","interfaceB",3.2,mode=1) 633 | cmd.distance("hbonds","interfaceA","interfaceB",4.5,mode=2) 634 | #cmd.distance("hbonds","interfaceA","interfaceB",3.2,mode=3) 635 | 636 | 637 | cmd.hide("labels") 638 | cmd.hide("lines") 639 | cmd.select("none") 640 | 641 | 642 | cmd.extend("stix",stix) 643 | 644 | 645 | -------------------------------------------------------------------------------- /scripts/InterfaceUtils_ori.py: -------------------------------------------------------------------------------- 1 | 2 | import pymol 3 | from pymol import cmd 4 | 5 | import sys,os 6 | 7 | from MoleculeUtils import selectPolarProtons 8 | from MoleculeUtils import selectApolarProtons 9 | from MoleculeUtils import colorCPK 10 | from PackingMeasureUtils import loadPackingPDB 11 | 12 | def loadInterfacePDB(file,name=None,native=None): 13 | 14 | print " Loading interface PDB %s"%(file) 15 | 16 | if name is None: 17 | name = name = os.path.basename(file) 18 | if name.endswith('.pdb'): 19 | name = name[:-4] 20 | 21 | # Call Will's packing PDB loading function 22 | # Note: proteins will be cartoons, cavities will be spheres 23 | # Rosetta radii will be enabled 24 | name = loadPackingPDB(file,name,native) 25 | 26 | cavselname = name+"cavities" 27 | protselname = name+"protein" 28 | cmd.hide("lines",protselname) 29 | 30 | backbone_colorlist = ['green', 'yellow', 'violet', 'cyan', \ 31 | 'salmon', 'lime', 'slate', 'magenta', 'orange', 'marine', \ 32 | 'olive', 'forest', 'firebrick', 'chocolate' ] 33 | curr_bb_color = 0 34 | 35 | carbon_colorlist = ['teal', 'wheat', 'grey', 'pink' ] 36 | curr_carbon_color = 0 37 | 38 | # Derive selections for the interface, color by chain 39 | cmd.select("interface", "none") 40 | cmd.select("heavy_interface", "none") 41 | selectPolarProtons("polar_protons") 42 | selectApolarProtons("apolar_protons") 43 | alphabet = list(('abcdefghijklmnopqrstuvwxyz').upper()) 44 | for letter in alphabet: 45 | chainname = "chain"+letter 46 | cmd.select( chainname, "chain %s and not hetatm and not symbol w"%(letter) ) 47 | 48 | # Check whether any protein atoms exist with this chain ID 49 | # JK Later, put in a special "non-interface" case for L/H antibody chains 50 | if cmd.count_atoms("chain%s"%(letter))>0: 51 | interfacename = "interface"+letter 52 | cmd.select("not_this_chain", "not hetatm and not symbol w and not %s"%(chainname) ) 53 | cmd.select(interfacename, "byres %s and (not_this_chain around 4.0)"%(chainname) ) 54 | cmd.select("heavy_%s"%(interfacename), "%s and not apolar_protons"%(interfacename)) 55 | cmd.select("interface", "interface or %s"%(interfacename) ) 56 | cmd.select("heavy_interface", "heavy_interface or heavy_%s"%(interfacename) ) 57 | cmd.delete("not_this_chain") 58 | 59 | cmd.color(backbone_colorlist[curr_bb_color], chainname) 60 | curr_bb_color = curr_bb_color+1 61 | if(curr_bb_color == len(backbone_colorlist)): 62 | curr_bb_color = 0 63 | 64 | colorCPK(interfacename,carbon_colorlist[curr_carbon_color]) 65 | curr_carbon_color = curr_carbon_color+1 66 | if(curr_carbon_color == len(carbon_colorlist)): 67 | curr_carbon_color = 0 68 | cmd.color("white", "%s and polar_protons"%(interfacename)) 69 | 70 | else: 71 | cmd.delete(chainname) 72 | 73 | cmd.delete("apolar_protons") 74 | cmd.delete("polar_protons") 75 | 76 | # Show the interface in sticks, colored cpk 77 | #cmd.hide( "cartoon", "interface" ) 78 | cmd.show( "sticks", "heavy_interface" ) 79 | cmd.zoom("interface") 80 | 81 | cmd.show( "cartoon", "(not interface) or byres(neighbor(interface)) or byres(neighbor(byres(neighbor(interface))))" ) 82 | 83 | # Show interface waters as small purple spheres 84 | cmd.select( "interface_water", "(symbol w or resn HOH) and (interface around 8.0)") 85 | if cmd.count_atoms("interface_water")>0: 86 | # Put the waters in a separate object, so that we can scale their radii 87 | newwatername = name+"waters" 88 | cmd.create(newwatername, "interface_water") 89 | cmd.remove("interface_water") 90 | cmd.color("purple", newwatername) 91 | cmd.show( "spheres", newwatername ) 92 | cmd.set( "sphere_scale", 0.5, newwatername ) 93 | 94 | else: 95 | cmd.delete("interface_water") 96 | 97 | # Show interface ligands as pink sticks 98 | cmd.select( "interface_hetero", "(not symbol w and not resn HOH) and (hetatm and not symbol w and not resn WSS) and (interface around 4.5)") 99 | if cmd.count_atoms("interface_hetero")>0: 100 | cmd.color("pink", "interface_hetero") 101 | cmd.show( "sticks", "interface_hetero" ) 102 | else: 103 | cmd.delete("interface_hetero") 104 | 105 | cmd.select("none") 106 | return name 107 | 108 | cmd.extend("loadInterfacePDB",loadInterfacePDB) 109 | 110 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /scripts/InterfaceUtils_try.py: -------------------------------------------------------------------------------- 1 | 2 | import pymol 3 | from pymol import cmd 4 | 5 | import sys,os 6 | 7 | from MoleculeUtils import selectPolarProtons 8 | from MoleculeUtils import selectApolarProtons 9 | from MoleculeUtils import colorCPK 10 | from PackingMeasureUtils import loadPackingPDB 11 | 12 | def loadInterfacePDB(file,name=None,native=None,wt=None): 13 | 14 | print " Loading interface PDB %s"%(file) 15 | 16 | if name is None: 17 | name = name = os.path.basename(file) 18 | if name.endswith('.pdb'): 19 | name = name[:-4] 20 | 21 | # Call Will's packing PDB loading function 22 | # Note: proteins will be cartoons, cavities will be spheres 23 | # Rosetta radii will be enabled 24 | name = loadPackingPDB(file,name,native) 25 | 26 | cavselname = name+"cavities" 27 | protselname = name+"protein" 28 | cmd.hide("lines",protselname) 29 | 30 | backbone_colorlist = ['green', 'yellow', 'violet', 'cyan', \ 31 | 'salmon', 'lime', 'slate', 'magenta', 'orange', 'marine', \ 32 | 'olive', 'forest', 'firebrick', 'chocolate' ] 33 | curr_bb_color = 0 34 | 35 | carbon_colorlist = ['teal', 'wheat', 'grey', 'pink' ] 36 | curr_carbon_color = 0 37 | 38 | # Derive selections for the interface, color by chain 39 | cmd.select("interface", "none") 40 | cmd.select("heavy_interface", "none") 41 | selectPolarProtons("polar_protons") 42 | selectApolarProtons("apolar_protons") 43 | alphabet = list(('abcdefghijklmnopqrstuvwxyz').upper()) 44 | for letter in alphabet: 45 | chainname = "chain"+letter 46 | cmd.select( chainname, "chain %s and not hetatm and not symbol w"%(letter) ) 47 | 48 | # Check whether any protein atoms exist with this chain ID 49 | # JK Later, put in a special "non-interface" case for L/H antibody chains 50 | if cmd.count_atoms("chain%s"%(letter))>0: 51 | interfacename = "interface"+letter 52 | cmd.select("not_this_chain", "not hetatm and not symbol w and not %s"%(chainname) ) 53 | cmd.select(interfacename, "byres %s and (not_this_chain around 4.0)"%(chainname) ) 54 | cmd.select("heavy_%s"%(interfacename), "%s and not apolar_protons"%(interfacename)) 55 | cmd.select("interface", "interface or %s"%(interfacename) ) 56 | cmd.select("heavy_interface", "heavy_interface or heavy_%s"%(interfacename) ) 57 | cmd.delete("not_this_chain") 58 | 59 | cmd.color(backbone_colorlist[curr_bb_color], chainname) 60 | curr_bb_color = curr_bb_color+1 61 | if(curr_bb_color == len(backbone_colorlist)): 62 | curr_bb_color = 0 63 | 64 | colorCPK(interfacename,carbon_colorlist[curr_carbon_color]) 65 | curr_carbon_color = curr_carbon_color+1 66 | if(curr_carbon_color == len(carbon_colorlist)): 67 | curr_carbon_color = 0 68 | cmd.color("white", "%s and polar_protons"%(interfacename)) 69 | 70 | else: 71 | cmd.delete(chainname) 72 | 73 | cmd.delete("apolar_protons") 74 | cmd.delete("polar_protons") 75 | 76 | # Show the interface in sticks, colored cpk 77 | #cmd.hide( "cartoon", "interface" ) 78 | cmd.show( "sticks", "heavy_interface" ) 79 | cmd.zoom("interface") 80 | 81 | cmd.show( "cartoon", "(not interface) or byres(neighbor(interface)) or byres(neighbor(byres(neighbor(interface))))" ) 82 | 83 | # Show interface waters as small purple spheres 84 | cmd.select( "interface_water", "(symbol w or resn HOH) and (interface around 8.0)") 85 | if cmd.count_atoms("interface_water")>0: 86 | # Put the waters in a separate object, so that we can scale their radii 87 | newwatername = name+"waters" 88 | cmd.create(newwatername, "interface_water") 89 | cmd.remove("interface_water") 90 | cmd.color("purple", newwatername) 91 | cmd.show( "spheres", newwatername ) 92 | #cmd.set( "sphere_scale", 0.5, newwatername ) 93 | cmd.set( "sphere_scale", 0.1, newwatername ) 94 | else: 95 | cmd.delete("interface_water") 96 | 97 | # Show interface ligands as pink sticks 98 | cmd.select( "interface_hetero", "(not symbol w and not resn HOH) and (hetatm and not symbol w and not resn WSS) and (interface around 4.5)") 99 | if cmd.count_atoms("interface_hetero")>0: 100 | cmd.color("pink", "interface_hetero") 101 | cmd.show( "sticks", "interface_hetero" ) 102 | else: 103 | cmd.delete("interface_hetero") 104 | 105 | cmd.select("none") 106 | cmd.load( wt, "wt" ) 107 | cmd.create( "wt_A", "wt and chain A" ) 108 | cmd.create( "wt_B", "wt and chain B" ) 109 | cmd.select("none") 110 | cmd.create( "des_A", "not wt and chain A" ) 111 | cmd.show( "surface", "des_A" ) 112 | cmd.create( "des_B", "not wt and chain B") 113 | cmd.show( "surface", "des_B" ) 114 | cmd.align( "wt_A", "des_A" ) 115 | cmd.align( "wt_B", "des_B" ) 116 | # cmd.show( "lines", "wt_A" ) 117 | # cmd.show( "lines", "wt_B" ) 118 | cmd.set( "transparency", 1 ) 119 | cmd.zoom("interface") 120 | return name 121 | 122 | cmd.extend("loadInterfacePDB",loadInterfacePDB) 123 | 124 | 125 | 126 | 127 | -------------------------------------------------------------------------------- /scripts/LigandView.py: -------------------------------------------------------------------------------- 1 | 2 | import pymol 3 | from pymol import * 4 | 5 | from rosetta_vdw import useRosettaRadii 6 | from PackingMeasureUtils import useTempRadii 7 | from GenUtils import zload 8 | 9 | def viewLig(prot = 'all' , lig = 'hetatm', niram = 'cbas'): 10 | 11 | cmd.show('spheres', prot) 12 | useRosettaRadii() 13 | cmd.hide('everything', lig) 14 | cmd.show('sticks', lig) 15 | cmd.hide('sticks', 'resn cav') 16 | cmd.show('spheres', 'resn cav') 17 | cmd.hide('everything', 'elem h and (neighbor elem c)') 18 | useTempRadii('resn cav') 19 | util.cbas() 20 | cmd.color("green", "elem c and hetatm and not resn cav") 21 | cmd.center('hetatm and not resn cav') 22 | 23 | def loadLigPDB(fname,name=None): 24 | 25 | if name is None: 26 | name = name = os.path.basename(fname) 27 | if name.endswith('.gz'): 28 | name = name[:-3] 29 | if name.endswith('.pdb'): 30 | name = name[:-4] 31 | if name.endswith('.'): 32 | name = name[:-1] 33 | 34 | zload(fname,name) 35 | viewLig() 36 | 37 | cmd.extend('viewLig',viewLig) 38 | cmd.extend('loadLigPDB',loadLigPDB) 39 | -------------------------------------------------------------------------------- /scripts/MoleculeUtils.py: -------------------------------------------------------------------------------- 1 | 2 | import pymol 3 | from pymol import cmd 4 | 5 | # Select protons which can participate in Hbonds (note: Rosetta names expected) 6 | def selectPolarProtons( name = None, hideother = False ): 7 | if name is None: name = "polar_protons" 8 | # protein 9 | cmd.select( name, 'not hetatm and name h') # backbone hn 10 | # iterative reselection to avoid large single selection (PyMOL can choke) 11 | cmd.select( name, '%s or (resn arg and name 1hh1+2hh1+1hh2+2hh2+he)' % name ) 12 | cmd.select( name, '%s or (resn asn and name 1hd2+2hd2)' % name ) 13 | cmd.select( name, '%s or (resn gln and name 1he2+2he2)' % name ) 14 | cmd.select( name, '%s or (resn his and name he2+hd1)' % name ) 15 | cmd.select( name, '%s or (resn lys and name 1hz+2hz+3hz)' % name ) 16 | cmd.select( name, '%s or (resn ser and name hg)' % name ) 17 | cmd.select( name, '%s or (resn thr and name hg1)' % name ) 18 | cmd.select( name, '%s or (resn trp and name he1)' % name ) 19 | cmd.select( name, '%s or (resn tyr and name hh)' % name ) 20 | cmd.select( name, '%s or (resn a and name 1h6+2h6)' % name ) # DNA 21 | cmd.select( name, '%s or (resn c and name 1h4+2h4)' % name ) # DNA 22 | cmd.select( name, '%s or (resn g and name h1+1h2+2h2)' % name ) # DNA 23 | cmd.select( name, '%s or (resn t and name h3)' % name ) # DNA 24 | cmd.disable( name ) # hide selection visuals 25 | if hideother: cmd.hide( 'everything', 'e. h and not %s' % name ) 26 | return name 27 | 28 | # Select protons which cannot participate in Hbonds 29 | def selectApolarProtons( name = None, hideother = False ): 30 | if name is None: name = "apolar_protons" 31 | polh = selectPolarProtons() 32 | cmd.select( name, 'symbol h and not %s' % polh ) 33 | # cmd.delete( polh ) # but why not keep it? 34 | if hideother: cmd.hide( 'everything', 'e. h and not %s' % name ) 35 | return name 36 | 37 | # Color by atom, with support for alternate C/H colors 38 | def colorCPK(selection="all",carbon='grey',hydrogen='white'): 39 | cmd.color(carbon,"(%s) and symbol C"%(selection)) 40 | cmd.color(hydrogen,"(%s) and symbol H"%(selection)) 41 | cmd.color('blue',"(%s) and symbol N"%(selection)) 42 | cmd.color('red',"(%s) and symbol O"%(selection)) 43 | cmd.color('yellow',"(%s) and symbol S"%(selection)) 44 | 45 | cmd.extend("selectPolarProtons",selectPolarProtons) 46 | cmd.extend("selectApolarProtons",selectApolarProtons) 47 | cmd.extend("colorCPK",colorCPK) 48 | 49 | -------------------------------------------------------------------------------- /scripts/Mutations.py: -------------------------------------------------------------------------------- 1 | ''' 2 | created by Christoph Malisi. 3 | 4 | Creates an alignment of two proteins and superimposes them. 5 | Aligned residues that are different in the two (i.e. mutations) are highlighted and 6 | colored according to their difference in the BLOSUM90 matrix. 7 | Is meant to be used for similar proteins, e.g. close homologs or point mutants, 8 | to visualize their differences. 9 | 10 | ''' 11 | 12 | import pymol 13 | from pymol import cmd 14 | 15 | aa_3l = {'ALA':0, 'ARG':1, 'ASN':2, 'ASP':3, 'CYS':4, 'GLN':5, 'GLU':6, 'GLY':7, 'HIS':8, 'ILE':9, 'LEU':10, 'LYS':11, 16 | 'MET':12, 'PHE':13, 'PRO':14, 'SER':15, 'THR':16, 'TRP':17, 'TYR':18, 'VAL':19, 'B':20, 'Z':21, 'X':22, '*':23} 17 | 18 | # A R N D C Q E G H I L K M F P S T W Y V B Z X * 19 | blosum90 = [[ 5, -2, -2, -3, -1, -1, -1, 0, -2, -2, -2, -1, -2, -3, -1, 1, 0, -4, -3, -1, -2, -1, -1, -6], 20 | [-2, 6, -1, -3, -5, 1, -1, -3, 0, -4, -3, 2, -2, -4, -3, -1, -2, -4, -3, -3, -2, 0, -2, -6], 21 | [-2, -1, 7, 1, -4, 0, -1, -1, 0, -4, -4, 0, -3, -4, -3, 0, 0, -5, -3, -4, 4, -1, -2, -6], 22 | [-3, -3, 1, 7, -5, -1, 1, -2, -2, -5, -5, -1, -4, -5, -3, -1, -2, -6, -4, -5, 4, 0, -2, -6], 23 | [-1, -5, -4, -5, 9, -4, -6, -4, -5, -2, -2, -4, -2, -3, -4, -2, -2, -4, -4, -2, -4, -5, -3, -6], 24 | [-1, 1, 0, -1, -4, 7, 2, -3, 1, -4, -3, 1, 0, -4, -2, -1, -1, -3, -3, -3, -1, 4, -1, -6], 25 | [-1, -1, -1, 1, -6, 2, 6, -3, -1, -4, -4, 0, -3, -5, -2, -1, -1, -5, -4, -3, 0, 4, -2, -6], 26 | [ 0, -3, -1, -2, -4, -3, -3, 6, -3, -5, -5, -2, -4, -5, -3, -1, -3, -4, -5, -5, -2, -3, -2, -6], 27 | [-2, 0, 0, -2, -5, 1, -1, -3, 8, -4, -4, -1, -3, -2, -3, -2, -2, -3, 1, -4, -1, 0, -2, -6], 28 | [-2, -4, -4, -5, -2, -4, -4, -5, -4, 5, 1, -4, 1, -1, -4, -3, -1, -4, -2, 3, -5, -4, -2, -6], 29 | [-2, -3, -4, -5, -2, -3, -4, -5, -4, 1, 5, -3, 2, 0, -4, -3, -2, -3, -2, 0, -5, -4, -2, -6], 30 | [-1, 2, 0, -1, -4, 1, 0, -2, -1, -4, -3, 6, -2, -4, -2, -1, -1, -5, -3, -3, -1, 1, -1, -6], 31 | [-2, -2, -3, -4, -2, 0, -3, -4, -3, 1, 2, -2, 7, -1, -3, -2, -1, -2, -2, 0, -4, -2, -1, -6], 32 | [-3, -4, -4, -5, -3, -4, -5, -5, -2, -1, 0, -4, -1, 7, -4, -3, -3, 0, 3, -2, -4, -4, -2, -6], 33 | [-1, -3, -3, -3, -4, -2, -2, -3, -3, -4, -4, -2, -3, -4, 8, -2, -2, -5, -4, -3, -3, -2, -2, -6], 34 | [ 1, -1, 0, -1, -2, -1, -1, -1, -2, -3, -3, -1, -2, -3, -2, 5, 1, -4, -3, -2, 0, -1, -1, -6], 35 | [ 0, -2, 0, -2, -2, -1, -1, -3, -2, -1, -2, -1, -1, -3, -2, 1, 6, -4, -2, -1, -1, -1, -1, -6], 36 | [-4, -4, -5, -6, -4, -3, -5, -4, -3, -4, -3, -5, -2, 0, -5, -4, -4, 11, 2, -3, -6, -4, -3, -6], 37 | [-3, -3, -3, -4, -4, -3, -4, -5, 1, -2, -2, -3, -2, 3, -4, -3, -2, 2, 8, -3, -4, -3, -2, -6], 38 | [-1, -3, -4, -5, -2, -3, -3, -5, -4, 3, 0, -3, 0, -2, -3, -2, -1, -3, -3, 5, -4, -3, -2, -6], 39 | [-2, -2, 4, 4, -4, -1, 0, -2, -1, -5, -5, -1, -4, -4, -3, 0, -1, -6, -4, -4, 4, 0, -2, -6], 40 | [-1, 0, -1, 0, -5, 4, 4, -3, 0, -4, -4, 1, -2, -4, -2, -1, -1, -4, -3, -3, 0, 4, -1, -6], 41 | [-1, -2, -2, -2, -3, -1, -2, -2, -2, -2, -2, -1, -1, -2, -2, -1, -1, -3, -2, -2, -2, -1, -2, -6], 42 | [-6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, 1]] 43 | 44 | def getBlosum90ColorName(aa1, aa2): 45 | '''returns a rgb color name of a color that represents the similarity of the two residues according to 46 | the BLOSUM90 matrix. the color is on a spectrum from blue to red, where blue is very similar, and 47 | red very disimilar.''' 48 | # return red for residues that are not part of the 20 amino acids 49 | if aa1 not in aa_3l or aa2 not in aa_3l: 50 | return 'red' 51 | 52 | # if the two are the same, return blue 53 | if aa1 == aa2: 54 | return 'blue' 55 | i1 = aa_3l[aa1] 56 | i2 = aa_3l[aa2] 57 | b = blosum90[i1][i2] 58 | 59 | # 3 is the highest score for non-identical substitutions, so substract 4 to get into range [-10, -1] 60 | b = abs(b - 4) 61 | 62 | # map to (0, 1]: 63 | b = 1. - (b / 10.0) 64 | 65 | # red = [1.0, 0.0, 0.0], blue = [0.0, 0.0, 1.0] 66 | colvec = [(1., 0., 0.), (0.,0.,1.)] 67 | #bcolor = (1.-b, 0., b) 68 | bcolor = (1.-b, 0., b) 69 | col_name = '0x%02x%02x%02x'%(bcolor[0]*255, bcolor[1]*255, bcolor[2]*255) 70 | return col_name 71 | 72 | def color_by_mutation(obj1, obj2, waters=0, labels=0): 73 | ''' 74 | DESCRIPTION 75 | 76 | Creates an alignment of two proteins and superimposes them. 77 | Aligned residues that are different in the two (i.e. mutations) are highlighted and 78 | colored according to their difference in the BLOSUM90 matrix. 79 | Is meant to be used for similar proteins, e.g. close homologs or point mutants, 80 | to visualize their differences. 81 | 82 | USAGE 83 | 84 | color_by_mutation selection1, selection2 [,waters [,labels ]] 85 | 86 | ARGUMENTS 87 | 88 | obj1: object or selection 89 | 90 | obj2: object or selection 91 | 92 | waters: bool (0 or 1). If 1, waters are included in the view, colored 93 | differently for the both input structures. 94 | default = 0 95 | 96 | labels: bool (0 or 1). If 1, the possibly mutated sidechains are 97 | labeled by their chain, name and id 98 | default = 0 99 | 100 | EXAMPLE 101 | 102 | color_by_mutation protein1, protein2 103 | 104 | SEE ALSO 105 | 106 | super 107 | ''' 108 | from pymol import stored, CmdException 109 | 110 | if cmd.count_atoms(obj1) == 0: 111 | print '%s is empty'%obj1 112 | return 113 | if cmd.count_atoms(obj2) == 0: 114 | print '%s is empty'%obj2 115 | return 116 | waters = int(waters) 117 | labels = int(labels) 118 | 119 | # align the two proteins 120 | aln = '__aln' 121 | 122 | # first, an alignment with 0 cycles (no atoms are rejected, which maximized the number of aligned residues) 123 | # for some mutations in the same protein this works fine). This is essentially done to get a 124 | # sequence alignment 125 | cmd.super(obj2, obj1, object=aln, cycles=0) 126 | 127 | # superimpose the the object using the default parameters to get a slightly better superimposition, 128 | # i.e. get the best structural alignment 129 | cmd.super(obj2, obj1) 130 | 131 | stored.resn1, stored.resn2 = [], [] 132 | stored.resi1, stored.resi2 = [], [] 133 | stored.chain1, stored.chain2 = [], [] 134 | 135 | # store residue ids, residue names and chains of aligned residues 136 | cmd.iterate(obj1 + ' and name CA and ' + aln, 'stored.resn1.append(resn)') 137 | cmd.iterate(obj2 + ' and name CA and ' + aln, 'stored.resn2.append(resn)') 138 | 139 | cmd.iterate(obj1 + ' and name CA and ' + aln, 'stored.resi1.append(resi)') 140 | cmd.iterate(obj2 + ' and name CA and ' + aln, 'stored.resi2.append(resi)') 141 | 142 | cmd.iterate(obj1 + ' and name CA and ' + aln, 'stored.chain1.append(chain)') 143 | cmd.iterate(obj2 + ' and name CA and ' + aln, 'stored.chain2.append(chain)') 144 | 145 | 146 | mutant_selection = '' 147 | non_mutant_selection = 'none or ' 148 | colors = [] 149 | 150 | # loop over the aligned residues 151 | for n1, n2, i1, i2, c1, c2 in zip(stored.resn1, stored.resn2, 152 | stored.resi1, stored.resi2, 153 | stored.chain1, stored.chain2): 154 | # take care of 'empty' chain names 155 | if c1 == '': 156 | c1 = '""' 157 | if c2 == '': 158 | c2 = '""' 159 | if n1 == n2: 160 | non_mutant_selection += '((%s and resi %s and chain %s) or (%s and resi %s and chain %s)) or '%(obj2, i1, c1, obj1, i2, c2 ) 161 | else: 162 | mutant_selection += '((%s and resi %s and chain %s) or (%s and resi %s and chain %s)) or '%(obj2, i1, c1, obj1, i2, c2 ) 163 | # get the similarity (according to the blosum matrix) of the two residues and 164 | c = getBlosum90ColorName(n1, n2) 165 | colors.append((c, '%s and resi %s and chain %s and elem C'%(obj2, i2, c2))) 166 | 167 | if mutant_selection == '': 168 | print ' Error: No mutations found' 169 | raise CmdException 170 | 171 | # create selections 172 | cmd.select('mutations', mutant_selection[:-4]) 173 | cmd.select('non_mutations', non_mutant_selection[:-4]) 174 | cmd.select('not_aligned', '(%s or %s) and not mutations and not non_mutations'%(obj2, obj1)) 175 | 176 | # create the view and coloring 177 | cmd.hide('everything', '%s or %s'%(obj2, obj1)) 178 | cmd.show('cartoon', '%s or %s'%(obj2, obj1)) 179 | cmd.show('lines', '(%s or %s) and ((non_mutations or not_aligned) and not name c+o+n)'%(obj2, obj1)) 180 | cmd.show('sticks', '(%s or %s) and mutations and not name c+o+n'%(obj2, obj1)) 181 | cmd.color('white', 'elem C and not_aligned') 182 | cmd.color('wheat', 'elem C and non_mutations') 183 | cmd.color('cyan', 'elem C and mutations and %s'%obj1) 184 | for (col, sel) in colors: 185 | cmd.color(col, sel) 186 | 187 | cmd.hide('everything', '(hydro) and (%s or %s)'%(obj2, obj1)) 188 | cmd.center('%s or %s'%(obj2, obj1)) 189 | if labels: 190 | cmd.label('mutations and name CA','"(%s-%s-%s)"%(chain, resi, resn)') 191 | if waters: 192 | cmd.set('sphere_scale', '0.1') 193 | cmd.show('spheres', 'resn HOH and (%s or %s)'%(obj2, obj1)) 194 | cmd.color('red', 'resn HOH and %s'%obj1) 195 | cmd.color('salmon', 'resn HOH and %s'%obj2) 196 | print ''' 197 | Mutations are highlighted in blue and red. 198 | All mutated sidechains of %s are colored blue, the corresponding ones from %s are 199 | colored on a spectrum from blue to red according to how similar the two amino acids are 200 | (as measured by the BLOSUM90 substitution matrix). 201 | Aligned regions without mutations are colored white. 202 | Regions not used for the alignment are gray. 203 | NOTE: There could be mutations in the gray regions that were not detected.'''%(obj2, obj1) 204 | cmd.delete(aln) 205 | cmd.deselect() 206 | 207 | 208 | 209 | cmd.extend("color_by_mutation", color_by_mutation) 210 | 211 | 212 | def muta(): 213 | ''' 214 | DESCRIPTION 215 | 216 | Creates an alignment of two proteins and superimposes them. 217 | Aligned residues that are different in the two (i.e. mutations) are highlighted and 218 | colored according to their difference in the BLOSUM90 matrix. 219 | Is meant to be used for similar proteins, e.g. close homologs or point mutants, 220 | to visualize their differences. 221 | 222 | USAGE 223 | 224 | color_by_mutation selection1, selection2 [,waters [,labels ]] 225 | 226 | ARGUMENTS 227 | 228 | obj1: object or selection 229 | 230 | obj2: object or selection 231 | 232 | waters: bool (0 or 1). If 1, waters are included in the view, colored 233 | differently for the both input structures. 234 | default = 0 235 | 236 | labels: bool (0 or 1). If 1, the possibly mutated sidechains are 237 | labeled by their chain, name and id 238 | default = 0 239 | 240 | EXAMPLE 241 | 242 | color_by_mutation protein1, protein2 243 | 244 | SEE ALSO 245 | 246 | super 247 | ''' 248 | from pymol import stored, CmdException 249 | 250 | obj1 = "native_na" 251 | obj2 = "design_na" 252 | waters = 0 253 | labels = 0 254 | 255 | if cmd.count_atoms(obj1) == 0: 256 | print '%s is empty'%obj1 257 | return 258 | if cmd.count_atoms(obj2) == 0: 259 | print '%s is empty'%obj2 260 | return 261 | waters = int(waters) 262 | labels = int(labels) 263 | 264 | # align the two proteins 265 | aln = '__aln' 266 | 267 | # first, an alignment with 0 cycles (no atoms are rejected, which maximized the number of aligned residues) 268 | # for some mutations in the same protein this works fine). This is essentially done to get a 269 | # sequence alignment 270 | cmd.super(obj2, obj1, object=aln, cycles=0) 271 | 272 | # superimpose the the object using the default parameters to get a slightly better superimposition, 273 | # i.e. get the best structural alignment 274 | cmd.super(obj2, obj1) 275 | 276 | stored.resn1, stored.resn2 = [], [] 277 | stored.resi1, stored.resi2 = [], [] 278 | stored.chain1, stored.chain2 = [], [] 279 | 280 | # store residue ids, residue names and chains of aligned residues 281 | cmd.iterate(obj1 + ' and name CA and ' + aln, 'stored.resn1.append(resn)') 282 | cmd.iterate(obj2 + ' and name CA and ' + aln, 'stored.resn2.append(resn)') 283 | 284 | cmd.iterate(obj1 + ' and name CA and ' + aln, 'stored.resi1.append(resi)') 285 | cmd.iterate(obj2 + ' and name CA and ' + aln, 'stored.resi2.append(resi)') 286 | 287 | cmd.iterate(obj1 + ' and name CA and ' + aln, 'stored.chain1.append(chain)') 288 | cmd.iterate(obj2 + ' and name CA and ' + aln, 'stored.chain2.append(chain)') 289 | 290 | 291 | mutant_selection = '' 292 | non_mutant_selection = 'none or ' 293 | colors = [] 294 | 295 | # loop over the aligned residues 296 | for n1, n2, i1, i2, c1, c2 in zip(stored.resn1, stored.resn2, 297 | stored.resi1, stored.resi2, 298 | stored.chain1, stored.chain2): 299 | # take care of 'empty' chain names 300 | if c1 == '': 301 | c1 = '""' 302 | if c2 == '': 303 | c2 = '""' 304 | if n1 == n2: 305 | non_mutant_selection += '((%s and resi %s and chain %s) or (%s and resi %s and chain %s)) or '%(obj1, i1, c1, obj2, i2, c2 ) 306 | else: 307 | mutant_selection += '((%s and resi %s and chain %s) or (%s and resi %s and chain %s)) or '%(obj1, i1, c1, obj2, i2, c2 ) 308 | # get the similarity (according to the blosum matrix) of the two residues and 309 | c = getBlosum90ColorName(n1, n2) 310 | colors.append((c, '%s and resi %s and chain %s and elem C'%(obj2, i2, c2))) 311 | 312 | if mutant_selection == '': 313 | print ' Error: No mutations found' 314 | raise CmdException 315 | 316 | # create selections 317 | cmd.select('mutations', mutant_selection[:-4]) 318 | cmd.select('non_mutations', non_mutant_selection[:-4]) 319 | cmd.select('not_aligned', '(%s or %s) and not mutations and not non_mutations'%(obj1, obj2)) 320 | 321 | # create the view and coloring 322 | cmd.hide('everything', '%s or %s'%(obj1, obj1)) 323 | cmd.show('cartoon', '%s or %s'%(obj2, obj1)) 324 | cmd.show('lines', '(%s or %s) and ((non_mutations or not_aligned) and not name c+o+n)'%(obj2, obj1)) 325 | cmd.show('sticks', '(%s or %s) and mutations and not name c+o+n'%(obj2, obj1)) 326 | cmd.color('white', 'elem C and non_mutations') 327 | cmd.color('cyan', 'elem C and mutations and %s'%obj1) 328 | cmd.color('gray', 'elem C and not_aligned') 329 | cmd.color('limon', 'chainA') 330 | cmd.util.cnc("all") 331 | for (col, sel) in colors: 332 | cmd.color(col, sel) 333 | 334 | cmd.hide('everything', '(hydro) and (%s or %s)'%(obj2, obj1)) 335 | cmd.center('%s or %s'%(obj2, obj1)) 336 | if labels: 337 | cmd.label('mutations and name CA','"(%s-%s-%s)"%(chain, resi, resn)') 338 | if waters: 339 | cmd.set('sphere_scale', '0.1') 340 | cmd.show('spheres', 'resn HOH and (%s or %s)'%(obj2, obj1)) 341 | cmd.color('red', 'resn HOH and %s'%obj1) 342 | cmd.color('salmon', 'resn HOH and %s'%obj2) 343 | print ''' 344 | Mutations are highlighted in blue and red. 345 | All mutated sidechains of %s are colored blue, the corresponding ones from %s are 346 | colored on a spectrum from blue to red according to how similar the two amino acids are 347 | (as measured by the BLOSUM90 substitution matrix). 348 | Aligned regions without mutations are colored white. 349 | Regions not used for the alignment are gray. 350 | NOTE: There could be mutations in the gray regions that were not detected.'''%(obj2, obj1) 351 | cmd.delete(aln) 352 | cmd.deselect() 353 | cmd.zoom("interface") 354 | 355 | cmd.extend("muta", muta) 356 | 357 | -------------------------------------------------------------------------------- /scripts/Native-network.py: -------------------------------------------------------------------------------- 1 | import pymol 2 | from pymol import cmd 3 | 4 | import sys,os 5 | 6 | 7 | def nat(pdbid,chainid): 8 | 9 | cmd.view('v', 'store'); 10 | 11 | object = cmd.get_names()[0] 12 | 13 | cmd.fetch(pdbid) 14 | cmd.select("design_nat","%s and chain %s"%(object,"B")) 15 | cmd.select("native_nat","%s and chain %s"%(pdbid,chainid)) 16 | 17 | cmd.select("other_nat","%s and not chain %s"%(pdbid,chainid)) 18 | cmd.hide("everything","other") 19 | cmd.hide('(resn HOH)') 20 | 21 | cmd.super("design_nat","native_nat") 22 | 23 | cmd.select("none") 24 | cmd.orient(object) 25 | 26 | cmd.system("rm %s.pdb"%(pdbid)); 27 | 28 | cmd.view('v', 'recall') 29 | 30 | cmd.extend("nat",nat) 31 | 32 | def na(): 33 | 34 | cmd.view('v', 'store'); 35 | 36 | object = cmd.get_names()[0] 37 | 38 | pdbid = object[0:4] 39 | chainid = object[4:5] 40 | 41 | cmd.fetch(pdbid) 42 | cmd.select("design_na","%s and chain %s"%(object,"B")) 43 | cmd.select("native_na","%s and chain %s"%(pdbid,chainid)) 44 | 45 | cmd.select("other_na","%s and not chain %s"%(pdbid,chainid)) 46 | cmd.hide("everything","other") 47 | cmd.hide('(resn HOH)') 48 | 49 | cmd.super("design_na","native_na") 50 | 51 | cmd.select("none") 52 | cmd.orient(object) 53 | 54 | cmd.system("rm %s.pdb"%(pdbid)); 55 | 56 | cmd.view('v', 'recall') 57 | 58 | cmd.extend("na",na) 59 | -------------------------------------------------------------------------------- /scripts/Native.py: -------------------------------------------------------------------------------- 1 | import pymol 2 | from pymol import cmd 3 | 4 | import sys,os 5 | 6 | 7 | def nat(pdbid,chainid): 8 | 9 | cmd.view('v', 'store'); 10 | 11 | object = cmd.get_names()[0] 12 | 13 | cmd.fetch(pdbid) 14 | cmd.select("design_nat","%s and chain %s and not hydro"%(object,"B")) 15 | cmd.select("native_nat","%s and chain %s and not hydro"%(pdbid,chainid)) 16 | 17 | cmd.select("other_nat","%s and not chain %s"%(pdbid,chainid)) 18 | cmd.hide("everything","other") 19 | cmd.hide('(resn HOH)') 20 | 21 | cmd.super("design_nat","native_nat") 22 | 23 | cmd.select("none") 24 | cmd.orient(object) 25 | 26 | cmd.hide("lines","all"); 27 | cmd.show("sticks","native_nat"); 28 | cmd.show("cartoon","native_nat"); 29 | 30 | cmd.system("rm %s.pdb"%(pdbid)); 31 | 32 | cmd.view('v', 'recall') 33 | 34 | cmd.extend("nat",nat) 35 | 36 | def na(): 37 | 38 | cmd.view('v', 'store'); 39 | 40 | 41 | object = cmd.get_names()[0] 42 | 43 | if object[0] == 'd': 44 | pdbid = object[1:5] 45 | chainid = object[5:6] 46 | else: 47 | pdbid = object[0:4] 48 | chainid = object[4:5] 49 | 50 | cmd.fetch(pdbid) 51 | cmd.select("design_na","%s and chain %s and not hydro"%(object,"B")) 52 | cmd.select("native_na","%s and chain %s and not hydro"%(pdbid,chainid)) 53 | 54 | cmd.select("other_na","%s and not chain %s"%(pdbid,chainid)) 55 | cmd.hide("everything","other") 56 | cmd.hide('(resn HOH)') 57 | 58 | cmd.super("native_na","design_na") 59 | 60 | cmd.hide("lines","all"); 61 | cmd.show("sticks","native_na"); 62 | cmd.show("cartoon","native_na"); 63 | 64 | cmd.select("none") 65 | cmd.orient(object) 66 | 67 | pdbid = pdbid.lower() 68 | cmd.system("rm %s.pdb"%(pdbid)); 69 | 70 | cmd.view('v', 'recall') 71 | 72 | cmd.extend("na",na) 73 | 74 | def info(): 75 | 76 | object = cmd.get_names()[0] 77 | 78 | if object[0] == 'd': 79 | pdbid = object[1:5] 80 | chainid = object[5:6] 81 | else: 82 | pdbid = object[0:4] 83 | chainid = object[4:5] 84 | 85 | pdbid = pdbid.lower() 86 | cmd.system("open http://pdb.org/pdb/explore/explore.do?structureId=%s"%(pdbid)) 87 | 88 | cmd.extend("info",info) 89 | -------------------------------------------------------------------------------- /scripts/PDBBrowser.py: -------------------------------------------------------------------------------- 1 | from pymol import cmd 2 | import sys,os,glob,random 3 | 4 | 5 | POINTER = -1 6 | LOADLIST = [] 7 | 8 | 9 | 10 | def loadTag( tag , directory , name=None, native=None, increment=True, extra="" ): 11 | global POINTER,LOADLIST 12 | if name is None: 13 | name = tag 14 | if tag.endswith("_packing.pdb"): 15 | if increment: 16 | LOADLIST.append( (tag,directory,name,native) ) 17 | POINTER = len(LOADLIST)-1 18 | print POINTER 19 | if native is None: 20 | cmd.do('loadPackingPDB '+directory+'/'+tag+","+name ) 21 | else: 22 | cmd.do('loadPackingPDB '+directory+'/'+tag+","+name+','+native) 23 | elif tag.endswith('.pdb'): 24 | cmd.load(directory+'/'+tag) 25 | else: 26 | pattern = directory+'/'+tag+'*.pdb' 27 | print pattern 28 | g = glob.glob( pattern ) 29 | #print g 30 | cmd.load( g[0], name ) 31 | cmd.show('cartoon') 32 | print "DO:",extra #TODO FIXME 33 | cmd.do(extra) 34 | 35 | 36 | 37 | def loadFromGlob(pattern, name=None, native=None, delete=True,extra="", pickrandom=False): 38 | if delete: 39 | cmd.delete('all') 40 | if not ( pattern.endswith(".pdb") or pattern.endswith(".pdb.gz") ): 41 | pattern += "*.pdb" 42 | pattern += "*.pdb.gz" 43 | print pattern 44 | g = glob.glob( pattern ) 45 | if len(g) < 1: 46 | print "CAN'T FIND ANY FILES MATCHING:",pattern 47 | return 48 | if pickrandom: 49 | random.shuffle(g) 50 | #print g 51 | directory = os.path.dirname(g[0]) 52 | tag = os.path.basename(g[0]) 53 | print directory,tag 54 | loadTag( tag , directory, name, native, extra=extra ) 55 | 56 | def loadprev(): 57 | global POINTER, LOADLIST 58 | if POINTER < 1: 59 | print "loadprev CAN'T GO BACK ANY FURTHER" 60 | return 61 | cmd.delete( LOADLIST[POINTER][2] ) # delete name 62 | POINTER -= 1 63 | tag,directory,name,native = LOADLIST[POINTER] 64 | loadTag(tag,directory,name,native,increment=False) 65 | print POINTER 66 | 67 | def browseReset(): 68 | POINTER = -1 69 | LOADLIST = [] 70 | 71 | def loadnext(): 72 | global POINTER, LOADLIST 73 | if POINTER >= len(LOADLIST)-1: 74 | print "loadnext CAN'T GO FORWARD ANY FURTHER" 75 | return 76 | print "delete", LOADLIST[POINTER][2] 77 | cmd.delete( LOADLIST[POINTER][2] ) # delete name 78 | POINTER += 1 79 | tag,directory,name,native = LOADLIST[POINTER] 80 | loadTag(tag,directory,name,native,increment=False) 81 | print POINTER 82 | 83 | cmd.extend("browseReset",browseReset) 84 | cmd.extend('loadTag',loadTag) 85 | cmd.extend('loadFromGlob',loadFromGlob) 86 | cmd.extend('loadprev',loadprev) 87 | cmd.extend('loadnext',loadnext) 88 | 89 | -------------------------------------------------------------------------------- /scripts/PDBinfo.py: -------------------------------------------------------------------------------- 1 | # Derrick 2 | # This script should create pymol objects containing all residues belonging to a PODBinfo label 3 | 4 | 5 | import re, string, gzip 6 | from pymol import cmd, cgo 7 | 8 | def create_PDBinfo_objs( lines, name ): 9 | 10 | model = cmd.get_model(name) 11 | 12 | PDBinfo_objects = [] 13 | PDBinfo_dict = {} 14 | for line in lines: 15 | split_line = line.split() 16 | split_line = split_line[2:] 17 | for info_name in split_line[1:]: 18 | PDBinfo_dict.setdefault(info_name, []).append(split_line[0]) 19 | for key in PDBinfo_dict: 20 | print key, "residues = ",PDBinfo_dict[key] 21 | for key in PDBinfo_dict: 22 | print key 23 | residues = "" 24 | for residue in PDBinfo_dict[key]: 25 | residues = residues + "," + str(residue) 26 | print residues 27 | cmd.select(key, "resi %s" % (residues[1:])) 28 | cmd.create("%s_obj" %key, "%s" %key) 29 | cmd.delete("%s" %key) 30 | 31 | # match = hb_re.search(line) 32 | # if match == None: continue 33 | # (d_resi, d_chain, d_atom, a_resi, a_chain, a_atom, energy) = match.groups() 34 | # energy = float(energy) 35 | # 36 | # if energy < -0.05: # ingores very weak "hydrogen bonds" 37 | # 38 | # d_addr = '/%s//%s/%s/%s' % ( name, d_chain, d_resi, d_atom ) 39 | # a_addr = '/%s//%s/%s/%s' % ( name, a_chain, a_resi, a_atom ) 40 | # 41 | # d_atm = model.atom[ cmd.index(d_addr)[0][1] - 1 ] 42 | # a_atm = model.atom[ cmd.index(a_addr)[0][1] - 1 ] 43 | # 44 | # if energy <= -0.9: colorscale = 1.0 45 | # else: colorscale = -1 * energy + 0.1 # ratio to strong, with offset 46 | # hbonds.extend( hbond( d_atm, a_atm, colorscale, colorscale, 0.0 ) ) 47 | # cmd.load_cgo( hbonds, 'hb_%s' % name ) 48 | 49 | ########################### 50 | ### begin main function ### 51 | ########################### 52 | 53 | def get_PDBinfo(): 54 | 55 | # look in object list for rosetta pdb's with source files in pwd 56 | for name in cmd.get_names(): 57 | 58 | source = None 59 | if os.path.exists( '%s.pdb' % name ): source = file( name + '.pdb', 'r' ) 60 | elif os.path.exists( '%s.pdb.gz' % name ): source = gzip.open( '%s.pdb.gz' % name, 'r' ) 61 | else: print 'cannot find source pdb file for', name; continue 62 | 63 | PDBinfo_lines = []; 64 | 65 | for line in source: 66 | if line.startswith('REMARK PDBinfo-LABEL'): PDBinfo_lines.append(line) 67 | 68 | if PDBinfo_lines == []: print 'no PDBinfo lines found for %s' % name 69 | else: 70 | print 'Showing Rosetta PDBinfo for %s...' % name 71 | create_PDBinfo_objs( PDBinfo_lines, name ) 72 | 73 | cmd.extend('PDBinfo',get_PDBinfo) 74 | -------------------------------------------------------------------------------- /scripts/PackingMeasureUtils.py: -------------------------------------------------------------------------------- 1 | import pymol 2 | from pymol import cmd 3 | import sys,os,random 4 | from math import floor 5 | 6 | sys.path.append("/Users/sheffler/svn/trunk/python_scripts/pymol_scripts") 7 | from GenUtils import zload 8 | 9 | rainbow = ['0xCCFF00', '0xFF0000', '0xCC00FF', '0x00FF66', '0x80FF00', '0x0019FF', '0x00FF19', '0x33FF00', '0xFF0099', '0xFF004D', '0xFF00E6', '0x00FFFF', '0x0066FF', '0x8000FF', '0x00B3FF', '0xFFE500', '0x00FFB2', '0xFF4C00', '0x3300FF', '0xFF9900'] 10 | 11 | 12 | def useRosettaRadii(): 13 | cmd.alter("element C", "vdw=2.00") 14 | cmd.alter("element N", "vdw=1.75") 15 | cmd.alter("element O", "vdw=1.55") 16 | cmd.alter("element H", "vdw=1.00") 17 | cmd.alter("element P", "vdw=1.90") 18 | cmd.set("sphere_scale", 1.0) 19 | 20 | def expandRadii(delta=1.0, sel='all'): 21 | for a in cmd.get_model(sel).atom: 22 | r = float(a.vdw) + float(delta) 23 | cmd.alter("index "+`a.index`,'vdw='+`r`) 24 | cmd.rebuild(sel,"spheres") 25 | 26 | def contractRadii(delta=1.0, sel='all'): 27 | for a in cmd.get_model(sel).atom: 28 | r = float(a.vdw) - float(delta) 29 | cmd.alter("index "+`a.index`,'vdw='+`r`) 30 | cmd.rebuild(sel,"spheres") 31 | 32 | def useOccColors(sel="all"): 33 | d = {} 34 | for a in cmd.get_model().atom: 35 | d[a.q] = True 36 | colors = rainbow 37 | # random.shuffle(colors) 38 | # colors *= len(d)/len(colors)+1 39 | for ii in range(len(d.keys())): 40 | cmd.color( colors[ii] ,"%s and q=%i"%(sel,d.keys()[ii])) 41 | 42 | def useTempColors(sel="all"): 43 | for a in cmd.get_model(sel).atom: 44 | q = a.b 45 | c = intcolors[ int(floor(q))%len(intcolors) ] 46 | cmd.color( c ,"%s and resi %s and name %s"%(sel,a.resi,a.name)) 47 | 48 | 49 | def useOccRadii(sel="all"): 50 | for a in cmd.get_model(sel).atom: 51 | q = a.q 52 | if q >= 3: 53 | print "shrik radius" 54 | q <- 0.1 55 | cmd.alter("%s and resi %s and name %s"%(sel,a.resi,a.name),"vdw=%f"%(q)) 56 | cmd.rebuild() 57 | 58 | def useTempRadii(sel="all"): 59 | for ii in range(30): 60 | radius = "%0.1f"%(float(ii+1)/10) 61 | vdw = "%0.1f"%(float(ii+1)/5) 62 | cmd.alter(sel+" and b="+radius,"vdw="+vdw) 63 | cmd.rebuild() 64 | 65 | def loadPackingPDB(file,name=None,native=None): 66 | """ 67 | usage: loadPackingPDB , [] 68 | loads a foo_packing.pdb file and colors it all pretty-like 69 | creates two selections along with the loaded object called 70 | NAMEcavities and NAMEprotein which are the heteratoms representing 71 | holes and everything else, respectively. Names can get pretty long, 72 | by pymol lets you do good stuff like "select NA*cav*", which will 73 | match a selection called NAMEISREALLYLONGcavities. 74 | """ 75 | 76 | if name is None: 77 | name = name = os.path.basename(file) 78 | if name.endswith('.gz'): 79 | name = name[:-3] 80 | if name.endswith('.pdb'): 81 | name = name[:-4] 82 | if name.endswith('.'): 83 | name = name[:-1] 84 | if name.endswith("_packing"): 85 | name = name[:-8] 86 | 87 | zload(file,name) 88 | cmd.hide('everything',name) 89 | 90 | if native is not None: 91 | cmd.align(name,native) 92 | cmd.zoom(native) 93 | 94 | useRosettaRadii() 95 | 96 | cavselname = name+"cavities" 97 | protselname = name+"protein" 98 | 99 | cmd.select(cavselname, "resn CAV and b > 0.1 and %s"%(name) ) 100 | cmd.select(protselname,"(not resn CAV) and %s"%(name) ) 101 | 102 | useTempRadii(cavselname) 103 | useOccColors(cavselname) 104 | cmd.color("white",protselname) 105 | 106 | cmd.show('spheres', cavselname ) 107 | cmd.show("cartoon",protselname) 108 | cmd.show("lines",protselname) 109 | 110 | cmd.select("none") 111 | cmd.delete("sele*") 112 | cmd.move('z',-50) 113 | 114 | return name 115 | 116 | cmd.extend("loadPackingPDB",loadPackingPDB) 117 | cmd.extend("useOccRadii",useOccRadii) 118 | cmd.extend("useOccColors",useOccColors) 119 | cmd.extend("useTempRadii",useTempRadii) 120 | cmd.extend("useTempColors",useTempColors) 121 | cmd.extend('useRosettaRadii', useRosettaRadii) 122 | cmd.extend('expandRadii',expandRadii) 123 | cmd.extend('contractRadii',contractRadii) 124 | 125 | 126 | -------------------------------------------------------------------------------- /scripts/ShowContacts.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | '''PyMOL plugin that provides show_contacts command and GUI 4 | for highlighting good and bad polar contacts. Factored out of 5 | clustermols by Matthew Baumgartner. 6 | The advantage of this package is it requires many fewer dependencies. 7 | ''' 8 | from __future__ import print_function 9 | 10 | import sys,os 11 | 12 | import Pmw 13 | from pymol import cmd 14 | 15 | DEBUG=1 16 | 17 | def show_contacts(selection,selection2,result="contacts",cutoff=3.6, bigcutoff = 4.0, SC_DEBUG = DEBUG): 18 | """ 19 | USAGE 20 | 21 | show_contacts selection, selection2, [result=contacts],[cutoff=3.6],[bigcutoff=4.0] 22 | 23 | Show various polar contacts, the good, the bad, and the ugly. 24 | 25 | Edit MPB 6-26-14: The distances are heavy atom distances, so I upped the default cutoff to 4.0 26 | 27 | Returns: 28 | True/False - if False, something went wrong 29 | """ 30 | if SC_DEBUG > 4: 31 | print('Starting show_contacts') 32 | print('selection = "' + selection + '"') 33 | print('selection2 = "' + selection2 + '"') 34 | 35 | 36 | #if the group of contacts already exist, delete them 37 | cmd.delete(result) 38 | 39 | # ensure only N and O atoms are in the selection 40 | all_don_acc1 = selection + " and (donor or acceptor)" 41 | all_don_acc2 = selection2 + " and (donor or acceptor)" 42 | 43 | if SC_DEBUG > 4: 44 | print('all_don_acc1 = "' + all_don_acc1 + '"') 45 | print('all_don_acc2 = "' + all_don_acc2 + '"') 46 | 47 | #if theses selections turn out not to have any atoms in them, pymol throws cryptic errors when calling the dist function like: 48 | #'Selector-Error: Invalid selection name' 49 | #So for each one, manually perform the selection and then pass the reference to the distance command and at the end, clean up the selections 50 | #the return values are the count of the number of atoms 51 | all1_sele_count = cmd.select('all_don_acc1_sele', all_don_acc1) 52 | all2_sele_count = cmd.select('all_don_acc2_sele', all_don_acc2) 53 | 54 | #print out some warnings 55 | if DEBUG > 3: 56 | if not all1_sele_count: 57 | print('Warning: all_don_acc1 selection empty!') 58 | if not all2_sele_count: 59 | print('Warning: all_don_acc2 selection empty!') 60 | 61 | ######################################## 62 | allres = result + "_all" 63 | if all1_sele_count and all2_sele_count: 64 | cmd.distance(allres, 'all_don_acc1_sele', 'all_don_acc2_sele', bigcutoff, mode = 0) 65 | cmd.set("dash_radius", "0.05", allres) 66 | cmd.set("dash_color", "purple", allres) 67 | cmd.hide("labels", allres) 68 | 69 | ######################################## 70 | #compute good polar interactions according to pymol 71 | polres = result + "_polar" 72 | if all1_sele_count and all2_sele_count: 73 | cmd.distance(polres, 'all_don_acc1_sele', 'all_don_acc2_sele', cutoff, mode = 2) #hopefully this checks angles? Yes 74 | cmd.set("dash_radius","0.126",polres) 75 | 76 | ######################################## 77 | #When running distance in mode=2, the cutoff parameter is ignored if set higher then the default of 3.6 78 | #so set it to the passed in cutoff and change it back when you are done. 79 | old_h_bond_cutoff_center = cmd.get('h_bond_cutoff_center') # ideal geometry 80 | old_h_bond_cutoff_edge = cmd.get('h_bond_cutoff_edge') # minimally acceptable geometry 81 | cmd.set('h_bond_cutoff_center', bigcutoff) 82 | cmd.set('h_bond_cutoff_edge', bigcutoff) 83 | 84 | #compute possibly suboptimal polar interactions using the user specified distance 85 | pol_ok_res = result + "_polar_ok" 86 | if all1_sele_count and all2_sele_count: 87 | cmd.distance(pol_ok_res, 'all_don_acc1_sele', 'all_don_acc2_sele', bigcutoff, mode = 2) 88 | cmd.set("dash_radius", "0.06", pol_ok_res) 89 | 90 | #now reset the h_bond cutoffs 91 | cmd.set('h_bond_cutoff_center', old_h_bond_cutoff_center) 92 | cmd.set('h_bond_cutoff_edge', old_h_bond_cutoff_edge) 93 | 94 | 95 | ######################################## 96 | 97 | onlyacceptors1 = selection + " and (acceptor and !donor)" 98 | onlyacceptors2 = selection2 + " and (acceptor and !donor)" 99 | onlydonors1 = selection + " and (!acceptor and donor)" 100 | onlydonors2 = selection2 + " and (!acceptor and donor)" 101 | 102 | #perform the selections 103 | onlyacceptors1_sele_count = cmd.select('onlyacceptors1_sele', onlyacceptors1) 104 | onlyacceptors2_sele_count = cmd.select('onlyacceptors2_sele', onlyacceptors2) 105 | onlydonors1_sele_count = cmd.select('onlydonors1_sele', onlydonors1) 106 | onlydonors2_sele_count = cmd.select('onlydonors2_sele', onlydonors2) 107 | 108 | #print out some warnings 109 | if SC_DEBUG > 2: 110 | if not onlyacceptors1_sele_count: 111 | print('Warning: onlyacceptors1 selection empty!') 112 | if not onlyacceptors2_sele_count: 113 | print('Warning: onlyacceptors2 selection empty!') 114 | if not onlydonors1_sele_count: 115 | print('Warning: onlydonors1 selection empty!') 116 | if not onlydonors2_sele_count: 117 | print('Warning: onlydonors2 selection empty!') 118 | 119 | 120 | accres = result+"_aa" 121 | if onlyacceptors1_sele_count and onlyacceptors2_sele_count: 122 | aa_dist_out = cmd.distance(accres, 'onlyacceptors1_sele', 'onlyacceptors2_sele', cutoff, 0) 123 | 124 | if aa_dist_out < 0: 125 | print('\n\nCaught a pymol selection error in acceptor-acceptor selection of show_contacts') 126 | print('accres:', accres) 127 | print('onlyacceptors1', onlyacceptors1) 128 | print('onlyacceptors2', onlyacceptors2) 129 | return False 130 | 131 | cmd.set("dash_color","red",accres) 132 | cmd.set("dash_radius","0.125",accres) 133 | 134 | ######################################## 135 | 136 | donres = result+"_dd" 137 | if onlydonors1_sele_count and onlydonors2_sele_count: 138 | dd_dist_out = cmd.distance(donres, 'onlydonors1_sele', 'onlydonors2_sele', cutoff, 0) 139 | 140 | #try to catch the error state 141 | if dd_dist_out < 0: 142 | print('\n\nCaught a pymol selection error in dd selection of show_contacts') 143 | print('donres:', donres) 144 | print('onlydonors1', onlydonors1) 145 | print('onlydonors2', onlydonors2) 146 | print("cmd.distance('" + donres + "', '" + onlydonors1 + "', '" + onlydonors2 + "', " + str(cutoff) + ", 0)") 147 | return False 148 | 149 | cmd.set("dash_color","red",donres) 150 | cmd.set("dash_radius","0.125",donres) 151 | 152 | ########################################################## 153 | ##### find the buried unpaired atoms of the receptor ##### 154 | ########################################################## 155 | 156 | #initialize the variable for when CALC_SASA is False 157 | unpaired_atoms = '' 158 | 159 | 160 | ## Group 161 | cmd.group(result,"%s %s %s %s %s %s" % (polres, allres, accres, donres, pol_ok_res, unpaired_atoms)) 162 | 163 | ## Clean up the selection objects 164 | #if the show_contacts debug level is high enough, don't delete them. 165 | if SC_DEBUG < 5: 166 | cmd.delete('all_don_acc1_sele') 167 | cmd.delete('all_don_acc2_sele') 168 | cmd.delete('onlyacceptors1_sele') 169 | cmd.delete('onlyacceptors2_sele') 170 | cmd.delete('onlydonors1_sele') 171 | cmd.delete('onlydonors2_sele') 172 | 173 | 174 | return True 175 | cmd.extend('contacts', show_contacts) #contacts to avoid clashing with cluster_mols version 176 | 177 | 178 | 179 | 180 | 181 | ################################################################################# 182 | ########################### Start of pymol plugin code ########################## 183 | ################################################################################# 184 | 185 | 186 | about_text = '''show_contacts was factored out of the much more full-featured cluster_mols 187 | by Dr. Matt Baumgartner (https://pymolwiki.org/index.php/Cluster_mols). It provides 188 | an easy way to highlight polar contacts (and clashes) between two selections without 189 | requiring the installation of additional dependencies. 190 | ''' 191 | 192 | class Show_Contacts: 193 | ''' Main Pymol Plugin Class ''' 194 | def __init__(self, app): 195 | parent = app.root 196 | self.parent = parent 197 | 198 | self.app = app 199 | 200 | 201 | ############################################################################################ 202 | ### Open a window with options to select to loaded objects ### 203 | ############################################################################################ 204 | 205 | self.select_dialog = Pmw.Dialog(parent, 206 | buttons = ('Ok','Cancel'), 207 | title = 'Show Contacts Plugin', 208 | command = self.button_pressed ) 209 | 210 | self.select_dialog.withdraw() 211 | 212 | 213 | #allow the user to select from objects already loaded in pymol 214 | self.select_object_combo_box = Pmw.ComboBox(self.select_dialog.interior(), 215 | scrolledlist_items=[], 216 | labelpos='w', 217 | label_text='Select loaded object:', 218 | listbox_height = 2, 219 | dropdown=True) 220 | self.select_object_combo_box2 = Pmw.ComboBox(self.select_dialog.interior(), 221 | scrolledlist_items=[], 222 | labelpos='w', 223 | label_text='Select loaded object:', 224 | listbox_height = 2, 225 | dropdown=True) 226 | self.select_object_combo_box.grid(column=1, row=0) 227 | self.select_object_combo_box2.grid(column=2, row=0) 228 | self.populate_ligand_select_list() 229 | self.select_dialog.show() 230 | 231 | 232 | 233 | def button_pressed(self, result): 234 | if hasattr(result,'keycode'): 235 | if result.keycode == 36: 236 | print('keycode:', result.keycode) 237 | elif result == 'Ok' or result == 'Exit' or result == None: 238 | s1 = self.select_object_combo_box.get() 239 | s2 = self.select_object_combo_box2.get() 240 | show_contacts(s1,s2,'%s_%s'%(s1,s2)) 241 | self.select_dialog.withdraw() 242 | elif result == 'Cancel' or result == None: 243 | self.select_dialog.withdraw() 244 | 245 | 246 | 247 | 248 | def populate_ligand_select_list(self): 249 | ''' Go thourgh the loaded objects in PyMOL and add them to the selected list. ''' 250 | #get the loaded objects 251 | loaded_objects = [ name for name in cmd.get_names('all') if '_cluster_' not in name ] 252 | 253 | self.select_object_combo_box.clear() 254 | self.select_object_combo_box2.clear() 255 | 256 | for ob in loaded_objects: 257 | self.select_object_combo_box.insert('end', ob) 258 | self.select_object_combo_box2.insert('end', ob) 259 | 260 | 261 | 262 | 263 | def __init__(self): 264 | self.menuBar.addmenuitem('Plugin', 'command', 'Show Contacts', label = 'Show Contacts', command = lambda s=self : Show_Contacts(s)) -------------------------------------------------------------------------------- /scripts/__init__.py: -------------------------------------------------------------------------------- 1 | """Python utilities to interact with PyMOL. 2 | 3 | This package contains the following modules: 4 | 5 | list -- Description. 6 | 7 | them -- Description. 8 | 9 | here -- Description. 10 | 11 | """ 12 | 13 | __all__ = [ 14 | "aaindex", 15 | "Mutations", 16 | "Native", 17 | "Cycler", 18 | "DNAselections", 19 | "GenUtils", 20 | "InterfaceUtils", 21 | "MoleculeUtils", 22 | "PDBBrowser", 23 | "PackingMeasureUtils", 24 | "pdb_hb_uns", 25 | "rosetta_vdw", 26 | "LigandView", 27 | "CavityView", 28 | "spectrumbar", 29 | "FindSeq", 30 | "ShowContacts", 31 | ] 32 | 33 | 34 | -------------------------------------------------------------------------------- /scripts/aaindex.py: -------------------------------------------------------------------------------- 1 | ''' 2 | (c) 2010-2011 Thomas Holder, MPI for Developmental Biology 3 | 4 | Python parser for AAindex: Amino Acid Index Database 5 | http://www.genome.jp/aaindex/ 6 | 7 | PyMOL commands: 8 | 9 | aaindex2b 10 | pmf 11 | ''' 12 | 13 | import sys, os 14 | 15 | _aaindex = dict() 16 | _pymol_auto_arg_update = lambda: None 17 | 18 | def search(pattern, searchtitle=True, casesensitive=False): 19 | ''' 20 | Search for pattern in description and title (optional) of all records and 21 | return matched records as list. By default search case insensitive. 22 | ''' 23 | whatcase = lambda i: i 24 | if not casesensitive: 25 | pattern = pattern.lower() 26 | whatcase = lambda i: i.lower() 27 | matches = [] 28 | for record in _aaindex.itervalues(): 29 | if pattern in whatcase(record.desc) or searchtitle and pattern in whatcase(record.title): 30 | matches.append(record) 31 | return matches 32 | 33 | def grep(pattern): 34 | ''' 35 | Search for pattern in title and description of all records (case 36 | insensitive) and print results on standard output. 37 | ''' 38 | for record in search(pattern): 39 | print record 40 | 41 | class Record: 42 | ''' 43 | Amino acid index (AAindex) Record 44 | ''' 45 | aakeys = 'ARNDCQEGHILKMFPSTWYV' 46 | def __init__(self): 47 | self.key = None 48 | self.desc = '' 49 | self.ref = '' 50 | self.authors = '' 51 | self.title = '' 52 | self.journal = '' 53 | self.correlated = dict() 54 | self.index = dict() 55 | self.comment = '' 56 | def extend(self, row): 57 | i = len(self.index) 58 | for x in row: 59 | self.index[self.aakeys[i]] = x 60 | i += 1 61 | def get(self, aai, aaj=None, d=None): 62 | assert aaj is None 63 | return self.index.get(aai, d) 64 | def __getitem__(self, aai): 65 | return self.get(aai) 66 | def median(self): 67 | x = sorted(filter(None, self.index.values())) 68 | half = len(x)/2 69 | if len(x) % 2 == 1: 70 | return x[half] 71 | return (x[half-1] + x[half])/2.0 72 | def __str__(self): 73 | desc = self.desc.replace('\n', ' ').strip() 74 | return '%s(%s: %s)' % (self.__class__.__name__, self.key, desc) 75 | 76 | class MatrixRecord(Record): 77 | ''' 78 | Matrix record for mutation matrices or pair-wise contact potentials 79 | ''' 80 | def __init__(self): 81 | Record.__init__(self) 82 | self.index = [] 83 | self.rows = dict() 84 | self.cols = dict() 85 | def extend(self, row): 86 | self.index.append(row) 87 | def _get(self, aai, aaj): 88 | i = self.rows[aai] 89 | j = self.cols[aaj] 90 | return self.index[i][j] 91 | def get(self, aai, aaj, d=None): 92 | try: 93 | return self._get(aai, aaj) 94 | except: 95 | pass 96 | try: 97 | return self._get(aaj, aai) 98 | except: 99 | return d 100 | def __getitem__(self, aaij): 101 | return self.get(aaij[0], aaij[1]) 102 | def median(self): 103 | x = [] 104 | for y in self.index: 105 | x.extend(filter(None, y)) 106 | x.sort() 107 | if len(x) % 2 == 1: 108 | return x[len(x)/2] 109 | return sum(x[len(x)/2-1:len(x)/2+1])/2.0 110 | 111 | def get(key): 112 | ''' 113 | Get record for key 114 | ''' 115 | if len(_aaindex) == 0: 116 | init() 117 | return _aaindex[key] 118 | 119 | def _float_or_None(x): 120 | if x == 'NA' or x == '-': 121 | return None 122 | return float(x) 123 | 124 | def init(path=None, index='13'): 125 | ''' 126 | Read in the aaindex files. You need to run this (once) before you can 127 | access any records. If the files are not within the current directory, 128 | you need to specify the correct directory path. By default all three 129 | aaindex files are read in. 130 | ''' 131 | index = str(index) 132 | if path is None: 133 | for path in [os.path.split(__file__)[0], '.', cmd.get('fetch_path')]: 134 | if os.path.exists(os.path.join(path, 'aaindex' + index[0])): 135 | break 136 | print >> sys.stderr, 'path =', path 137 | if '1' in index: 138 | _parse(path + '/aaindex1', Record) 139 | if '2' in index: 140 | _parse(path + '/aaindex2', MatrixRecord) 141 | if '3' in index: 142 | _parse(path + '/aaindex3', MatrixRecord) 143 | _pymol_auto_arg_update() 144 | 145 | def init_from_file(filename, type=Record): 146 | _parse(filename, type) 147 | 148 | def _parse(filename, rec, quiet=True): 149 | ''' 150 | Parse aaindex input file. `rec` must be `Record` for aaindex1 and 151 | `MarixRecord` for aaindex2 and aaindex3. 152 | ''' 153 | if not os.path.exists(filename): 154 | import urllib 155 | url = 'ftp://ftp.genome.jp/pub/db/community/aaindex/' + os.path.split(filename)[1] 156 | print 'Downloading "%s"' % (url) 157 | filename = urllib.urlretrieve(url, filename)[0] 158 | print 'Saved to "%s"' % (filename) 159 | f = open(filename) 160 | 161 | current = rec() 162 | lastkey = None 163 | 164 | for line in f: 165 | key = line[0:2] 166 | if key[0] == ' ': 167 | key = lastkey 168 | 169 | if key == '//': 170 | _aaindex[current.key] = current 171 | current = rec() 172 | elif key == 'H ': 173 | current.key = line[2:].strip() 174 | elif key == 'R ': 175 | current.ref += line[2:] 176 | elif key == 'D ': 177 | current.desc += line[2:] 178 | elif key == 'A ': 179 | current.authors += line[2:] 180 | elif key == 'T ': 181 | current.title += line[2:] 182 | elif key == 'J ': 183 | current.journal += line[2:] 184 | elif key == '* ': 185 | current.comment += line[2:] 186 | elif key == 'C ': 187 | a = line[2:].split() 188 | for i in range(0, len(a), 2): 189 | current.correlated[a[i]] = float(a[i+1]) 190 | elif key == 'I ': 191 | a = line[1:].split() 192 | if a[0] != 'A/L': 193 | current.extend(map(_float_or_None, a)) 194 | elif list(Record.aakeys) != [i[0] for i in a] + [i[-1] for i in a]: 195 | print 'Warning: wrong amino acid sequence for', current.key 196 | else: 197 | try: 198 | assert list(Record.aakeys[:10]) == [i[0] for i in a] 199 | assert list(Record.aakeys[10:]) == [i[2] for i in a] 200 | except: 201 | print 'Warning: wrong amino acid sequence for', current.key 202 | elif key =='M ': 203 | a = line[2:].split() 204 | if a[0] == 'rows': 205 | if a[4] == 'rows': 206 | a.pop(4) 207 | assert a[3] == 'cols' and len(a) == 6 208 | i = 0 209 | for aa in a[2]: 210 | current.rows[aa] = i 211 | i += 1 212 | i = 0 213 | for aa in a[5]: 214 | current.cols[aa] = i 215 | i += 1 216 | else: 217 | current.extend(map(_float_or_None, a)) 218 | elif not quiet: 219 | print 'Warning: line starts with "%s"' % (key) 220 | 221 | lastkey = key 222 | 223 | ########## PYMOL ########### 224 | 225 | # from Bio.SCOP.Raf import to_one_letter_code 226 | # See also http://www.pymolwiki.org/index.php/Aa_codes 227 | to_one_letter_code = {'PAQ': 'Y', 'AGM': 'R', 'ILE': 'I', 'PR3': 'C', 228 | 'GLN': 'Q', 'DVA': 'V', 'CCS': 'C', 'ACL': 'R', 'GLX': 'Z', 'GLY': 'G', 229 | 'GLZ': 'G', 'DTH': 'T', 'OAS': 'S', 'C6C': 'C', 'NEM': 'H', 'DLY': 'K', 230 | 'MIS': 'S', 'SMC': 'C', 'GLU': 'E', 'NEP': 'H', 'BCS': 'C', 'ASQ': 'D', 231 | 'ASP': 'D', 'SCY': 'C', 'SER': 'S', 'LYS': 'K', 'SAC': 'S', 'PRO': 'P', 232 | 'ASX': 'B', 'DGN': 'Q', 'DGL': 'E', 'MHS': 'H', 'ASB': 'D', 'ASA': 'D', 233 | 'NLE': 'L', 'DCY': 'C', 'ASK': 'D', 'GGL': 'E', 'STY': 'Y', 'SEL': 'S', 234 | 'CGU': 'E', 'ASN': 'N', 'ASL': 'D', 'LTR': 'W', 'DAR': 'R', 'VAL': 'V', 235 | 'CHG': 'A', 'TPO': 'T', 'CLE': 'L', 'GMA': 'E', 'HAC': 'A', 'AYA': 'A', 236 | 'THR': 'T', 'TIH': 'A', 'SVA': 'S', 'MVA': 'V', 'SAR': 'G', 'LYZ': 'K', 237 | 'BNN': 'A', '5HP': 'E', 'IIL': 'I', 'SHR': 'K', 'HAR': 'R', 'FME': 'M', 238 | 'PYX': 'C', 'ALO': 'T', 'PHI': 'F', 'ALM': 'A', 'PHL': 'F', 'MEN': 'N', 239 | 'TPQ': 'A', 'GSC': 'G', 'PHE': 'F', 'ALA': 'A', 'MAA': 'A', 'MET': 'M', 240 | 'UNK': 'X', 'LEU': 'L', 'ALY': 'K', 'SET': 'S', 'GL3': 'G', 'TRG': 'K', 241 | 'CXM': 'M', 'TYR': 'Y', 'SCS': 'C', 'DIL': 'I', 'TYQ': 'Y', '3AH': 'H', 242 | 'DPR': 'P', 'PRR': 'A', 'CME': 'C', 'IYR': 'Y', 'CY1': 'C', 'TYY': 'Y', 243 | 'HYP': 'P', 'DTY': 'Y', '2AS': 'D', 'DTR': 'W', 'FLA': 'A', 'DPN': 'F', 244 | 'DIV': 'V', 'PCA': 'E', 'MSE': 'M', 'MSA': 'G', 'AIB': 'A', 'CYS': 'C', 245 | 'NLP': 'L', 'CYQ': 'C', 'HIS': 'H', 'DLE': 'L', 'CEA': 'C', 'DAL': 'A', 246 | 'LLP': 'K', 'DAH': 'F', 'HMR': 'R', 'TRO': 'W', 'HIC': 'H', 'CYG': 'C', 247 | 'BMT': 'T', 'DAS': 'D', 'TYB': 'Y', 'BUC': 'C', 'PEC': 'C', 'BUG': 'L', 248 | 'CYM': 'C', 'NLN': 'L', 'CY3': 'C', 'HIP': 'H', 'CSO': 'C', 'TPL': 'W', 249 | 'LYM': 'K', 'DHI': 'H', 'MLE': 'L', 'CSD': 'A', 'HPQ': 'F', 'MPQ': 'G', 250 | 'LLY': 'K', 'DHA': 'A', 'DSN': 'S', 'SOC': 'C', 'CSX': 'C', 'OMT': 'M', 251 | 'DSP': 'D', 'PTR': 'Y', 'TRP': 'W', 'CSW': 'C', 'EFC': 'C', 'CSP': 'C', 252 | 'CSS': 'C', 'SCH': 'C', 'OCS': 'C', 'NMC': 'G', 'SEP': 'S', 'BHD': 'D', 253 | 'KCX': 'K', 'SHC': 'C', 'C5C': 'C', 'HTR': 'W', 'ARG': 'R', 'TYS': 'Y', 254 | 'ARM': 'R', 'DNP': 'A'} 255 | 256 | def aaindex2b(key='KYTJ820101', selection='(all)', quiet=0, var='b'): 257 | ''' 258 | DESCRIPTION 259 | 260 | "aaindex" looks up the Amino Acid Index from 261 | http://www.genome.jp/aaindex/ 262 | for the given key and assignes b-factors to the given selection. Unknown 263 | residues get the average index value assigned. 264 | 265 | USAGE 266 | 267 | aaindex2b [key [, selection]] 268 | 269 | ARGUMENTS 270 | 271 | key = string: Key of AAindex entry 272 | 273 | selection = string: atoms to assign b-factors {default: (all)} 274 | 275 | EXAMPLE 276 | 277 | # Hydropathy index by Kyte-Doolittle 278 | aaindex2b KYTJ820101 279 | spectrumany b, white yellow forest 280 | show surface 281 | ''' 282 | from pymol import cmd, stored 283 | entry = get(key) 284 | median = entry.median() 285 | 286 | if int(quiet) != 0: 287 | print entry.desc.strip() 288 | 289 | def lookup(resn): 290 | one_letter = to_one_letter_code.get(resn, 'X') 291 | value = entry.get(one_letter) 292 | if value is None: 293 | return median 294 | return value 295 | stored.aaindex = lookup 296 | 297 | cmd.alter(selection, var + '=stored.aaindex(resn)') 298 | 299 | def pmf(key, cutoff=7.0, selection1='(name CB)', selection2='', state=1, quiet=1): 300 | ''' 301 | DESCRIPTION 302 | 303 | Potential of Mean Force 304 | 305 | ARGUMENTS 306 | 307 | key = string: aaindex key 308 | 309 | cutoff = float: distance cutoff {default: 7.0} 310 | cutoff = (float, float): distance shell 311 | 312 | selection1 = string: atom selection {default: (name CB)} 313 | 314 | selection2 = string: atom selection {default: selection1} 315 | 316 | NOTES 317 | 318 | Does also support a list of keys and a list of cutoffs to deal with 319 | multiple distance shells. 320 | 321 | EXAMPLES 322 | 323 | # distance dependent c-beta contact potentials 324 | pmf SIMK990101, 5, /2x19//A//CB 325 | pmf SIMK990102, [5, 7.5], /2x19//A//CB 326 | pmf [SIMK990101, SIMK990102, SIMK990103], [0, 5, 7.5, 10], /2x19//A//CB 327 | 328 | # interface potential 329 | sidechaincenters 2x19_scc, 2x19 330 | pmf KESO980102, 7.0, /2x19_scc//A, /2x19_scc//B 331 | distance /2x19_scc//A, /2x19_scc//B, cutoff=7.0 332 | ''' 333 | from pymol import cmd, stored 334 | from chempy import cpv 335 | if cmd.is_string(key): 336 | if key.lstrip().startswith('['): 337 | key = cmd.safe_alpha_list_eval(key) 338 | else: 339 | key = [key] 340 | if cmd.is_string(cutoff): 341 | cutoff = eval(cutoff) 342 | if not cmd.is_sequence(cutoff): 343 | cutoff = [cutoff] 344 | if len(cutoff) == len(key): 345 | cutoff = [0.0] + list(cutoff) 346 | if len(cutoff) != len(key) + 1: 347 | print 'Error: Number of keys and number of cutoffs inconsistent' 348 | return 349 | state = int(state) 350 | quiet = int(quiet) 351 | if len(selection2) == 0: 352 | selection2 = selection1 353 | if not quiet and len(key) > 1: 354 | print 'Distance shells:' 355 | for i in range(len(key)): 356 | print '%s %.1f-%.1f' % (key[i], cutoff[i], cutoff[i+1]) 357 | 358 | idmap = dict() 359 | cmd.iterate_state(state, '(%s) or (%s)' % (selection1, selection2), 360 | 'idmap[model,index] = [(resn,name),(x,y,z)]', space={'idmap': idmap}) 361 | twoN = cmd.count_atoms(selection1) + cmd.count_atoms(selection2) 362 | pairs = cmd.find_pairs(selection1, selection2, cutoff=max(cutoff), 363 | state1=state, state2=state) 364 | if len(pairs) == 0: 365 | print 'Empty pair list' 366 | return 0.0 367 | 368 | matrix = map(get, key) 369 | for i in matrix: 370 | assert isinstance(i, MatrixRecord) 371 | 372 | i_list = range(len(key)) 373 | u_sum = 0 374 | count = 0 375 | for id1, id2 in pairs: 376 | a1 = idmap[id1] 377 | a2 = idmap[id2] 378 | r = cpv.distance(a1[1], a2[1]) 379 | for i in i_list: 380 | if cutoff[i] <= r and r < cutoff[i+1]: 381 | try: 382 | aa1 = to_one_letter_code[a1[0][0]] 383 | aa2 = to_one_letter_code[a2[0][0]] 384 | u_sum += matrix[i].get(aa1, aa2) 385 | count += 1 386 | except: 387 | print 'Failed for', a1[0], a2[0] 388 | 389 | value = float(u_sum) / twoN 390 | if not quiet: 391 | print 'PMF: %.4f (%d contacts, %d residues)' % (value, count, twoN) 392 | return value 393 | 394 | try: 395 | from pymol import cmd 396 | cmd.extend('aaindex2b', aaindex2b) 397 | cmd.extend('pmf', pmf) 398 | def pymol_auto_arg_update(): 399 | aaindexkey_sc = cmd.Shortcut(_aaindex.keys()) 400 | cmd.auto_arg[0].update({ 401 | 'aaindex2b' : [ aaindexkey_sc , 'aaindexkey' , ', ' ], 402 | 'pmf' : [ aaindexkey_sc , 'aaindexkey' , ', ' ], 403 | }) 404 | cmd.auto_arg[1].update({ 405 | 'aaindex2b' : [ cmd.selection_sc , 'selection' , '' ], 406 | }) 407 | cmd.auto_arg[2].update({ 408 | 'pmf' : [ cmd.selection_sc , 'selection' , '' ], 409 | }) 410 | cmd.auto_arg[3].update({ 411 | 'pmf' : [ cmd.selection_sc , 'selection' , '' ], 412 | }) 413 | _pymol_auto_arg_update = pymol_auto_arg_update 414 | except: 415 | pass 416 | 417 | # vi: ts=4:sw=4:smarttab:expandtab 418 | -------------------------------------------------------------------------------- /scripts/align_sg.py: -------------------------------------------------------------------------------- 1 | import cmd 2 | 3 | def alignsg(sele): 4 | allsg = cmd.get_model("(("+sele+") and (name VSG))").atom 5 | allsf = cmd.get_model("(("+sele+") and (name S5,S6,S7,S8))").atom 6 | while allsg: 7 | closest = [9e9,None,None] 8 | for sga in allsg: 9 | for sfa in allsf: 10 | sg = Vec(sga.coord) 11 | sf = Vec(sfa.coord) 12 | if (sg-sf).length() < closest[0]: 13 | closest = [(sg-sf).length(),sga,sfa] 14 | sga,sfa = closest[1:] 15 | allsg.remove(sga) 16 | allsf.remove(sfa) 17 | if closest[0] > 10.0: break 18 | cmd.do("alter_state 1, (("+sele+") and (resi %s and name %s))"%(sga.resi,sga.name)+",x=%f"%sfa.coord[0]) 19 | cmd.do("alter_state 1, (("+sele+") and (resi %s and name %s))"%(sga.resi,sga.name)+",y=%f"%sfa.coord[1]) 20 | cmd.do("alter_state 1, (("+sele+") and (resi %s and name %s))"%(sga.resi,sga.name)+",z=%f"%sfa.coord[2]) 21 | 22 | for i in range(1,10): 23 | alignsg("wire%i"%i) 24 | -------------------------------------------------------------------------------- /scripts/axes.py: -------------------------------------------------------------------------------- 1 | from pymol.cgo import * 2 | from pymol import cmd 3 | from pymol.vfont import plain 4 | 5 | # create the axes object, draw axes with cylinders coloured red, green, 6 | #blue for X, Y and Z 7 | 8 | obj = [ 9 | BEGIN, LINES, 10 | COLOR, 1.0, 0.0, 0.0, 11 | VERTEX, 0.0, 0.0, 0.0, 12 | VERTEX, 20.0, 0.0, 0.0, 13 | COLOR, 0.0, 1.0, 0.0, 14 | VERTEX, 0.0, 0.0, 0.0, 15 | VERTEX, 0.0, 20.0, 0.0, 16 | COLOR, 0.0, 0.0, 1.0, 17 | VERTEX, 0.0, 0.0, 0.0, 18 | VERTEX, 00, 0.0, 20.0, 19 | 20 | END 21 | ] 22 | 23 | 24 | # obj = [ 25 | # CYLINDER, 0., 0., 0., 10., 0., 0., 0.2, 1.0, 1.0, 1.0, 1.0, 0.0, 0., 26 | # CYLINDER, 0., 0., 0., 0., 10., 0., 0.2, 1.0, 1.0, 1.0, 0., 1.0, 0., 27 | # CYLINDER, 0., 0., 0., 0., 0., 10., 0.2, 1.0, 1.0, 1.0, 0., 0.0, 1.0, 28 | # 29 | # ] 30 | # 31 | # # add labels to axes object 32 | # 33 | # cyl_text(obj,plain,[-5.,-5.,-1],'Origin',0.20,axes=[[3.0,0.0,0.0],[0.0,3.0,0.0],[0.0,0.0,3.0]]) 34 | # cyl_text(obj,plain,[10.,0.,0.],'X',0.20,axes=[[3.0,0.0,0.0],[0.0,3.0,0.0],[0.0,0.0,3.0]]) 35 | # cyl_text(obj,plain,[0.,10.,0.],'Y',0.20,axes=[[3.0,0.0,0.0],[0.0,3.0,0.0],[0.0,0.0,3.0]]) 36 | # cyl_text(obj,plain,[0.,0.,10.],'Z',0.20,axes=[[3.0,0.0,0.0],[0.0,3.0,0.0],[0.0,0.0,3.0]]) 37 | 38 | # then we load it into PyMOL 39 | cmd.load_cgo(obj,'axes') 40 | 41 | 42 | -------------------------------------------------------------------------------- /scripts/axes_cyl.py: -------------------------------------------------------------------------------- 1 | from pymol.cgo import * 2 | from pymol import cmd 3 | from pymol.vfont import plain 4 | 5 | # create the axes object, draw axes with cylinders coloured red, green, 6 | #blue for X, Y and Z 7 | 8 | obj = [ 9 | CYLINDER, 0., 0., 0., 10., 0., 0., 0.2, 1.0, 1.0, 1.0, 1.0, 0.0, 0., 10 | CYLINDER, 0., 0., 0., 0., 10., 0., 0.2, 1.0, 1.0, 1.0, 0., 1.0, 0., 11 | CYLINDER, 0., 0., 0., 0., 0., 10., 0.2, 1.0, 1.0, 1.0, 0., 0.0, 1.0, 12 | 13 | ] 14 | 15 | # add labels to axes object 16 | 17 | cyl_text(obj,plain,[-5.,-5.,-1],'Origin',0.20,axes=[[3.0,0.0,0.0],[0.0,3.0,0.0],[0.0,0.0,3.0]]) 18 | cyl_text(obj,plain,[10.,0.,0.],'X',0.20,axes=[[3.0,0.0,0.0],[0.0,3.0,0.0],[0.0,0.0,3.0]]) 19 | cyl_text(obj,plain,[0.,10.,0.],'Y',0.20,axes=[[3.0,0.0,0.0],[0.0,3.0,0.0],[0.0,0.0,3.0]]) 20 | cyl_text(obj,plain,[0.,0.,10.],'Z',0.20,axes=[[3.0,0.0,0.0],[0.0,3.0,0.0],[0.0,0.0,3.0]]) 21 | 22 | # then we load it into PyMOL 23 | cmd.load_cgo(obj,'axes') 24 | 25 | 26 | -------------------------------------------------------------------------------- /scripts/gensymm.py: -------------------------------------------------------------------------------- 1 | import sys,os,math 2 | from util import * 3 | 4 | # assumes 3 identical objs called r1,r2,r3 5 | # places r2 an r3 based on r1 6 | 7 | axis = Vec(1,1,1).normalized() 8 | # cen = Vec(22.487567, 67.710289, -0.116232 ) 9 | cen = Vec(19.855878, 64.881564, -2.624470 ) 10 | print axis,cen 11 | rots = {"obj02":120.0,"obj03":240.0} 12 | 13 | for n in ("obj02","obj03"): 14 | R = rotation_matrix(axis,rots[n]) 15 | m = cmd.get_model("obj01") 16 | print m.atom[0].coord 17 | for i in range(len(m.atom)): 18 | tmp = ( R * (Vec(m.atom[i].coord)-cen) ) + cen 19 | m.atom[i].coord = [tmp.x,tmp.y,tmp.z] 20 | print m.atom[0].coord 21 | cmd.load_model(m,n,1,discrete=1) 22 | 23 | -------------------------------------------------------------------------------- /scripts/pdb_hb_uns.py: -------------------------------------------------------------------------------- 1 | # ashworth 2 | 3 | # this is a script for reading the source file (in pwd) for a pdb that is already loaded, and displaying the hbonds and buried unsatisfieds contained in their respective tables (if found). Similar functionality was recently introduced into the Rosetta Pymol Plugin by Ron Jacak, and this script borrows a couple of improvements from it. I hope to keep this script as a simple standalone (it's not meant to compete with the Rosetta Pymol Plugin). 4 | 5 | import re, string, gzip 6 | from pymol import cmd, cgo 7 | 8 | class UnsAtom: 9 | def __init__( self, uns_info ): 10 | info = uns_info.split() 11 | self.resi = info[6] 12 | self.chain = info[7] 13 | self.atom = info[10] 14 | 15 | def hbond(don,acc,red,green,blue): 16 | 17 | obj = [] 18 | rad = 0.08 19 | num_dash = 4 20 | steps = num_dash*3+1 21 | 22 | xyz = [] 23 | step = [] 24 | for dim in range(3): 25 | xyz.append( don.coord[dim] ) 26 | dis = acc.coord[dim]-don.coord[dim] 27 | step.append( dis/steps ) 28 | 29 | obj = [ cgo.LINEWIDTH, 3.0, cgo.BEGIN, cgo.LINES, cgo.COLOR, red, green, blue ] 30 | 31 | for dash in range(num_dash): # number of dashes 32 | for dim in range(3): xyz[dim] += 2*step[dim] 33 | obj.append( cgo.VERTEX ) 34 | obj.extend( xyz ) 35 | for dim in range(3): xyz[dim] += step[dim] 36 | obj.append( cgo.VERTEX ) 37 | obj.extend( xyz ) 38 | obj.append( cgo.END ) 39 | return obj 40 | 41 | def create_hbonds( lines, name ): 42 | 43 | model = cmd.get_model(name) 44 | 45 | # Ron Jacak's cool monster regex, borrowed from the Rosetta Pymol Plugin 46 | hb_re = re.compile("(?:PROT|BASE) \s*[A-Z]+ \s*\d+ \s*(\d+) ([ A-Z]) \s*([A-Z0-9]+) \s*[A-Z]+ \s*\d+ \s*(\d+) ([ A-Z]) \s*([A-Z0-9]+)\s* (-?[\d\.]*)") 47 | hbonds = [] 48 | for line in lines: 49 | match = hb_re.search(line) 50 | if match == None: continue 51 | (d_resi, d_chain, d_atom, a_resi, a_chain, a_atom, energy) = match.groups() 52 | energy = float(energy) 53 | 54 | if energy < -0.05: # ingores very weak "hydrogen bonds" 55 | 56 | d_addr = '/%s//%s/%s/%s' % ( name, d_chain, d_resi, d_atom ) 57 | a_addr = '/%s//%s/%s/%s' % ( name, a_chain, a_resi, a_atom ) 58 | 59 | d_atm = model.atom[ cmd.index(d_addr)[0][1] - 1 ] 60 | a_atm = model.atom[ cmd.index(a_addr)[0][1] - 1 ] 61 | 62 | if energy <= -0.9: colorscale = 1.0 63 | else: colorscale = -1 * energy + 0.1 # ratio to strong, with offset 64 | hbonds.extend( hbond( d_atm, a_atm, colorscale, colorscale, 0.0 ) ) 65 | cmd.load_cgo( hbonds, 'hb_%s' % name ) 66 | 67 | def create_ds_uns( lines, name ): 68 | uns = { 'uns_sc':[], 'uns_bb':[] } 69 | for line in lines: 70 | type = line[3:8] 71 | if type == 'SCACC' or type == 'SCDON': uns['uns_sc'].append( UnsAtom(line) ) 72 | elif type == 'BBACC' or type == 'BBDON': uns['uns_bb'].append( UnsAtom(line) ) 73 | 74 | for type,list in uns.items(): 75 | if list == []: continue 76 | selstr = string.join( [ '/%s//%s/%s/%s' % ( name, atom.chain, atom.resi, atom.atom ) for atom in list ], ' or ' ) 77 | typename = '%s_%s' % ( type, name ) 78 | cmd.select( typename, selstr ) 79 | 80 | # copy unsatisfieds into a separate object (allows unique transparency, among other things) 81 | for type in uns: 82 | typename = '%s_%s' % ( type, name ) 83 | cmd.disable( typename ) 84 | obj = '%s_obj' % typename 85 | cmd.create( obj, typename ) 86 | cmd.show( 'spheres', obj ) 87 | cmd.set( 'sphere_scale' , '0.75', obj ) 88 | cmd.set( 'sphere_transparency', '0.5', obj ) 89 | 90 | ########################### 91 | ### begin main function ### 92 | ########################### 93 | 94 | def pdb_hbonds_and_uns(): 95 | 96 | # look in object list for rosetta pdb's with source files in pwd 97 | for name in cmd.get_names(): 98 | 99 | source = None 100 | if os.path.exists( '%s.pdb' % name ): source = file( name + '.pdb', 'r' ) 101 | elif os.path.exists( '%s.pdb.gz' % name ): source = gzip.open( '%s.pdb.gz' % name, 'r' ) 102 | else: print 'cannot find source pdb file for', name; continue 103 | 104 | hb_lines = []; ds_lines = [] 105 | 106 | hb_start = False 107 | for line in source: 108 | # hbond line collection uses Ron Jacak's method, for improved generality 109 | if line == '\n': hb_start = False 110 | if hb_start == True: hb_lines.append(line) 111 | if line.startswith("Loc, res, pos, pdb"): hb_start = True 112 | if line.startswith("DS "): ds_lines.append( line ) 113 | 114 | if hb_lines == []: print 'no hbond lines found for %s' % name 115 | else: 116 | print 'Showing Rosetta hbonds for %s...' % name 117 | create_hbonds( hb_lines, name ) 118 | if ds_lines == []: print 'no decoystats lines found for %s' % name 119 | else: 120 | print 'Showing Rosetta buried unsatisfieds for %s...' % name 121 | create_ds_uns( ds_lines, name ) 122 | 123 | cmd.extend('pdb_hb_uns',pdb_hbonds_and_uns) 124 | -------------------------------------------------------------------------------- /scripts/rawAsBfact.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | 3 | from pymol import cmd 4 | from numpy import * 5 | 6 | 7 | def zero_residues(sel1,offset=0,chains=0): 8 | offset = int(offset) 9 | 10 | # variable to store the offset 11 | stored.first = None 12 | # get the names of the proteins in the selection 13 | 14 | names = ['(model %s and (%s))' % (p, sel1) 15 | for p in cmd.get_object_list('(' + sel1 + ')')] 16 | 17 | if int (chains): 18 | names = ['(%s and chain %s)' % (p, chain) 19 | for p in names 20 | for chain in cmd.get_chains(p)] 21 | 22 | # for each name shown 23 | for p in names: 24 | # get this offset 25 | ok = cmd.iterate("first %s and polymer and n. CA" % p,"stored.first=resv") 26 | # don't waste time if we don't have to 27 | if not ok or stored.first == offset: 28 | continue; 29 | # reassign the residue numbers 30 | #cmd.alter("%s" % p, "resi=str(int(resi)-%s)" % str(int(stored.first)-offset)) 31 | # update pymol 32 | 33 | cmd.rebuild() 34 | 35 | 36 | def drab( nlim=-2.0, plim=2.0 ): 37 | #zero the indexes 38 | #zero_residues("all", 1, 1) 39 | #Read the values in 40 | fileName=cmd.get_names()[0]; 41 | print fileName 42 | fileName=fileName+".dat" 43 | cmd.alter("all", "b=0.0") 44 | #file = open(fileName, 'r') 45 | #table = [row.strip().split('\t') for row in file] 46 | bVals = [] 47 | #print table 48 | for line in file(fileName): 49 | line=line.strip().split() 50 | if ( line[0][0] != "#" ): 51 | selection="resi %s" % line[0] 52 | #Normalize the values 53 | bval=(float(line[1])-nlim)/(plim-nlim) 54 | #print bval 55 | cmd.alter( selection, "b=%f"%bval ) 56 | print ( selection, "b=%f"%bval ) 57 | bVals.append([selection, bval]) 58 | cmd.hide("all") 59 | cmd.show("cartoon") 60 | cmd.spectrum("b", "blue_white_red", "all", "0.0", "1.0" , "1") 61 | cmd.ramp_new("rawFac_ramp", cmd.get_names()[0], [nlim, plim], color="[blue, white, red ]") 62 | cmd.recolor() 63 | -------------------------------------------------------------------------------- /scripts/roeAsBfact.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | 3 | from pymol import cmd 4 | from numpy import * 5 | 6 | 7 | def zero_residues(sel1,offset=0,chains=0): 8 | offset = int(offset) 9 | 10 | # variable to store the offset 11 | stored.first = None 12 | # get the names of the proteins in the selection 13 | 14 | names = ['(model %s and (%s))' % (p, sel1) 15 | for p in cmd.get_object_list('(' + sel1 + ')')] 16 | 17 | if int (chains): 18 | names = ['(%s and chain %s)' % (p, chain) 19 | for p in names 20 | for chain in cmd.get_chains(p)] 21 | 22 | # for each name shown 23 | for p in names: 24 | # get this offset 25 | ok = cmd.iterate("first %s and polymer and n. CA" % p,"stored.first=resv") 26 | # don't waste time if we don't have to 27 | if not ok or stored.first == offset: 28 | continue; 29 | # reassign the residue numbers 30 | cmd.alter("%s" % p, "resi=str(int(resi)-%s)" % str(int(stored.first)-offset)) 31 | # update pymol 32 | 33 | cmd.rebuild() 34 | 35 | 36 | def rener(inName=""): 37 | #zero the indexes 38 | zero_residues("all", 1, 1) 39 | #Read the values in 40 | infileName="" 41 | if (inName==""): 42 | infileName=cmd.get_names()[0]; 43 | else: 44 | infileName=inName 45 | fileName=infileName+".pdb" 46 | cmd.alter("all", "b=0.0") 47 | file = open(fileName, 'r') 48 | table = [row.strip().split() for row in file] 49 | bVals = [] 50 | did_start=False 51 | rowcount=0 52 | for i in table: 53 | if ( i[0] == "#BEGIN_POSE_ENERGIES_TABLE" ): 54 | did_start=True 55 | rowcount=0 56 | continue 57 | elif did_start: 58 | rowcount+=1 59 | if (rowcount>3): 60 | if (i[0] == "#END_POSE_ENERGIES_TABLE"): 61 | did_start=False 62 | continue 63 | resn=i[0].split('_')[-1] 64 | selection="resi %s" % resn 65 | val=i[-1] 66 | #if (val > 1.67): 67 | # val=1.67 68 | #elif (val < 0.08): 69 | # val=0.08 70 | bfac=val 71 | bVals.append([selection, bfac]) 72 | numres=len(bVals) 73 | bValsAvg = zeros(numres) 74 | for i in range( 0, numres): 75 | bValsAvg[i]=float(bVals[i][1]) 76 | # for j in range( 0, frag_size): 77 | # tmpval=float(bVals[i][1]) 78 | # if(bValsAvg[i+j] < tmpval): 79 | # bValsAvg[i+j] = tmpval 80 | # bValsAvg[i]+= (float(bVals[i+j][1])/float(frag_size)) 81 | # bValsAvg=bValsAvg+bValsAvg[i].min() 82 | for i in range( 0, numres): 83 | print bVals[i][0], bValsAvg[i] 84 | bfac = ("b=%f" % bValsAvg[i]) 85 | cmd.alter(bVals[i][0], bfac) 86 | #cmd.hide("all") 87 | #cmd.show("cartoon") 88 | # cmd.spectrum("b", "blue_white_red", infileName, bValsAvg.min(), bValsAvg.max(), "1") 89 | cmd.spectrum("b", "blue_white_red", infileName, -2.0, 0.0, "1") 90 | -------------------------------------------------------------------------------- /scripts/rosetta_vdw.py: -------------------------------------------------------------------------------- 1 | # rosetta radii for sphere representation in PyMOL 2 | # values taken from etable.cc 3 | 4 | from pymol import cmd 5 | 6 | def useRosettaRadii(): 7 | cmd.alter("element C", "vdw=2.00") 8 | cmd.alter("element N", "vdw=1.75") 9 | cmd.alter("element O", "vdw=1.55") 10 | # cmd.alter("element H", "vdw=1.00") # rosetta polar H 11 | cmd.alter("element H", "vdw=1.20") #ja rosetta nonpolar H, probably more appropriate for packing 12 | cmd.alter("element P", "vdw=1.90") 13 | cmd.alter("element S", "vdw=1.90") 14 | cmd.alter("element O and r. HOH","1.4") # water 15 | cmd.alter("element W", "vdw=0.5") # Rosetta rotameric waters (small to avoid dominating structure) 16 | 17 | cmd.set("sphere_scale", 1.0) # forces spheres to update (I think) 18 | 19 | cmd.extend('useRosettaRadii', useRosettaRadii) 20 | -------------------------------------------------------------------------------- /scripts/sample_pymolrc: -------------------------------------------------------------------------------- 1 | # To use, rename this file to ~/.pymolrc 2 | 3 | # deprecated 4 | # run ~/python_scripts/pymol_scripts/all_commands.py 5 | 6 | # note that the following standard syntax will work as long as the package is defined correctly and Python knows where to find it (the PYTHONPATH environment variable should indicate the base directory where the user's additional Python packages are located) -Ashworth Aug 2008 7 | 8 | # the following method /may/ work if you do not want to set PYTHONPATH 9 | import sys 10 | sys.path.append("~/python_scripts/") 11 | 12 | from pymol_scripts import * 13 | -------------------------------------------------------------------------------- /scripts/showaxes.py: -------------------------------------------------------------------------------- 1 | from pymol.cgo import * 2 | from pymol import cmd 3 | from pymol.vfont import plain 4 | 5 | 6 | #this is a plugin version of the axes_cyl scripts by Dr. Robert L. Campbell (in fact I only added 7 | #the __init__ function and englobed the resto of the code in a main function) 8 | #As a very minor change I replaced the "ORIGIN" label for the origin with an "O" 9 | 10 | def main(): 11 | # create the axes object, draw axes with cylinders coloured red, green, 12 | #blue for X, Y and Z 13 | 14 | obj = [ 15 | CYLINDER, 0., 0., 0., 10., 0., 0., 0.2, 1.0, 1.0, 1.0, 1.0, 0.0, 0., 16 | CYLINDER, 0., 0., 0., 0., 10., 0., 0.2, 1.0, 1.0, 1.0, 0., 1.0, 0., 17 | CYLINDER, 0., 0., 0., 0., 0., 10., 0.2, 1.0, 1.0, 1.0, 0., 0.0, 1.0, 18 | 19 | ] 20 | 21 | # add labels to axes object 22 | 23 | cyl_text(obj,plain,[-5.,-5.,-1],'O',0.20,axes=[[3.0,0.0,0.0],[0.0,3.0,0.0],[0.0,0.0,3.0]]) 24 | cyl_text(obj,plain,[10.,0.,0.],'X',0.20,axes=[[3.0,0.0,0.0],[0.0,3.0,0.0],[0.0,0.0,3.0]]) 25 | cyl_text(obj,plain,[0.,10.,0.],'Y',0.20,axes=[[3.0,0.0,0.0],[0.0,3.0,0.0],[0.0,0.0,3.0]]) 26 | cyl_text(obj,plain,[0.,0.,10.],'Z',0.20,axes=[[3.0,0.0,0.0],[0.0,3.0,0.0],[0.0,0.0,3.0]]) 27 | 28 | # then we load it into PyMOL 29 | cmd.load_cgo(obj,'axes') 30 | 31 | def __init__(self): 32 | self.menuBar.addmenuitem('Plugin', 'command', 33 | 'Showaxes', 34 | label = 'Showaxes', 35 | command = lambda s=self : main()) 36 | 37 | 38 | -------------------------------------------------------------------------------- /scripts/spectrumbar.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | 3 | from pymol.cgo import * 4 | from math import * 5 | from pymol import cmd 6 | import re 7 | 8 | 9 | def spectrumbar(*args, **kwargs): 10 | """ 11 | Author Sean M. Law 12 | University of Michigan 13 | seanlaw_(at)_umich_dot_edu 14 | 15 | USAGE 16 | 17 | While in PyMOL 18 | 19 | run spectrumbar.py 20 | 21 | spectrumbar (RGB_Colors,radius=1.0,name=spectrumbar,head=(0.0,0.0,0.0),tail=(10.0,0.0,0.0),length=10.0, ends=square) 22 | 23 | Parameter Preset Type Description 24 | RGB_Colors [1.0,1.0,1.0] N/A RGB colors can be specified as a 25 | triplet RGB value or as PyMOL 26 | internal color name (i.e. red) 27 | radius 1.0 float Radius of cylindrical spectrum bar 28 | name spectrumbar string CGO object name for spectrum bar 29 | head (0.0,0.0,0.0) float Starting coordinate for spectrum bar 30 | tail (10.0,0.0,0.0) float Ending coordinate for spectrum bar 31 | length 10.0 float Length of spectrum bar 32 | ends square string For rounded ends use ends=rounded 33 | 34 | Examples: 35 | 36 | spectrumbar red, green, blue 37 | spectrumbar 1.0,0.0,0.0, 0.0,1.0,0.0, 0.0,0.0,1.0 38 | 39 | The above two examples produce the same spectrumbar! 40 | 41 | spectrumbar radius=5.0 42 | spectrumbar length=20.0 43 | 44 | """ 45 | 46 | rgb = [1.0, 1.0, 1.0] 47 | name = "spectrumbar" 48 | radius = 1.0 49 | ends = "square" 50 | x1 = 0 51 | y1 = 0 52 | z1 = 0 53 | x2 = 10 54 | y2 = 0 55 | z2 = 0 56 | num = re.compile('[0-9]') 57 | abc = re.compile('[a-z]') 58 | 59 | for key in kwargs: 60 | if (key == "radius"): 61 | radius = float(kwargs["radius"]) 62 | elif (key == "name"): 63 | name = kwargs["name"] 64 | elif (key == "head"): 65 | head = kwargs["head"] 66 | head = head.strip('" []()') 67 | x1, y1, z1 = list(map(float, head.split(','))) 68 | elif (key == "tail"): 69 | tail = kwargs["tail"] 70 | tail = tail.strip('" []()') 71 | x2, y2, z2 = list(map(float, tail.split(','))) 72 | elif (key == "length"): 73 | if (abc.search(kwargs["length"])): 74 | print("Error: The length must be a value") 75 | return 76 | else: 77 | x2 = float(kwargs["length"]) 78 | elif (key == "ends"): 79 | ends = kwargs["ends"] 80 | elif (key != "_self"): 81 | print("Ignoring unknown option \"" + key + "\"") 82 | else: 83 | continue 84 | 85 | args = list(args) 86 | if (len(args) >= 1): 87 | rgb = [] 88 | while (len(args) >= 1): 89 | if (num.search(args[0]) and abc.search(args[0])): 90 | if (str(cmd.get_color_tuple(args[0])) != "None"): 91 | rgb.extend(cmd.get_color_tuple(args.pop(0))) 92 | else: 93 | return 94 | elif (num.search(args[0])): 95 | rgb.extend([float(args.pop(0))]) 96 | elif (abc.search(args[0])): 97 | if (str(cmd.get_color_tuple(args[0])) != "None"): 98 | rgb.extend(cmd.get_color_tuple(args.pop(0))) 99 | else: 100 | return 101 | else: 102 | print("Error: Unrecognized color format \"" + args[0] + "\"") 103 | return 104 | 105 | if (len(rgb) % 3): 106 | print("Error: Missing RGB value") 107 | print("Please double check RGB values") 108 | return 109 | 110 | dx = x2 - x1 111 | dy = y2 - y1 112 | dz = z2 - z1 113 | if (len(rgb) == 3): 114 | rgb.extend([rgb[0]]) 115 | rgb.extend([rgb[1]]) 116 | rgb.extend([rgb[2]]) 117 | t = 1.0 / (len(rgb) / 3.0 - 1) 118 | c = len(rgb) / 3 - 1 119 | s = 0 120 | bar = [] 121 | 122 | while (s < c): 123 | if (len(rgb) > 0): 124 | r = rgb.pop(0) 125 | g = rgb.pop(0) 126 | b = rgb.pop(0) 127 | if (s == 0 and ends == "rounded"): 128 | bar.extend([COLOR, float(r), float(g), float(b), SPHERE, x1 + (s * t) * dx, y1 + (s * t) * dy, z1 + (s * t) * dz, radius]) 129 | bar.extend([CYLINDER]) 130 | bar.extend([x1 + (s * t) * dx, y1 + (s * t) * dy, z1 + (s * t) * dz]) 131 | bar.extend([x1 + (s + 1) * t * dx, y1 + (s + 1) * t * dy, z1 + (s + 1) * t * dz]) 132 | bar.extend([radius, float(r), float(g), float(b)]) 133 | if (len(rgb) >= 3): 134 | bar.extend([float(rgb[0]), float(rgb[1]), float(rgb[2])]) 135 | r = rgb[0] 136 | g = rgb[1] 137 | b = rgb[2] 138 | else: 139 | bar.extend([float(r), float(g), float(b)]) 140 | if (s == c - 1 and ends == "rounded"): 141 | bar.extend([COLOR, float(r), float(g), float(b), SPHERE, x1 + (s + 1) * t * dx, y1 + (s + 1) * t * dy, z1 + (s + 1) * t * dz, radius]) 142 | s = s + 1 143 | 144 | cmd.delete(name) 145 | cmd.load_cgo(bar, name) 146 | 147 | return 148 | cmd.extend("spectrumbar", spectrumbar) 149 | -------------------------------------------------------------------------------- /scripts/test.py: -------------------------------------------------------------------------------- 1 | from vecmat import * 2 | 3 | 4 | 5 | 6 | a = Vec(34.155998, 66.834000, 0.232000 ) 7 | b = Vec(22.784122, 79.173546, -0.705234 ) 8 | c = Vec(21.641096, 67.769714, 11.566982 ) 9 | 10 | print (a-b).cross(a-c) 11 | -------------------------------------------------------------------------------- /scripts/tmalign.py: -------------------------------------------------------------------------------- 1 | ''' 2 | (c) 2011-2012 Thomas Holder, MPI for Developmental Biology 3 | ''' 4 | 5 | __author__ = 'Thomas Holder' 6 | __version__ = '1.1' 7 | __license__ = 'BSD-2-Clause' 8 | 9 | from pymol import cmd, CmdException 10 | 11 | def save_pdb_without_ter(filename, selection, **kwargs): 12 | ''' 13 | DESCRIPTION 14 | 15 | Save PDB file without TER records. External applications like TMalign and 16 | DynDom stop reading PDB files at TER records, which might be undesired in 17 | case of missing loops. 18 | ''' 19 | v = cmd.get_setting_boolean('pdb_use_ter_records') 20 | if v: cmd.unset('pdb_use_ter_records') 21 | cmd.save(filename, selection, **kwargs) 22 | if v: cmd.set('pdb_use_ter_records') 23 | 24 | def alignwithanymethod(mobile, target, methods='align super cealign tmalign', 25 | async=1, quiet=1): 26 | ''' 27 | DESCRIPTION 28 | 29 | Align copies of mobile to target with several alignment methods 30 | 31 | ARGUMENTS 32 | 33 | mobile = string: atom selection 34 | 35 | target = string: atom selection 36 | 37 | methods = string: space separated list of PyMOL commands which take 38 | arguments "mobile" and "target" (in any order) {default: align super 39 | cealign tmalign} 40 | ''' 41 | import threading 42 | import time 43 | methods = methods.split() 44 | async, quiet = int(async), int(quiet) 45 | mobile_obj = cmd.get_object_list('first (' + mobile + ')')[0] 46 | def myalign(method): 47 | newmobile = cmd.get_unused_name(mobile_obj + '_' + method) 48 | cmd.create(newmobile, mobile_obj) 49 | start = time.time() 50 | cmd.do('%s mobile=%s in %s, target=%s' % (method, newmobile, mobile, target)) 51 | if not quiet: 52 | print 'Finished: %s (%.2f sec)' % (method, time.time() - start) 53 | for method in methods: 54 | if async: 55 | t = threading.Thread(target=myalign, args=(method,)) 56 | t.setDaemon(1) 57 | t.start() 58 | else: 59 | myalign(method) 60 | 61 | def tmalign(mobile, target, args='', exe='~/bin/TMalign', ter=0, transform=1, object=None, quiet=0): 62 | ''' 63 | DESCRIPTION 64 | 65 | TMalign wrapper 66 | 67 | Reference: Y. Zhang and J. Skolnick, Nucl. Acids Res. 2005 33, 2302-9 68 | http://zhanglab.ccmb.med.umich.edu/TM-align/ 69 | 70 | USAGE 71 | 72 | tmalign mobile, target [, args [, exe ]] 73 | 74 | ARGUMENTS 75 | 76 | mobile, target = string: atom selections 77 | 78 | args = string: Extra arguments like -d0 5 -L 100 79 | 80 | exe = string: Path to TMalign executable {default: TMalign} 81 | 82 | ter = 0/1: If ter=0, then ignore chain breaks because TMalign will stop 83 | at first TER record {default: 0} 84 | 85 | SEE ALSO 86 | 87 | tmscore, mmalign 88 | ''' 89 | import subprocess, tempfile, os, re 90 | 91 | ter, quiet = int(ter), int(quiet) 92 | 93 | mobile_filename = tempfile.mktemp('.pdb', 'mobile') 94 | target_filename = tempfile.mktemp('.pdb', 'target') 95 | matrix_filename = tempfile.mktemp('.txt', 'matrix') 96 | mobile_ca_sele = '(%s) and (not hetatm) and name CA and alt +A' % (mobile) 97 | target_ca_sele = '(%s) and (not hetatm) and name CA and alt +A' % (target) 98 | 99 | if ter: 100 | save = cmd.save 101 | else: 102 | save = save_pdb_without_ter 103 | save(mobile_filename, mobile_ca_sele) 104 | save(target_filename, target_ca_sele) 105 | 106 | exe = cmd.exp_path(exe) 107 | args = [exe, mobile_filename, target_filename, '-m', matrix_filename] + args.split() 108 | 109 | try: 110 | process = subprocess.Popen(args, stdout=subprocess.PIPE) 111 | lines = process.stdout.readlines() 112 | except OSError: 113 | print 'Cannot execute "%s", please provide full path to TMscore or TMalign executable' % (exe) 114 | raise CmdException 115 | finally: 116 | os.remove(mobile_filename) 117 | os.remove(target_filename) 118 | 119 | # TMalign >= 2012/04/17 120 | if os.path.exists(matrix_filename): 121 | lines += open(matrix_filename).readlines() 122 | os.remove(matrix_filename) 123 | 124 | r = None 125 | re_score = re.compile(r'TM-score\s*=\s*(\d*\.\d*)') 126 | rowcount = 0 127 | matrix = [] 128 | line_it = iter(lines) 129 | alignment = [] 130 | for line in line_it: 131 | if 4 >= rowcount > 0: 132 | if rowcount >= 2: 133 | a = map(float, line.split()) 134 | matrix.extend(a[2:5]) 135 | matrix.append(a[1]) 136 | rowcount += 1 137 | elif line.lower().startswith(' -------- rotation matrix'): 138 | rowcount = 1 139 | elif line.startswith('(":" denotes'): 140 | alignment = [line_it.next().rstrip() for i in range(3)] 141 | else: 142 | match = re_score.search(line) 143 | if match is not None: 144 | r = float(match.group(1)) 145 | if not quiet: 146 | print line.rstrip() 147 | 148 | if not quiet: 149 | for i in range(0, len(alignment[0])-1, 78): 150 | for line in alignment: 151 | print line[i:i+78] 152 | print '' 153 | 154 | assert len(matrix) == 3*4 155 | matrix.extend([0,0,0,1]) 156 | 157 | if int(transform): 158 | cmd.transform_selection('byobject (%s)' % (mobile), matrix, homogenous=1) 159 | 160 | # alignment object 161 | if object is not None: 162 | mobile_idx, target_idx = [], [] 163 | space = {'mobile_idx': mobile_idx, 'target_idx': target_idx} 164 | cmd.iterate(mobile_ca_sele, 'mobile_idx.append("%s`%d" % (model, index))', space=space) 165 | cmd.iterate(target_ca_sele, 'target_idx.append("%s`%d" % (model, index))', space=space) 166 | for i, aa in enumerate(alignment[0]): 167 | if aa == '-': 168 | mobile_idx.insert(i, None) 169 | for i, aa in enumerate(alignment[2]): 170 | if aa == '-': 171 | target_idx.insert(i, None) 172 | if (len(mobile_idx) == len(target_idx) == len(alignment[2])): 173 | cmd.rms_cur( 174 | ' '.join(idx for (idx, m) in zip(mobile_idx, alignment[1]) if m in ':.'), 175 | ' '.join(idx for (idx, m) in zip(target_idx, alignment[1]) if m in ':.'), 176 | cycles=0, matchmaker=4, object=object) 177 | else: 178 | print 'Could not load alignment object' 179 | 180 | if not quiet and r is not None: 181 | print 'Found in output TM-score = %.4f' % (r) 182 | 183 | return r 184 | 185 | def tmscore(mobile, target, args='', exe='~/bin/TMscore', quiet=0, **kwargs): 186 | ''' 187 | DESCRIPTION 188 | 189 | TMscore wrapper 190 | 191 | Reference: Yang Zhang and Jeffrey Skolnick, Proteins 2004 57: 702-710 192 | http://zhanglab.ccmb.med.umich.edu/TM-score/ 193 | 194 | ARGUMENTS 195 | 196 | mobile, target = string: atom selections 197 | 198 | args = string: Extra arguments like -d 5 199 | 200 | exe = string: Path to TMscore executable {default: TMscore} 201 | 202 | ter = 0/1: If ter=0, then ignore chain breaks because TMscore will stop 203 | at first TER record {default: 0} 204 | 205 | SEE ALSO 206 | 207 | tmalign, mmalign 208 | ''' 209 | kwargs.pop('_self', None) 210 | return tmalign(mobile, target, args, exe, quiet=quiet, **kwargs) 211 | 212 | def mmalign(mobile, target, args='', exe='~/bin/MMalign', ter=0, transform=1, quiet=0): 213 | ''' 214 | DESCRIPTION 215 | 216 | MMalign wrapper 217 | 218 | Reference: S. Mukherjee and Y. Zhang, Nucleic Acids Research 2009; 37: e83 219 | http://zhanglab.ccmb.med.umich.edu/MM-align/ 220 | 221 | SEE ALSO 222 | 223 | tmalign, tmscore 224 | ''' 225 | return tmalign(mobile, target, args, exe, ter, transform, quiet=quiet) 226 | 227 | # pymol commands 228 | cmd.extend('alignwithanymethod', alignwithanymethod) 229 | cmd.extend('tmalign', tmalign) 230 | cmd.extend('tmscore', tmscore) 231 | cmd.extend('mmalign', tmalign) 232 | 233 | # autocompletion 234 | cmd.auto_arg[0].update({ 235 | 'tmalign': cmd.auto_arg[0]['align'], 236 | 'tmscore': cmd.auto_arg[0]['align'], 237 | 'mmalign': cmd.auto_arg[0]['align'], 238 | }) 239 | cmd.auto_arg[1].update({ 240 | 'tmalign': cmd.auto_arg[1]['align'], 241 | 'tmscore': cmd.auto_arg[1]['align'], 242 | 'mmalign': cmd.auto_arg[1]['align'], 243 | }) 244 | -------------------------------------------------------------------------------- /scripts/vecmat.py: -------------------------------------------------------------------------------- 1 | # 2 | # class Vec(object): 3 | # def __init__(self,x,y=None,z=None): 4 | # if type(x) is type(self): 5 | # self.x,self.y,self.z = x.x,x.y,x.z 6 | # elif type(x) in (type([]),type((1,))): 7 | # self.x,self.y,self.z = x[0],x[1],x[2] 8 | # elif y is None: 9 | # assert type(x) in (type(0),type(0.0)) 10 | # self.x,self.y,self.z = x,x,x 11 | # else: 12 | # self.x,self.y,self.z = float(x),float(y),float(z) 13 | # def dot(u,v): 14 | # return u.x*v.x+u.y*v.y+u.z*v.z 15 | # def length(u): 16 | # return math.sqrt(u.dot(u)) 17 | # def cross(u,v): 18 | # return Vec(u.y*v.z-u.z*v.y,u.z*v.x-u.x*v.z,u.x*v.y-u.y*v.x) 19 | # def __mul__(u,a): 20 | # if type(a) is type(0) or type(a) is type(0.0): 21 | # return Vec(u.x*a,u.y*a,u.z*a) 22 | # elif type(a) is Vec: 23 | # return u.dot(a) 24 | # else: 25 | # # print type(a) 26 | # assert False 27 | # def __rmul__(u,a): 28 | # return u*a 29 | # def __add__(u,v): 30 | # if type(v) is type(u): 31 | # return Vec(u.x+v.x,u.y+v.y,u.z+v.z) 32 | # else: 33 | # assert type(v) in (type(0),type(0.0)) 34 | # # print type(v),type(u.x),type(u.y),type(u.z) 35 | # return Vec(u.x+v,u.y+v,u.z+v) 36 | # def __radd__(u,v): 37 | # return u+v 38 | # def __sub__(u,v): 39 | # return u+(-v) 40 | # def __rsub__(u,v): 41 | # return u+(-v) 42 | # def __neg__(u): 43 | # return Vec(-u.x,-u.y,-u.z) 44 | # def __div__(u,a): 45 | # return u*(1.0/a) 46 | # def __str__(self): 47 | # return "%f, %f, %f"%(self.x,self.y,self.z) 48 | # def __repr__(self): 49 | # return "Vec( %f, %f, %f )"%(self.x,self.y,self.z) 50 | # def normalize(u): 51 | # l = u.length() 52 | # u.x /= l 53 | # u.y /= l 54 | # u.z /= l 55 | # return u 56 | # def cgofrompoint(a,c): 57 | # return [ 58 | # COLOR, 1.0, 1.0, 1.0, 59 | # SPHERE, c.x, c.y, c.z, 1.0, 60 | # CYLINDER,c.x ,c.y ,c.z , 61 | # c.x+a.x,c.y+a.y,c.z+a.z,0.5, 62 | # 1,1,1,1,1,1, 63 | # ] 64 | # 65 | # 66 | # 67 | # 68 | # class Mat(object): 69 | # """docstring for Mat""" 70 | # def __init__(self, xx, xy, xz, yx, yy, yz, zx, zy, zz): 71 | # super(Mat, self).__init__() 72 | # self.xx = float(xx) 73 | # self.xy = float(xy) 74 | # self.xz = float(xz) 75 | # self.yx = float(yx) 76 | # self.yy = float(yy) 77 | # self.yz = float(yz) 78 | # self.zx = float(zx) 79 | # self.zy = float(zy) 80 | # self.zz = float(zz) 81 | # def row(m,i): 82 | # assert type(i) is type(1) 83 | # if i is 0: return Vec(m.xx,m.xy,m.xz) 84 | # elif i is 1: return Vec(m.yx,m.yy,m.yz) 85 | # elif i is 2: return Vec(m.zx,m.zy,m.zz) 86 | # else: assert 0 <= i and i <= 2 87 | # def col(m,i): 88 | # assert type(i) is type(1) 89 | # if i is 0: return Vec(m.xx,m.yx,m.zx) 90 | # elif i is 1: return Vec(m.xy,m.yy,m.zy) 91 | # elif i is 2: return Vec(m.xz,m.yz,m.zz) 92 | # else: assert 0 <= i and i <= 2 93 | # def rowx(m): return m.row(0) 94 | # def rowy(m): return m.row(1) 95 | # def rowz(m): return m.row(2) 96 | # def colx(m): return m.col(0) 97 | # def coly(m): return m.col(1) 98 | # def colz(m): return m.col(2) 99 | # def __mul__(m,v): 100 | # if type(v) in(type(0),type(0.0)): 101 | # return Mat( v*m.xx, v*m.xy, v*m.xz, v*m.yx, v*m.yy, v*m.yz, v*m.zx, v*m.zy, v*m.zz ) 102 | # elif type(v) is Vec: 103 | # return Vec( m.rowx()*v, m.rowy()*v, m.rowz()*v ) 104 | # elif type(v) is Mat: 105 | # return Mat( m.rowx()*v.colx(), m.rowy()*v.colx(), m.rowz()*v.colx(), 106 | # m.rowx()*v.coly(), m.rowy()*v.coly(), m.rowz()*v.coly(), 107 | # m.rowx()*v.colz(), m.rowy()*v.colz(), m.rowz()*v.colz() ) 108 | # else: 109 | # try: 110 | # return v.__rmul__(m) 111 | # except: 112 | # print type(v) 113 | # raise NotImplementedError 114 | # def __str__(m): 115 | # return "Mat( "+str(m.rowx())+"\n "+str(m.rowy())+"\n "+str(m.rowz()) + " )" 116 | # def transpose(m): 117 | # return Mat( m.xx, m.yx, m.zx, m.xy, m.yy, m.zy, m.xz, m.yz, m.zz ) 118 | # 119 | --------------------------------------------------------------------------------