1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 """The automatic relaxation curve fitting protocol."""
25
26
27 from os import sep
28
29
30 from generic_fns.pipes import cdp_name, has_pipe, switch
31 import generic_fns.structure.main
32 from prompt.interpreter import Interpreter
33 from status import Status; status = Status()
34
35
36
38 - def __init__(self, pipe_name=None, file_root='rx', results_dir=None, grid_inc='11', mc_sim_num=500, view_plots=True):
39 """Perform relaxation curve fitting.
40
41 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:
42
43 - All the spins loaded.
44 - Unresolved spins deselected.
45 - All the peak intensities loaded and relaxation delay times set.
46 - Either the baseplane noise RMDS values should be set or replicated spectra loaded.
47
48 @keyword pipe_name: The name of the data pipe containing all of the data for the analysis.
49 @type pipe_name: 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_name, mode='auto-analysis')
64
65
66 status.init_auto_analysis(pipe_name, type='relax_fit')
67 status.current_analysis = pipe_name
68
69
70 self.pipe_name = pipe_name
71 self.file_root = file_root
72 self.results_dir = results_dir
73 if self.results_dir:
74 self.grace_dir = results_dir + sep + 'grace'
75 else:
76 self.grace_dir = 'grace'
77 self.mc_sim_num = mc_sim_num
78 self.grid_inc = grid_inc
79 self.view_plots = view_plots
80
81
82 self.check_vars()
83
84
85 if self.pipe_name != cdp_name():
86 switch(self.pipe_name)
87
88
89 self.interpreter = Interpreter(show_script=False, quit=False, raise_relax_error=True)
90 self.interpreter.populate_self()
91 self.interpreter.on(verbose=False)
92
93
94 self.run()
95
96
97 status.auto_analysis[self.pipe_name].fin = True
98 status.current_analysis = None
99 status.exec_lock.release()
100
101
103 """Set up and run the curve-fitting."""
104
105
106 self.interpreter.spectrum.error_analysis()
107
108
109 self.interpreter.relax_fit.select_model('exp')
110
111
112 self.interpreter.grid_search(inc=self.grid_inc)
113
114
115 self.interpreter.minimise('simplex', scaling=False, constraints=False)
116
117
118 self.interpreter.monte_carlo.setup(number=self.mc_sim_num)
119 self.interpreter.monte_carlo.create_data()
120 self.interpreter.monte_carlo.initial_values()
121 self.interpreter.minimise('simplex', scaling=False, constraints=False)
122 self.interpreter.monte_carlo.error_analysis()
123
124
125 self.interpreter.value.write(param='rx', file=self.file_root+'.out', dir=self.results_dir, force=True)
126
127
128 self.interpreter.results.write(file='results', dir=self.results_dir, force=True)
129
130
131 self.interpreter.grace.write(y_data_type='chi2', file='chi2.agr', dir=self.grace_dir, force=True)
132 self.interpreter.grace.write(y_data_type='i0', file='i0.agr', dir=self.grace_dir, force=True)
133 self.interpreter.grace.write(y_data_type='rx', file=self.file_root+'.agr', dir=self.grace_dir, force=True)
134 self.interpreter.grace.write(x_data_type='relax_times', y_data_type='intensities', file='intensities.agr', dir=self.grace_dir, force=True)
135 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)
136
137
138 if self.view_plots:
139 self.interpreter.grace.view(file='chi2.agr', dir=self.grace_dir)
140 self.interpreter.grace.view(file='i0.agr', dir=self.grace_dir)
141 self.interpreter.grace.view(file=self.file_root+'.agr', dir=self.grace_dir)
142 self.interpreter.grace.view(file='intensities.agr', dir=self.grace_dir)
143 self.interpreter.grace.view(file='intensities_norm.agr', dir=self.grace_dir)
144
145
146 self.interpreter.state.save(state=self.file_root+'.save', dir=self.results_dir, force=True)
147
148
150 """Check that the user has set the variables correctly."""
151
152
153 if not has_pipe(self.pipe_name):
154 raise RelaxNoPipeError(self.pipe_name)
155