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

Source Code for Module Biskit.StructureMaster

  1  ## 
  2  ## Biskit, a toolkit for the manipulation of macromolecular structures 
  3  ## Copyright (C) 2004-2005 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  ## 
 21  ## last $Author: leckner $ 
 22  ## last $Date: 2006/12/21 09:33:09 $ 
 23  ## $Revision: 1.5 $ 
 24   
 25  """ 
 26  Parallizes the convertion of PDB files into pickled PDBModel objects. 
 27  """ 
 28   
 29  import Biskit.hosts as hosts 
 30  import Biskit.tools as T 
 31  ## from Biskit.PVM.TrackingJobMaster import TrackingJobMaster 
 32  from Biskit.PVM import TrackingJobMaster 
 33   
 34   
35 -class StructMaster(TrackingJobMaster):
36
37 - def __init__(self, dat, chunk, hosts, outFolder, skipWat=0, amber=0, 38 sort=0, add_hosts=1, **kw):
39 """ 40 @param dat: data dictionary 41 @type dat: dict 42 @param chunk: chunk size passed to slave 43 @type chunk: int 44 @param hosts: list of host-names 45 @type hosts: [str] 46 @param outFolder: alternative output folder 47 @type outFolder: str 48 """ 49 niceness = {'default': 0} 50 slave_script = T.projectRoot() + '/Biskit/StructureSlave.py' 51 52 TrackingJobMaster.__init__(self, dat, chunk, hosts, niceness, 53 slave_script, **kw) 54 55 self.options = {} 56 self.options['out'] = outFolder 57 58 self.options['skipRes'] = None 59 if skipWat: 60 self.options['skipRes'] = ['WAT','TIP3','H2O','WWW','Na+','Cl-'] 61 62 if kw.has_key('show_output'): 63 self.options['report'] = not kw['show_output'] 64 65 self.options['amber'] = amber 66 67 self.options['sort'] = sort
68 69
70 - def getInitParameters(self, slave_tid):
71 """ 72 hand over parameters to slave once. 73 74 @param slave_tid: slave task id 75 @type slave_tid: int 76 77 @return: dictionary with init parameters 78 @rtype: {param:value} 79 """ 80 return self.options
81 82
83 - def done(self):
84 85 self.exit()
86 87 88 89 ############# 90 ## TESTING 91 ############# 92
93 -class Test:
94 """ 95 Test class 96 """ 97
98 - def run( self, local=0 ):
99 """ 100 run function test 101 102 @param local: transfer local variables to global and perform 103 other tasks only when run locally 104 @type local: 1|0 105 106 @return: 1 107 @rtype: int 108 """ 109 import tempfile 110 out_folder = tempfile.mkdtemp( '_test_StructureMaster' ) 111 112 pdbs = {T.testRoot() + '/lig/1A19.pdb':'', 113 T.testRoot() + '/rec/1A2P.pdb':'', 114 T.testRoot() + '/com/1BGS.pdb':''} 115 116 master = StructMaster( pdbs, 117 2, 118 hosts=hosts.cpus_all, 119 outFolder=out_folder, 120 show_output=local, 121 verbose=local, 122 add_hosts=1 ) 123 124 ## run and wait for result 125 r = master.calculateResult() 126 127 if local: 128 print 'The converted pdb files has been written to %s'%out_folder 129 globals().update( locals() ) 130 131 ## cleanup 132 T.tryRemove( out_folder, tree=1 ) 133 134 return 1
135 136
137 - def expected_result( self ):
138 """ 139 Precalculated result to check for consistent performance. 140 141 @return: 1 142 @rtype: int 143 """ 144 return 1
145 146 147 if __name__ == '__main__': 148 149 test = Test() 150 151 assert test.run( local=1 ) == test.expected_result() 152