1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 """Functions for interfacing with Michael Bieri's NESSY program."""
25
26
27 from os import getcwd
28
29
30 from lib.errors import RelaxError, RelaxNoSequenceError
31 from lib.float import isNaN
32 from lib.io import mkdir_nofail, open_write_file
33 from lib.periodic_table import periodic_table
34 from pipe_control.pipes import check_pipe
35 from pipe_control.spectrometer import get_frequencies
36 from pipe_control.mol_res_spin import exists_mol_res_spin_data, spin_loop
37 from specific_analyses.relax_disp.data import find_intensity_keys, loop_exp_frq_offset, loop_exp_frq_point_time, loop_point
38
39
83
84
86 """Create the NESSY CPMG datasets.
87
88 @keyword file: The file object to write to.
89 @type file: file object
90 @keyword data: The NESSY data object.
91 @type data: Nessy_data instance
92 @keyword ei: The index of the experiment to output.
93 @type ei: int
94 """
95
96
97 for i in range(30):
98
99 file.write("Datasets:<>%s<>%i<>%s\n" % (ei, i+1, data.cpmg_data[ei][i]))
100
101
103 """Create the NESSY experimental setup entries.
104
105 @keyword file: The file object to write to.
106 @type file: file object
107 @keyword data: The NESSY data object.
108 @type data: Nessy_data instance
109 @keyword ei: The index of the experiment to output.
110 @type ei: int
111 """
112
113
114 file.write("CPMG relaxation delay:<>%s<>%s\n" % (ei, data.cpmg_delay[ei]))
115
116
117 file.write("HD Exchange:<>%s<>%s\n" % (ei, data.hd_exchange[ei]))
118
119
120 file.write("Experiment:<>%s<>%s\n" % (ei, data.experiment[ei]))
121
122
123 file.write("CPMG frequencies:<>%s<>%s\n" % (ei, data.cpmg_frqs[ei]))
124
125
126 file.write("Spin Lock / Offset:<>%s<>%s\n" % (ei, data.spin_lock[ei]))
127
128
130 """Create the NESSY setup entries at the start of the file.
131
132 @keyword file: The file object to write to.
133 @type file: file object
134 @keyword dir: The optional directory to place the files into. If None, then the files will be placed into the current directory.
135 @type dir: str or None
136 @keyword data: The NESSY data object.
137 @type data: Nessy_data instance
138 """
139
140
141 file.write("NESSY save file<><>\n")
142
143
144 file.write("Settings:<>['AICc', '500', '30', '2.0', '50.0', '0', '40']\n")
145 file.write("Models:<>[1, 1, 1, 0, 0, 0, 0]\n")
146 file.write("Fitting accuracy:<>1.49012e-20\n")
147
148
149 if dir == None:
150 dir = getcwd()
151 file.write("Project folder:<>%s\n" % dir)
152
153
154 file.write("CPMG delay:<>%s\n" % data.cpmg_delay)
155 file.write("HD noise:<>%s\n" % data.hd_noise)
156 file.write("Shift difference:<>%s\n" % data.shift_diff)
157 file.write("Spec freq:<>%s\n" % data.spec_frq)
158 file.write("B0:<>%s\n" % data.B0)
159 file.write("PDB file:<>%s\n" % data.pdb_file)
160 file.write("Number of experiments:<>%s\n" % data.num_exp)
161
162
163 file.write("Results:<>Plot<>[]\n")
164 file.write("Results:<>Model1<>[]\n")
165 file.write("Results:<>Model2<>[]\n")
166 file.write("Results:<>Model3<>[]\n")
167 file.write("Results:<>Model4<>[]\n")
168 file.write("Results:<>Model5<>[]\n")
169 file.write("Results:<>Model6<>[]\n")
170 file.write("Results:<>Final<>[]\n")
171 file.write("Results:<>ColorCode<>[]\n")
172 file.write("Results:<>Textfiles:<>[]\n")
173 file.write("Results:<>2D Plots:<>[]\n")
174 file.write("Results:<>3D Plots:<>[]\n")
175 file.write("Results:<>Intensities:<>[]\n")
176 file.write("Final Results:<>[]\n")
177
178
180 """Create the NESSY sequence entry.
181
182 @keyword file: The file object to write to.
183 @type file: file object
184 @keyword data: The NESSY data object.
185 @type data: Nessy_data instance
186 @keyword ei: The index of the experiment to output.
187 @type ei: int
188 """
189
190
191 file.write("Sequence:<>%s<>%s\n" % (ei, data.sequence))
192
193
195 """Create the NESSY R1rho datasets.
196
197 @keyword file: The file object to write to.
198 @type file: file object
199 @keyword data: The NESSY data object.
200 @type data: Nessy_data instance
201 @keyword ei: The index of the experiment to output.
202 @type ei: int
203 """
204
205
206 for i in range(30):
207
208 for j in range(30):
209
210 file.write("Datasets Spinlock:<>%s<>%s<>%s<>%s\n" % (ei, i+1, j+1, data.r1rho_data[ei][i][j]))
211
212
213
216 """Create the NESSY data object container.
217
218 @keyword spin_id: The spin ID string to restrict data to.
219 @type spin_id: str
220 """
221
222
223 if len(cdp.relax_time_list) != 1:
224 raise RelaxError("NESSY only supports the fixed time relaxation dispersion experiments.")
225
226
227 self.num_exp = 1
228 if hasattr(cdp, 'spectrometer_frq_count'):
229 self.num_exp = cdp.spectrometer_frq_count
230
231
232 self.cpmg_delay = ['0.04'] * self.num_exp
233 self.hd_noise = ['1000'] * self.num_exp
234 self.shift_diff = [None] * 700
235 self.spec_frq = ['60.77'] * self.num_exp
236 self.B0 = ['14.1'] * self.num_exp
237 self.pdb_file = ''
238 self.sequence = [''] * 700
239 self.cpmg_data = []
240 self.r1rho_data = []
241 self.hd_exchange = []
242 self.experiment = []
243 self.cpmg_frqs = []
244 self.spin_lock = []
245 for ei in range(self.num_exp):
246 self.cpmg_data.append([])
247 self.r1rho_data.append([])
248 self.hd_exchange.append([''] * 30)
249 self.experiment.append('cpmg')
250 self.cpmg_frqs.append([''] * 30)
251 self.spin_lock.append([''] * 31)
252 for i in range(30):
253 self.cpmg_data[ei].append([''] * 700)
254 self.r1rho_data[ei].append([])
255 for j in range(30):
256 self.r1rho_data[ei][-1].append([''] * 700)
257
258
259 self._assemble_experiment()
260 self._assemble_cpmg_data(spin_id=spin_id)
261
262
264 """Assemble the CPMG data.
265
266 @keyword spin_id: The spin ID string to restrict data to.
267 @type spin_id: str
268 """
269
270
271 for spin, mol_name, res_num, res_name, id in spin_loop(full_info=True, selection=spin_id, return_id=True, skip_desel=True):
272
273 res_index = res_num - 1
274
275
276 if res_index < 0:
277 raise RelaxError("A residue number of less than 1 is not supported in NESSY.")
278 elif res_index > 699:
279 raise RelaxError("A residue number of greater than 700 is not supported in NESSY.")
280
281
282 for exp_type, frq, offset, ei, mi, oi in loop_exp_frq_offset(return_indices=True):
283
284 di_new = 0
285 for point, di in loop_point(exp_type=exp_type, frq=frq, offset=offset, skip_ref=False, return_indices=True):
286
287 keys = find_intensity_keys(exp_type=exp_type, frq=frq, point=point, time=cdp.relax_time_list[0])
288
289
290 if point == None or isNaN(point):
291 point = 0
292
293
294 for key in keys:
295
296 if self.cpmg_data[mi][di_new][res_index] != '':
297 raise RelaxError("Only one spin system per residue is supported in NESSY.")
298
299
300 if key in spin.peak_intensity:
301 self.cpmg_data[mi][di_new][res_index] = str(spin.peak_intensity[key])
302
303
304 self.cpmg_frqs[mi][di_new] = str(point)
305
306
307 di_new += 1
308
309
327