mailr20186 - in /branches/relax_disp/specific_analyses/relax_disp: api.py parameters.py


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

Header


Content

Posted by edward on June 17, 2013 - 19:55:
Author: bugman
Date: Mon Jun 17 19:55:44 2013
New Revision: 20186

URL: http://svn.gna.org/viewcvs/relax?rev=20186&view=rev
Log:
Added support for converting between kex and tex, and pA and pB for the 
dispersion analysis.

This is performed by the new 
specific_analyses.relax_disp.parameters.param_conversion() function.
For this, most of the code from the assemble_param_vector() function has been 
shifted into
get_value(), and most of disassemble_param_vector() into set_value().  The 
dispersion analysis now
also has a custom sim_init_values() method to handle these parameters.


Modified:
    branches/relax_disp/specific_analyses/relax_disp/api.py
    branches/relax_disp/specific_analyses/relax_disp/parameters.py

Modified: branches/relax_disp/specific_analyses/relax_disp/api.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/relax_disp/specific_analyses/relax_disp/api.py?rev=20186&r1=20185&r2=20186&view=diff
==============================================================================
--- branches/relax_disp/specific_analyses/relax_disp/api.py (original)
+++ branches/relax_disp/specific_analyses/relax_disp/api.py Mon Jun 17 
19:55:44 2013
@@ -47,7 +47,7 @@
 from specific_analyses.api_base import API_base
 from specific_analyses.api_common import API_common
 from specific_analyses.relax_disp.disp_data import average_intensity, 
find_intensity_keys, loop_cluster, loop_frq, loop_frq_point, 
loop_frq_point_key, loop_frq_point_time, loop_point, loop_time, relax_time, 
return_cpmg_frqs, return_index_from_disp_point, return_index_from_frq, 
return_key_from_disp_point_index, return_param_key_from_data, 
return_r2eff_arrays, return_spin_lock_nu1, return_value_from_frq_index, 
spin_ids_to_containers
-from specific_analyses.relax_disp.parameters import assemble_param_vector, 
assemble_scaling_matrix, disassemble_param_vector, linear_constraints, 
loop_parameters, param_index_to_param_info, param_num
+from specific_analyses.relax_disp.parameters import assemble_param_vector, 
assemble_scaling_matrix, disassemble_param_vector, linear_constraints, 
loop_parameters, param_conversion, param_index_to_param_info, param_num
 from specific_analyses.relax_disp.variables import CPMG_EXP, FIXED_TIME_EXP, 
MODEL_LIST_FULL, MODEL_LM63, MODEL_CR72, MODEL_DPL94, MODEL_IT99, MODEL_M61, 
MODEL_M61B, MODEL_NOREX, MODEL_R2EFF, R1RHO_EXP, VAR_TIME_EXP
 from target_functions.relax_disp import Dispersion
 from user_functions.data import Uf_tables; uf_tables = Uf_tables()
@@ -73,7 +73,6 @@
         self.return_conversion_factor = self._return_no_conversion_factor
         self.return_value = self._return_value_general
         self.set_param_values = self._set_param_values_spin
-        self.sim_init_values = self._sim_init_values_spin
 
         # Set up the spin parameters.
         self.PARAMS.add('intensities', scope='spin', py_type=dict, 
grace_string='\\qPeak intensities\\Q')
@@ -1131,6 +1130,7 @@
 
             # Disassemble the parameter vector.
             disassemble_param_vector(param_vector=param_vector, spins=spins, 
sim_index=sim_index)
+            param_conversion(spins=spins, sim_index=sim_index)
 
             # Monte Carlo minimisation statistics.
             if sim_index != None:
@@ -1431,6 +1431,92 @@
             spin.select_sim = deepcopy(select_sim)
 
 
