Package specific_analyses :: Module api
[hide private]
[frames] | no frames]

Source Code for Module specific_analyses.api

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2004,2007-2009,2014 Edward d'Auvergne                         # 
  4  # Copyright (C) 2008 Sebastien Morin                                          # 
  5  #                                                                             # 
  6  # This file is part of the program relax (http://www.nmr-relax.com).          # 
  7  #                                                                             # 
  8  # This program is free software: you can redistribute it and/or modify        # 
  9  # it under the terms of the GNU General Public License as published by        # 
 10  # the Free Software Foundation, either version 3 of the License, or           # 
 11  # (at your option) any later version.                                         # 
 12  #                                                                             # 
 13  # This program is distributed in the hope that it will be useful,             # 
 14  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
 15  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
 16  # GNU General Public License for more details.                                # 
 17  #                                                                             # 
 18  # You should have received a copy of the GNU General Public License           # 
 19  # along with this program.  If not, see <http://www.gnu.org/licenses/>.       # 
 20  #                                                                             # 
 21  ############################################################################### 
 22   
 23  # Module docstring. 
 24  """The specific analysis API. 
 25   
 26  This module is for directly accessing the specific analysis API.  The individual API objects should not be accessed directly, but instead the functions here should be used. 
 27  """ 
 28   
 29  # relax module imports. 
 30  from data_store import Relax_data_store; ds = Relax_data_store() 
 31  from lib.errors import RelaxError 
 32  from pipe_control.pipes import check_pipe 
 33   
 34   
