mailr4822 - in /1.3: generic_fns/value.py specific_fns/__init__.py specific_fns/base_class.py


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

Header


Content

Posted by edward on January 17, 2008 - 16:19:
Author: bugman
Date: Thu Jan 17 16:07:22 2008
New Revision: 4822

URL: http://svn.gna.org/viewcvs/relax?rev=4822&view=rev
Log:
Big refactorisation of the value setting code.  Expect breakages as the 
changes aren't complete!

The parameter setting set() base class method has been shifted from the 
specific code to
the generic_fns.value module (and has been converted to a function).  This 
method simply sets spin
specific functions and hence has been renamed to the set_spin_params() 
function.


Modified:
    1.3/generic_fns/value.py
    1.3/specific_fns/__init__.py
    1.3/specific_fns/base_class.py

Modified: 1.3/generic_fns/value.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/generic_fns/value.py?rev=4822&r1=4821&r2=4822&view=diff
==============================================================================
--- 1.3/generic_fns/value.py (original)
+++ 1.3/generic_fns/value.py Thu Jan 17 16:07:22 2008
@@ -161,7 +161,6 @@
 
     # Specific functions.
     return_value = get_specific_fn('return_value', cdp.pipe_type)
-    set = get_specific_fn('set', cdp.pipe_type)
 
     # Partition the parameters into those which are spin specific and those 
which are not.
     spin_params, spin_values, other_params, other_values = 
partition_params(val, param)
@@ -200,7 +199,7 @@
 
             # Go to the specific code.
             for j in xrange(len(spin_params)):
-                set(value=spin_values[j], error=None, spin=spin, 
param=spin_params[j])
+                set_spin_params(value=spin_values[j], error=None, spin=spin, 
param=spin_params[j])
 
 
     # All other parameters.
@@ -213,6 +212,125 @@
 
     # Reset all minimisation statistics.
     reset_min_stats()
+
+
+def set_spin_params(value=None, error=None, param=None, scaling=1.0, 
spin=None):
+    """Function for setting spin specific parameter values.
+
+    @param value:   The value to change the parameter to.
+    @type value:    float or str
+    @param error:   The error value associated with the parameter, also to 
be set.
+    @type error:    float or str
+    @param param:   The name of the parameter to change.
+    @type param:    str
+    @param scaling: The scaling factor for the value or error parameters.
+    @type scaling:  float
+    @param spin:    The SpinContainer object.
+    @type spin:     SpinContainer
+    """
+
+    # Alias the current data pipe.
+    cdp = relax_data_store[relax_data_store.current_pipe]
+
+    # Specific functions.
+    data_init = get_specific_fn('data_init', cdp.pipe_type)
+    default_value = get_specific_fn('default_value', cdp.pipe_type)
+    return_data_name = get_specific_fn('return_data_name', cdp.pipe_type)
+    set_update = get_specific_fn('set_update', cdp.pipe_type)
+
+
+    # Setting the model parameters prior to minimisation.
+    #####################################################
+
+    if param == None:
+        # The values are supplied by the user:
+        if value:
+            # Test if the length of the value array is equal to the length 
of the parameter array.
+            if len(value) != len(spin.params):
+                raise RelaxError, "The length of " + `len(value)` + " of the 
value array must be equal to the length of the parameter array, " + 
`spin.params` + ", for residue " + `spin.num` + " " + spin.name + "."
+
+        # Default values.
+        else:
+            # Set 'value' to an empty array.
+            value = []
+
+            # Loop over the parameters.
+            for i in xrange(len(spin.params)):
+                value.append(default_value(spin.params[i]))
+
+        # Loop over the parameters.
+        for i in xrange(len(spin.params)):
+            # Get the object.
+            object_name = return_data_name(spin.params[i])
+            if not object_name:
+                raise RelaxError, "The data type " + `spin.params[i]` + " 
does not exist."
+
+            # Initialise all data if it doesn't exist.
+            if not hasattr(spin, object_name):
+                data_init(spin)
+
+            # Set the value.
+            if value[i] == None:
+                setattr(spin, object_name, None)
+            else:
+                # Catch parameters with string values.
+                try:
+                    value[i] = float(value[i]) * scaling
+                except ValueError:
+                    pass
+
+                # Set the attribute.
+                setattr(spin, object_name, value[i])
+
+
+    # Individual data type.
+    #######################
+
+    else:
+        # Get the object.
+        object_name = return_data_name(param)
+        if not object_name:
+            raise RelaxError, "The data type " + `param` + " does not exist."
+
+        # Initialise all data if it doesn't exist.
+        if not hasattr(spin, object_name):
+            data_init(spin)
+
+        # Default value.
+        if value == None:
+            value = default_value(object_name)
+
+        # No default value, hence the parameter cannot be set.
+        if value == None:
+            raise RelaxParamSetError, param
+
+        # Set the value.
+        if value == None:
+            setattr(spin, object_name, None)
+        else:
+            # Catch parameters with string values.
+            try:
+                value = float(value) * scaling
+            except ValueError:
+                pass
+
+            # Set the attribute.
+            setattr(spin, object_name, value)
+
+        # Set the error.
+        if error != None:
+            # Catch parameters with string values.
+            try:
+                error = float(error) * scaling
+            except ValueError:
+                pass
+
+            # Set the attribute.
+            setattr(spin, object_name+'_err', error)
+
+        # Update the other parameters if necessary.
+        set_update(param=param, spin=spin)
+
 
 
 

