1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 """The automatic relaxation curve fitting protocol."""
24
25
26 from os import sep
27
28
29 from pipe_control.pipes import cdp_name, has_pipe, switch
30 from prompt.interpreter import Interpreter
31 from status import Status; status = Status()
32
33
34
36 - def __init__(self, pipe_name=None, pipe_bundle=None, file_root='rx', results_dir=None, grid_inc='11', mc_sim_num=500, view_plots=True):
37 """Perform relaxation curve fitting.
38
39 To use this auto-analysis, a data pipe with all the required data needs to be set up. This data pipe should contain the following:
40
41 - All the spins loaded.
42 - Unresolved spins deselected.
43 - All the peak intensities loaded and relaxation delay times set.
44 - Either the baseplane noise RMDS values should be set or replicated spectra loaded.
45
46 @keyword pipe_name: The name of the data pipe containing all of the data for the analysis.
47 @type pipe_name: str
48 @keyword pipe_bundle: The data pipe bundle to associate all spawned data pipes with.
49 @type pipe_bundle: str
50 @keyword file_root: File root of the output filea.
51 @type file_root: str
52 @keyword results_dir: The directory where results files are saved.
53 @type results_dir: str
54 @keyword grid_inc: Number of grid search increments.
55 @type grid_inc: int
56 @keyword mc_sim_num: The number of Monte Carlo simulations to be used for error analysis at the end of the analysis.
57 @type mc_sim_num: int
58 @keyword view_plots: Flag to automatically view grace plots after calculation.
59 @type view_plots: bool
60 """
61
62
63 status.exec_lock.acquire(pipe_bundle, mode='auto-analysis')
64
65
66 status.init_auto_analysis(pipe_bundle, type='relax_fit')
67 status.current_analysis = pipe_bundle
68
69
70 self.pipe_name = pipe_name
71 self.pipe_bundle = pipe_bundle
72 self.file_root = file_root
73 self.results_dir = results_dir
74 if self.results_dir:
75 self.grace_dir = results_dir + sep + 'grace'
76 else:
77 self.grace_dir = 'grace'
78 self.mc_sim_num = mc_sim_num
79 self.grid_inc = grid_inc
80 self.view_plots = view_plots
81
82
83 self.check_vars()
84
85
86 if self.pipe_name != cdp_name():
87 switch(self.pipe_name)
88
89
90 self.interpreter = Interpreter(show_script=False, quit=False, raise_relax_error=True)
91 self.interpreter.populate_self()
92 self.interpreter.on(verbose=False)
93
94
95 self.run()
96
97
98 status.auto_analysis[self.pipe_bundle].fin = True
99 status.current_analysis = None
100 status.exec_lock.release()
101
102
104 """Set up and run the curve-fitting."""
105
106
107 self.interpreter.spectrum.error_analysis()
108
109
110 self.interpreter.relax_fit.select_model('exp')
111
112
113 self.interpreter.grid_search(inc=self.grid_inc)
114
115
116 self.interpreter.minimise('simplex', scaling=False, constraints=False)
117
118
119 self.interpreter.monte_carlo.setup(number=self.mc_sim_num)
120 self.interpreter.monte_carlo.create_data()
121 self.interpreter.monte_carlo.initial_values()
122 self.interpreter.minimise('simplex', scaling=False, constraints=False)
123 self.interpreter.monte_carlo.error_analysis()
124
125
126 self.interpreter.value.write(param='rx', file=self.file_root+'.out', dir=self.results_dir, force=True)
127
128
129 self.interpreter.results.write(file='results', dir=self.results_dir, force=True)
130
131
132 self.interpreter.grace.write(y_data_type='chi2', file='chi2.agr', dir=self.grace_dir, force=True)
133 self.interpreter.grace.write(y_data_type='i0', file='i0.agr', dir=self.grace_dir, force=True)
134 self.interpreter.grace.write(y_data_type='rx', file=self.file_root+'.agr', dir=self.grace_dir, force=True)
135 self.interpreter.grace.write(x_data_type='relax_times', y_data_type='intensities', file='intensities.agr', dir=self.grace_dir, force=True)
136 self.interpreter.grace.write(x_data_type='relax_times', y_data_type='intensities', norm=True, file='intensities_norm.agr', dir=self.grace_dir, force=True)
137
138
139 if self.view_plots:
140 self.interpreter.grace.view(file='chi2.agr', dir=self.grace_dir)
141 self.interpreter.grace.view(file='i0.agr', dir=self.grace_dir)
142 self.interpreter.grace.view(file=self.file_root+'.agr', dir=self.grace_dir)
143 self.interpreter.grace.view(file='intensities.agr', dir=self.grace_dir)
144 self.interpreter.grace.view(file='intensities_norm.agr', dir=self.grace_dir)
145
146
147 self.interpreter.state.save(state=self.file_root+'.save', dir=self.results_dir, force=True)
148
149
151 """Check that the user has set the variables correctly."""
152
153
154 if not has_pipe(self.pipe_name):
155 raise RelaxNoPipeError(self.pipe_name)
156