Package auto_analyses :: Module relax_fit
[hide private]
[frames] | no frames]

Source Code for Module auto_analyses.relax_fit

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2004-2011 Edward d'Auvergne                                   # 
  4  #                                                                             # 
  5  # This file is part of the program relax.                                     # 
  6  #                                                                             # 
  7  # relax is free software; you can redistribute it and/or modify               # 
  8  # it under the terms of the GNU General Public License as published by        # 
  9  # the Free Software Foundation; either version 2 of the License, or           # 
 10  # (at your option) any later version.                                         # 
 11  #                                                                             # 
 12  # relax is distributed in the hope that it will be useful,                    # 
 13  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
 14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
 15  # GNU General Public License for more details.                                # 
 16  #                                                                             # 
 17  # You should have received a copy of the GNU General Public License           # 
 18  # along with relax; if not, write to the Free Software                        # 
 19  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   # 
 20  #                                                                             # 
 21  ############################################################################### 
 22   
 23  # Module docstring. 
 24  """The automatic relaxation curve fitting protocol.""" 
 25   
 26  # Python module imports. 
 27  from os import sep 
 28   
 29  # relax module imports. 
 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   
37 -class Relax_fit:
38 - 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):
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 pipe_bundle: The data pipe bundle to associate all spawned data pipes with. 51 @type pipe_bundle: str 52 @keyword file_root: File root of the output filea. 53 @type file_root: str 54 @keyword results_dir: The directory where results files are saved. 55 @type results_dir: str 56 @keyword grid_inc: Number of grid search increments. 57 @type grid_inc: int 58 @keyword mc_sim_num: The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 59 @type mc_sim_num: int 60 @keyword view_plots: Flag to automatically view grace plots after calculation. 61 @type view_plots: bool 62 """ 63 64 # Execution lock. 65 status.exec_lock.acquire(pipe_bundle, mode='auto-analysis') 66 67 # Set up the analysis status object. 68 status.init_auto_analysis(pipe_bundle, type='relax_fit') 69 status.current_analysis = pipe_bundle 70 71 # Store the args. 72 self.pipe_name = pipe_name 73 self.pipe_bundle = pipe_bundle 74 self.file_root = file_root 75 self.results_dir = results_dir 76 if self.results_dir: 77 self.grace_dir = results_dir + sep + 'grace' 78 else: 79 self.grace_dir = 'grace' 80 self.mc_sim_num = mc_sim_num 81 self.grid_inc = grid_inc 82 self.view_plots = view_plots 83 84 # Data checks. 85 self.check_vars() 86 87 # Set the data pipe to the current data pipe. 88 if self.pipe_name != cdp_name(): 89 switch(self.pipe_name) 90 91 # Load the interpreter. 92 self.interpreter = Interpreter(show_script=False, quit=False, raise_relax_error=True) 93 self.interpreter.populate_self() 94 self.interpreter.on(verbose=False) 95 96 # Execute. 97 self.run() 98 99 # Finish and unlock execution. 100 status.auto_analysis[self.pipe_bundle].fin = True 101 status.current_analysis = None 102 status.exec_lock.release()
103 104
105 - def run(self):
106 """Set up and run the curve-fitting.""" 107 108 # Peak intensity error analysis. 109 self.interpreter.spectrum.error_analysis() 110 111 # Set the relaxation curve type. 112 self.interpreter.relax_fit.select_model('exp') 113 114 # Grid search. 115 self.interpreter.grid_search(inc=self.grid_inc) 116 117 # Minimise. 118 self.interpreter.minimise('simplex', scaling=False, constraints=False) 119 120 # Monte Carlo simulations. 121 self.interpreter.monte_carlo.setup(number=self.mc_sim_num) 122 self.interpreter.monte_carlo.create_data() 123 self.interpreter.monte_carlo.initial_values() 124 self.interpreter.minimise('simplex', scaling=False, constraints=False) 125 self.interpreter.monte_carlo.error_analysis() 126 127 # Save the relaxation rates. 128 self.interpreter.value.write(param='rx', file=self.file_root+'.out', dir=self.results_dir, force=True) 129 130 # Save the results. 131 self.interpreter.results.write(file='results', dir=self.results_dir, force=True) 132 133 # Create Grace plots of the data. 134 self.interpreter.grace.write(y_data_type='chi2', file='chi2.agr', dir=self.grace_dir, force=True) # Minimised chi-squared value. 135 self.interpreter.grace.write(y_data_type='i0', file='i0.agr', dir=self.grace_dir, force=True) # Initial peak intensity. 136 self.interpreter.grace.write(y_data_type='rx', file=self.file_root+'.agr', dir=self.grace_dir, force=True) # Relaxation rate. 137 self.interpreter.grace.write(x_data_type='relax_times', y_data_type='intensities', file='intensities.agr', dir=self.grace_dir, force=True) # Average peak intensities. 138 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) # Average peak intensities (normalised). 139 140 # Display the Grace plots if selected. 141 if self.view_plots: 142 self.interpreter.grace.view(file='chi2.agr', dir=self.grace_dir) 143 self.interpreter.grace.view(file='i0.agr', dir=self.grace_dir) 144 self.interpreter.grace.view(file=self.file_root+'.agr', dir=self.grace_dir) 145 self.interpreter.grace.view(file='intensities.agr', dir=self.grace_dir) 146 self.interpreter.grace.view(file='intensities_norm.agr', dir=self.grace_dir) 147 148 # Save the program state. 149 self.interpreter.state.save(state=self.file_root+'.save', dir=self.results_dir, force=True)
150 151
152 - def check_vars(self):
153 """Check that the user has set the variables correctly.""" 154 155 # The pipe name. 156 if not has_pipe(self.pipe_name): 157 raise RelaxNoPipeError(self.pipe_name)
158