Modified: 1.3/specific_fns/__init__.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/specific_fns/__init__.py?rev=4822&r1=4821&r2=4822&view=diff
==============================================================================
--- 1.3/specific_fns/__init__.py (original)
+++ 1.3/specific_fns/__init__.py Thu Jan 17 16:07:22 2008
@@ -179,10 +179,6 @@
         if eqi == 'return_value':
             function = inst.return_value
 
-        # Set function.
-        if eqi == 'set':
-            function = inst.set
-
         # Set error function.
         if eqi == 'set_error':
             function = inst.set_error

Modified: 1.3/specific_fns/base_class.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/specific_fns/base_class.py?rev=4822&r1=4821&r2=4822&view=diff
==============================================================================
--- 1.3/specific_fns/base_class.py (original)
+++ 1.3/specific_fns/base_class.py Thu Jan 17 16:07:22 2008
@@ -180,114 +180,6 @@
 
         # Return the data.
         return value, error
-
-
-    def set(self, value=None, error=None, param=None, scaling=1.0, 
spin=None):
-        """Common function for setting parameter values.
-
-        @param value:   The value to change the parameter to.
-        @type value:    float or str
-        @param error:   The error value associated with the parameter, also 
to be set.
-        @type error:    float or str
-        @param param:   The name of the parameter to change.
-        @type param:    str
-        @param scaling: The scaling factor for the value or error parameters.
-        @type scaling:  float
-        @param spin:    The SpinContainer object.
-        @type spin:     SpinContainer
-        """
-
-        # Setting the model parameters prior to minimisation.
-        #####################################################
-
-        if param == None:
-            # The values are supplied by the user:
-            if value:
-                # Test if the length of the value array is equal to the 
length of the parameter array.
-                if len(value) != len(spin.params):
-                    raise RelaxError, "The length of " + `len(value)` + " of 
the value array must be equal to the length of the parameter array, " + 
`spin.params` + ", for residue " + `spin.num` + " " + spin.name + "."
-
-            # Default values.
-            else:
-                # Set 'value' to an empty array.
-                value = []
-
-                # Loop over the parameters.
-                for i in xrange(len(spin.params)):
-                    value.append(self.default_value(spin.params[i]))
-
-            # Loop over the parameters.
-            for i in xrange(len(spin.params)):
-                # Get the object.
-                object_name = self.return_data_name(spin.params[i])
-                if not object_name:
-                    raise RelaxError, "The data type " + `spin.params[i]` + 
" does not exist."
-
-                # Initialise all data if it doesn't exist.
-                if not hasattr(spin, object_name):
-                    self.data_init(spin)
-
-                # Set the value.
-                if value[i] == None:
-                    setattr(spin, object_name, None)
-                else:
-                    # Catch parameters with string values.
-                    try:
-                        value[i] = float(value[i]) * scaling
-                    except ValueError:
-                        pass
-
-                    # Set the attribute.
-                    setattr(spin, object_name, value[i])
-
-
-        # Individual data type.
-        #######################
-
-        else:
-            # Get the object.
-            object_name = self.return_data_name(param)
-            if not object_name:
-                raise RelaxError, "The data type " + `param` + " does not 
exist."
-
-            # Initialise all data if it doesn't exist.
-            if not hasattr(spin, object_name):
-                self.data_init(spin)
-
-            # Default value.
-            if value == None:
-                value = self.default_value(object_name)
-
-            # No default value, hence the parameter cannot be set.
-            if value == None:
-                raise RelaxParamSetError, param
-
-            # Set the value.
-            if value == None:
-                setattr(spin, object_name, None)
-            else:
-                # Catch parameters with string values.
-                try:
-                    value = float(value) * scaling
-                except ValueError:
-                    pass
-
-                # Set the attribute.
-                setattr(spin, object_name, value)
-
-            # Set the error.
-            if error != None:
-                # Catch parameters with string values.
-                try:
-                    error = float(error) * scaling
-                except ValueError:
-                    pass
-
-                # Set the attribute.
-                setattr(spin, object_name+'_err', error)
-
-            # Update the other parameters if necessary.
-            self.set_update(param=param, spin=spin)
 
 
     def set_error(self, run, instance, index, error):




Related Messages


Powered by MHonArc, Updated Thu Jan 17 16:40:18 2008