mailr21573 - in /branches/relax_disp/specific_analyses/relax_disp: api.py disp_data.py optimisation.py


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

Header


Content

Posted by edward on November 21, 2013 - 13:55:
Author: bugman
Date: Thu Nov 21 13:55:14 2013
New Revision: 21573

URL: http://svn.gna.org/viewcvs/relax?rev=21573&view=rev
Log:
The relaxation dispersion calculate user function now stores the back 
calculated R2eff values.

A number of changes were required for this.  The code from the end of the 
Disp_result_command.run()
method was converted to the function 
specific_analyses.relax_disp.disp_data.pack_back_calc_r2eff().
This allows the back calculation R2eff unpacking code to be shared.  The new 
has_proton_mmq_cpmg()
function has also been created to simplify the code.


Modified:
    branches/relax_disp/specific_analyses/relax_disp/api.py
    branches/relax_disp/specific_analyses/relax_disp/disp_data.py
    branches/relax_disp/specific_analyses/relax_disp/optimisation.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=21573&r1=21572&r2=21573&view=diff
==============================================================================
--- branches/relax_disp/specific_analyses/relax_disp/api.py (original)
+++ branches/relax_disp/specific_analyses/relax_disp/api.py Thu Nov 21 
13:55:14 2013
@@ -45,7 +45,7 @@
 from specific_analyses.api_base import API_base
 from specific_analyses.api_common import API_common
 from specific_analyses.relax_disp.checks import check_c_modules, 
check_disp_points, check_exp_type, check_exp_type_fixed_time, 
check_model_type, check_pipe_type, check_spectra_id_setup
-from specific_analyses.relax_disp.disp_data import average_intensity, 
find_intensity_keys, get_curve_type, has_exponential_exp_type, 
has_proton_mq_cpmg, has_proton_sq_cpmg, loop_cluster, loop_exp_frq_point, 
loop_exp_frq_point_time, loop_frq, loop_time, return_cpmg_frqs, 
return_index_from_disp_point, return_index_from_exp_type, 
return_index_from_frq, return_offset_data, return_param_key_from_data, 
return_r1_data, return_r2eff_arrays, return_spin_lock_nu1, 
spin_ids_to_containers
+from specific_analyses.relax_disp.disp_data import average_intensity, 
find_intensity_keys, get_curve_type, has_exponential_exp_type, 
has_proton_mmq_cpmg, loop_cluster, loop_exp_frq_point, 
loop_exp_frq_point_time, loop_frq, loop_time, pack_back_calc_r2eff, 
return_cpmg_frqs, return_index_from_disp_point, return_index_from_exp_type, 
return_index_from_frq, return_offset_data, return_param_key_from_data, 
return_r1_data, return_r2eff_arrays, return_spin_lock_nu1, 
spin_ids_to_containers
 from specific_analyses.relax_disp.optimisation import Disp_memo, 
Disp_minimise_command, grid_search_setup
 from specific_analyses.relax_disp.parameters import assemble_param_vector, 
assemble_scaling_matrix, disassemble_param_vector, get_param_names, 
linear_constraints, param_index_to_param_info, param_num
 from specific_analyses.relax_disp.variables import MODEL_LIST_FULL, 
MODEL_LM63, MODEL_LM63_3SITE, MODEL_CR72, MODEL_CR72_FULL, MODEL_DPL94, 
MODEL_IT99, MODEL_LIST_MMQ, MODEL_M61, MODEL_M61B, MODEL_MMQ_2SITE, 
MODEL_MP05, MODEL_MQ_CR72, MODEL_NOREX, MODEL_NS_CPMG_2SITE_3D, 
MODEL_NS_CPMG_2SITE_3D_FULL, MODEL_NS_CPMG_2SITE_EXPANDED, 
MODEL_NS_CPMG_2SITE_STAR, MODEL_NS_CPMG_2SITE_STAR_FULL, 
MODEL_NS_R1RHO_2SITE, MODEL_R2EFF, MODEL_TAP03, MODEL_TP02, MODEL_TSMFK01
@@ -155,26 +155,13 @@
         # Store the chi2 value.
         spin.chi2 = chi2
 
