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

Source Code for Module Biskit.PDBParseModel

  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  ## last $Author: graik $ 
 21  ## last $Date: 2006/12/17 00:00:25 $ 
 22  ## $Revision: 2.3 $ 
 23  """ 
 24  Parse a in-memory PDBModel instance into a new PDBModel 
 25   
 26  @see L{PDBModel} 
 27  @see L{PDBParserFactory} 
 28  """ 
 29  import Numeric as N 
 30   
 31  import Biskit.tools as T 
 32  import Biskit as B 
 33  from PDBParser import PDBParser, PDBParserError 
 34   
 35   
36 -class PDBParseModel( PDBParser ):
37 38 @staticmethod
39 - def supports( source ):
40 """ 41 The method is static and can thus be called directly with the parser 42 class rather than with an instance:: 43 44 >>> if ParsePDBModel.supports( model ): 45 >>> ... 46 47 @return: True if the given source is supported by this parser 48 implementation (equivalent to isinstance( source, PDBModel) ) 49 @rtype: bool 50 """ 51 return isinstance( source, B.PDBModel )
52 53 @staticmethod
54 - def description():
55 """ 56 The method is static and can thus be called directly with the parser 57 class rather than with an instance:: 58 59 >>> if ParsePDBModel.description(): 60 >>> ... 61 62 @return: short free text description of the supported format 63 @rtype: str 64 """ 65 return 'in-memory instances of PDBModel'
66 67
68 - def update( self, model, source, skipRes=None, lookHarder=0 ):
69 """ 70 Update empty or missing fields of model from the source. The 71 model will be connected to the source via model.source. 72 Override! 73 @param model: existing model 74 @type model: PDBModel 75 @param source: PDBModel object 76 @type source: str | file | PDBModel 77 @param skipRes: list residue names that should not be parsed 78 @type skipRes: [ str ] 79 """ 80 try: 81 ## atoms and/or coordinates need to be updated from PDB 82 if self.needsUpdate( model ): 83 84 s = source 85 86 model.fileName = model.fileName or s.fileName 87 88 model.pdbCode = model.pdbCode or s.pdbCode 89 90 model.atoms = model.atoms or s.getAtoms() 91 92 model.xyz = model.xyz or s.getXyz() 93 94 model.__terAtoms = getattr(model, '_PDBModel__terAtoms',[])or \ 95 getattr(s,'_PDBModel__terAtoms',[]) 96 97 model.rProfiles.updateMissing( s.rProfiles, 98 copyMissing=lookHarder) 99 model.aProfiles.updateMissing( s.aProfiles, 100 copyMissing=lookHarder) 101 102 if skipRes: 103 model.removeRes( skipRes ) 104 105 except B.ProfileError, why: 106 EHandler.warning("Cannot read/update profiles from source: %r"\ 107 %why) 108 109 model.setSource( source )
110
111 -class Test:
112 """ 113 Test class 114 """ 115
116 - def run( self, local=0 ):
117 """ 118 run function test 119 120 @param local: transfer local variables to global and perform 121 other tasks only when run locally 122 @type local: 1|0 123 124 @return: coordinates of center of mass 125 @rtype: array 126 """ 127 128 ## loading output file from X-plor 129 if local: 130 print 'Loading pdb file ..' 131 132 p = PDBParseModel() 133 m = p.parse2new( B.PDBModel(T.testRoot()+'/rec/1A2P.pdb') ) 134 135 if local: 136 globals().update( locals() ) 137 138 return N.sum( m.centerOfMass() )
139 140
141 - def expected_result( self ):
142 """ 143 Precalculated result to check for consistent performance. 144 145 @return: coordinates of center of mass 146 @rtype: array 147 """ 148 return N.sum( N.array([ 29.53385022, 46.39655482, 37.75218589]))
149 150 151 if __name__ == '__main__': 152 153 test = Test() 154 155 assert abs( test.run( local=1 ) - test.expected_result() ) < 1e-8 156