1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
37
38 @staticmethod
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
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
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
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
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
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