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

Source Code for Module Biskit.StructureSlave

  1  ## Convert PDB files to a pickled PDBModel object. 
  2  ## 
  3  ## Biskit, a toolkit for the manipulation of macromolecular structures 
  4  ## Copyright (C) 2004-2005 Raik Gruenberg & Johan Leckner 
  5  ## 
  6  ## This program is free software; you can redistribute it and/or 
  7  ## modify it under the terms of the GNU General Public License as 
  8  ## published by the Free Software Foundation; either version 2 of the 
  9  ## License, or any later version. 
 10  ## 
 11  ## This program is distributed in the hope that it will be useful, 
 12  ## but WITHOUT ANY WARRANTY; without even the implied warranty of 
 13  ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
 14  ## General Public License for more details. 
 15  ## 
 16  ## You find a copy of the GNU General Public License in the file 
 17  ## license.txt along with this program; if not, write to the Free 
 18  ## Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 
 19  ## 
 20  ## 
 21  ## $Revision: 2.4 $ 
 22  ## last $Date: 2006/12/22 14:27:30 $ 
 23  ## last $Author: graik $ 
 24  ## 
 25  ## required by pdbs2struct.py 
 26   
 27  """ 
 28  Convert a PDB file to a pickled PDBModel object. 
 29  """ 
 30       
 31  from PDBModel import PDBModel 
 32  import tools as T 
 33   
 34  ## PVM imports 
 35  from Biskit.PVM import JobSlave 
 36   
 37   
38 -class StructureSlave(JobSlave):
39 """ 40 Convert a PDB file to a pickled PDBModel object. 41 """ 42
43 - def initialize(self, params):
44 """ 45 Copy the parameters that Master is passing in as dict into 46 fields of this class. 47 48 @param params: defined in Master 49 @type params: dict 50 """ 51 self.params = params
52 53
54 - def renameAmberRes( self, model ):
55 """ 56 Rename special residues (from Amber) back into standard 57 names (i.e CYX S{->} CYS). 58 59 @param model: model 60 @type model: PDBModel 61 """ 62 for a in model.getAtoms(): 63 if a['residue_name'] == 'CYX': 64 a['residue_name'] = 'CYS' 65 if a['residue_name'] in ['HIE','HID','HIP']: 66 a['residue_name'] = 'HIS'
67 68
69 - def renameToAmberAtoms( self, model ):
70 """ 71 ptraj puts last letter/number of 4-letter atom names first. Undo. 72 73 @param model: model 74 @type model: PDBModel 75 76 @note: could be avoided if ptraj would be told: 77 trajout |file| pdb nowrap 78 """ 79 numbers = map( str, range(10) ) 80 81 for a in model.getAtoms(): 82 if len(a['name'])==4 and a['name'][0] in numbers: 83 a['name'] = a['name'][1:] + a['name'][0]
84 85
86 - def go(self, dict):
87 """ 88 Calculate rmsd values for trajectory and plot them. 89 90 @param dict: dictionary with path to pdb files as keys 91 @type dict: dict 92 93 @return: dictionary mapping input:output names 94 @rtype: dict 95 """ 96 d = {} 97 98 print "working on :", 99 for pdbIn, out in dict.items(): 100 101 print T.stripFilename( pdbIn ) 102 103 ## set file name for pickled Structure object 104 dir = os.path.dirname( pdbIn ) 105 if self.params['out'] <> None: 106 dir = self.params['out'] 107 108 out = dir + '/' + T.stripFilename( pdbIn) + '.model' 109 110 try: 111 m = PDBModel( pdbIn, skipRes=self.params['skipRes'] ) 112 113 if self.params['amber']: 114 self.renameAmberRes( m ) 115 self.renameToAmberAtoms( m ) 116 117 if self.params['sort']: 118 m = m.sort() 119 120 m.saveAs( out ) 121 122 except: 123 if self.params.has_key('report') and self.params['report']: 124 f = open( out[:-6] + '.error', 'w' ) 125 f.write( T.lastError() ) 126 f.close() 127 else: 128 T.errWriteln("Error" + T.lastError() ) 129 130 131 out = '' 132 133 d[pdbIn] = out 134 135 print "Done." 136 return d
137 138 if __name__ == '__main__': 139 140 import os, sys 141 142 if len(sys.argv) == 2: 143 144 niceness = int(sys.argv[1]) 145 os.nice(niceness) 146 147 slave = StructureSlave() 148 slave.start() 149