Package specific_fns :: Package noe :: Module main
[hide private]
[frames] | no frames]

Source Code for Module specific_fns.noe.main

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2004-2012 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  # Python module imports. 
 24  from math import sqrt 
 25  from re import match 
 26  from warnings import warn 
 27   
 28  # relax module imports. 
 29  from generic_fns import pipes 
 30  from generic_fns.mol_res_spin import exists_mol_res_spin_data, spin_loop 
 31  from relax_errors import RelaxArgNotInListError, RelaxError, RelaxNoSequenceError 
 32  from relax_warnings import RelaxDeselectWarning 
 33  from specific_fns.api_common import API_common 
 34   
 35   
36 -class Noe_main:
37 """Class containing functions for relaxation data.""" 38
39 - def _assign_function(self, spin=None, intensity=None, spectrum_type=None):
40 """Place the peak intensity data into the spin container. 41 42 The intensity data can be either that of the reference or saturated spectrum. 43 44 @keyword spin: The spin container. 45 @type spin: SpinContainer instance 46 @keyword intensity: The intensity value. 47 @type intensity: float 48 @keyword spectrum_type: The type of spectrum, one of 'ref' or 'sat'. 49 @type spectrum_type: str 50 """ 51 52 # Add the data. 53 if spectrum_type == 'ref': 54 spin.ref = intensity 55 elif spectrum_type == 'sat': 56 spin.sat = intensity 57 else: 58 raise RelaxError("The spectrum type '%s' is unknown." % spectrum_type)
59 60
61 - def _spectrum_type(self, spectrum_type=None, spectrum_id=None):
62 """Set the spectrum type corresponding to the spectrum_id. 63 64 @keyword spectrum_type: The type of NOE spectrum, one of 'ref' or 'sat'. 65 @type spectrum_type: str 66 @keyword spectrum_id: The spectrum id string. 67 @type spectrum_id: str 68 """ 69 70 # Test if the current pipe exists 71 pipes.test() 72 73 # Test the spectrum id string. 74 if spectrum_id not in cdp.spectrum_ids: 75 raise RelaxError("The peak intensities corresponding to the spectrum id '%s' does not exist." % spectrum_id) 76 77 # Initialise or update the spectrum_type data structure as necessary. 78 if not hasattr(cdp, 'spectrum_type'): 79 cdp.spectrum_type = {} 80 81 # Set the error. 82 cdp.spectrum_type[spectrum_id] = spectrum_type
83 84
85 - def calculate(self, spin_id=None, verbosity=1, sim_index=None):
86 """Calculate the NOE and its error. 87 88 The error for each peak is calculated using the formula:: 89 ___________________________________________ 90 \/ {sd(sat)*I(unsat)}^2 + {sd(unsat)*I(sat)}^2 91 sd(NOE) = ----------------------------------------------- 92 I(unsat)^2 93 94 @keyword spin_id: The spin identification string. 95 @type spin_id: None or str 96 @keyword verbosity: The amount of information to print. The higher the value, the greater the verbosity. 97 @type verbosity: int 98 @keyword sim_index: The MC simulation index (unused). 99 @type sim_index: None 100 """ 101 102 # Test if the current pipe exists. 103 pipes.test() 104 105 # The spectrum types have not been set. 106 if not hasattr(cdp, 'spectrum_type'): 107 raise RelaxError("The spectrum types have not been set.") 108 109 # Test if the 2 spectra types 'ref' and 'sat' exist. 110 if not 'ref' in cdp.spectrum_type.values() or not 'sat' in cdp.spectrum_type.values(): 111 raise RelaxError("The reference and saturated NOE spectra have not been loaded.") 112 113 # Loop over the spins. 114 for spin in spin_loop(): 115 # Skip deselected spins. 116 if not spin.select: 117 continue 118 119 # Average intensities (if required). 120 sat = 0.0 121 sat_err = 0.0 122 ref = 0.0 123 ref_err = 0.0 124 for id in cdp.spectrum_ids: 125 # Sat spectra. 126 if cdp.spectrum_type[id] == 'sat': 127 sat = sat + spin.intensities[id] 128 sat_err = sat_err + spin.intensity_err[id] 129 130 # Ref spectra. 131 if cdp.spectrum_type[id] == 'ref': 132 ref = ref + spin.intensities[id] 133 ref_err = ref_err + spin.intensity_err[id] 134 135 # Calculate the NOE. 136 spin.noe = sat / ref 137 138 # Calculate the error. 139 spin.noe_err = sqrt((sat_err * ref)**2 + (ref_err * sat)**2) / ref**2
140 141
142 - def data_names(self, set='all', error_names=False, sim_names=False):
143 """Return a list of all spin container specific model-free object names. 144 145 Description 146 =========== 147 148 The names are as follows: 149 150 - 'model', the model-free model name. 151 - 'equation', the model-free equation type. 152 - 'params', an array of the model-free parameter names associated with the model. 153 - 's2', S2. 154 - 's2f', S2f. 155 - 's2s', S2s. 156 - 'local_tm', local tm. 157 - 'te', te. 158 - 'tf', tf. 159 - 'ts', ts. 160 - 'rex', Rex. 161 - 'r', bond length. 162 - 'csa', CSA value. 163 - 'nucleus', the heteronucleus type. 164 - 'chi2', chi-squared value. 165 - 'iter', iterations. 166 - 'f_count', function count. 167 - 'g_count', gradient count. 168 - 'h_count', hessian count. 169 - 'warning', minimisation warning. 170 171 172 @keyword set: The set of object names to return. This can be set to 'all' for all 173 names, to 'generic' for generic object names, 'params' for 174 model-free parameter names, or to 'min' for minimisation specific 175 object names. 176 @type set: str 177 @keyword error_names: A flag which if True will add the error object names as well. 178 @type error_names: bool 179 @keyword sim_names: A flag which if True will add the Monte Carlo simulation object 180 names as well. 181 @type sim_names: bool 182 @return: The list of object names. 183 @rtype: list of str 184 """ 185 186 # Initialise. 187 names = [] 188 189 # Generic. 190 if set == 'all' or set == 'generic': 191 names.append('select') 192 names.append('fixed') 193 names.append('ref') 194 names.append('sat') 195 196 # Parameters. 197 if set == 'all' or set == 'params': 198 names.append('noe') 199 200 # Parameter errors. 201 if error_names and (set == 'all' or set == 'params'): 202 names.append('noe_err') 203 204 # Return the names. 205 return names
206 207
208 - def overfit_deselect(self):
209 """Deselect spins which have insufficient data to support calculation.""" 210 211 # Print out. 212 print("\n\nOver-fit spin deselection.\n") 213 214 # Test the sequence data exists. 215 if not exists_mol_res_spin_data(): 216 raise RelaxNoSequenceError 217 218 # Loop over spin data. 219 for spin, spin_id in spin_loop(return_id=True): 220 # Skip deselected spins. 221 if not spin.select: 222 continue 223 224 # Check for sufficient data. 225 if not hasattr(spin, 'intensities') or not len(spin.intensities) == 2: 226 warn(RelaxDeselectWarning(spin_id, 'insufficient data')) 227 spin.select = False 228 229 # Check for sufficient errors. 230 elif not hasattr(spin, 'intensity_err') or not len(spin.intensity_err) == 2: 231 warn(RelaxDeselectWarning(spin_id, 'missing errors')) 232 spin.select = False
233 234 235 return_data_name_doc = ["NOE calculation data type string matching patterns", """ 236 _________________________________________ 237 | | | 238 | Data type | Object name | 239 |________________________|______________| 240 | | | 241 | Reference intensity | 'ref' | 242 | | | 243 | Saturated intensity | 'sat' | 244 | | | 245 | NOE | 'noe' | 246 |________________________|______________| 247 248 """] 249 250
251 - def return_units(self, param):
252 """Dummy function which returns None as the stats have no units. 253 254 @param param: The name of the parameter to return the units string for. 255 @type param: str 256 @return: Nothing. 257 @rtype: None 258 """ 259 260 return None
261