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 (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  # Python module imports. 
 23  from math import sqrt 
 24  from re import match 
 25  from warnings import warn 
 26   
 27  # relax module imports. 
 28  from generic_fns import pipes 
 29  from generic_fns.mol_res_spin import exists_mol_res_spin_data, spin_loop 
 30  from relax_errors import RelaxArgNotInListError, RelaxError, RelaxNoSequenceError 
 31  from relax_warnings import RelaxDeselectWarning 
 32  from specific_fns.api_common import API_common 
 33  from user_functions.data import Uf_tables; uf_tables = Uf_tables() 
 34  from user_functions.objects import Desc_container 
 35   
 36   
37 -class Noe_main:
38 """Class containing functions for relaxation data.""" 39
40 - def _assign_function(self, spin=None, intensity=None, spectrum_type=None):
41 """Place the peak intensity data into the spin container. 42 43 The intensity data can be either that of the reference or saturated spectrum. 44 45 @keyword spin: The spin container. 46 @type spin: SpinContainer instance 47 @keyword intensity: The intensity value. 48 @type intensity: float 49 @keyword spectrum_type: The type of spectrum, one of 'ref' or 'sat'. 50 @type spectrum_type: str 51 """ 52 53 # Add the data. 54 if spectrum_type == 'ref': 55 spin.ref = intensity 56 elif spectrum_type == 'sat': 57 spin.sat = intensity 58 else: 59 raise RelaxError("The spectrum type '%s' is unknown." % spectrum_type)
60 61
62 - def _spectrum_type(self, spectrum_type=None, spectrum_id=None):
63 """Set the spectrum type corresponding to the spectrum_id. 64 65 @keyword spectrum_type: The type of NOE spectrum, one of 'ref' or 'sat'. 66 @type spectrum_type: str 67 @keyword spectrum_id: The spectrum id string. 68 @type spectrum_id: str 69 """ 70 71 # Test if the current pipe exists 72 pipes.test() 73 74 # Test the spectrum id string. 75 if spectrum_id not in cdp.spectrum_ids: 76 raise RelaxError("The peak intensities corresponding to the spectrum id '%s' does not exist." % spectrum_id) 77 78 # Initialise or update the spectrum_type data structure as necessary. 79 if not hasattr(cdp, 'spectrum_type'): 80 cdp.spectrum_type = {} 81 82 # Set the error. 83 cdp.spectrum_type[spectrum_id] = spectrum_type
84 85
86 - def calculate(self, spin_id=None, verbosity=1, sim_index=None):
87 """Calculate the NOE and its error. 88 89 The error for each peak is calculated using the formula:: 90 ___________________________________________ 91 \/ {sd(sat)*I(unsat)}^2 + {sd(unsat)*I(sat)}^2 92 sd(NOE) = ----------------------------------------------- 93 I(unsat)^2 94 95 @keyword spin_id: The spin identification string. 96 @type spin_id: None or str 97 @keyword verbosity: The amount of information to print. The higher the value, the greater the verbosity. 98 @type verbosity: int 99 @keyword sim_index: The MC simulation index (unused). 100 @type sim_index: None 101 """ 102 103 # Test if the current pipe exists. 104 pipes.test() 105 106 # The spectrum types have not been set. 107 if not hasattr(cdp, 'spectrum_type'): 108 raise RelaxError("The spectrum types have not been set.") 109 110 # Test if the 2 spectra types 'ref' and 'sat' exist. 111 if not 'ref' in cdp.spectrum_type.values() or not 'sat' in cdp.spectrum_type.values(): 112 raise RelaxError("The reference and saturated NOE spectra have not been loaded.") 113 114 # Loop over the spins. 115 for spin in spin_loop(): 116 # Skip deselected spins. 117 if not spin.select: 118 continue 119 120 # Average intensities (if required). 121 sat = 0.0 122 sat_err = 0.0 123 ref = 0.0 124 ref_err = 0.0 125 for id in cdp.spectrum_ids: 126 # Sat spectra. 127 if cdp.spectrum_type[id] == 'sat': 128 sat = sat + spin.intensities[id] 129 sat_err = sat_err + spin.intensity_err[id] 130 131 # Ref spectra. 132 if cdp.spectrum_type[id] == 'ref': 133 ref = ref + spin.intensities[id] 134 ref_err = ref_err + spin.intensity_err[id] 135 136 # Calculate the NOE. 137 spin.noe = sat / ref 138 139 # Calculate the error. 140 spin.noe_err = sqrt((sat_err * ref)**2 + (ref_err * sat)**2) / ref**2
141 142
143 - def overfit_deselect(self, data_check=True, verbose=True):
144 """Deselect spins which have insufficient data to support calculation. 145 146 @keyword data_check: A flag to signal if the presence of base data is to be checked for. 147 @type data_check: bool 148 @keyword verbose: A flag which if True will allow printouts. 149 @type verbose: bool 150 """ 151 152 # Print out. 153 if verbose: 154 print("\nOver-fit spin deselection:") 155 156 # Test the sequence data exists. 157 if not exists_mol_res_spin_data(): 158 raise RelaxNoSequenceError 159 160 # Loop over spin data. 161 deselect_flag = False 162 for spin, spin_id in spin_loop(return_id=True): 163 # Skip deselected spins. 164 if not spin.select: 165 continue 166 167 # Check for sufficient data. 168 if not hasattr(spin, 'intensities') or not len(spin.intensities) == 2: 169 warn(RelaxDeselectWarning(spin_id, 'insufficient data')) 170 spin.select = False 171 deselect_flag = True 172 continue 173 174 # Check for sufficient errors. 175 elif not hasattr(spin, 'intensity_err') or not len(spin.intensity_err) == 2: 176 warn(RelaxDeselectWarning(spin_id, 'missing errors')) 177 spin.select = False 178 deselect_flag = True 179 continue 180 181 # Final printout. 182 if verbose and not deselect_flag: 183 print("No spins have been deselected.")
184 185 186 return_data_name_doc = Desc_container("NOE calculation data type string matching patterns") 187 _table = uf_tables.add_table(label="table: NOE data type patterns", caption="NOE data type string matching patterns.") 188 _table.add_headings(["Data type", "Object name"]) 189 _table.add_row(["Reference intensity", "'ref'"]) 190 _table.add_row(["Saturated intensity", "'sat'"]) 191 _table.add_row(["NOE", "'noe'"]) 192 return_data_name_doc.add_table(_table.label) 193 194
195 - def return_units(self, param):
196 """Dummy function which returns None as the stats have no units. 197 198 @param param: The name of the parameter to return the units string for. 199 @type param: str 200 @return: Nothing. 201 @rtype: None 202 """ 203 204 return None
205