Package prompt :: Module relax_fit
[hide private]
[frames] | no frames]

Source Code for Module prompt.relax_fit

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2004, 2006 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  import sys 
 24   
 25  import help 
 26   
 27   
28 -class Relax_fit:
29 - def __init__(self, relax):
30 # Help. 31 self.__relax_help__ = \ 32 """Class for relaxation curve fitting.""" 33 34 # Add the generic help string. 35 self.__relax_help__ = self.__relax_help__ + "\n" + help.relax_class_help 36 37 # Place relax in the class namespace. 38 self.__relax__ = relax
39 40
41 - def mean_and_error(self, run=None):
42 """Function for calculating the average intensity and standard deviation of all spectra. 43 44 Keyword Arguments 45 ~~~~~~~~~~~~~~~~~ 46 47 run: The name of the run. 48 49 50 Errors of individual residues at a single time point 51 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 52 53 The standard deviation for a single residue at a single time point is calculated by the 54 formula 55 56 ----- 57 58 sigma = sum({Ii - Iav}^2) / (n - 1) , 59 60 ----- 61 62 where sigma is the variance or square of the standard deviation, n is the total number of 63 collected spectra for the time point and i is the corresponding index, Ii is the peak 64 intensity for spectrum i, Iav is the mean over all spectra, ie the sum of all peak 65 intensities divided by n. 66 67 68 Averaging of the errors 69 ~~~~~~~~~~~~~~~~~~~~~~~ 70 71 As the value of n in the above equation is always very low, normally only a couple of 72 spectra are collected per time point, the variance of all spins is averaged for a single 73 time point. Although this results in all spins having the same error, the accuracy of the 74 error estimate is significantly improved. 75 76 77 Errors across multiple time points 78 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 79 80 If all spectra are collected in duplicate (triplicate or higher number of spectra are 81 supported), the each time point will have its own error estimate. However, if there are 82 time points in the series which only consist of a single spectrum, then the variances of 83 replicated time points will be averaged. Hence, for the entire experiment there will be a 84 single error value for all spins and for all time points. 85 86 A better approach rather than averaging across all time points would be to use a form of 87 interpolation as the errors across time points generally decreases for longer time periods. 88 This is currently not implemented. 89 """ 90 91 92 # Function intro text. 93 if self.__relax__.interpreter.intro: 94 text = sys.ps3 + "relax_fit.mean_and_error(" 95 text = text + "run=" + `run` + ")" 96 print text 97 98 # The run argument. 99 if type(run) != str: 100 raise RelaxStrError, ('run', run) 101 102 # Execute the functional code. 103 self.__relax__.specific.relax_fit.mean_and_error(run=run)
104 105
106 - def read(self, run=None, file=None, dir=None, relax_time=0.0, format='sparky', heteronuc='N', proton='HN', int_col=None):
107 """Function for reading peak intensities from a file. 108 109 Keyword Arguments 110 ~~~~~~~~~~~~~~~~~ 111 112 run: The name of the run. 113 114 file: The name of the file containing the sequence data. 115 116 dir: The directory where the file is located. 117 118 relax_time: The time, in seconds, of the relaxation period. 119 120 format: The type of file containing peak intensities. 121 122 heteronuc: The name of the heteronucleus as specified in the peak intensity file. 123 124 proton: The name of the proton as specified in the peak intensity file. 125 126 int_col: The column containing the peak intensity data (for a non-standard formatted file). 127 128 129 Description 130 ~~~~~~~~~~~ 131 132 The peak intensity can either be from peak heights or peak volumes. 133 134 135 The format argument can currently be set to: 136 'sparky' 137 'xeasy' 138 139 If the format argument is set to 'sparky', the file should be a Sparky peak list saved after 140 typing the command 'lt'. The default is to assume that columns 0, 1, 2, and 3 (1st, 2nd, 141 3rd, and 4th) contain the Sparky assignment, w1, w2, and peak intensity data respectively. 142 The frequency data w1 and w2 are ignored while the peak intensity data can either be the 143 peak height or volume displayed by changing the window options. If the peak intensity data 144 is not within column 3, set the argument int_col to the appropriate value (column numbering 145 starts from 0 rather than 1). 146 147 If the format argument is set to 'xeasy', the file should be the saved XEasy text window 148 output of the list peak entries command, 'tw' followed by 'le'. As the columns are fixed, 149 the peak intensity column is hardwired to number 10 (the 11th column) which contains either 150 the peak height or peak volume data. Because the columns are fixed, the int_col argument 151 will be ignored. 152 153 154 The heteronuc and proton arguments should be set respectively to the name of the 155 heteronucleus and proton in the file. Only those lines which match these labels will be 156 used. 157 158 159 """ 160 161 # Function intro text. 162 if self.__relax__.interpreter.intro: 163 text = sys.ps3 + "relax_fit.read(" 164 text = text + "run=" + `run` 165 text = text + ", file=" + `file` 166 text = text + ", dir=" + `dir` 167 text = text + ", relax_time=" + `relax_time` 168 text = text + ", format=" + `format` 169 text = text + ", heteronuc=" + `heteronuc` 170 text = text + ", proton=" + `proton` 171 text = text + ", int_col=" + `int_col` + ")" 172 print text 173 174 # The run argument. 175 if type(run) != str: 176 raise RelaxStrError, ('run', run) 177 178 # The file name. 179 if type(file) != str: 180 raise RelaxStrError, ('file name', file) 181 182 # Directory. 183 if dir != None and type(dir) != str: 184 raise RelaxNoneStrError, ('directory name', dir) 185 186 # The relaxation time. 187 if type(relax_time) != float: 188 raise RelaxFloatError, ('relaxation time', relax_time) 189 190 # The format. 191 if type(format) != str: 192 raise RelaxStrError, ('format', format) 193 194 # The heteronucleus name. 195 if type(heteronuc) != str: 196 raise RelaxStrError, ('heteronucleus name', heteronuc) 197 198 # The proton name. 199 if type(proton) != str: 200 raise RelaxStrError, ('proton name', proton) 201 202 # The intensity column. 203 if int_col and type(int_col) != int: 204 raise RelaxNoneIntError, ('intensity column', int_col) 205 206 # Execute the functional code. 207 self.__relax__.specific.relax_fit.read(run=run, file=file, dir=dir, relax_time=relax_time, format=format, heteronuc=heteronuc, proton=proton, int_col=int_col)
208 209
210 - def select_model(self, run=None, model='exp'):
211 """Function for the selection of the relaxation curve type. 212 213 Keyword Arguments 214 ~~~~~~~~~~~~~~~~~ 215 216 run: The name of the run. 217 218 model: The type of relaxation curve to fit. 219 220 221 The preset models 222 ~~~~~~~~~~~~~~~~~ 223 224 The supported relaxation experiments include the default two parameter exponential fit, 225 selected by setting the 'fit_type' argument to 'exp', and the three parameter inversion 226 recovery experiment in which the peak intensity limit is a non-zero value, selected by 227 setting the argument to 'inv'. 228 229 The parameters of these two models are 230 'exp': [Rx, I0], 231 'inv': [Rx, I0, Iinf]. 232 """ 233 234 # Function intro text. 235 if self.__relax__.interpreter.intro: 236 text = sys.ps3 + "relax_fit.select_model(" 237 text = text + "run=" + `run` 238 text = text + ", model=" + `model` + ")" 239 print text 240 241 # The run argument. 242 if type(run) != str: 243 raise RelaxStrError, ('run', run) 244 245 # The model argument. 246 if type(model) != str: 247 raise RelaxStrError, ('model', model) 248 249 # Execute the functional code. 250 self.__relax__.specific.relax_fit.select_model(run=run, model=model)
251