1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 from math import sqrt
24 from Numeric import Float64, dot, zeros
25 from os import F_OK, access
26 import Scientific.IO.PDB
27
28
31 """Class containing the PDB related functions."""
32
33 self.relax = relax
34
35
36 self.print_flag = 1
37
38
40 """Function for loading the structures from the PDB file."""
41
42
43 for run in self.relax.data.run_names:
44 if self.relax.data.pdb.has_key(run) and hasattr(self.relax.data.pdb[run], 'structures') and self.relax.data.pdb[run].file_name == self.file and self.relax.data.pdb[run].model == self.model:
45
46 self.relax.data.pdb[self.run].structures = self.relax.data.pdb[run].structures
47
48
49 if self.print_flag:
50 print "Using the structures from the run " + `run` + "."
51 for i in xrange(len(self.relax.data.pdb[self.run].structures)):
52 print self.relax.data.pdb[self.run].structures[i]
53
54
55 return
56
57
58 self.relax.data.pdb[self.run].structures = []
59
60
61 if type(self.model) == int:
62
63 if self.print_flag:
64 print "Loading structure " + `self.model` + " from the PDB file."
65
66
67 str = Scientific.IO.PDB.Structure(self.file_path, self.model)
68
69
70 if len(str) == 0:
71 raise RelaxPdbLoadError, self.file_path
72
73
74 if self.print_flag:
75 print str
76
77
78 self.relax.data.pdb[self.run].structures.append(str)
79
80
81
82 else:
83
84 if self.print_flag:
85 print "Loading all structures from the PDB file."
86
87
88 i = 1
89
90
91 while 1:
92
93 str = Scientific.IO.PDB.Structure(self.file_path, i)
94
95
96 if len(str) == 0 and i == 1:
97 str = Scientific.IO.PDB.Structure(self.file_path)
98 if len(str) == 0:
99 raise RelaxPdbLoadError, self.file_path
100
101
102 if len(str) == 0:
103 del str
104 break
105
106
107 if self.print_flag:
108 print str
109
110
111 self.relax.data.pdb[self.run].structures.append(str)
112
113
114 i = i + 1
115
116
117 - def load(self, run=None, file=None, dir=None, model=None, heteronuc=None, proton=None, load_seq=1, calc_vectors=1, fail=1, print_flag=1):
199
200
201 - def set_vector(self, run=None, res=None, xh_vect=None):
202 """Function for setting the XH unit vectors."""
203
204
205 self.relax.data.res[run][res].xh_vect = xh_vect
206
207
209 """Function for calculating the XH unit vector from the loaded structure."""
210
211
212 if self.print_flag:
213 print "\nCalculating unit XH vectors.\n"
214
215
216 num_str = len(self.relax.data.pdb[self.run].structures)
217
218
219 for i in xrange(len(self.relax.data.res[self.run])):
220 self.relax.data.res[self.run][i].xh_vect = []
221
222
223 for i in xrange(num_str):
224
225 if self.print_flag:
226 print "\nStructure " + `i + 1` + "\n"
227
228
229 if self.relax.data.pdb[self.run].structures[i].peptide_chains:
230 pdb_residues = self.relax.data.pdb[self.run].structures[i].peptide_chains[0].residues
231 elif self.relax.data.pdb[self.run].structures[i].nucleotide_chains:
232 pdb_residues = self.relax.data.pdb[self.run].structures[i].nucleotide_chains[0].residues
233 else:
234 raise RelaxNoPdbChainError
235
236
237 for j in xrange(len(self.relax.data.res[self.run])):
238
239 pdb_res = None
240 for k in xrange(len(pdb_residues)):
241 if self.relax.data.res[self.run][j].num == pdb_residues[k].number:
242 pdb_res = pdb_residues[k]
243 break
244 if pdb_res == None:
245 raise RelaxNoResError, self.relax.data.res[self.run][j].num
246
247
248 if not pdb_res.atoms.has_key(self.proton):
249 warn(RelaxNoAtomWarning(self.proton, self.relax.data.res[self.run][j].num))
250 self.relax.data.res[self.run][j].xh_vect.append(None)
251
252
253 elif not pdb_res.atoms.has_key(self.heteronuc):
254 warn(RelaxNoAtomWarning(self.heteronuc, self.relax.data.res[self.run][j].num))
255 self.relax.data.res[self.run][j].xh_vect.append(None)
256
257
258 else:
259
260 posH = pdb_res.atoms[self.proton].position.array
261
262
263 posX = pdb_res.atoms[self.heteronuc].position.array
264
265
266 vector = posH - posX
267
268
269 norm_factor = sqrt(dot(vector, vector))
270
271
272 if norm_factor == 0.0:
273 if self.print_flag:
274 print "The XH bond vector for residue " + `self.relax.data.res[self.run][j].num` + " is of zero length."
275 self.relax.data.res[self.run][j].xh_vect.append(None)
276
277
278 else:
279 self.relax.data.res[self.run][j].xh_vect.append(vector / norm_factor)
280
281
282 if self.print_flag:
283 if num_str > 1:
284 print "\nCalculating and averaging the unit XH vectors from all structures."
285 else:
286 print "\nCalculating the unit XH vectors from the structure."
287
288
289 for i in xrange(len(self.relax.data.res[self.run])):
290
291 if self.relax.data.res[self.run][i].xh_vect[0] == None:
292 del self.relax.data.res[self.run][i].xh_vect
293 self.relax.data.res[self.run][i].select = 0
294 continue
295
296
297 ave_vector = zeros(3, Float64)
298
299
300 for j in xrange(num_str):
301
302 ave_vector = ave_vector + self.relax.data.res[self.run][i].xh_vect[j]
303
304
305 ave_vector = ave_vector / num_str
306
307
308 self.relax.data.res[self.run][i].xh_vect = ave_vector / sqrt(dot(ave_vector, ave_vector))
309