1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
#############################################################################
#
# Author: Ruth HUEY, Michel F. SANNER
#
# Copyright: M. Sanner TSRI 2000
#
#############################################################################
#
# $Header: /opt/cvs/python/packages/share1.5/AutoDockTools/autodockHosts.py,v 1.2 2012/08/07 17:36:20 rhuey Exp $
#
# $Id: autodockHosts.py,v 1.2 2012/08/07 17:36:20 rhuey Exp $
#
#
#
import UserDict
class AutoDockHosts(UserDict.UserDict):
def __init__(self, localHostDict):
UserDict.UserDict.__init__(self)
self.update(localHostDict)
def buildEntry(self, host=None,agPath=None, adPath=None, vinaPath=None, qType='int', userSpecific=0):
d={}
d['host']=host
d['autogrid']=agPath
d['autodock']=adPath
d['vina']=vinaPath
d['queuetype']=qType
d['userSpecific']=userSpecific
return d
def addHost(self,macroName, hostdict=None, **kw):
host = kw['host']
agPath = kw['autogrid']
adPath = kw['autodock']
vinaPath = kw['vina']
qType = kw['queuetype']
userSpecific = kw['userSpecific']
if not hostdict:
hostdict=self.buildEntry(host=host, agPath=agPath, adPath=adPath,
qType=qType,userSpecific=userSpecific)
self[macroName]=hostdict
#nb: preexisting macroName entry is overwritten
def saveHostFile(self, filename, whichOnes='all'):
#will be in file called .adthosts.py
#and consist of python code for dictionary called 'newhosts'
fptr = open(filename, 'w')
outstr = 'hostMacros={'
#outstr = 'hosts={'
fptr.write(outstr)
#always write a localHost line
#get the correct macroList here
if whichOnes=='all':
macroList=self.keys()
elif whichOnes=='userSpecific':
#get the one with userSpecific=1, only
macroList=[]
for item in self.items():
if item[1]['userSpecific']:
macroList.append(item)
else:
macroList=[]
for item in self.items():
if not item[1]['userSpecific']:
macroList.append(item)
#get the other ones...
for i in range(len(macroList)):
h=macroList[i][0]
self.writeEntry(h,fptr)
if i<len(macroList)-1:
fptr.write('\t\t},\n')
else:
fptr.write('\t\t}\n')
#close the whole thing
outstr = '\t}\n'
fptr.write(outstr)
fptr.close()
def writeEntry(self, macroName,fptr):
outstr='\t\''+macroName+'\': {\n'
#outstr='\t\''+hostName+'\': {\n'
fptr.write(outstr)
d = self[macroName]
#d = self[hostName]
klist = d.keys()
for i in range(len(klist)):
k=klist[i]
if k=='userSpecific':
outstr= '\t\t\''+k + '\': '+ str(d[k])
else:
outstr= '\t\t\''+k + '\': \''+ str(d[k])+'\''
fptr.write(outstr)
if i<len(klist)-1:
outstr= ',\n'
else:
outstr= '\n'
fptr.write(outstr)
def loadHostFile(self, filename):
newStuff=__import__(filename)
self.update(filename.adhosts)
#self.update(adhosts)
|