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

Source Code for Module generic_fns.eliminate

 1  ############################################################################### 
 2  #                                                                             # 
 3  # Copyright (C) 2003, 2004 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 # Get the parameter names and values. 58 names = param_names(self.run, i) 59 values = param_values(self.run, i) 60 61 # No data. 62 if names == None or values == None: 63 continue 64 65 # Test that the names and values vectors are of equal length. 66 if len(names) != len(values): 67 raise RelaxError, "The names vector " + `names` + " is of a different length to the values vector " + `values` + "." 68 69 # Loop over the parameters. 70 flag = 0 71 for j in xrange(len(names)): 72 # Eliminate function. 73 if eliminate(names[j], values[j], self.run, i, args): 74 flag = 1 75 76 # Unselect. 77 if flag: 78 unselect(self.run, i)
79