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

Source Code for Package AutoDockTools

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