-        # Convert to a dictionary matching the R2eff data structure.
-        results = {}
-        for exp_type, frq, point, exp_type_index, frq_index, point_index in 
loop_exp_frq_point(return_indices=True):
-            # The parameter key.
-            param_key = return_param_key_from_data(exp_type=exp_type, 
frq=frq, point=point)
-
-            # Skip missing data.
-            if missing[exp_type_index][0][frq_index][point_index]:
-                continue
-
-            # Store the result for the MMQ experiment types.
-            if spin.model in MODEL_LIST_MMQ:
-                results[param_key] = 
model.back_calc[exp_type_index][0][frq_index][point_index]
-
-            # Store the result for the single experiment types.
-            else:
-                results[param_key] = 
model.back_calc[0][frq_index][point_index]
-
-        # Return the back calculated R2eff values.
-        return results
+        # Reconstruct the back_calc data structure.
+        back_calc = model.back_calc
+        if spin.model not in MODEL_LIST_MMQ:
+            back_calc = [back_calc]
+
+        # Return the structure.
+        return back_calc
 
 
     def _back_calc_peak_intensities(self, spin=None, exp_type=None, 
frq=None, point=None):
@@ -700,9 +687,7 @@
         # All other models (the base data is the R2eff/R1rho values).
         else:
             # MMQ flags.
-            proton_sq_flag = has_proton_sq_cpmg()
-            proton_mq_flag = has_proton_mq_cpmg()
-            proton_mmq_flag = proton_sq_flag or proton_mq_flag
+            proton_mmq_flag = has_proton_mmq_cpmg()
 
             # Loop over the sequence.
             for spin, spin_id in spin_loop(return_id=True):
@@ -749,8 +734,21 @@
 
         # Calculate the chi-squared value.
         else:
+            # MMQ flags.
+            proton_mmq_flag = has_proton_mmq_cpmg()
+
+            # Loop over all spins.
             for spin, spin_id in spin_loop(return_id=True, skip_desel=True):
-                self._back_calc_r2eff(spin=spin, spin_id=spin_id)
+                # Get the attached proton.
+                proton = None
+                if proton_mmq_flag:
+                    proton = return_attached_protons(spin_id)[0]
+
+                # The back calculated values.
+                back_calc = self._back_calc_r2eff(spin=spin, spin_id=spin_id)
+
+                # Pack the data.
+                pack_back_calc_r2eff(spin=spin, spin_index=0, 
back_calc=back_calc, proton_mmq_flag=proton_mmq_flag)
 
 
     def constraint_algorithm(self):
@@ -787,7 +785,20 @@
             spin, spin_id = data_id
 
             # Back calculate the R2eff/R1rho data.
-            values = self._back_calc_r2eff(spin=spin, spin_id=spin_id)
+            back_calc = self._back_calc_r2eff(spin=spin, spin_id=spin_id)
+
+            # Convert to a dictionary matching the R2eff data structure.
+            values = {}
+            for exp_type, frq, point, exp_type_index, frq_index, point_index 
in loop_exp_frq_point(return_indices=True):
+                # The parameter key.
+                param_key = return_param_key_from_data(exp_type=exp_type, 
frq=frq, point=point)
+
+                # Skip missing data.
+                if param_key not in spin.r2eff.keys():
+                    continue
+
+                # Store the result.
+                values[param_key] = 
back_calc[exp_type_index][0][frq_index][point_index]
 
         # Return the MC data.
         return values
@@ -1103,9 +1114,7 @@
         check_mol_res_spin_data()
 
         # MMQ flags.
-        proton_sq_flag = has_proton_sq_cpmg()
-        proton_mq_flag = has_proton_mq_cpmg()
-        proton_mmq_flag = proton_sq_flag or proton_mq_flag
+        proton_mmq_flag = has_proton_mmq_cpmg()
 
         # Loop over spin data.
         for spin, spin_id in spin_loop(return_id=True, skip_desel=True):
@@ -1204,9 +1213,7 @@
             spin, spin_id = data_id
 
             # MMQ flags.
-            proton_sq_flag = has_proton_sq_cpmg()
-            proton_mq_flag = has_proton_mq_cpmg()
-            proton_mmq_flag = proton_sq_flag or proton_mq_flag
+            proton_mmq_flag = has_proton_mmq_cpmg()
 
             # Get the attached proton.
             proton = None
@@ -1447,9 +1454,7 @@
             spin, spin_id = data_id
 
             # MMQ flags.
-            proton_sq_flag = has_proton_sq_cpmg()
-            proton_mq_flag = has_proton_mq_cpmg()
-            proton_mmq_flag = proton_sq_flag or proton_mq_flag
+            proton_mmq_flag = has_proton_mmq_cpmg()
 
             # Get the attached proton.
             proton = None

Modified: branches/relax_disp/specific_analyses/relax_disp/disp_data.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/relax_disp/specific_analyses/relax_disp/disp_data.py?rev=21573&r1=21572&r2=21573&view=diff
==============================================================================
--- branches/relax_disp/specific_analyses/relax_disp/disp_data.py (original)
+++ branches/relax_disp/specific_analyses/relax_disp/disp_data.py Thu Nov 21 
13:55:14 2013
@@ -450,6 +450,44 @@
     return False
 
 
