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

Source Code for Module Biskit.PDBParser

  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:30:05 $ 
 22  ## $Revision: 2.2 $ 
 23  """ 
 24  Parse a certain file / memory object into a PDBModel. 
 25   
 26  This module provides helper classes for L{Biskit.PDBModel}. In most 
 27  cases, it should not be necessary to use it directly. 
 28   
 29  @see L{Biskit.PDBModel} 
 30  @see L{Biskit.PDBParserFactory} 
 31  @see L{Biskit.PDBParseFile} 
 32  @see L{Biskit.PDBParseModel} 
 33  @see L{Biskit.PDBParsePickle} 
 34  """ 
 35  from Biskit import StdLog, ErrLog 
 36  import Biskit as B 
 37   
38 -class PDBParserError( Exception ):
39 """Error while parsing a structure file or object""" 40 pass
41
42 -class PDBParser(object):
43 """ 44 **Abstract** base class for parsers that generate PDBModel objects from 45 different source formats. 46 """ 47
48 - def __init__( self, log=None ):
49 """ 50 @param log: Log for warnings [default log to STDERR] 51 @type log: Biskit.LogFile.LogFile 52 53 Override if needed. Call parent method in overriding class! 54 """ 55 self.log = log or ErrLog()
56 57 58 @staticmethod
59 - def supports( source ):
60 """ 61 Override! 62 63 The method is static and can thus be called directly with the parser 64 class rather than with an instance:: 65 66 >>> if PDBParser.supports('myfile.pdb'): 67 >>> ... 68 69 @return: True if the given source is supported by this parser 70 implementation 71 @rtype: bool 72 """ 73 raise NotImplementedError, 'issupported() is not implemented.'
74 75 76 @staticmethod
77 - def description():
78 """ 79 Override! 80 81 The method is static and can thus be called directly with the parser 82 class rather than with an instance:: 83 84 >>> if PDBParser.description('myfile.pdb'): 85 >>> ... 86 87 @return: short free text description of the supported format 88 @rtype: str 89 """ 90 raise NotImplementedError, 'description() is not implemented.'
91 92
93 - def update( self, model, source, skipRes=None, lookHarder=0 ):
94 """ 95 Update empty or missing fields of model from the source. The 96 model will be connected to the source via model.source. 97 Override! 98 99 @param model: existing model 100 @type model: PDBModel 101 @param source: source PDB file or pickled PDBModel or PDBModel object 102 @type source: str || file || PDBModel 103 @param skipRes: list residue names that should not be parsed 104 @type skipRes: [ str ] 105 @param lookHarder: check source for additional profiles that are not 106 yet known for the model [False] 107 @type lookHarder: 1 || 0 108 """ 109 raise NotImplementedError, 'update() is not implemented.'
110 111
112 - def needsUpdate( self, model ):
113 """ 114 This function is called by update() to decide whether or not to open 115 the source. 116 Override if needed. 117 118 @param model: model 119 @type model: PDBModel 120 @return: true, if the model needs to be updated from its source 121 @rtype: bool 122 """ 123 return (model.atoms is None or model.xyz is None)
124 125
126 - def parse2new( self, source, disconnect=False, skipRes=None ):
127 """ 128 Create a new PDBModel from the source. 129 130 @param source: source PDB file or pickled PDBModel or PDBModel object 131 @type source: str || file || PDBModel 132 @param disconnect: do *not* associate new model with the source [False] 133 @type disconnect: bool 134 @param skipRes: list residues that should not be parsed 135 @type skipRes: [ str ] 136 137 @return: new model (always of type PDBModel, regardless of source type) 138 @rtype: PDBModel 139 """ 140 m = B.PDBModel() 141 self.update( m, source, skipRes=skipRes) 142 143 if disconnect: m.disconnect() 144 145 return m
146