+    def sim_init_values(self):
+        """Initialise the Monte Carlo parameter values."""
+
+        # Get the parameter object names.
+        param_names = self.data_names(set='params')
+
+        # Add the names of kex-tex pair.
+        pairs = {}
+        pairs['kex'] = 'tex'
+        pairs['tex'] = 'kex'
+
+        # Add the names of pA-pB pair.
+        pairs['pA'] = 'pB'
+        pairs['pB'] = 'pA'
+
+        # Get the minimisation statistic object names.
+        min_names = self.data_names(set='min')
+
+
+        # Test if Monte Carlo parameter values have already been set.
+        #############################################################
+
+        # Loop over the spins.
+        for spin in spin_loop():
+            # Skip deselected spins.
+            if not spin.select:
+                continue
+
+            # Loop over all the parameter names.
+            for object_name in param_names:
+                # Name for the simulation object.
+                sim_object_name = object_name + '_sim'
+
+
+        # Set the Monte Carlo parameter values.
+        #######################################
+
+        # Loop over the residues.
+        for spin in spin_loop():
+            # Skip deselected residues.
+            if not spin.select:
+                continue
+
+            # Loop over all the data names.
+            for object_name in param_names:
+                # Not a parameter of the model.
+                if not (object_name in spin.params or (object_name in pairs 
and pairs[object_name] in spin.params)):
+                    continue
+
+                # Name for the simulation object.
+                sim_object_name = object_name + '_sim'
+
+                # Create the simulation object.
+                setattr(spin, sim_object_name, [])
+
+                # Get the simulation object.
+                sim_object = getattr(spin, sim_object_name)
+
+                # Loop over the simulations.
+                for j in range(cdp.sim_number):
+                    # The non-simulation value.
+                    if object_name not in spin.params:
+                        value = deepcopy(getattr(spin, pairs[object_name]))
+                    else:
+                        value = deepcopy(getattr(spin, object_name))
+
+                    # Copy and append the data.
+                    sim_object.append(value)
+
+            # Loop over all the minimisation object names.
+            for object_name in min_names:
+                # Name for the simulation object.
+                sim_object_name = object_name + '_sim'
+
+                # Create the simulation object.
+                setattr(spin, sim_object_name, [])
+
+                # Get the simulation object.
+                sim_object = getattr(spin, sim_object_name)
+
+                # Loop over the simulations.
+                for j in range(cdp.sim_number):
+                    # Copy and append the data.
+                    sim_object.append(deepcopy(getattr(spin, object_name)))
+
+
     def sim_pack_data(self, data_id, sim_data):
         """Pack the Monte Carlo simulation data.
 

Modified: branches/relax_disp/specific_analyses/relax_disp/parameters.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/relax_disp/specific_analyses/relax_disp/parameters.py?rev=20186&r1=20185&r2=20186&view=diff
==============================================================================
--- branches/relax_disp/specific_analyses/relax_disp/parameters.py (original)
+++ branches/relax_disp/specific_analyses/relax_disp/parameters.py Mon Jun 17 
19:55:44 2013
@@ -52,49 +52,8 @@
 
     # Loop over the parameters of the cluster.
     for param_name, param_index, spin_index, frq_index in 
loop_parameters(spins=spins):
-        # Spin specific parameters.
-        if spin_index != None:
-            # Set the simulation value.
-            if sim_index != None:
-                # Get the simulation structure.
-                sim_obj = getattr(spins[spin_index], param_name+'_sim')
-
-                # Frequency specific parameter.
-                if frq_index != None:
-                    value = sim_obj[sim_index][frq_index]
-
-                # Set the normal value.
-                else:
-                    value = sim_obj[sim_index]
-
-            # Frequency specific parameter.
-            elif frq_index != None:
-                obj = getattr(spins[spin_index], param_name)
-                if obj == []:
-                    value = 0.0
-                else:
-                    value = obj[frq_index]
-
-            # Set the normal value.
-            else:
-                value = getattr(spins[spin_index], param_name)
-
-        # Cluster specific parameters - use the parameter value from the 
first spin.
-        else:
-            # Set the simulation value.
-            if sim_index != None:
-                value = getattr(spins[0], param_name+'_sim')[sim_index]
-
-            # Set the normal value.
-            else:
-                value = getattr(spins[0], param_name)
-
-        # The R2eff model parameters.
-        if key != None:
-            if not key in value:
-                value = 0.0
-            else:
-                value = value[key]
+        # Get the value.
+        value = get_value(key=key, spins=spins, sim_index=sim_index, 
param_name=param_name, spin_index=spin_index, frq_index=frq_index)
 
         # Add to the vector.
         param_vector.append(value)
@@ -189,59 +148,76 @@
                 for frq in loop_frq():
                     spin.r2.append(None)
 
-    # Loop over the parameters of the cluster.
+    # Loop over the parameters of the cluster, setting the values.
     for param_name, param_index, spin_index, frq_index in 
loop_parameters(spins=spins):
-        # Spin specific parameters.
-        if spin_index != None:
-            # Get the object.
-            if sim_index != None:
-                obj = getattr(spins[spin_index], param_name+'_sim')
-            else:
-                obj = getattr(spins[spin_index], param_name)
-
-            # Set the simulation value.
-            if sim_index != None:
-                # Frequency specific parameter.
-                if frq_index != None:
-                    if key != None:
-                        obj[sim_index][frq_index][key] = 
param_vector[param_index]
-                    else:
-                        obj[sim_index][frq_index] = param_vector[param_index]
-
-                # Set the normal value.
-                else:
-                    if key != None:
-                        obj[sim_index][key] = param_vector[param_index]
-                    else:
-                        obj[sim_index] = param_vector[param_index]
+        set_value(value=param_vector[param_index], key=key, spins=spins, 
sim_index=sim_index, param_name=param_name, spin_index=spin_index, 
frq_index=frq_index)
+
+
+def get_value(key=None, spins=None, sim_index=None, param_name=None, 
spin_index=None, frq_index=None):
+    """Return the value for the given parameter.
+
+    @keyword key:           The key for the R2eff and I0 parameters.
+    @type key:              str or None
+    @keyword spins:         The list of spin data containers for the block.
+    @type spins:            list of SpinContainer instances
+    @keyword sim_index:     The optional MC simulation index.
+    @type sim_index:        int
+    @keyword param_name:    The parameter name.
+    @type param_name:       str
+    @keyword spin_index:    The spin index (for the cluster).
+    @type spin_index:       int
+    @keyword frq_index:     The frequency index (for parameters with 
different values per spectrometer field strength).
+    @type frq_index:        int
+    @return:                The parameter value.
+    @rtype:                 float
+    """
+
+    # Spin specific parameters.
+    if spin_index != None:
+        # Set the simulation value.
+        if sim_index != None:
+            # Get the simulation structure.
+            sim_obj = getattr(spins[spin_index], param_name+'_sim')
 
             # Frequency specific parameter.
-            elif frq_index != None:
-                obj = getattr(spins[spin_index], param_name)
-                if key != None:
-                    obj[frq_index][key] = param_vector[param_index]
-                else:
-                    obj[frq_index] = param_vector[param_index]
+            if frq_index != None:
+                value = sim_obj[sim_index][frq_index]
 
             # Set the normal value.
             else:
-                if key != None:
-                    obj[key] = param_vector[param_index]
-                else:
-                    setattr(spins[spin_index], param_name, 
param_vector[param_index])
-
-        # Cluster specific parameters.
+                value = sim_obj[sim_index]
+
+        # Frequency specific parameter.
+        elif frq_index != None:
+            obj = getattr(spins[spin_index], param_name)
+            if obj == []:
+                value = 0.0
+            else:
+                value = obj[frq_index]
+
+        # Set the normal value.
         else:
-            # Set the same parameter value for all spins in the cluster.
-            for spin in spins:
-                # Set the simulation value.
-                if sim_index != None:
-                    sim_obj = getattr(spin, param_name+'_sim')
-                    sim_obj[sim_index] = param_vector[param_index]
-
-                # Set the normal value.
-                else:
-                    setattr(spin, param_name, param_vector[param_index])
+            value = getattr(spins[spin_index], param_name)
+
+    # Cluster specific parameters - use the parameter value from the first 
spin.
+    else:
+        # Set the simulation value.
+        if sim_index != None:
+            value = getattr(spins[0], param_name+'_sim')[sim_index]
+
+        # Set the normal value.
+        else:
+            value = getattr(spins[0], param_name)
+
+    # The R2eff model parameters.
+    if key != None:
+        if not key in value:
+            value = 0.0
+        else:
+            value = value[key]
+
+    # Return the value.
+    return value
 
 
 def linear_constraints(spins=None, scaling_matrix=None):
@@ -459,6 +435,43 @@
                 yield param, param_index, None, None
 
 
+def param_conversion(key=None, spins=None, sim_index=None):
+    """Convert Disassemble the parameter vector.
+
+    @keyword key:           The key for the R2eff and I0 parameters.
+    @type key:              str or None
+    @keyword spins:         The list of spin data containers for the block.
+    @type spins:            list of SpinContainer instances
+    @keyword sim_index:     The optional MC simulation index.
+    @type sim_index:        int
+    """
+
+    # Loop over the parameters of the cluster.
+    for param_name, param_index, spin_index, frq_index in 
loop_parameters(spins=spins):
+        # Get the value.
+        value = get_value(key=key, spins=spins, sim_index=sim_index, 
param_name=param_name, spin_index=spin_index, frq_index=frq_index)
+
+        # The pA to pB conversion.
+        if param_name == 'pA':
+            pB = 1.0 - value
+            set_value(value=pB, key=key, spins=spins, sim_index=sim_index, 
param_name='pB', spin_index=spin_index, frq_index=frq_index)
+
+        # The pB to pA conversion.
+        if param_name == 'pB':
+            pA = 1.0 - value
+            set_value(value=pA, key=key, spins=spins, sim_index=sim_index, 
param_name='pA', spin_index=spin_index, frq_index=frq_index)
+
+        # The kex to tex conversion.
+        if param_name == 'kex':
+            tex = 1.0 / (2.0 * value)
+            set_value(value=tex, key=key, spins=spins, sim_index=sim_index, 
param_name='tex', spin_index=spin_index, frq_index=frq_index)
+
+        # The tex to kex conversion.
+        if param_name == 'tex':
+            kex = 1.0 / (2.0 * value)
+            set_value(value=kex, key=key, spins=spins, sim_index=sim_index, 
param_name='kex', spin_index=spin_index, frq_index=frq_index)
+
+
 def param_index_to_param_info(index=None, spins=None):
     """Convert the given parameter array index to parameter identifying 