35 -def get_string(function_type):
36 """Function for returning a string corresponding to the function type.""" 37 38 # Consistency testing. 39 if function_type == 'ct': 40 return "consistency testing" 41 42 # The Frame Order theories. 43 if function_type == 'frame order': 44 return "Frame Order theories" 45 46 # NOE calculation. 47 if function_type == 'noe': 48 return "NOE calculations" 49 50 # The N-state model. 51 if function_type == 'N-state': 52 return "the N-state model" 53 54 # Relaxation dispersion curve fitting. 55 if function_type == 'relax_disp': 56 return "relaxation dispersion curve fitting" 57 58 # Relaxation curve fitting. 59 if function_type == 'relax_fit': 60 return "relaxation curve fitting" 61 62 # Reduced spectral density mapping. 63 if function_type == 'jw': 64 return "reduced spectral density mapping" 65 66 # Model-free analysis. 67 if function_type == 'mf': 68 return "Model-free analysis" 69 70 # Hybrid models. 71 if function_type == 'hybrid': 72 return "hybrid models" 73 74 # Unknown analysis. 75 raise RelaxError("The function_type " + repr(function_type) + " is unknown.")
76 77
78 -def return_api(analysis_type=None, pipe_name=None):
79 """Return the specific analysis API class instance corresponding to the function type. 80 81 @keyword analysis_type: The specific analysis type. This overrides the pipe_name argument. 82 @type analysis_type: str or None 83 @keyword pipe_name: The name of the data pipe to obtain the analysis type from. This is ignored if the analysis_type argument is given. If both arguments are None, then the current data pipe will be used. 84 """ 85 86 # The analysis type, if not given. 87 if analysis_type is None: 88 # Check if a data pipe exists. 89 check_pipe() 90 91 # Use a custom data pipe name. 92 if pipe_name: 93 analysis_type = ds[pipe_name].pipe_type 94 95 # Use the current data pipe. 96 else: 97 analysis_type = cdp.pipe_type 98 99 # Initialise the analysis object. 100 obj = None 101 102 # Consistency testing. 103 if analysis_type == 'ct': 104 from specific_analyses.consistency_tests.api import Consistency_tests 105 obj = Consistency_tests() 106 107 # The Frame Order theories. 108 elif analysis_type == 'frame order': 109 from specific_analyses.frame_order.api import Frame_order 110 obj = Frame_order() 111 112 # Hybrid models. 113 elif analysis_type == 'hybrid': 114 from specific_analyses.hybrid import Hybrid 115 obj = Hybrid() 116 117 # Reduced spectral density mapping. 118 elif analysis_type == 'jw': 119 from specific_analyses.jw_mapping.api import Jw_mapping 120 obj = Jw_mapping() 121 122 # Model-free analysis. 123 elif analysis_type == 'mf': 124 from specific_analyses.model_free.api import Model_free 125 obj = Model_free() 126 127 # The N-state model. 128 elif analysis_type == 'N-state': 129 from specific_analyses.n_state_model.api import N_state_model 130 obj = N_state_model() 131 132 # NOE calculation. 133 elif analysis_type == 'noe': 134 from specific_analyses.noe.api import Noe 135 obj = Noe() 136 137 # Relaxation dispersion curve fitting. 138 elif analysis_type == 'relax_disp': 139 from specific_analyses.relax_disp.api import Relax_disp 140 obj = Relax_disp() 141 142 # Relaxation curve fitting. 143 elif analysis_type == 'relax_fit': 144 from specific_analyses.relax_fit.api import Relax_fit 145 obj = Relax_fit() 146 147 # Return the object. 148 if obj != None: 149 return obj 150 151 # Unknown analysis. 152 raise RelaxError("The analysis type '%s' is unknown." % analysis_type)
153 154
155 -def return_parameter_object(analysis_type=None, pipe_name=None):
156 """Return the specific analysis API parameter object corresponding to the function type. 157 158 @keyword analysis_type: The specific analysis type. This overrides the pipe_name argument. 159 @type analysis_type: str or None 160 @keyword pipe_name: The name of the data pipe to obtain the analysis type from. This is ignored if the analysis_type argument is given. If both arguments are None, then the current data pipe will be used. 161 """ 162 163 # The analysis type, if not given. 164 if analysis_type is None: 165 # Check if a data pipe exists. 166 check_pipe() 167 168 # Use a custom data pipe name. 169 if pipe_name: 170 analysis_type = ds[pipe_name].pipe_type 171 172 # Use the current data pipe. 173 else: 174 analysis_type = cdp.pipe_type 175 176 # Consistency testing. 177 if analysis_type == 'ct': 178 from specific_analyses.consistency_tests.parameter_object import Consistency_tests_params 179 return Consistency_tests_params() 180 181 # The Frame Order theories. 182 elif analysis_type == 'frame order': 183 from specific_analyses.frame_order.parameter_object import Frame_order_params 184 return Frame_order_params() 185 186 # Hybrid models. 187 elif analysis_type == 'hybrid': 188 from specific_analyses.hybrid import Hybrid_params 189 return Hybrid_params() 190 191 # Reduced spectral density mapping. 192 elif analysis_type == 'jw': 193 from specific_analyses.jw_mapping.parameter_object import Jw_mapping_params 194 return Jw_mapping_params() 195 196 # Model-free analysis. 197 elif analysis_type == 'mf': 198 from specific_analyses.model_free.parameter_object import Model_free_params 199 return Model_free_params() 200 201 # The N-state model. 202 elif analysis_type == 'N-state': 203 from specific_analyses.n_state_model.parameter_object import N_state_params 204 return N_state_params() 205 206 # NOE calculation. 207 elif analysis_type == 'noe': 208 from specific_analyses.noe.parameter_object import Noe_params 209 return Noe_params() 210 211 # Relaxation dispersion curve fitting. 212 elif analysis_type == 'relax_disp': 213 from specific_analyses.relax_disp.parameter_object import Relax_disp_params 214 return Relax_disp_params() 215 216 # Relaxation curve fitting. 217 elif analysis_type == 'relax_fit': 218 from specific_analyses.relax_fit.parameter_object import Relax_fit_params 219 return Relax_fit_params() 220 221 # Unknown analysis. 222 else: 223 raise RelaxError("The analysis type '%s' is unknown." % analysis_type)
224