Module common_ops
[hide private]
[frames] | no frames]

Source Code for Module common_ops

  1  from re import match 
  2  from string import split 
  3  import sys 
  4   
  5   
6 -class common_operations:
7 - def __init__(self):
8 "Operations, functions, etc common to the different model-free analysis methods."
9 10
11 - def ask_stage(self):
12 "User input of stage number." 13 14 print "\n[ Select the stage for model-free analysis ]\n" 15 print "The stages are:" 16 print " Stage 1 (1): Creation of the files for the model-free calculations for models 1 to 5." 17 print " Stage 2 (2): Model selection and creation of a final run." 18 print " Stage 3 (3): Extraction of the data." 19 20 while 1: 21 input = raw_input('> ') 22 valid_stages = ['1', '2', '3'] 23 if input in valid_stages: 24 stage = input 25 break 26 else: 27 print "Invalid stage number. Choose either 1, 2, or 3." 28 if match('2', stage): 29 while 1: 30 print "Stage 2 has the following two options for the final run:" 31 print " (a): No optimization of the diffusion tensor." 32 print " (b): Optimization of the diffusion tensor." 33 input = raw_input('> ') 34 valid_stages = ['a', 'b'] 35 if input in valid_stages: 36 stage = stage + input 37 break 38 else: 39 print "Invalid option, choose either a or b." 40 41 print "The stage chosen is " + stage + "\n" 42 return stage
43 44
45 - def create_mfdata(self, res, flag='1'):
46 "Create the Modelfree input file mfdata" 47 48 mfdata = self.mf.mfdata 49 50 mfdata.write("\nspin " + self.mf.data.relax_data[0][res][1] + "_" + self.mf.data.relax_data[0][res][0] + "\n") 51 k = 0 52 for i in range(len(self.mf.data.nmr_frq)): 53 for j in range(3): 54 if match('1', self.mf.data.nmr_frq[i][j+2]): 55 mfdata.write('%-7s' % self.mf.data.input_info[k][0]) 56 mfdata.write('%-10s' % self.mf.data.input_info[k][1]) 57 mfdata.write('%10s' % self.mf.data.relax_data[k][res][2]) 58 mfdata.write('%10s' % self.mf.data.relax_data[k][res][3]) 59 mfdata.write(' %-3s\n' % flag) 60 k = k + 1 61 else: 62 if j == 0: 63 mfdata.write('%-7s' % 'R1') 64 if j == 1: 65 mfdata.write('%-7s' % 'R2') 66 if j == 2: 67 mfdata.write('%-7s' % 'NOE') 68 mfdata.write('%-10s' % self.mf.data.nmr_frq[i][0]) 69 mfdata.write('%10s' % '0.000') 70 mfdata.write('%10s' % '0.000') 71 mfdata.write(' %-3s\n' % '0')
72 73
74 - def create_mfin(self, sel='none', algorithm='fix', diffusion_search='none', sims='n', sim_type='pred'):
75 "Create the Modelfree input file mfin" 76 77 mfin = self.mf.mfin 78 79 mfin.write("optimization tval\n\n") 80 mfin.write("seed 0\n\n") 81 mfin.write("search grid\n\n") 82 mfin.write("diffusion " + self.mf.data.usr_param.diff + " " + diffusion_search + "\n\n") 83 mfin.write("algorithm " + algorithm + "\n\n") 84 if match('y', sims): 85 mfin.write("simulations " + sim_type + " " + self.mf.data.usr_param.no_sim) 86 mfin.write(" " + self.mf.data.usr_param.trim + "\n\n") 87 elif match('n', sims): 88 mfin.write("simulations none\n\n") 89 mfin.write("selection " + sel + "\n\n") 90 mfin.write("sim_algorithm " + algorithm + "\n\n") 91 mfin.write("fields " + `len(self.mf.data.nmr_frq)`) 92 for frq in range(len(self.mf.data.nmr_frq)): 93 mfin.write(" " + self.mf.data.nmr_frq[frq][0]) 94 mfin.write("\n") 95 # tm. 96 mfin.write('%-7s' % 'tm') 97 mfin.write('%14s' % self.mf.data.usr_param.tm['val']) 98 mfin.write('%2s' % self.mf.data.usr_param.tm['flag']) 99 mfin.write('%3s' % self.mf.data.usr_param.tm['bound']) 100 mfin.write('%5s' % self.mf.data.usr_param.tm['lower']) 101 mfin.write('%6s' % self.mf.data.usr_param.tm['upper']) 102 mfin.write('%4s\n' % self.mf.data.usr_param.tm['steps']) 103 # dratio. 104 mfin.write('%-7s' % 'Dratio') 105 mfin.write('%14s' % self.mf.data.usr_param.dratio['val']) 106 mfin.write('%2s' % self.mf.data.usr_param.dratio['flag']) 107 mfin.write('%3s' % self.mf.data.usr_param.dratio['bound']) 108 mfin.write('%5s' % self.mf.data.usr_param.dratio['lower']) 109 mfin.write('%6s' % self.mf.data.usr_param.dratio['upper']) 110 mfin.write('%4s\n' % self.mf.data.usr_param.dratio['steps']) 111 # theta. 112 mfin.write('%-7s' % 'Theta') 113 mfin.write('%14s' % self.mf.data.usr_param.theta['val']) 114 mfin.write('%2s' % self.mf.data.usr_param.theta['flag']) 115 mfin.write('%3s' % self.mf.data.usr_param.theta['bound']) 116 mfin.write('%5s' % self.mf.data.usr_param.theta['lower']) 117 mfin.write('%6s' % self.mf.data.usr_param.theta['upper']) 118 mfin.write('%4s\n' % self.mf.data.usr_param.theta['steps']) 119 # phi. 120 mfin.write('%-7s' % 'Phi') 121 mfin.write('%14s' % self.mf.data.usr_param.phi['val']) 122 mfin.write('%2s' % self.mf.data.usr_param.phi['flag']) 123 mfin.write('%3s' % self.mf.data.usr_param.phi['bound']) 124 mfin.write('%5s' % self.mf.data.usr_param.phi['lower']) 125 mfin.write('%6s' % self.mf.data.usr_param.phi['upper']) 126 mfin.write('%4s\n' % self.mf.data.usr_param.phi['steps'])
127 128
129 - def create_mfmodel(self, res, md, type='M1'):
130 "Create the M1 or M2 section of the Modelfree input file mfmodel" 131 132 mfmodel = self.mf.mfmodel 133 134 if match('M1', type): 135 mfmodel.write("\nspin " + self.mf.data.relax_data[0][res][1] + "_" + self.mf.data.relax_data[0][res][0] + "\n") 136 else: 137 mfmodel.write("\n") 138 139 # tloc. 140 mfmodel.write('%-3s' % type) 141 mfmodel.write('%-6s' % 'tloc') 142 mfmodel.write('%-6s' % md['tloc']['start']) 143 mfmodel.write('%-4s' % md['tloc']['flag']) 144 mfmodel.write('%-2s' % md['tloc']['bound']) 145 mfmodel.write('%11s' % md['tloc']['lower']) 146 mfmodel.write('%12s' % md['tloc']['upper']) 147 mfmodel.write(' %-4s\n' % md['tloc']['steps']) 148 # Theta. 149 mfmodel.write('%-3s' % type) 150 mfmodel.write('%-6s' % 'Theta') 151 mfmodel.write('%-6s' % md['theta']['start']) 152 mfmodel.write('%-4s' % md['theta']['flag']) 153 mfmodel.write('%-2s' % md['theta']['bound']) 154 mfmodel.write('%11s' % md['theta']['lower']) 155 mfmodel.write('%12s' % md['theta']['upper']) 156 mfmodel.write(' %-4s\n' % md['theta']['steps']) 157 # S2f. 158 mfmodel.write('%-3s' % type) 159 mfmodel.write('%-6s' % 'Sf2') 160 mfmodel.write('%-6s' % md['sf2']['start']) 161 mfmodel.write('%-4s' % md['sf2']['flag']) 162 mfmodel.write('%-2s' % md['sf2']['bound']) 163 mfmodel.write('%11s' % md['sf2']['lower']) 164 mfmodel.write('%12s' % md['sf2']['upper']) 165 mfmodel.write(' %-4s\n' % md['sf2']['steps']) 166 # S2s. 167 mfmodel.write('%-3s' % type) 168 mfmodel.write('%-6s' % 'Ss2') 169 mfmodel.write('%-6s' % md['ss2']['start']) 170 mfmodel.write('%-4s' % md['ss2']['flag']) 171 mfmodel.write('%-2s' % md['ss2']['bound']) 172 mfmodel.write('%11s' % md['ss2']['lower']) 173 mfmodel.write('%12s' % md['ss2']['upper']) 174 mfmodel.write(' %-4s\n' % md['ss2']['steps']) 175 # te. 176 mfmodel.write('%-3s' % type) 177 mfmodel.write('%-6s' % 'te') 178 mfmodel.write('%-6s' % md['te']['start']) 179 mfmodel.write('%-4s' % md['te']['flag']) 180 mfmodel.write('%-2s' % md['te']['bound']) 181 mfmodel.write('%11s' % md['te']['lower']) 182 mfmodel.write('%12s' % md['te']['upper']) 183 mfmodel.write(' %-4s\n' % md['te']['steps']) 184 # Rex. 185 mfmodel.write('%-3s' % type) 186 mfmodel.write('%-6s' % 'Rex') 187 mfmodel.write('%-6s' % md['rex']['start']) 188 mfmodel.write('%-4s' % md['rex']['flag']) 189 mfmodel.write('%-2s' % md['rex']['bound']) 190 mfmodel.write('%11s' % md['rex']['lower']) 191 mfmodel.write('%12s' % md['rex']['upper']) 192 mfmodel.write(' %-4s\n' % md['rex']['steps'])
193 194
195 - def create_mfpar(self, res):
196 "Create the Modelfree input file mfpar" 197 198 mfpar = self.mf.mfpar 199 200 mfpar.write("\nspin " + self.mf.data.relax_data[0][res][1] + "_" + self.mf.data.relax_data[0][res][0] + "\n") 201 202 mfpar.write('%-14s' % "constants") 203 mfpar.write('%-6s' % self.mf.data.relax_data[0][res][0]) 204 mfpar.write('%-7s' % self.mf.data.usr_param.const['nucleus']) 205 mfpar.write('%-8s' % self.mf.data.usr_param.const['gamma']) 206 mfpar.write('%-8s' % self.mf.data.usr_param.const['rxh']) 207 mfpar.write('%-8s\n' % self.mf.data.usr_param.const['csa']) 208 209 mfpar.write('%-10s' % "vector") 210 mfpar.write('%-4s' % self.mf.data.usr_param.vector['atom1']) 211 mfpar.write('%-4s\n' % self.mf.data.usr_param.vector['atom2'])
212 213
214 - def create_run(self, dir):
215 "Create the file 'run' to execute the model-free run" 216 217 text = "modelfree4 -i mfin -d mfdata -p mfpar -m mfmodel -o mfout -e out" 218 if self.mf.data.usr_param.diff == 'axial': 219 # Copy the pdb file to the model directory so there are no problems with the *.rotate 220 # file already existing. 221 copy(self.mf.data.usr_param.pdb_full, dir) 222 text = text + " -s " + self.mf.data.usr_param.pdb_file 223 text = text + "\n" 224 self.mf.run.write(text)
225 226
227 - def extract_input(self, input):
228 "Extract all the information from the input file." 229 230 lines = input.readlines() 231 frq = 0 232 num_data = 0 233 for i in range(len(lines)): 234 row = [[]] 235 row[0] = split(lines[i]) 236 try: 237 row[0][0] 238 except IndexError: 239 continue 240 if match('NMR_frq_label', row[0][0]): 241 self.mf.data.nmr_frq.append([]) 242 row.append(split(lines[i+1])) 243 row.append(split(lines[i+2])) 244 row.append(split(lines[i+3])) 245 row.append(split(lines[i+4])) 246 # NMR data. 247 self.mf.data.nmr_frq[frq].append(row[0][1]) 248 self.mf.data.nmr_frq[frq].append(row[1][1]) 249 # R1 data. 250 if not match('none', row[2][1]): 251 self.mf.data.nmr_frq[frq].append('1') 252 self.mf.data.input_info.append([]) 253 self.mf.data.relax_data.append([]) 254 self.mf.data.input_info[num_data].append("R1") 255 self.mf.data.input_info[num_data].append(row[0][1]) 256 self.mf.data.input_info[num_data].append(float(row[1][1])) 257 self.mf.data.input_info[num_data].append(row[2][1]) 258 num_data = num_data + 1 259 else: 260 self.mf.data.nmr_frq[frq].append('0') 261 # R2 data. 262 if not match('none', row[3][1]): 263 self.mf.data.nmr_frq[frq].append('1') 264 self.mf.data.input_info.append([]) 265 self.mf.data.relax_data.append([]) 266 self.mf.data.input_info[num_data].append("R2") 267 self.mf.data.input_info[num_data].append(row[0][1]) 268 self.mf.data.input_info[num_data].append(float(row[1][1])) 269 self.mf.data.input_info[num_data].append(row[3][1]) 270 num_data = num_data + 1 271 else: 272 self.mf.data.nmr_frq[frq].append('0') 273 # NOE data. 274 if not match('none', row[4][1]): 275 self.mf.data.nmr_frq[frq].append('1') 276 self.mf.data.input_info.append([]) 277 self.mf.data.relax_data.append([]) 278 self.mf.data.input_info[num_data].append("NOE") 279 self.mf.data.input_info[num_data].append(row[0][1]) 280 self.mf.data.input_info[num_data].append(float(row[1][1])) 281 self.mf.data.input_info[num_data].append(row[4][1]) 282 num_data = num_data + 1 283 else: 284 self.mf.data.nmr_frq[frq].append('0') 285 frq = frq + 1 286 self.mf.data.num_frq = frq 287 self.mf.data.num_data_sets = num_data
288 289
290 - def extract_relax_data(self):
291 "Extract the relaxation data from the files given in the file 'input'" 292 print "\n[ Relaxation data extraction ]\n" 293 for i in range(len(self.mf.data.input_info)): 294 data = self.mf.file_ops.relax_data(self.mf.data.input_info[i][3]) 295 self.mf.data.relax_data[i] = data
296 297
298 - def fill_results(self, data, model='0'):
299 "Initialize the next row of the results data structure." 300 301 results = {} 302 results['res_num'] = data['res_num'] 303 results['model'] = model 304 if match('0', model) or match('2\+3', model) or match('4\+5', model): 305 results['s2'] = '' 306 results['s2_err'] = '' 307 results['s2f'] = '' 308 results['s2f_err'] = '' 309 results['s2s'] = '' 310 results['s2s_err'] = '' 311 results['te'] = '' 312 results['te_err'] = '' 313 results['rex'] = '' 314 results['rex_err'] = '' 315 results['sse'] = data['sse'] 316 else: 317 results['s2'] = data['s2'] 318 results['s2_err'] = data['s2_err'] 319 results['s2f'] = data['s2f'] 320 results['s2f_err'] = data['s2f_err'] 321 results['s2s'] = data['s2s'] 322 results['s2s_err'] = data['s2s_err'] 323 results['te'] = data['te'] 324 results['te_err'] = data['te_err'] 325 results['rex'] = data['rex'] 326 results['rex_err'] = data['rex_err'] 327 results['sse'] = data['sse'] 328 return results
329 330
331 - def final_run(self):
332 """Model selection and the creation of the final run. 333 334 Monte Carlo simulations are used to find errors, and the diffusion tensor is unoptimized. 335 Files are placed in the directory 'final'. 336 """ 337 338 self.mf.file_ops.open_mf_files(dir='final') 339 self.create_mfin(sims='y') 340 341 self.create_run(dir='final') 342 for res in range(len(self.mf.data.relax_data[0])): 343 if match('0', self.mf.data.results[res]['model']): 344 model = 'none' 345 elif match('2+3', self.mf.data.results[res]['model']): 346 model = 'none' 347 elif match('4+5', self.mf.data.results[res]['model']): 348 model = 'none' 349 elif match('^1', self.mf.data.results[res]['model']): 350 model = "m1" 351 else: 352 model = 'm' + self.mf.data.results[res]['model'] 353 self.set_run_flags(model) 354 # Mfdata. 355 if match('none', model): 356 self.create_mfdata(res, flag='0') 357 else: 358 self.create_mfdata(res, flag='1') 359 # Mfmodel. 360 self.create_mfmodel(res, self.mf.data.usr_param.md1, type='M1') 361 # Mfpar. 362 self.create_mfpar(res) 363 self.mf.file_ops.close_mf_files(dir='final')
364 365
366 - def final_run_optimized(self):
367 """The final optimization run. 368 369 Create the modelfree4 files for the optimization of the diffusion tensor together with 370 the model free parameters for the selected models. 371 """ 372 373 self.mf.file_ops.open_mf_files(dir='final') 374 if match('isotropic', self.mf.data.usr_param.diff): 375 self.create_mfin(algorithm='brent', diffusion_search='grid') 376 elif match('axial', self.mf.data.usr_param.diff): 377 self.create_mfin(algorithm='powell') 378 379 self.create_run(dir='final') 380 for res in range(len(self.mf.data.relax_data[0])): 381 if match('0', self.mf.data.results[res]['model']): 382 model = 'none' 383 elif match('2+3', self.mf.data.results[res]['model']): 384 model = 'none' 385 elif match('4+5', self.mf.data.results[res]['model']): 386 model = 'none' 387 elif match('^1', self.mf.data.results[res]['model']): 388 model = "m1" 389 else: 390 model = 'm' + self.mf.data.results[res]['model'] 391 self.set_run_flags(model) 392 # Mfdata. 393 if match('none', model): 394 self.create_mfdata(res, flag='0') 395 else: 396 self.create_mfdata(res, flag='1') 397 # Mfmodel. 398 self.create_mfmodel(res, self.mf.data.usr_param.md1, type='M1') 399 # Mfpar. 400 self.create_mfpar(res) 401 self.mf.file_ops.close_mf_files(dir='final')
402 403
404 - def goto_stage(self):
405 if match('1', self.mf.data.stage): 406 print "\n[ Stage 1 ]\n" 407 self.initial_runs() 408 print "\n[ End of stage 1 ]\n\n" 409 410 if match('^2', self.mf.data.stage): 411 print "\n[ Stage 2 ]\n" 412 self.mf.file_ops.mkdir('final') 413 self.stage2() 414 if match('a$', self.mf.data.stage): 415 self.final_run() 416 if match('b$', self.mf.data.stage): 417 self.final_run_optimized() 418 print "\n[ End of stage 2 ]\n\n" 419 420 if match('3', self.mf.data.stage): 421 print "\n[ Stage 3 ]\n" 422 self.stage3() 423 print "\n[ End of stage 3 ]\n\n"
424 425
426 - def grace(self, file_name, type, subtitle):
427 "Create grace files for the results." 428 429 file = open(file_name, 'w') 430 431 if match('SSE', type): 432 file.write(self.grace_header(type + ' values', subtitle, 'Residue Number', type, 'xy')) 433 else: 434 file.write(self.grace_header(type + ' values', subtitle, 'Residue Number', type, 'xydy')) 435 436 for res in range(len(self.mf.data.results)): 437 if match('S2', type) and match('^[0-9]', self.mf.data.results[res]['s2']): 438 file.write(self.mf.data.results[res]['res_num'] + " ") 439 file.write(self.mf.data.results[res]['s2'] + " ") 440 file.write(self.mf.data.results[res]['s2_err'] + "\n") 441 elif match('S2s', type) and match('^[0-9]', self.mf.data.results[res]['s2s']): 442 file.write(self.mf.data.results[res]['res_num'] + " ") 443 file.write(self.mf.data.results[res]['s2s'] + " ") 444 file.write(self.mf.data.results[res]['s2s_err'] + "\n") 445 elif match('S2f', type) and match('^[0-9]', self.mf.data.results[res]['s2f']): 446 file.write(self.mf.data.results[res]['res_num'] + " ") 447 file.write(self.mf.data.results[res]['s2f'] + " ") 448 file.write(self.mf.data.results[res]['s2f_err'] + "\n") 449 elif match('te', type) and match('^[0-9]', self.mf.data.results[res]['te']): 450 file.write(self.mf.data.results[res]['res_num'] + " ") 451 file.write(self.mf.data.results[res]['te'] + " ") 452 file.write(self.mf.data.results[res]['te_err'] + "\n") 453 elif match('Rex', type) and match('^[0-9]', self.mf.data.results[res]['rex']): 454 file.write(self.mf.data.results[res]['res_num'] + " ") 455 file.write(self.mf.data.results[res]['rex'] + " ") 456 file.write(self.mf.data.results[res]['rex_err'] + "\n") 457 elif match('SSE', type): 458 file.write(self.mf.data.results[res]['res_num'] + " ") 459 file.write(`self.mf.data.results[res]['sse']` + "\n") 460 file.write("&\n") 461 file.close()
462 463
464 - def grace_header(self, title, subtitle, x, y, type):
465 "Create and return a grace header." 466 467 text = "@version 50100\n" 468 text = text + "@with g0\n" 469 if match('Residue Number', x): 470 text = text + "@ world xmax 165\n" 471 if match('R1', x) and match('SSE', y): 472 text = text + "@ world xmin 0.8\n" 473 text = text + "@ world xmax 2\n" 474 text = text + "@ world ymin 0\n" 475 text = text + "@ world ymax 2000\n" 476 if match('R2', x) and match('SSE', y): 477 text = text + "@ world xmin 5\n" 478 text = text + "@ world xmax 45\n" 479 text = text + "@ world ymin 0\n" 480 text = text + "@ world ymax 2000\n" 481 if match('NOE', x) and match('SSE', y): 482 text = text + "@ world xmin 0\n" 483 text = text + "@ world xmax 1\n" 484 text = text + "@ world ymin 0\n" 485 text = text + "@ world ymax 2000\n" 486 text = text + "@ view xmax 1.22\n" 487 text = text + "@ title \"" + title + "\"\n" 488 text = text + "@ subtitle \"" + subtitle + "\"\n" 489 text = text + "@ xaxis label \"" + x + "\"\n" 490 if match('Residue Number', x): 491 text = text + "@ xaxis tick major 10\n" 492 if match('R1', x) and match('SSE', y): 493 text = text + "@ xaxis tick major 0.2\n" 494 if match('R2', x) and match('SSE', y): 495 text = text + "@ xaxis tick major 5\n" 496 if match('NOE', x) and match('SSE', y): 497 text = text + "@ xaxis tick major 0.1\n" 498 text = text + "@ xaxis tick major size 0.480000\n" 499 text = text + "@ xaxis tick major linewidth 0.5\n" 500 text = text + "@ xaxis tick minor linewidth 0.5\n" 501 text = text + "@ xaxis tick minor size 0.240000\n" 502 text = text + "@ xaxis ticklabel char size 0.790000\n" 503 text = text + "@ yaxis label \"" + y + "\"\n" 504 if match('R1', x) and match('SSE', y): 505 text = text + "@ yaxis tick major 200\n" 506 if match('R2', x) and match('SSE', y): 507 text = text + "@ yaxis tick major 200\n" 508 if match('NOE', x) and match('SSE', y): 509 text = text + "@ yaxis tick major 200\n" 510 text = text + "@ yaxis tick major size 0.480000\n" 511 text = text + "@ yaxis tick major linewidth 0.5\n" 512 text = text + "@ yaxis tick minor linewidth 0.5\n" 513 text = text + "@ yaxis tick minor size 0.240000\n" 514 text = text + "@ yaxis ticklabel char size 0.790000\n" 515 text = text + "@ frame linewidth 0.5\n" 516 text = text + "@ s0 symbol 1\n" 517 text = text + "@ s0 symbol size 0.49\n" 518 text = text + "@ s0 symbol fill pattern 1\n" 519 text = text + "@ s0 symbol linewidth 0.5\n" 520 text = text + "@ s0 line linestyle 0\n" 521 text = text + "@target G0.S0\n@type " + type + "\n" 522 return text
523 524
525 - def initialize(self):
526 "A few operations to start up the program." 527 528 self.mf.data.stage = self.ask_stage() 529 title = "<<< Stage " + self.mf.data.stage + " - " 530 title = title + self.mf.data.usr_param.method + " model selection >>>\n\n\n" 531 self.mf.file_ops.init_log_file(title) 532 input = self.mf.file_ops.open_input() 533 self.extract_input(input) 534 self.extract_relax_data() 535 self.log_input_info()
536 537
538 - def log_input_info(self):
539 self.mf.log.write("The input info data structure is:\n" + `self.mf.data.input_info` + "\n\n") 540 for i in range(len(self.mf.data.input_info)): 541 self.mf.log.write('%-25s%-20s\n' % ("Data label:", self.mf.data.input_info[i][0])) 542 self.mf.log.write('%-25s%-20s\n' % ("NMR frequency label:", self.mf.data.input_info[i][1])) 543 self.mf.log.write('%-25s%-20s\n' % ("NMR proton frequency:", `self.mf.data.input_info[i][2]`)) 544 self.mf.log.write('%-25s%-20s\n\n' % ("File name:", self.mf.data.input_info[i][3])) 545 self.mf.log.write("Number of frequencies:\t" + `self.mf.data.num_frq` + "\n") 546 self.mf.log.write("Number of data sets:\t" + `self.mf.data.num_data_sets` + "\n\n")
547 548
549 - def log_params(self, name, mdx):
550 "Put the parameter data structures into the log file." 551 552 self.mf.log.write("\n" + name + " data structure\n") 553 for param in ['tloc', 'theta', 'ss2', 'sf2', 'te', 'rex']: 554 self.mf.log.write('%-10s' % ( param + ":" )) 555 self.mf.log.write('%-15s' % ( "start = " + mdx[param]['start'] )) 556 self.mf.log.write('%-11s' % ( "flag = " + mdx[param]['flag'] )) 557 self.mf.log.write('%-13s' % ( "bound = " + mdx[param]['bound'] )) 558 self.mf.log.write('%-20s' % ( "lower = " + mdx[param]['lower'] )) 559 self.mf.log.write('%-20s' % ( "upper = " + mdx[param]['upper'] )) 560 self.mf.log.write('%-10s\n' % ( "steps = " + mdx[param]['steps'] ))
561 562
563 - def print_data(self, ftests='n'):
564 "Print the results into the results file." 565 566 file = open('data_all', 'w') 567 568 sys.stdout.write("[") 569 for res in range(len(self.mf.data.results)): 570 sys.stdout.write("-") 571 file.write("<<< Residue " + self.mf.data.results[res]['res_num']) 572 file.write(", Model " + self.mf.data.results[res]['model'] + " >>>\n") 573 file.write('%-10s' % '') 574 file.write('%-8s%-8s%-8s%-8s' % ( 'S2', 'S2_err', 'S2f', 'S2f_err' )) 575 file.write('%-8s%-8s' % ( 'S2s', 'S2s_err' )) 576 file.write('%-10s%-10s%-8s%-8s' % ( 'te', 'te_err', 'Rex', 'Rex_err' )) 577 file.write('%-10s%-10s%-10s' % ( 'SSE', 'SSElim', 'SSEtest' )) 578 file.write('%-10s%-10s\n' % ( 'LargeSSE', 'ZeroSSE' )) 579 for run in self.mf.data.runs: 580 if match('^m', run): 581 file.write('%-10s' % run) 582 file.write('%-8s' % self.mf.data.data[run][res]['s2']) 583 file.write('%-8s' % self.mf.data.data[run][res]['s2_err']) 584 file.write('%-8s' % self.mf.data.data[run][res]['s2f']) 585 file.write('%-8s' % self.mf.data.data[run][res]['s2f_err']) 586 file.write('%-8s' % self.mf.data.data[run][res]['s2s']) 587 file.write('%-8s' % self.mf.data.data[run][res]['s2s_err']) 588 file.write('%-10s' % self.mf.data.data[run][res]['te']) 589 file.write('%-10s' % self.mf.data.data[run][res]['te_err']) 590 file.write('%-8s' % self.mf.data.data[run][res]['rex']) 591 file.write('%-8s' % self.mf.data.data[run][res]['rex_err']) 592 file.write('%-10s' % self.mf.data.data[run][res]['sse']) 593 file.write('%-10s' % self.mf.data.data[run][res]['sse_lim']) 594 file.write('%-10s' % self.mf.data.data[run][res]['sse_test']) 595 file.write('%-10s' % self.mf.data.data[run][res]['large_sse']) 596 file.write('%-10s\n' % self.mf.data.data[run][res]['zero_sse']) 597 if match('y', ftests): 598 file.write('%-10s' % '') 599 file.write('%-18s' % 'F-stat') 600 file.write('%-18s' % 'F-stat limit') 601 file.write('%-18s\n' % 'F-test result') 602 for run in self.mf.data.runs: 603 if match('^f', run): 604 file.write('%-10s' % run) 605 file.write('%-18s' % self.mf.data.data[run][res]['fstat']) 606 file.write('%-18s' % self.mf.data.data[run][res]['fstat_lim']) 607 file.write('%-18s\n' % self.mf.data.data[run][res]['ftest']) 608 file.write('\n') 609 sys.stdout.write("]\n") 610 611 file.close()
612 613
614 - def print_results(self):
615 "Print the results into the results file." 616 617 file = open('results', 'w') 618 619 file.write('%-6s%-6s%-13s%-13s%-13s' % ( 'ResNo', 'Model', ' S2', ' S2f', ' S2s' )) 620 file.write('%-19s%-13s%-10s\n' % ( ' te', ' Rex', ' SSE' )) 621 sys.stdout.write("[") 622 for res in range(len(self.mf.data.results)): 623 sys.stdout.write("-") 624 file.write('%-6s' % self.mf.data.results[res]['res_num']) 625 file.write('%-6s' % self.mf.data.results[res]['model']) 626 627 if match('[1,2,3,4,5]', self.mf.data.results[res]['model']): 628 file.write('%5s%1s%-5s ' % ( self.mf.data.results[res]['s2'], '±', self.mf.data.results[res]['s2_err'] )) 629 else: 630 file.write('%13s' % '') 631 if match('5', self.mf.data.results[res]['model']): 632 file.write('%5s%1s%-5s ' % ( self.mf.data.results[res]['s2f'], '±', self.mf.data.results[res]['s2f_err'] )) 633 file.write('%5s%1s%-5s ' % ( self.mf.data.results[res]['s2s'], '±', self.mf.data.results[res]['s2s_err'] )) 634 else: 635 file.write('%26s' % '') 636 if match('[2,4,5]', self.mf.data.results[res]['model']): 637 file.write('%8s%1s%-8s ' % ( self.mf.data.results[res]['te'], '±', self.mf.data.results[res]['te_err'] )) 638 else: 639 file.write('%19s' % '') 640 if match('[3,4]', self.mf.data.results[res]['model']): 641 file.write('%5s%1s%-5s ' % ( self.mf.data.results[res]['rex'], '±', self.mf.data.results[res]['rex_err'] )) 642 else: 643 file.write('%13s' % '') 644 file.write('%10s\n' % self.mf.data.results[res]['sse']) 645 sys.stdout.write("]\n") 646 647 file.close()
648 649
650 - def set_run_flags(self, run):
651 "Reset, and then set the flags in self.mf.data.usr_param.md1 and md2." 652 653 self.mf.data.usr_param.md1['sf2']['flag'] = '0' 654 self.mf.data.usr_param.md1['ss2']['flag'] = '0' 655 self.mf.data.usr_param.md1['te']['flag'] = '0' 656 self.mf.data.usr_param.md1['rex']['flag'] = '0' 657 658 self.mf.data.usr_param.md2['sf2']['flag'] = '0' 659 self.mf.data.usr_param.md2['ss2']['flag'] = '0' 660 self.mf.data.usr_param.md2['te']['flag'] = '0' 661 self.mf.data.usr_param.md2['rex']['flag'] = '0' 662 663 # Normal runs. 664 if run == "m1": 665 self.mf.data.usr_param.md1['ss2']['flag'] = '1' 666 if run == "m2": 667 self.mf.data.usr_param.md1['ss2']['flag'] = '1' 668 self.mf.data.usr_param.md1['te']['flag'] = '1' 669 if run == "m3": 670 self.mf.data.usr_param.md1['ss2']['flag'] = '1' 671 self.mf.data.usr_param.md1['rex']['flag'] = '1' 672 if run == "m4": 673 self.mf.data.usr_param.md1['ss2']['flag'] = '1' 674 self.mf.data.usr_param.md1['te']['flag'] = '1' 675 self.mf.data.usr_param.md1['rex']['flag'] = '1' 676 if run == "m5": 677 self.mf.data.usr_param.md1['sf2']['flag'] = '1' 678 self.mf.data.usr_param.md1['ss2']['flag'] = '1' 679 self.mf.data.usr_param.md1['te']['flag'] = '1' 680 681 # F-tests. 682 if run == "f-m1m2": 683 self.mf.data.usr_param.md1['ss2']['flag'] = '1' 684 self.mf.data.usr_param.md2['ss2']['flag'] = '1' 685 self.mf.data.usr_param.md2['te']['flag'] = '1' 686 if run == "f-m1m3": 687 self.mf.data.usr_param.md1['ss2']['flag'] = '1' 688 self.mf.data.usr_param.md2['ss2']['flag'] = '1' 689 self.mf.data.usr_param.md2['rex']['flag'] = '1' 690 if run == "f-m1m4": 691 self.mf.data.usr_param.md1['ss2']['flag'] = '1' 692 self.mf.data.usr_param.md2['ss2']['flag'] = '1' 693 self.mf.data.usr_param.md2['te']['flag'] = '1' 694 self.mf.data.usr_param.md2['rex']['flag'] = '1' 695 if run == "f-m1m5": 696 self.mf.data.usr_param.md1['ss2']['flag'] = '1' 697 self.mf.data.usr_param.md2['ss2']['flag'] = '1' 698 self.mf.data.usr_param.md2['sf2']['flag'] = '1' 699 self.mf.data.usr_param.md2['te']['flag'] = '1' 700 if run == "f-m2m4": 701 self.mf.data.usr_param.md1['ss2']['flag'] = '1' 702 self.mf.data.usr_param.md1['te']['flag'] = '1' 703 self.mf.data.usr_param.md2['ss2']['flag'] = '1' 704 self.mf.data.usr_param.md2['te']['flag'] = '1' 705 self.mf.data.usr_param.md2['rex']['flag'] = '1' 706 if run == "f-m2m5": 707 self.mf.data.usr_param.md1['ss2']['flag'] = '1' 708 self.mf.data.usr_param.md1['te']['flag'] = '1' 709 self.mf.data.usr_param.md2['ss2']['flag'] = '1' 710 self.mf.data.usr_param.md2['sf2']['flag'] = '1' 711 self.mf.data.usr_param.md2['te']['flag'] = '1' 712 if run == "f-m3m4": 713 self.mf.data.usr_param.md1['ss2']['flag'] = '1' 714 self.mf.data.usr_param.md1['rex']['flag'] = '1' 715 self.mf.data.usr_param.md2['ss2']['flag'] = '1' 716 self.mf.data.usr_param.md2['te']['flag'] = '1' 717 self.mf.data.usr_param.md2['rex']['flag'] = '1'
718 719
720 - def stage3(self):
721 print "Stage 3 not implemented yet.\n" 722 sys.exit()
723