information.
     
@@ -517,3 +530,75 @@
 
     # Return the number.
     return num
+
+
+def set_value(value=None, key=None, spins=None, sim_index=None, 
param_name=None, spin_index=None, frq_index=None):
+    """Return the value for the given parameter.
+
+    @keyword value:         The parameter value to set.
+    @type value:            float
+    @keyword key:           The key for the R2eff and I0 parameters.
+    @type key:              str or None
+    @keyword spins:         The list of spin data containers for the block.
+    @type spins:            list of SpinContainer instances
+    @keyword sim_index:     The optional MC simulation index.
+    @type sim_index:        int
+    @keyword param_name:    The parameter name.
+    @type param_name:       str
+    @keyword spin_index:    The spin index (for the cluster).
+    @type spin_index:       int
+    @keyword frq_index:     The frequency index (for parameters with 
different values per spectrometer field strength).
+    @type frq_index:        int
+    """
+
+    # Spin specific parameters.
+    if spin_index != None:
+        # Get the object.
+        if sim_index != None:
+            obj = getattr(spins[spin_index], param_name+'_sim')
+        else:
+            obj = getattr(spins[spin_index], param_name)
+
+        # Set the simulation value.
+        if sim_index != None:
+            # Frequency specific parameter.
+            if frq_index != None:
+                if key != None:
+                    obj[sim_index][frq_index][key] = value
+                else:
+                    obj[sim_index][frq_index] = value
+
+            # Set the normal value.
+            else:
+                if key != None:
+                    obj[sim_index][key] = value
+                else:
+                    obj[sim_index] = value
+
+        # Frequency specific parameter.
+        elif frq_index != None:
+            obj = getattr(spins[spin_index], param_name)
+            if key != None:
+                obj[frq_index][key] = value
+            else:
+                obj[frq_index] = value
+
+        # Set the normal value.
+        else:
+            if key != None:
+                obj[key] = value
+            else:
+                setattr(spins[spin_index], param_name, value)
+
+    # Cluster specific parameters.
+    else:
+        # Set the same parameter value for all spins in the cluster.
+        for spin in spins:
+            # Set the simulation value.
+            if sim_index != None:
+                sim_obj = getattr(spin, param_name+'_sim')
+                sim_obj[sim_index] = value
+
+            # Set the normal value.
+            else:
+                setattr(spin, param_name, value)




Related Messages


Powered by MHonArc, Updated Tue Jun 18 10:20:03 2013