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

Source Code for Module specific_analyses.noe.api

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2003-2005,2007-2012,2014 Edward d'Auvergne                    # 
  4  # Copyright (C) 2006 Chris MacRaild                                           # 
  5  # Copyright (C) 2008 Sebastien Morin                                          # 
  6  #                                                                             # 
  7  # This file is part of the program relax (http://www.nmr-relax.com).          # 
  8  #                                                                             # 
  9  # This program is free software: you can redistribute it and/or modify        # 
 10  # it under the terms of the GNU General Public License as published by        # 
 11  # the Free Software Foundation, either version 3 of the License, or           # 
 12  # (at your option) any later version.                                         # 
 13  #                                                                             # 
 14  # This program is distributed in the hope that it will be useful,             # 
 15  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
 16  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
 17  # GNU General Public License for more details.                                # 
 18  #                                                                             # 
 19  # You should have received a copy of the GNU General Public License           # 
 20  # along with this program.  If not, see <http://www.gnu.org/licenses/>.       # 
 21  #                                                                             # 
 22  ############################################################################### 
 23   
 24  # Module docstring. 
 25  """The steady-state heteronuclear NOE API object.""" 
 26   
 27  # Python module imports. 
 28  from math import sqrt 
 29  from warnings import warn 
 30   
 31  # relax module imports. 
 32  from lib.errors import RelaxError, RelaxNoSequenceError 
 33  from lib.warnings import RelaxDeselectWarning 
 34  from pipe_control.mol_res_spin import exists_mol_res_spin_data, spin_loop 
 35  from pipe_control.pipes import check_pipe 
 36  from specific_analyses.api_base import API_base 
 37  from specific_analyses.api_common import API_common 
 38  from specific_analyses.noe.parameter_object import Noe_params 
 39   
 40   
41 -class Noe(API_base, API_common):
42 """Specific analysis API class for the steady-state heternuclear NOE analysis.""" 43 44 # Class variable for storing the class instance (for the singleton design pattern). 45 instance = None 46
47 - def __init__(self):
48 """Initialise the class by placing API_common methods into the API.""" 49 50 # Place methods into the API. 51 self.model_loop = self._model_loop_spin 52 self.return_conversion_factor = self._return_no_conversion_factor 53 self.return_value = self._return_value_general 54 55 # Place a copy of the parameter list object in the instance namespace. 56 self._PARAMS = Noe_params()
57 58
59 - def calculate(self, spin_id=None, scaling_matrix=None, verbosity=1, sim_index=None):
60 """Calculate the NOE and its error. 61 62 The error for each peak is calculated using the formula:: 63 ___________________________________________ 64 \/ {sd(sat)*I(unsat)}^2 + {sd(unsat)*I(sat)}^2 65 sd(NOE) = ----------------------------------------------- 66 I(unsat)^2 67 68 @keyword spin_id: The spin identification string. 69 @type spin_id: None or str 70 @keyword scaling_matrix: The per-model list of diagonal and square scaling matrices. 71 @type scaling_matrix: list of numpy rank-2, float64 array or list of None 72 @keyword verbosity: The amount of information to print. The higher the value, the greater the verbosity. 73 @type verbosity: int 74 @keyword sim_index: The MC simulation index (unused). 75 @type sim_index: None 76 """ 77 78 # Test if the current pipe exists. 79 check_pipe() 80 81 # The spectrum types have not been set. 82 if not hasattr(cdp, 'spectrum_type'): 83 raise RelaxError("The spectrum types have not been set.") 84 85 # Test if the 2 spectra types 'ref' and 'sat' exist. 86 if not 'ref' in list(cdp.spectrum_type.values()) or not 'sat' in list(cdp.spectrum_type.values()): 87 raise RelaxError("The reference and saturated NOE spectra have not been loaded.") 88 89 # Loop over the spins. 90 for spin in spin_loop(): 91 # Skip deselected spins. 92 if not spin.select: 93 continue 94 95 # Average intensities and squared errors (if required). 96 sat = 0.0 97 sat_err2 = 0.0 98 sat_count = 0 99 ref = 0.0 100 ref_err2 = 0.0 101 ref_count = 0 102 for id in cdp.spectrum_ids: 103 # Sat spectra. 104 if cdp.spectrum_type[id] == 'sat': 105 sat += spin.peak_intensity[id] 106 sat_err2 += spin.peak_intensity_err[id]**2 107 sat_count += 1 108 109 # Ref spectra. 110 if cdp.spectrum_type[id] == 'ref': 111 ref += spin.peak_intensity[id] 112 ref_err2 += spin.peak_intensity_err[id]**2 113 ref_count += 1 114 115 # Average the values and errors (variance averaging). 116 sat = sat / sat_count 117 sat_err2 = sat_err2 / sat_count 118 ref = ref / ref_count 119 ref_err2 = ref_err2 / ref_count 120 121 # Calculate the NOE. 122 spin.noe = sat / ref 123 124 # Calculate the error. 125 spin.noe_err = sqrt(sat_err2 * ref**2 + ref_err2 * sat**2) / ref**2
126 127
128 - def get_param_names(self, model_info=None):
129 """Return a vector of parameter names. 130 131 @keyword model_info: The spin container and the spin ID string from the _model_loop_spin() method. 132 @type model_info: SpinContainer instance, str 133 @return: The vector of parameter names. 134 @rtype: list of str 135 """ 136 137 # Simply return the two parameter names. 138 return ['noe']
139 140
141 - def overfit_deselect(self, data_check=True, verbose=True):
142 """Deselect spins which have insufficient data to support calculation. 143 144 @keyword data_check: A flag to signal if the presence of base data is to be checked for. 145 @type data_check: bool 146 @keyword verbose: A flag which if True will allow printouts. 147 @type verbose: bool 148 """ 149 150 # Print out. 151 if verbose: 152 print("\nOver-fit spin deselection:") 153 154 # Test the sequence data exists. 155 if not exists_mol_res_spin_data(): 156 raise RelaxNoSequenceError 157 158 # Loop over spin data. 159 deselect_flag = False 160 all_desel = True 161 for spin, spin_id in spin_loop(return_id=True): 162 # Skip deselected spins. 163 if not spin.select: 164 continue 165 166 # No intensity data. 167 if not hasattr(spin, 'peak_intensity'): 168 warn(RelaxDeselectWarning(spin_id, 'the absence of intensity data')) 169 spin.select = False 170 deselect_flag = True 171 continue 172 173 # Check for sufficient data. 174 if not len(spin.peak_intensity) >= 2: 175 warn(RelaxDeselectWarning(spin_id, 'insufficient data (less than two data points)')) 176 spin.select = False 177 deselect_flag = True 178 continue 179 180 # No error data. 181 if not hasattr(spin, 'peak_intensity_err'): 182 warn(RelaxDeselectWarning(spin_id, 'the absence of errors')) 183 spin.select = False 184 deselect_flag = True 185 continue 186 187 # Check for sufficient errors. 188 if not len(spin.peak_intensity_err) >= 2: 189 warn(RelaxDeselectWarning(spin_id, 'missing errors (less than two error points)')) 190 spin.select = False 191 deselect_flag = True 192 continue 193 194 # Not all spins have been deselected. 195 all_desel = False 196 197 # Final printout. 198 if verbose and not deselect_flag: 199 print("No spins have been deselected.") 200 201 # Catch complete failures - i.e. no spins are selected. 202 if all_desel: 203 raise RelaxError("All spins have been deselected.")
204