Package Biskit :: Module AmberEntropySlave
[hide private]
[frames] | no frames]

Source Code for Module Biskit.AmberEntropySlave

  1  ## 
  2  ## Biskit, a toolkit for the manipulation of macromolecular structures 
  3  ## Copyright (C) 2004-2006 Raik Gruenberg & Johan Leckner 
  4  ## 
  5  ## This program is free software; you can redistribute it and/or 
  6  ## modify it under the terms of the GNU General Public License as 
  7  ## published by the Free Software Foundation; either version 2 of the 
  8  ## License, or any later version. 
  9  ## 
 10  ## This program is distributed in the hope that it will be useful, 
 11  ## but WITHOUT ANY WARRANTY; without even the implied warranty of 
 12  ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
 13  ## General Public License for more details. 
 14  ## 
 15  ## You find a copy of the GNU General Public License in the file 
 16  ## license.txt along with this program; if not, write to the Free 
 17  ## Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 
 18  ## 
 19  ## 
 20  ## $Revision: 2.7 $ 
 21  ## last $Date: 2007/03/05 10:28:21 $ 
 22  ## last $Author: graik $ 
 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   
38 -class AmberEntropySlave( JobSlave ):
39 """ 40 Collect AmberEntropist jobs from AmberEntropyMaster and return result. 41 """ 42
43 - def initialize(self, params):
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
55 - def reportError(self, msg, id ):
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
80 - def go(self, jobs):
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 ## free memory from previous run 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