1
2
3
4
5
6
7
8 import sys
9 from re import match
10
11 from common_ops import common_operations
12
13
14 -class farrow(common_operations):
16 "The model-free analysis of Farrow."
17
18 self.mf = mf
19
20 print "Farrow's method for model-free analysis. (Farrow et al., 1994)"
21 self.initialize()
22 self.mf.data.runs = ['m1', 'm2', 'm3', 'm4', 'm5', 'f-m1m2', 'f-m1m3']
23 if self.mf.data.num_data_sets > 3:
24 self.mf.data.runs.append('f-m2m4')
25 self.mf.data.runs.append('f-m2m5')
26 self.mf.data.runs.append('f-m3m4')
27 self.goto_stage()
28
29
31 "Creation of the files for the Modelfree calculations for models 1 to 5 and the F-tests."
32
33 for run in self.mf.data.runs:
34 if match('^m', run):
35 print "Creating input files for model " + run
36 self.mf.log.write("\n\n<<< Model " + run + " >>>\n\n")
37 elif match('^f', run):
38 print "Creating input files for the F-test " + run
39 self.mf.log.write("\n\n<<< F-test " + run + " >>>\n\n")
40 else:
41 print "The run '" + run + "'does not start with an m or f, quitting script!\n\n"
42 sys.exit()
43 self.mf.file_ops.mkdir(dir=run)
44 self.mf.file_ops.open_mf_files(dir=run)
45 self.set_run_flags(run)
46 self.log_params('M1', self.mf.data.usr_param.md1)
47 self.log_params('M2', self.mf.data.usr_param.md2)
48 if match('^m', run):
49 self.create_mfin(sims='y', sim_type='pred')
50 elif match('^f', run):
51 self.create_mfin(sel='ftest', sims='y', sim_type='pred')
52 self.create_run(dir=run)
53 for res in range(len(self.mf.data.relax_data[0])):
54
55 self.create_mfdata(res)
56
57 self.create_mfmodel(res, self.mf.data.usr_param.md1, type='M1')
58 if match('^f', run):
59 self.create_mfmodel(res, self.mf.data.usr_param.md2, type='M2')
60
61 self.create_mfpar(res)
62 self.mf.file_ops.close_mf_files(dir=run)
63
64
66 "Farrow's model selection."
67
68 data = self.mf.data.data
69
70 self.mf.log.write("\n\n<<< Farrow's model selection >>>")
71 for res in range(len(self.mf.data.relax_data[0])):
72 self.mf.data.results.append({})
73 self.mf.log.write('\n%-22s' % ( " Checking res " + data['m1'][res]['res_num'] ))
74
75
76 if data['m1'][res]['sse_test'] == 1:
77 self.mf.log.write('%-12s' % '[Model 1]')
78 self.mf.data.results[res] = self.fill_results(data['m1'][res], model='1')
79
80
81 elif data['m2'][res]['sse_test'] == 1 and data['f-m1m2'][res]['ftest'] == 1 \
82 and data['m3'][res]['sse_test'] == 1 and data['f-m1m3'][res]['ftest'] == 1:
83 self.mf.log.write('%-12s' % '[Model 2 and 3]')
84 self.mf.data.results[res] = self.fill_results(data['m1'][res], model='2+3')
85
86
87 elif data['m2'][res]['sse_test'] == 1 and data['f-m1m2'][res]['ftest'] == 1:
88 self.mf.log.write('%-12s' % '[Model 2]')
89 self.mf.data.results[res] = self.fill_results(data['m2'][res], model='2')
90
91
92 elif data['m3'][res]['sse_test'] == 1 and data['f-m1m3'][res]['ftest'] == 1:
93 self.mf.log.write('%-12s' % '[Model 3]')
94 self.mf.data.results[res] = self.fill_results(data['m3'][res], model='3')
95
96
97 elif data['m1'][res]['large_sse'] == 0:
98 self.mf.log.write('%-12s' % '[Model 1*]')
99 self.mf.data.results[res] = self.fill_results(data['m1'][res], model='1')
100
101
102 elif data['m4'][res]['zero_sse'] == 1 and data['m5'][res]['zero_sse'] == 1:
103 self.mf.log.write('%-12s' % '[Model 4 and 5]')
104 self.mf.data.results[res] = self.fill_results(data['m1'][res], model='4+5')
105
106
107 elif data['m4'][res]['zero_sse'] == 1:
108 self.mf.log.write('%-12s' % '[Model 4]')
109 self.mf.data.results[res] = self.fill_results(data['m4'][res], model='4')
110
111
112 elif data['m5'][res]['zero_sse'] == 1:
113 self.mf.log.write('%-12s' % '[Model 5]')
114 self.mf.data.results[res] = self.fill_results(data['m5'][res], model='5')
115
116
117 else:
118 self.mf.log.write('%-12s' % '[Model 0]')
119 self.mf.data.results[res] = self.fill_results(data['m1'][res], model='0')
120
121
123 self.mf.file_ops.mkdir('grace')
124
125 print "\n[ Model-free data extraction ]\n"
126 for run in self.mf.data.runs:
127 mfout = self.mf.file_ops.read_file(run + '/mfout')
128 mfout_lines = mfout.readlines()
129 mfout.close()
130 print "Extracting model-free data from " + run + "/mfout."
131 num_res = len(self.mf.data.relax_data[0])
132 if match('^m', run):
133 self.mf.data.data[run] = self.mf.star.extract(mfout_lines, num_res, self.mf.data.usr_param.sse_lim, self.mf.data.usr_param.ftest_lim, float(self.mf.data.usr_param.large_sse), ftest='n')
134 if match('^f', run):
135 self.mf.data.data[run] = self.mf.star.extract(mfout_lines, num_res, self.mf.data.usr_param.sse_lim, self.mf.data.usr_param.ftest_lim, float(self.mf.data.usr_param.large_sse), ftest='y')
136
137 print "\n[ Farrow's model selection ]\n"
138 self.mf.log.write("Farrow's model selection.\n\n")
139 self.model_selection()
140
141 print "\n[ Printing results ]\n"
142 self.print_results()
143
144 print "\n[ Placing data structures into \"data_all\" ]\n"
145 self.print_data(ftests='y')
146
147 print "\n[ Grace file creation ]\n"
148 self.grace('grace/S2.agr', 'S2', subtitle="After model selection, unoptimized")
149 self.grace('grace/S2f.agr', 'S2f', subtitle="After model selection, unoptimized")
150 self.grace('grace/S2s.agr', 'S2s', subtitle="After model selection, unoptimized")
151 self.grace('grace/te.agr', 'te', subtitle="After model selection, unoptimized")
152 self.grace('grace/Rex.agr', 'Rex', subtitle="After model selection, unoptimized")
153 self.grace('grace/SSE.agr', 'SSE', subtitle="After model selection, unoptimized")
154