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):
196
197
198 - def set_vector(self, run=None, res=None, xh_vect=None):
199 """Function for setting the XH unit vectors."""
200
201
202 self.relax.data.res[run][res].xh_vect = xh_vect
203
204
206 """Function for calculating the XH unit vector from the loaded structure."""
207
208
209 if self.print_flag:
210 print "\nCalculating unit XH vectors.\n"
211
212
213 num_str = len(self.relax.data.pdb[self.run].structures)
214
215
216 for i in xrange(len(self.relax.data.res[self.run])):
217 self.relax.data.res[self.run][i].xh_vect = []
218
219
220 for i in xrange(num_str):
221
222 if self.print_flag:
223 print "\nStructure " + `i + 1` + "\n"
224
225
226 pdb_residues = self.relax.data.pdb[self.run].structures[i].peptide_chains[0].residues
227
228
229 for j in xrange(len(self.relax.data.res[self.run])):
230
231 pdb_res = None
232 for k in xrange(len(pdb_residues)):
233 if self.relax.data.res[self.run][j].num == pdb_residues[k].number:
234 pdb_res = pdb_residues[k]
235 break
236 if pdb_res == None:
237 raise RelaxNoResError, self.relax.data.res[self.run][j].num
238
239
240 if not pdb_res.atoms.has_key(self.proton):
241 if self.print_flag:
242 print "The proton atom " + `self.proton` + " could not be found for residue '" + `self.relax.data.res[self.run][j].num` + " " + self.relax.data.res[self.run][j].name + "'."
243 self.relax.data.res[self.run][j].xh_vect.append(None)
244
245
246 elif not pdb_res.atoms.has_key(self.heteronuc):
247 if self.print_flag:
248 print "The heteronucleus atom " + `self.heteronuc` + " could not be found for residue '" + `self.relax.data.res[self.run][j].num` + " " + self.relax.data.res[self.run][j].name + "'."
249 self.relax.data.res[self.run][j].xh_vect.append(None)
250
251
252 else:
253
254 posH = pdb_res.atoms[self.proton].position.array
255
256
257 posX = pdb_res.atoms[self.heteronuc].position.array
258
259
260 vector = posH - posX
261 self.relax.data.res[self.run][j].xh_vect.append(vector / sqrt(dot(vector, vector)))
262
263
264 if self.print_flag:
265 if num_str > 1:
266 print "\nCalculating and averaging the unit XH vectors from all structures."
267 else:
268 print "\nCalculating the unit XH vectors from the structure."
269
270
271 for i in xrange(len(self.relax.data.res[self.run])):
272
273 if self.relax.data.res[self.run][i].xh_vect[0] == None:
274 del self.relax.data.res[self.run][i].xh_vect
275 continue
276
277
278 ave_vector = zeros(3, Float64)
279
280
281 for j in xrange(num_str):
282
283 ave_vector = ave_vector + self.relax.data.res[self.run][i].xh_vect[j]
284
285
286 ave_vector = ave_vector / num_str
287
288
289 self.relax.data.res[self.run][i].xh_vect = ave_vector / sqrt(dot(ave_vector, ave_vector))
290