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 Parallellized AmberEntropist calculation.
26 """
27
28 from Biskit.PVM import JobSlave
29 import Biskit.tools as T
30 import Biskit.settings as settings
31
32 from Biskit import LogFile
33 from Biskit.AmberEntropist import AmberEntropist
34 from Biskit.AmberCrdEntropist import EntropistError
35
36 import os, time
37
39 """
40 Collect AmberEntropist jobs from AmberEntropyMaster and return result.
41 """
42
44 """
45 expects::
46 {'nice':int, 'ferror':str, .. }
47
48 @param params: initialisation parameters passed from the master
49 @type params: dict
50 """
51 self.__dict__.update( params )
52 self.errorLog = LogFile( self.ferror, mode='a' )
53
54
56 try:
57 try:
58 print msg
59 except:
60 pass
61
62 msg = 'trouble with ' + msg
63 s = '%s on %s, run %s\n' % (msg, os.uname()[1], id)
64 s += '\Error:' + T.lastError()
65 s += '\nErrorTrace:\n' + T.lastErrorTrace() + '\n'
66 s += '\n'
67
68 self.errorLog.add( s )
69
70 except Exception, why:
71 f = open('ErrorReportError_AmberEntropySlave','a')
72 f.write( str(type(why)) )
73 try:
74 f.write( T.lastErrorTrace() )
75 except:
76 pass
77 f.close()
78
79
81 """
82 The calculation.
83
84 @param jobs: dictionary with { int_id : str_protocol }
85 @type jobs: dict
86
87 @return: result from AmberEntropist.run()
88 @rtype: dict
89 """
90 result = {}
91
92 startTime = time.time()
93
94 for id, protocol in jobs.items():
95
96 try:
97 T.flushPrint( "%s " % str(id) )
98
99 protocol.update( {'nice':self.nice} )
100
101 x = None
102
103 x = AmberEntropist( **protocol )
104
105 x.run()
106
107 r = x.result
108
109 if r:
110 r['__version_AmberEntropist'] = x.version()
111
112 result[ id ] = r
113 else:
114 result[ id ] = None
115
116 except EntropistError, why:
117 self.reportError( str(type(why)), id )
118 except IOError, why:
119 self.reportError( str(why), id )
120 except Exception, why:
121 self.reportError( 'ERROR '+str(type(why)), id )
122
123 print "\navg time for last %i jobs: %f s" %\
124 ( len(jobs), (time.time()-startTime)/len(jobs))
125
126 return result
127
128
129 if __name__ == '__main__':
130
131 import sys
132
133 if len(sys.argv) == 2:
134
135 nice = int(sys.argv[1])
136 os.nice(nice)
137
138 slave = AmberEntropySlave()
139 slave.start()
140