Package Pmv
[hide private]
[frames] | no frames]

Source Code for Package Pmv

  1  # $Header: /opt/cvs/python/packages/share1.5/Pmv/__init__.py,v 1.21.2.2 2007/08/12 16:13:15 sargis Exp $ 
  2  # $Id: __init__.py,v 1.21.2.2 2007/08/12 16:13:15 sargis Exp $ 
  3  # this makes this directory a package 
  4   
  5  import sys, os, getopt, time 
  6  from string import split 
  7   
8 -def setdmode(mode, mv):
9 """ 10 load display commands for mode and set them as default command for new molecule 11 """ 12 if mode=='cpk': 13 mv.browseCommands('displayCommands', commands=['displayCPK'], 14 log=0, package='Pmv') 15 mv.addOnAddObjectCmd(mv.displayCPK) 16 17 elif mode=='lines': 18 mv.browseCommands('bondsCommands', 19 commands=('buildBondsByDistance',), log=0) 20 mv.addOnAddObjectCmd(mv.buildBondsByDistance) 21 mv.browseCommands('displayCommands', commands=('ribbon',), log=0) 22 mv.addOnAddObjectCmd(mv.displayLines) 23 24 elif mode=='ss': 25 mv.browseCommands('secondaryStructureCommands', 26 commands=('ribbon',), log=0) 27 mv.addOnAddObjectCmd(mv.ribbon) 28 29 elif mode=='sb': 30 mv.browseCommands('bondsCommands', 31 commands=('buildBondsByDistance',), log=0) 32 mv.addOnAddObjectCmd(mv.buildBondsByDistance) 33 mv.browseCommands('displayCommands', 34 commands=('displaySticksAndBalls',), log=0) 35 mv.addOnAddObjectCmd(mv.displaySticksAndBalls, (), 36 {'cquality':0, 'bquality':0}) 37 38 elif mode=='lic': 39 mv.browseCommands('bondsCommands', 40 commands=('buildBondsByDistance',), log=0) 41 mv.addOnAddObjectCmd(mv.buildBondsByDistance) 42 mv.browseCommands('displayCommands', 43 commands=('displaySticksAndBalls',), log=0) 44 mv.addOnAddObjectCmd(mv.displaySticksAndBalls, (), 45 {'sticksBallsLicorice':'Licorice', 'cquality':0, 'cradius':.2}) 46 47 elif mode=='ms': 48 mv.browseCommands('msmsCommands', commands=('computeMSMS',), log=0) 49 mv.browseCommands('msmsCommands', commands=('displayMSMS',), log=0) 50 mv.addOnAddObjectCmd(mv.computeMSMS, (), {'density':3.0}) 51 mv.addOnAddObjectCmd(mv.displayMSMS) 52 53 elif mode=='ca': 54 mv.browseCommands('traceCommands', commands=('computeTrace',), log=0) 55 mv.browseCommands('traceCommands', commands=('extrudeTrace',), log=0) 56 mv.browseCommands('traceCommands', commands=('displayTrace',), log=0) 57 mv.addOnAddObjectCmd(mv.computeTrace) 58 mv.addOnAddObjectCmd(mv.extrudeTrace) 59 mv.addOnAddObjectCmd(mv.displayTrace) 60 61 elif mode=='bt': 62 mv.browseCommands('bondsCommands', 63 commands=('buildBondsByDistance',), log=0) 64 mv.browseCommands('displayCommands', 65 commands=('displayBackboneTrace',), log=0) 66 mv.addOnAddObjectCmd(mv.displayBackboneTrace, (), 67 {'cquality':0, 'bquality':0, 'cradius':0.25, 68 'bRad':0.33} ) 69 70 elif mode=='sp': 71 mv.browseCommands('splineCommands', commands=('computeSpline',), log=0) 72 mv.browseCommands('splineCommands', commands=('extrudeSpline',), log=0) 73 mv.browseCommands('splineCommands', 74 commands=('displayExtrudedSpline',), log=0) 75 mv.addOnAddObjectCmd(mv.computeSpline) 76 mv.addOnAddObjectCmd(mv.extrudeSpline) 77 mv.addOnAddObjectCmd(mv.displayExtrudedSpline) 78 79 elif mode=='sssb': 80 mv.browseCommands('displayCommands', 81 commands=('displaySSSB',), log=0, package='Pmv') 82 mv.addOnAddObjectCmd(mv.displaySSSB)
83 84
85 -def setcmode(mode, mv):
86 """ 87 load color commands for mode and set them as default command for new molecule 88 """ 89 if mode=='ca': 90 mv.browseCommands('colorCommands', commands=('colorByAtomType',), 91 log=0, package='Pmv') 92 mv.addOnAddObjectCmd(mv.colorByAtomType) 93 94 elif mode=='cr': 95 mv.browseCommands('colorCommands', 96 commands=('colorByResidueType',), log=0) 97 mv.addOnAddObjectCmd(mv.colorByResidueType) 98 99 elif mode=='cc': 100 mv.browseCommands('colorCommands', commands=('colorByChains',), 101 log=0, package='Pmv') 102 mv.addOnAddObjectCmd(mv.colorByChains) 103 104 elif mode=='cm': 105 mv.self.browseCommands('colorCommands', commands=('colorByMolecules',), 106 log=0, package='Pmv') 107 mv.addOnAddObjectCmd(mv.colorByMolecules) 108 109 elif mode=='cdg': 110 mv.browseCommands('colorCommands', commands=('colorAtomsUsingDG',), 111 log=0, package='Pmv') 112 mv.addOnAddObjectCmd(mv.colorAtomsUsingDG) 113 114 elif mode=='cs': 115 mv.browseCommands('colorCommands', 116 commands=('colorResiduesUsingShapely',), log=0 ) 117 mv.addOnAddObjectCmd(mv.colorResiduesUsingShapely) 118 119 elif mode=='css': 120 mv.browseCommands('secondaryStructureCommands', 121 commands=('colorBySecondaryStructure',), log=0) 122 mv.addOnAddObjectCmd(mv.colorBySecondaryStructure)
123 124 125 ################################################################## 126 # Define a bunch of useful methods 127 ##################################################################
128 -def ed():
129 return self.vision.ed
130 131
132 -def net():
133 return self.vision.ed.currentNetwork
134 135
136 -def nodes():
137 return self.vision.ed.currentNetwork.nodes
138 139
140 -def startPMV(argv, PmvScriptPath):
141 """The main function for running PMV""" 142 import os, sys, pdb 143 optlist, args = getopt.getopt(argv[1:], 'haid:c:', ['update', 144 'help', 'again', 'overwriteLog', 'uniqueLog', 'noLog', 'die', 145 'customizer=', 'interactive', 'dmode=', 'cmode=', 'noSplash'] ) 146 147 help_msg = """usage: pmv <options> 148 -h or --help : print this message 149 -a or --again : play back lastlog file 150 --overwriteLog : overwrite log file 151 --uniqueLog : create a log file with a unique name 152 --noLog : turn off logging 153 --noSplash : turn off Splash Screen 154 --die : do not start GUI event loop 155 --customizer file : run the user specified file 156 --lib packageName : add a libraries of commands 157 158 --update [nightly|tested|clear] : update MGLTools 159 if no arguments are given Update Manager GUI is provided 160 'nightly': download and install Nightly Builds 161 'tested' : download and install tested Nightly Builds 162 'clear' : clear/uninstall all the updates 163 164 -d or --dmode modes : specify a display mode 165 modes can be any a combination of display mode 166 'cpk' : cpk 167 'lines': lines 168 'ss' : secondary structure ribbon 169 'sb' : sticks and balls 170 'lic' : licorice 171 'ms' : molecular surface 172 'ca' : C-alpha trace 173 'bt' : backbone trace 174 'sp' : CA-spline 175 'sssb' : secondary structure for proteins, 176 sticks and balls for other residues with bonds 177 lines for other residues without bonds 178 179 -c or --cmode modes : specify a dispaly mode 180 color scheme: 181 'ca' : color by atom 182 'cr' : color by residue (RASMOL scheme) 183 'cc' : color by chain 184 'cm' : color by molecule 185 'cdg': color using David Goodsell's scheme 186 'cs' : color residues using Shapely scheme 187 'css': color by secondary structure element 188 189 example: 190 display protein as ribbon, non protein as sticks and balls 191 and color by atom type 192 pmv -i --dmode sssb --cmode cr myprot.pdb 193 pmv -i -m sssb -c cr myprot.pdb 194 195 """ 196 197 customizer = None 198 logmode = 'overwrite' 199 libraries = [] 200 again = 0 201 interactive = 0 202 die=0 203 noSplash = False 204 dmode = cmode = None 205 dmodes = ['cpk', 'lines', 'ss', 'sb', 'lic', 'ms', 'ca', 'bt', 'sp', 'sssb' ] 206 cmodes = ['ca', 'cr', 'cc', 'cm', 'cdg', 'cs', 'css'] 207 208 for opt in optlist: 209 if opt[ 0] in ('-h', '--help'): 210 print help_msg 211 sys.exit() 212 elif opt[ 0] in ('-a', '--again'): 213 again = 1 214 os.system("mv mvAll.log.py .tmp.py") 215 elif opt[ 0] =='--overwriteLog': logmode = 'overwrite' 216 elif opt[ 0] =='--uniqueLog': logmode = 'unique' 217 elif opt[ 0] =='--noLog': logmode = 'no' 218 elif opt[ 0] =='--die': die = 1 219 elif opt[ 0] =='--noSplash': noSplash = True 220 elif opt[ 0] == '--customizer': 221 customFile = opt[1] 222 elif opt[ 0] == '--lib': 223 libraries.append(opt[1]) 224 elif opt[ 0] in ('-i', '--interactive'): 225 interactive = 1 226 elif opt[ 0] in ('-d', '--dmode'): 227 assert min([mo in dmodes for mo in opt[1].split('|')])==True 228 dmode = opt[1] 229 elif opt[ 0] in ('-c', '--cmode'): 230 assert min([mo in cmodes for mo in opt[1].split('|')])==True 231 cmode = opt[1] 232 elif opt[0] == '--update': 233 try: 234 from Support.update import Update 235 except ImportError: 236 print "Support package is needed to get updates" 237 break 238 239 update = Update() 240 if 'nightly' in args: 241 update.latest = 'nightly' 242 update.getUpdates() 243 elif 'tested' in args: 244 update.latest = 'tested' 245 update.getUpdates() 246 elif 'clear' in args: 247 print "Removing all updates" 248 update.clearUpdates() 249 else: 250 waitTk = update.gui() 251 update.master.wait_variable(waitTk) 252 else: 253 print "unknown option %s %s"%tuple(opt) 254 print help_msg 255 sys.exit(1) 256 257 text = 'Python executable : '+sys.executable+'\n' 258 text += 'PMV script : '+PmvScriptPath+'\n' 259 text += 'MGLTool packages '+'\n' 260 261 from Support.path import path_text, release_path 262 from Support.version import __version__ 263 version = __version__ 264 text += path_text 265 text += version+': '+release_path 266 267 path_data = text 268 269 import Pmv 270 print 'Run PMV from ', Pmv.__path__[0] 271 sys.modules['__main__'] = sys.modules['Pmv'] 272 # if MGLPYTHONPATH environment variable exists - insert the specified path 273 # into sys.path 274 275 #if os.environ.has_key("MGLPYTHONPATH"): 276 # if sys.platform == "win32": 277 # mglPath = split(os.environ["MGLPYTHONPATH"], ";") 278 # else: 279 # mglPath = split(os.environ["MGLPYTHONPATH"], ":") 280 # mglPath.reverse() 281 # for p in mglPath: 282 # sys.path.insert(0, os.path.abspath(p)) 283 284 try: 285 ################################################################## 286 # Splash Screen 287 ################################################################## 288 image_dir = os.path.join( Pmv.__path__[0],'Icons','Images') 289 copyright = """(c) 1999-2007 Molecular Simulation Laboratory, The Scripps Research Institute 290 ALL RIGHTS RESERVED """ 291 authors = """Authors: Michel F. Sanner, Chris Carrillo, Kevin Chan, 292 Sophie Coon, Sargis Dallakyan, Alex Gillet, Ruth Huey, Sowjanya Karnati, 293 William (Lindy) Lindstrom, Garrett M. Morris, Brian Norledge, Anna Omelchenko, 294 Daniel Stoffler, Vincenzo Tschinke, Guillaume Vareille, Yong Zhao""" 295 icon = os.path.join(Pmv.__path__[0],'Icons','64x64','ss64.png') 296 third_party = """Fast Isocontouring, Volume Rendering -- Chandrait Bajaj, UT Austin 297 Adaptive Poisson Bolzman Solver (APBS) -- Nathan Baker Wash. Univ. St Louis 298 GL extrusion Library (GLE) -- Linas Vepstas 299 Secondary Structure Assignment (Stride) -- Patrick Argos EMBL 300 Mesh Decimation (QSlim 2.0) -- Micheal Garland, Univeristy of Illinois 301 Tiled Rendering (TR 1.3) -- Brian Paul 302 GLF font rendering library -- Roman Podobedov 303 PyMedia video encoder/decoder -- http://pymedia.org""" 304 title="Python Molecule Viewer" 305 #create a root and hide it 306 try: 307 from TkinterDnD2 import TkinterDnD 308 root = TkinterDnD.Tk() 309 except ImportError: 310 from Tkinter import Tk 311 root = Tk() 312 root.withdraw() 313 314 from mglutil.splashregister.splashscreen import SplashScreen 315 from mglutil.splashregister.about import About 316 about = About(image_dir=image_dir, third_party=third_party, 317 path_data=path_data, title=title, version=version, 318 copyright=copyright, authors=authors, icon=icon) 319 splash = SplashScreen(about, noSplash=noSplash) 320 321 from Pmv.moleculeViewer import MoleculeViewer 322 323 mv = MoleculeViewer( logMode=logmode, customizer=customizer, master=root, 324 title=title, withShell= not interactive, verbose=False) 325 # libraries=libraries) 326 mv.help_about = about 327 328 font = mv.GUI.ROOT.option_get('font', '*') 329 mv.browseCommands('visionCommands', commands=('vision',), topCommand=0) 330 mv.browseCommands('coarseMolSurfaceCommands', topCommand=0) 331 if mv.vision.ed is None: 332 mv.vision(log=0) 333 mv.vision(log=0) 334 mv.GUI.ROOT.option_add('*font', font) 335 self = mv 336 337 #show the application after it built 338 splash.finish() 339 root.deiconify() 340 globals().update(locals()) 341 342 mv.GUI.VIEWER.suspendRedraw = True 343 cwd = os.getcwd() 344 #mv._cwd differs from cwd when 'Startup Directory' userpref is set 345 os.chdir(mv._cwd) 346 if dmode is not None or cmode is not None: 347 # save current list of commands run when a molecule is loaded 348 addCmds = mv.getOnAddObjectCmd() 349 # remove them 350 if dmode is not None: 351 for c in addCmds: 352 mv.removeOnAddObjectCmd(c[0]) 353 # set the mode 354 setdmode(dmode, mv) 355 356 if cmode is not None: 357 # set the mode 358 setcmode(cmode, mv) 359 360 for a in args: 361 if a[0]=='-':# skip all command line options 362 continue 363 364 elif (a[-10:]=='_pmvnet.py') or (a[-7:]=='_net.py'): # Vision networks 365 mv.browseCommands('visionCommands', commands=('vision',) ) 366 if mv.vision.ed is None: 367 mv.vision() 368 mv.vision.ed.loadNetwork(a) 369 370 elif a[-3:]=='.py': # command script 371 print 'sourcing', a 372 mv.source(a) 373 374 elif a[-4:] in ['.pdb', '.pqr', 'pdbq', 'mol2', '.cif', '.gro'] or a[-5:]=='pdbqs' or a[-5:]=='pdbqt': 375 mv.readMolecule(a) 376 377 elif a in ['clear', 'tested', 'nighlty']: 378 pass 379 380 else: 381 print 'WARNING: unable to process %s command line argument'%a 382 if again: 383 mv.source(".tmp.py") 384 if dmode is not None or cmode is not None: 385 # get current list of commands run when a molecule is loaded 386 cmds = mv.getOnAddObjectCmd() 387 # remove them 388 for c in cmds: 389 mv.removeOnAddObjectCmd(c[0]) 390 # restore original list of commands 391 for c in addCmds: 392 apply( mv.addOnAddObjectCmd, c ) 393 394 mv.GUI.VIEWER.suspendRedraw = False 395 os.chdir(cwd) 396 if interactive: 397 sys.stdin = sys.__stdin__ 398 sys.stdout = sys.__stdout__ 399 sys.stderr = sys.__stderr__ 400 import code 401 code.interact( 'PMV Interactive Shell', local=globals() ) 402 elif not die: 403 mv.GUI.pyshell.interp.locals = globals() 404 mv.GUI.ROOT.mainloop() 405 406 except: 407 import traceback 408 traceback.print_exc() 409 raw_input("hit enter to continue") 410 import sys 411 sys.exit(1)
412 413 414 FlagCheck = 1 415 416 CRITICAL_DEPENDENCIES =['Numeric', 'Pmw', 'mglutil', 'ViewerFramework', 'MolKit', 'DejaVu', 'opengltk'] 417 NONCRITICAL_DEPENDENCIES =['ZSI', 'geomutils', 'UTpackages', 'SpatialLogic', 'bhtree', 'sff', 'PyBabel', 'Volume', 'mslib', 'Vision', 'NetworkEditor', 'ARTK', 'PIL', 'symserv','QSlimLib', 'AutoDockTools', 'PyMead', 'isocontour','Support'] 418