mailr6597 - /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:45:51 2008
New Revision: 6597

URL: http://svn.gna.org/viewcvs/relax?rev=6597&view=rev
Log:
Converted the eliminate() function to the new relax design.


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=6597&r1=6596&r2=6597&view=diff
==============================================================================
--- 1.3/generic_fns/eliminate.py (original)
+++ 1.3/generic_fns/eliminate.py Sun Jun 29 15:45:51 2008
@@ -29,47 +29,84 @@
 # relax module imports.
 from data import Relax_data_store; ds = Relax_data_store()
 from relax_errors import RelaxError, RelaxNoPipeError
+from specific_fns.setup import get_specific_fn
 
 
 
-def eliminate(run=None, function=None, args=None):
-    """Function for model elimination."""
+def eliminate(function=None, args=None):
+    """Model elimination.
 
-    # Create the list of runs.
-    self.runs = self.relax.generic.runs.list_of_runs(run)
+    @keyword function:  A user supplied function for model elimination.  
This function should accept
+                        five arguments, a string defining a certain 
parameter, the value of the
+                        parameter, the minimisation instance (ie the residue 
index if the model
+                        is residue specific), and the function arguments.  
If the model is rejected,
+                        the function should return True, otherwise it should 
return False.  The
+                        function will be executed multiple times, once for 
each parameter of the model. 
+    @type function:     function
+    @param args:        The arguments to be passed to the user supplied 
function.
+    @type args:         tuple
+    """
 
-    # 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
+    # Test if the current data pipe exists.
+    if not ds.current_pipe:
+        raise RelaxNoPipeError
 
-        # Function type.
-        function_type = ds.run_types[ds.run_names.index(self.run)]
+    # Alias the current data pipe.
+    cdp = ds[ds.current_pipe]
 
-        # 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)
+    # Specific eliminate, parameter names, parameter values, number of 
instances, and deselect function setup.
+    eliminate = get_specific_fn('eliminate', cdp.pipe_type)
+    param_names = get_specific_fn('param_names', cdp.pipe_type)
+    param_values = get_specific_fn('param_values', cdp.pipe_type)
+    num_instances = get_specific_fn('num_instances', cdp.pipe_type)
+    deselect = get_specific_fn('deselect', cdp.pipe_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
+    # Get the number of instances and loop over them.
+    for i in xrange(num_instances()):
+        # Determine if simulations are active.
+        if hasattr(cdp, 'sim_state') and cdp.sim_state == True:
+            sim_state = True
+        else:
+            sim_state = False
 
 
-            # Model elimination.
-            ####################
+        # Model elimination.
+        ####################
 
-            if sim_state == 0:
+        if not sim_state:
+            # Get the parameter names and values.
+            names = param_names(i)
+            values = param_values(i)
+
+            # 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 = False
+            for j in xrange(len(names)):
+                # Eliminate function.
+                if eliminate(names[j], values[j], i, args):
+                    flag = True
+
+            # Deselect.
+            if flag:
+                deselect(i)
+
+
+        # Simulation elimination.
+        #########################
+
+        else:
+            # Loop over the simulations.
+            for j in xrange(cdp.sim_number):
                 # Get the parameter names and values.
-                names = param_names(self.run, i)
-                values = param_values(self.run, i)
+                names = param_names(i)
+                values = param_values(i, sim_index=j)
 
                 # No data.
                 if names == None or values == None:
@@ -80,42 +117,12 @@
                     raise RelaxError, "The names vector " + `names` + " is 
of a different length to the values vector " + `values` + "."
 
                 # Loop over the parameters.
-                flag = 0
-                for j in xrange(len(names)):
+                flag = False
+                for k in xrange(len(names)):
                     # Eliminate function.
-                    if eliminate(names[j], values[j], self.run, i, args):
-                        flag = 1
+                    if eliminate(names[k], values[k], i, args):
+                        flag = True
 
                 # 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(i, sim_index=j)




Related Messages


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