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