mailr6594 - /1.3/generic_fns/eliminate.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by edward on June 29, 2008 - 15:55:
Author: bugman
Date: Sun Jun 29 15:27:16 2008
New Revision: 6594

URL: http://svn.gna.org/viewcvs/relax?rev=6594&view=rev
Log:
Converted the Eliminate.eliminate() method to a module function.


Modified:
    1.3/generic_fns/eliminate.py

Modified: 1.3/generic_fns/eliminate.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/generic_fns/eliminate.py?rev=6594&r1=6593&r2=6594&view=diff
==============================================================================
--- 1.3/generic_fns/eliminate.py (original)
+++ 1.3/generic_fns/eliminate.py Sun Jun 29 15:27:16 2008
@@ -1,6 +1,6 @@
 
###############################################################################
 #                                                                            
 #
-# Copyright (C) 2003-2005, 2007 Edward d'Auvergne                            
 #
+# Copyright (C) 2003-2005, 2007-2008 Edward d'Auvergne                       
 #
 #                                                                            
 #
 # This file is part of the program relax.                                    
 #
 #                                                                            
 #
@@ -29,52 +29,74 @@
 
 
 
+def eliminate(run=None, function=None, args=None):
+    """Function for model elimination."""
 
-class Eliminate:
-    def __init__(self, relax):
-        """Class containing the function for model elimination."""
+    # Create the list of runs.
+    self.runs = self.relax.generic.runs.list_of_runs(run)
 
-        self.relax = relax
+    # Loop over the runs.
+    for self.run in self.runs:
+        # Test if the run exists.
+        if not self.run in ds.run_names:
+            raise RelaxNoPipeError, self.run
+
+        # Function type.
+        function_type = ds.run_types[ds.run_names.index(self.run)]
+
+        # Specific eliminate, parameter names, parameter values, number of 
instances, and deselect function setup.
+        eliminate = self.relax.specific_setup.setup('eliminate', 
function_type)
+        param_names = self.relax.specific_setup.setup('param_names', 
function_type)
+        param_values = self.relax.specific_setup.setup('param_values', 
function_type)
+        num_instances = self.relax.specific_setup.setup('num_instances', 
function_type)
+        deselect = self.relax.specific_setup.setup('deselect', function_type)
+
+        # Get the number of instances and loop over them.
+        for i in xrange(num_instances(self.run)):
+            # Determine if simulations are active for the run.
+            if hasattr(ds, 'sim_state') and ds.sim_state.has_key(self.run) 
and ds.sim_state[self.run] == 1:
+                sim_state = 1
+            else:
+                sim_state = 0
 
 
-    def eliminate(self, run=None, function=None, args=None):
-        """Function for model elimination."""
+            # Model elimination.
+            ####################
 
-        # Create the list of runs.
-        self.runs = self.relax.generic.runs.list_of_runs(run)
+            if sim_state == 0:
+                # Get the parameter names and values.
+                names = param_names(self.run, i)
+                values = param_values(self.run, i)
 
-        # Loop over the runs.
-        for self.run in self.runs:
-            # Test if the run exists.
-            if not self.run in ds.run_names:
-                raise RelaxNoPipeError, self.run
+                # No data.
+                if names == None or values == None:
+                    continue
 
-            # Function type.
-            function_type = ds.run_types[ds.run_names.index(self.run)]
+                # Test that the names and values vectors are of equal length.
+                if len(names) != len(values):
+                    raise RelaxError, "The names vector " + `names` + " is 
of a different length to the values vector " + `values` + "."
 
-            # Specific eliminate, parameter names, parameter values, number 
of instances, and deselect function setup.
-            eliminate = self.relax.specific_setup.setup('eliminate', 
function_type)
-            param_names = self.relax.specific_setup.setup('param_names', 
function_type)
-            param_values = self.relax.specific_setup.setup('param_values', 
function_type)
-            num_instances = self.relax.specific_setup.setup('num_instances', 
function_type)
-            deselect = self.relax.specific_setup.setup('deselect', 
function_type)
+                # Loop over the parameters.
+                flag = 0
+                for j in xrange(len(names)):
+                    # Eliminate function.
+                    if eliminate(names[j], values[j], self.run, i, args):
+                        flag = 1
 
-            # Get the number of instances and loop over them.
-            for i in xrange(num_instances(self.run)):
-                # Determine if simulations are active for the run.
-                if hasattr(ds, 'sim_state') and 
ds.sim_state.has_key(self.run) and ds.sim_state[self.run] == 1:
-                    sim_state = 1
-                else:
-                    sim_state = 0
+                # Deselect.
+                if flag:
+                    deselect(self.run, i)
 
 
-                # Model elimination.
-                ####################
+            # Simulation elimination.
+            #########################
 
-                if sim_state == 0:
+            else:
+                # Loop over the simulations.
+                for j in xrange(ds.sim_number[self.run]):
                     # Get the parameter names and values.
                     names = param_names(self.run, i)
-                    values = param_values(self.run, i)
+                    values = param_values(self.run, i, sim_index=j)
 
                     # No data.
                     if names == None or values == None:
@@ -86,41 +108,11 @@
 
                     # Loop over the parameters.
                     flag = 0
-                    for j in xrange(len(names)):
+                    for k in xrange(len(names)):
                         # Eliminate function.
-                        if eliminate(names[j], values[j], self.run, i, args):
+                        if eliminate(names[k], values[k], self.run, i, args):
                             flag = 1
 
                     # Deselect.
                     if flag:
-                        deselect(self.run, i)
-
-
-                # Simulation elimination.
-                #########################
-
-                else:
-                    # Loop over the simulations.
-                    for j in xrange(ds.sim_number[self.run]):
-                        # Get the parameter names and values.
-                        names = param_names(self.run, i)
-                        values = param_values(self.run, i, sim_index=j)
-
-                        # No data.
-                        if names == None or values == None:
-                            continue
-
-                        # Test that the names and values vectors are of 
equal length.
-                        if len(names) != len(values):
-                            raise RelaxError, "The names vector " + `names` 
+ " is of a different length to the values vector " + `values` + "."
-
-                        # Loop over the parameters.
-                        flag = 0
-                        for k in xrange(len(names)):
-                            # Eliminate function.
-                            if eliminate(names[k], values[k], self.run, i, 
args):
-                                flag = 1
-
-                        # Deselect.
-                        if flag:
-                            deselect(self.run, i, sim_index=j)
+                        deselect(self.run, i, sim_index=j)




Related Messages


Powered by MHonArc, Updated Sun Jun 29 16:00:20 2008