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

Source Code for Module auto_analyses.noe

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2004-2005,2008,2010-2012,2017 Edward d'Auvergne               # 
  4  #                                                                             # 
  5  # This file is part of the program relax (http://www.nmr-relax.com).          # 
  6  #                                                                             # 
  7  # This program 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 3 of the License, or           # 
 10  # (at your option) any later version.                                         # 
 11  #                                                                             # 
 12  # This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.       # 
 19  #                                                                             # 
 20  ############################################################################### 
 21   
 22  # Module docstring. 
 23  """The automatic relaxation curve fitting protocol.""" 
 24   
 25  # Python module imports. 
 26  from os import sep 
 27  import sys 
 28  from time import time 
 29   
 30  # relax module imports. 
 31  from lib.io import get_file_path, open_write_file 
 32  from lib.plotting.grace import create_grace2images 
 33  from lib.text.sectioning import title 
 34  from lib.timing import print_elapsed_time 
 35  from pipe_control.pipes import cdp_name, has_pipe, switch 
 36  from prompt.interpreter import Interpreter 
 37  from status import Status; status = Status() 
 38   
 39   
 40   
41 -class NOE_calc:
42 - def __init__(self, pipe_name=None, pipe_bundle=None, file_root='noe', results_dir=None, save_state=True):
43 """Perform relaxation curve fitting. 44 45 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: 46 47 - All the spins loaded. 48 - Unresolved spins deselected. 49 - The NOE peak intensities from the saturated and reference spectra. 50 - Either the baseplane noise RMSD values should be set or replicated spectra loaded. 51 52 @keyword pipe_name: The name of the data pipe containing all of the data for the analysis. 53 @type pipe_name: str 54 @keyword pipe_bundle: The data pipe bundle to associate all spawned data pipes with. 55 @type pipe_bundle: str 56 @keyword file_root: File root of the output filea. 57 @type file_root: str 58 @keyword results_dir: The directory where results files are saved. 59 @type results_dir: str 60 @keyword save_state: A flag which if True will cause a relax save state to be created at the end of the analysis. 61 @type save_state: bool 62 """ 63 64 # Initial printout. 65 title(file=sys.stdout, text="Steady-state NOE auto-analysis") 66 67 # Safely execute the full protocol. 68 try: 69 # Execution lock. 70 status.exec_lock.acquire(pipe_bundle, mode='auto-analysis') 71 72 # Set up the analysis status object. 73 status.init_auto_analysis(pipe_bundle, type='noe') 74 status.current_analysis = pipe_bundle 75 76 # Store the args. 77 self.save_state = save_state 78 self.pipe_name = pipe_name 79 self.pipe_bundle = pipe_bundle 80 self.file_root = file_root 81 self.results_dir = results_dir 82 if self.results_dir: 83 self.grace_dir = results_dir + sep + 'grace' 84 else: 85 self.grace_dir = 'grace' 86 87 # Data checks. 88 self.check_vars() 89 90 # Set the data pipe to the current data pipe. 91 if self.pipe_name != cdp_name(): 92 switch(self.pipe_name) 93 94 # Load the interpreter. 95 self.interpreter = Interpreter(show_script=False, raise_relax_error=True) 96 self.interpreter.populate_self() 97 self.interpreter.on(verbose=False) 98 99 # Execute. 100 self.run() 101 102 # Clean up. 103 finally: 104 # Final printout. 105 title(file=sys.stdout, text="Completion of the steady-state NOE auto-analysis") 106 print_elapsed_time(time() - status.start_time) 107 108 # Finish and unlock execution. 109 status.auto_analysis[self.pipe_bundle].fin = True 110 status.current_analysis = None 111 status.exec_lock.release()
112 113
114 - def run(self):
115 """Set up and run the NOE analysis.""" 116 117 # Peak intensity error analysis. 118 self.interpreter.spectrum.error_analysis() 119 120 # Calculate the NOEs. 121 self.interpreter.minimise.calculate() 122 123 # Save the NOEs. 124 self.interpreter.value.write(param='noe', file=self.file_root+'.out', dir=self.results_dir, force=True) 125 126 # Save the results. 127 self.interpreter.results.write(file='results', dir=self.results_dir, force=True) 128 129 # Create Grace plots of the data. 130 self.interpreter.grace.write(y_data_type='peak_intensity', file='intensities.agr', dir=self.grace_dir, force=True) 131 self.interpreter.grace.write(y_data_type='noe', file='noe.agr', dir=self.grace_dir, force=True) 132 133 # Create the Python "grace to PNG/EPS/SVG..." conversion script. 134 create_grace2images(dir=self.grace_dir) 135 136 # Save the program state. 137 if self.save_state: 138 self.interpreter.state.save(state='state', dir=self.results_dir, force=True)
139 140
141 - def check_vars(self):
142 """Check that the user has set the variables correctly.""" 143 144 # The pipe name. 145 if not has_pipe(self.pipe_name): 146 raise RelaxNoPipeError(self.pipe_name)
147