Package generic_fns :: Module eliminate
[hide private]
[frames] | no frames]

Source Code for Module generic_fns.eliminate

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2003-2005 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 Eliminate:
27 - def __init__(self, relax):
28 """Class containing the function for model elimination.""" 29 30 self.relax = relax
31 32
33 - def eliminate(self, run=None, function=None, args=None):
34 """Function for model elimination.""" 35 36 # Create the list of runs. 37 self.runs = self.relax.generic.runs.list_of_runs(run) 38 39 # Loop over the runs. 40 for self.run in self.runs: 41 # Test if the run exists. 42 if not self.run in self.relax.data.run_names: 43 raise RelaxNoRunError, self.run 44 45 # Function type. 46 function_type = self.relax.data.run_types[self.relax.data.run_names.index(self.run)] 47 48 # Specific eliminate, parameter names, parameter values, number of instances, and unselect function setup. 49 eliminate = self.relax.specific_setup.setup('eliminate', function_type) 50 param_names = self.relax.specific_setup.setup('param_names', function_type) 51 param_values = self.relax.specific_setup.setup('param_values', function_type) 52 num_instances = self.relax.specific_setup.setup('num_instances', function_type) 53 unselect = self.relax.specific_setup.setup('unselect', function_type) 54 55 # Get the number of instances and loop over them. 56 for i in xrange(num_instances(self.run)): 57 # Determine if simulations are active for the run. 58 if hasattr(self.relax.data, 'sim_state') and self.relax.data.sim_state.has_key(self.run) and self.relax.data.sim_state[self.run] == 1: 59 sim_state = 1 60 else: 61 sim_state = 0 62 63 64 # Model elimination. 65 #################### 66 67 if sim_state == 0: 68 # Get the parameter names and values. 69 names = param_names(self.run, i) 70 values = param_values(self.run, i) 71 72 # No data. 73 if names == None or values == None: 74 continue 75 76 # Test that the names and values vectors are of equal length. 77 if len(names) != len(values): 78 raise RelaxError, "The names vector " + `names` + " is of a different length to the values vector " + `values` + "." 79 80 # Loop over the parameters. 81 flag = 0 82 for j in xrange(len(names)): 83 # Eliminate function. 84 if eliminate(names[j], values[j], self.run, i, args): 85 flag = 1 86 87 # Unselect. 88 if flag: 89 unselect(self.run, i) 90 91 92 # Simulation elimination. 93 ######################### 94 95 else: 96 # Loop over the simulations. 97 for j in xrange(self.relax.data.sim_number[self.run]): 98 # Get the parameter names and values. 99 names = param_names(self.run, i) 100 values = param_values(self.run, i, sim_index=j) 101 102 # No data. 103 if names == None or values == None: 104 continue 105 106 # Test that the names and values vectors are of equal length. 107 if len(names) != len(values): 108 raise RelaxError, "The names vector " + `names` + " is of a different length to the values vector " + `values` + "." 109 110 # Loop over the parameters. 111 flag = 0 112 for k in xrange(len(names)): 113 # Eliminate function. 114 if eliminate(names[k], values[k], self.run, i, args): 115 flag = 1 116 117 # Unselect. 118 if flag: 119 unselect(self.run, i, sim_index=j)
120