+def has_proton_mmq_cpmg():
+    """Determine if the current data pipe contains either proton SQ or MQ 
(MMQ) CPMG data.
+
+    This is only for the MMQ models.
+
+
+    @return:    True if either proton SQ or MQ CPMG data exists, False 
otherwise.
+    @rtype:     bool
+    """
+
+    # 1H MMQ data exists.
+    if has_proton_sq_cpmg():
+        return True
+    if has_proton_mq_cpmg():
+        return True
+
+    # No 1H MMQ CPMG data.
+    return False
+
+
+def has_proton_mq_cpmg():
+    """Determine if the current data pipe contains proton MQ CPMG data.
+
+    This is only for the MMQ models.
+
+
+    @return:    True if proton MQ CPMG data exists, False otherwise.
+    @rtype:     bool
+    """
+
+    # Proton MQ CPMG data is present.
+    if EXP_TYPE_CPMG_PROTON_MQ in cdp.exp_type_list:
+        return True
+
+    # No 1H MQ CPMG data.
+    return False
+
+
 def has_proton_sq_cpmg():
     """Determine if the current data pipe contains proton SQ CPMG data.
 
@@ -465,24 +503,6 @@
         return True
 
     # No 1H SQ CPMG data.
-    return False
-
-
-def has_proton_mq_cpmg():
-    """Determine if the current data pipe contains proton MQ CPMG data.
-
-    This is only for the MMQ models.
-
-
-    @return:    True if proton MQ CPMG data exists, False otherwise.
-    @rtype:     bool
-    """
-
-    # Proton MQ CPMG data is present.
-    if EXP_TYPE_CPMG_PROTON_MQ in cdp.exp_type_list:
-        return True
-
-    # No 1H MQ CPMG data.
     return False
 
 
@@ -1029,6 +1049,46 @@
 
     # Return the count.
     return count
+
+
+def pack_back_calc_r2eff(spin=None, spin_index=None, back_calc=None, 
proton_mmq_flag=False):
+    """Store the back calculated R2eff data for the given spin.
+
+    @keyword spin:              The spin data container to store the data in.
+    @type spin:                 SpinContainer instance
+    @keyword spin_index:        The index of the given spin in the cluster.
+    @type spin_index:           int
+    @keyword back_calc:         The back calculated data.  The first index 
corresponds to the experiment type, the second is the spin of the cluster, 
the third is the magnetic field strength, and the fourth is the dispersion 
point.
+    @type back_calc:            list of lists of lists of lists of float
+    @keyword proton_mmq_flag:   The flag specifying if proton SQ or MQ CPMG 
data exists for the spin.
+    @type proton_mmq_flag:      bool
+    """
+
+    # Get the attached proton.
+    proton = None
+    if proton_mmq_flag:
+        proton = return_attached_protons(memo.spin_ids[spin_index])[0]
+
+    # Loop over the R2eff data.
+    for exp_type, frq,  point, exp_type_index, frq_index, point_index in 
loop_exp_frq_point(return_indices=True):
+        # The R2eff key.
+        key = return_param_key_from_data(exp_type=exp_type, frq=frq, 
point=point)
+
+        # Alias the correct spin.
+        current_spin = spin
+        if exp_type in [EXP_TYPE_CPMG_PROTON_SQ, EXP_TYPE_CPMG_PROTON_MQ]:
+            current_spin = proton
+
+        # Missing data.
+        if not hasattr(current_spin, 'r2eff') or key not in 
current_spin.r2eff.keys():
+            continue
+
+        # Initialise.
+        if not hasattr(current_spin, 'r2eff_bc'):
+            current_spin.r2eff_bc = {}
+
+        # Store the back-calculated data.
+        current_spin.r2eff_bc[key] = 
back_calc[exp_type_index][spin_index][frq_index][point_index]
 
 
 def plot_disp_curves(dir=None, force=None):

Modified: branches/relax_disp/specific_analyses/relax_disp/optimisation.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/relax_disp/specific_analyses/relax_disp/optimisation.py?rev=21573&r1=21572&r2=21573&view=diff
==============================================================================
--- branches/relax_disp/specific_analyses/relax_disp/optimisation.py 
(original)
+++ branches/relax_disp/specific_analyses/relax_disp/optimisation.py Thu Nov 
21 13:55:14 2013
@@ -35,10 +35,9 @@
 from lib.errors import RelaxError
 from lib.text.sectioning import subsection
 from multi import Memo, Result_command, Slave_command
-from pipe_control.sequence import return_attached_protons
-from specific_analyses.relax_disp.disp_data import has_disp_data, 
has_proton_mq_cpmg, has_proton_sq_cpmg, loop_exp_frq, loop_exp_frq_point, 
loop_point, return_cpmg_frqs, return_index_from_disp_point, 
return_index_from_exp_type, return_index_from_frq, return_offset_data, 
return_param_key_from_data, return_r1_data, return_r2eff_arrays, 
return_spin_lock_nu1, return_value_from_frq_index
+from specific_analyses.relax_disp.disp_data import has_disp_data, 
has_proton_mmq_cpmg, loop_exp_frq, loop_exp_frq_point, loop_point, 
pack_back_calc_r2eff, return_cpmg_frqs, return_index_from_disp_point, 
return_index_from_exp_type, return_index_from_frq, return_offset_data, 
return_param_key_from_data, return_r1_data, return_r2eff_arrays, 
return_spin_lock_nu1, return_value_from_frq_index
 from specific_analyses.relax_disp.parameters import assemble_param_vector, 
disassemble_param_vector, linear_constraints, loop_parameters, 
param_conversion, param_num
-from specific_analyses.relax_disp.variables import EXP_TYPE_CPMG_PROTON_MQ, 
EXP_TYPE_CPMG_PROTON_SQ, MODEL_CR72, MODEL_CR72_FULL, MODEL_DPL94, 
MODEL_LIST_CPMG_NUM, MODEL_LM63, MODEL_M61, MODEL_M61B, MODEL_MMQ_2SITE, 
MODEL_MP05, MODEL_NS_R1RHO_2SITE, MODEL_TAP03, MODEL_TP02
+from specific_analyses.relax_disp.variables import EXP_TYPE_CPMG_PROTON_MQ, 
EXP_TYPE_CPMG_PROTON_SQ, MODEL_CR72, MODEL_CR72_FULL, MODEL_DPL94, 
MODEL_LIST_CPMG_NUM, MODEL_LIST_MMQ, MODEL_LM63, MODEL_M61, MODEL_M61B, 
MODEL_MP05, MODEL_NS_R1RHO_2SITE, MODEL_TAP03, MODEL_TP02
 from target_functions.relax_disp import Dispersion
 
 
@@ -479,40 +478,14 @@
 
         # Store the back-calculated values.
         if memo.sim_index == None:
+            # MMQ flag.
+            proton_mmq_flag = has_proton_mmq_cpmg()
+
+            # Reconstruct the back_calc data structure.
+            back_calc = self.back_calc
+            if memo.spins[0].model not in MODEL_LIST_MMQ:
+                back_calc = [back_calc]
+
+            # Loop over each spin, packing the data.
             for spin_index in range(len(memo.spins)):
-                # Alias the spin.
-                spin = memo.spins[spin_index]
-
-                # MMQ flags.
-                proton_sq_flag = has_proton_sq_cpmg()
-                proton_mq_flag = has_proton_mq_cpmg()
-                proton_mmq_flag = proton_sq_flag or proton_mq_flag
-
-                # Get the attached proton.
-                proton = None
-                if proton_mmq_flag:
-                    proton = 
return_attached_protons(memo.spin_ids[spin_index])[0]
-
-                # Loop over the R2eff data.
-                for exp_type, frq,  point, exp_type_index, frq_index, 
point_index in loop_exp_frq_point(return_indices=True):
-                    # Missing data.
-                    if 
self.missing[exp_type_index][spin_index][frq_index][point_index]:
-                        continue
-
-                    # Alias the correct spin.
-                    current_spin = spin
-                    if exp_type in [EXP_TYPE_CPMG_PROTON_SQ, 
EXP_TYPE_CPMG_PROTON_MQ]:
-                        current_spin = proton
-
-                    # Initialise.
-                    if not hasattr(current_spin, 'r2eff_bc'):
-                        current_spin.r2eff_bc = {}
-
-                    # The R2eff key.
-                    key = return_param_key_from_data(exp_type=exp_type, 
frq=frq, point=point)
-
-                    # Store the back-calculated data.
-                    if memo.spins[0].model in [MODEL_MMQ_2SITE]:
-                        current_spin.r2eff_bc[key] = 
self.back_calc[exp_type_index][spin_index][frq_index][point_index]
-                    else:
-                        current_spin.r2eff_bc[key] = 
self.back_calc[spin_index][frq_index][point_index]
+                pack_back_calc_r2eff(spin=memo.spins[spin_index], 
spin_index=spin_index, back_calc=back_calc, proton_mmq_flag=proton_mmq_flag)




Related Messages


Powered by MHonArc, Updated Thu Nov 21 14:20:03 2013