Package specific_fns :: Module base_class
[hide private]
[frames] | no frames]

Source Code for Module specific_fns.base_class

  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  from copy import deepcopy 
 24   
 25   
26 -class Common_functions:
27 - def __init__(self):
28 """Base class containing functions common to the specific functions."""
29 30
31 - def has_errors(self):
32 """Function for testing if errors exist for the run.""" 33 34 # Diffusion tensor errors. 35 if self.relax.data.diff.has_key(self.run): 36 for object_name in dir(self.relax.data.diff[self.run]): 37 # The object error name. 38 object_error = object_name + '_err' 39 40 # Error exists. 41 if hasattr(self.relax.data.diff[self.run], object_error): 42 return 1 43 44 # Loop over the sequence. 45 for i in xrange(len(self.relax.data.res[self.run])): 46 # Reassign data structure. 47 data = self.relax.data.res[self.run][i] 48 49 # Parameter errors. 50 for object_name in dir(data): 51 # The object error name. 52 object_error = object_name + '_err' 53 54 # Error exists. 55 if hasattr(data, object_error): 56 return 1 57 58 # No errors found. 59 return 0
60 61
62 - def return_data(self, run, i):
63 """Function for returning the Ri data structure.""" 64 65 return self.relax.data.res[run][i].relax_data
66 67
68 - def return_error(self, run, i):
69 """Function for returning the Ri error structure.""" 70 71 return self.relax.data.res[run][i].relax_error
72 73
74 - def return_value(self, run, i, param, sim=None):
75 """Function for returning the value and error corresponding to 'param'. 76 77 If sim is set to an integer, return the value of the simulation and None. 78 """ 79 80 # Arguments. 81 self.run = run 82 83 # Get the object name. 84 object_name = self.return_data_name(param) 85 86 # The data type does not exist. 87 if not object_name: 88 raise RelaxError, "The parameter " + `param` + " does not exist." 89 90 # The error and simulation names. 91 object_error = object_name + '_err' 92 object_sim = object_name + '_sim' 93 94 # Alias the residue specific data structure. 95 data = self.relax.data.res[self.run][i] 96 97 # Value and error. 98 if sim == None: 99 # Get the value. 100 if hasattr(data, object_name): 101 value = getattr(data, object_name) 102 elif hasattr(self.relax.data, object_name): 103 object = getattr(self.relax.data, object_name) 104 value = object[self.run] 105 else: 106 value = None 107 108 # Get the error. 109 if hasattr(data, object_error): 110 error = getattr(data, object_error) 111 elif hasattr(self.relax.data, object_error): 112 object = getattr(self.relax.data, object_error) 113 error = object[self.run] 114 else: 115 error = None 116 117 # Return the data. 118 return value, error 119 120 # Simulation value. 121 else: 122 # Get the value. 123 if hasattr(data, object_sim): 124 object = getattr(data, object_sim) 125 value = object[sim] 126 elif hasattr(self.relax.dat, object_sim): 127 object = getattr(self.relax.dat, object_sim) 128 value = object[self.run][sim] 129 else: 130 value = None 131 132 # Return the data. 133 return value, None
134 135
136 - def set(self, run=None, value=None, error=None, param=None, scaling=1.0, index=None):
137 """Common function for setting parameter values.""" 138 139 # Arguments. 140 self.run = run 141 142 # Setting the model parameters prior to minimisation. 143 ##################################################### 144 145 if param == None: 146 # The values are supplied by the user: 147 if value: 148 # Test if the length of the value array is equal to the length of the parameter array. 149 if len(value) != len(self.relax.data.res[self.run][index].params): 150 raise RelaxError, "The length of " + `len(value)` + " of the value array must be equal to the length of the parameter array, " + `self.relax.data.res[self.run][index].params` + ", for residue " + `self.relax.data.res[self.run][index].num` + " " + self.relax.data.res[self.run][index].name + "." 151 152 # Default values. 153 else: 154 # Set 'value' to an empty array. 155 value = [] 156 157 # Loop over the parameters. 158 for i in xrange(len(self.relax.data.res[self.run][index].params)): 159 value.append(self.default_value(self.relax.data.res[self.run][index].params[i])) 160 161 # Loop over the parameters. 162 for i in xrange(len(self.relax.data.res[self.run][index].params)): 163 # Get the object. 164 object_name = self.return_data_name(self.relax.data.res[self.run][index].params[i]) 165 if not object_name: 166 raise RelaxError, "The data type " + `self.relax.data.res[self.run][index].params[i]` + " does not exist." 167 168 # Initialise all data if it doesn't exist. 169 if not hasattr(self.relax.data.res[self.run][index], object_name): 170 self.data_init(self.relax.data.res[self.run][index]) 171 172 # Set the value. 173 if value[i] == None: 174 setattr(self.relax.data.res[self.run][index], object_name, None) 175 else: 176 setattr(self.relax.data.res[self.run][index], object_name, float(value[i]) * scaling) 177 178 179 # Individual data type. 180 ####################### 181 182 else: 183 # Get the object. 184 object_name = self.return_data_name(param) 185 if not object_name: 186 raise RelaxError, "The data type " + `param` + " does not exist." 187 188 # Initialise all data if it doesn't exist. 189 if not hasattr(self.relax.data.res[self.run][index], object_name): 190 self.data_init(self.relax.data.res[self.run][index]) 191 192 # Default value. 193 if value == None: 194 value = self.default_value(object_name) 195 196 # Set the value. 197 if value == None: 198 setattr(self.relax.data.res[self.run][index], object_name, None) 199 else: 200 setattr(self.relax.data.res[self.run][index], object_name, float(value) * scaling) 201 202 # Set the error. 203 if error != None: 204 setattr(self.relax.data.res[self.run][index], object_name+'_err', float(error) * scaling) 205 206 # Update the other parameters if necessary. 207 self.set_update(run=run, param=param, index=index)
208 209
210 - def set_error(self, run, instance, index, error):
211 """Function for setting parameter errors.""" 212 213 # Arguments. 214 self.run = run 215 216 # Skip unselected residues. 217 if not self.relax.data.res[self.run][instance].select: 218 return 219 220 # Parameter increment counter. 221 inc = 0 222 223 # Loop over the residue specific parameters. 224 for param in self.data_names(set='params'): 225 # Return the parameter array. 226 if index == inc: 227 setattr(self.relax.data.res[self.run][instance], param + "_err", error) 228 229 # Increment. 230 inc = inc + 1
231 232
233 - def set_update(self, run, param, index):
234 """Dummy function to do nothing!""" 235 236 return
237 238
239 - def sim_init_values(self, run):
240 """Function for initialising Monte Carlo parameter values.""" 241 242 # Arguments. 243 self.run = run 244 245 # Get the parameter object names. 246 param_names = self.data_names(set='params') 247 248 # Get the minimisation statistic object names. 249 min_names = self.data_names(set='min') 250 251 252 # Test if Monte Carlo parameter values have already been set. 253 ############################################################# 254 255 # Loop over the residues. 256 for i in xrange(len(self.relax.data.res[self.run])): 257 # Skip unselected residues. 258 if not self.relax.data.res[self.run][i].select: 259 continue 260 261 # Loop over all the parameter names. 262 for object_name in param_names: 263 # Name for the simulation object. 264 sim_object_name = object_name + '_sim' 265 266 # Test if the simulation object already exists. 267 if hasattr(self.relax.data.res[self.run][i], sim_object_name): 268 raise RelaxError, "Monte Carlo parameter values have already been set." 269 270 271 # Set the Monte Carlo parameter values. 272 ####################################### 273 274 # Loop over the residues. 275 for i in xrange(len(self.relax.data.res[self.run])): 276 # Skip unselected residues. 277 if not self.relax.data.res[self.run][i].select: 278 continue 279 280 # Loop over all the data names. 281 for object_name in param_names: 282 # Name for the simulation object. 283 sim_object_name = object_name + '_sim' 284 285 # Create the simulation object. 286 setattr(self.relax.data.res[self.run][i], sim_object_name, []) 287 288 # Get the simulation object. 289 sim_object = getattr(self.relax.data.res[self.run][i], sim_object_name) 290 291 # Loop over the simulations. 292 for j in xrange(self.relax.data.sim_number[self.run]): 293 # Copy and append the data. 294 sim_object.append(deepcopy(getattr(self.relax.data.res[self.run][i], object_name))) 295 296 # Loop over all the minimisation object names. 297 for object_name in min_names: 298 # Name for the simulation object. 299 sim_object_name = object_name + '_sim' 300 301 # Create the simulation object. 302 setattr(self.relax.data.res[self.run][i], sim_object_name, []) 303 304 # Get the simulation object. 305 sim_object = getattr(self.relax.data.res[self.run][i], sim_object_name) 306 307 # Loop over the simulations. 308 for j in xrange(self.relax.data.sim_number[self.run]): 309 # Copy and append the data. 310 sim_object.append(deepcopy(getattr(self.relax.data.res[self.run][i], object_name)))
311 312
313 - def sim_return_param(self, run, instance, index):
314 """Function for returning the array of simulation parameter values.""" 315 316 # Arguments. 317 self.run = run 318 319 # Skip unselected residues. 320 if not self.relax.data.res[self.run][instance].select: 321 return 322 323 # Parameter increment counter. 324 inc = 0 325 326 # Loop over the residue specific parameters. 327 for param in self.data_names(set='params'): 328 # Return the parameter array. 329 if index == inc: 330 return getattr(self.relax.data.res[self.run][instance], param + "_sim") 331 332 # Increment. 333 inc = inc + 1
334 335
336 - def sim_return_selected(self, run, index):
337 """Function for returning the array of selected simulation flags.""" 338 339 # Arguments. 340 self.run = run 341 342 # Return the array. 343 return self.relax.data.res[self.run][index].select_sim
344