mailr19667 - in /branches/relax_disp/specific_analyses/relax_disp: __init__.py disp_data.py


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

Header


Content

Posted by edward on May 06, 2013 - 16:16:
Author: bugman
Date: Mon May  6 16:16:23 2013
New Revision: 19667

URL: http://svn.gna.org/viewcvs/relax?rev=19667&view=rev
Log:
Shifted the R2eff/R1rho value and error assembly into 
specific_analyses.relax_disp.disp_data.

This is in the new return_r2eff_arrays() function.  The code has also been 
debugged and made
functional.


Modified:
    branches/relax_disp/specific_analyses/relax_disp/__init__.py
    branches/relax_disp/specific_analyses/relax_disp/disp_data.py

Modified: branches/relax_disp/specific_analyses/relax_disp/__init__.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/relax_disp/specific_analyses/relax_disp/__init__.py?rev=19667&r1=19666&r2=19667&view=diff
==============================================================================
--- branches/relax_disp/specific_analyses/relax_disp/__init__.py (original)
+++ branches/relax_disp/specific_analyses/relax_disp/__init__.py Mon May  6 
16:16:23 2013
@@ -55,7 +55,7 @@
 from pipe_control.result_files import add_result_file
 from specific_analyses.api_base import API_base
 from specific_analyses.api_common import API_common
-from specific_analyses.relax_disp.disp_data import exp_curve_index_from_key, 
exp_curve_key_from_index, intensity_key, loop_all_data, 
loop_dispersion_point, loop_exp_curve, loop_spectrometer, relax_time, 
return_cpmg_frqs, return_key, return_spin_lock_nu1
+from specific_analyses.relax_disp.disp_data import exp_curve_index_from_key, 
exp_curve_key_from_index, intensity_key, loop_all_data, 
loop_dispersion_point, loop_exp_curve, loop_spectrometer, relax_time, 
return_cpmg_frqs, return_key, return_r2eff_arrays, return_spin_lock_nu1
 from specific_analyses.relax_disp.parameters import assemble_param_vector, 
assemble_scaling_matrix, disassemble_param_vector, linear_constraints, 
param_index_to_param_info, param_num
 from specific_analyses.relax_disp.variables import CPMG_EXP, FIXED_TIME_EXP, 
MODEL_R2EFF, MODEL_LM63, MODEL_CR72, R1RHO_EXP, VAR_TIME_EXP
 from target_functions.relax_disp import Dispersion
@@ -964,9 +964,9 @@
         field_count = 1
         fields = []
         if hasattr(cdp, 'frq'):
-            field_count = count_unique_elements(cdp.frq.values())
             fields = unique_elements(cdp.frq.values())
             fields.sort()
+            field_count = len(fields)
 
         # The number of time points for the exponential curves (if present).
         num_time_pts = 1
@@ -975,51 +975,8 @@
 
         # Loop over the spin blocks.
         for spins, spin_ids in self.model_loop():
-            # The spin count.
-            spin_num = len(spins)
-
-            # Initialise the data structures for the target function.
-            values = zeros((spin_num, field_count, cdp.dispersion_points), 
float64)
-            errors = zeros((spin_num, field_count, cdp.dispersion_points), 
float64)
-
-            # Pack the R2eff/R1rho data.
-            data_flag = False
-            for spin_index in range(spin_num):
-                # Alias the spin.
-                spin = spins[spin_index]
-
-                # No data.
-                if not hasattr(spin, 'r2eff'):
-                    continue
-                data_flag = True
-
-                # The keys.
-                keys = list(spin.r2eff.keys())
-
-                # Loop over the R2eff data.
-                for key in keys:
-                    # The indices.
-                    disp_pt_index = 0
-                    if cdp.exp_type == 'cpmg':
-                        disp_pt_index = 
cdp.cpmg_frqs_list.index(cdp.cpmg_frqs[key])
-                    elif cdp.exp_type == 'r1rho':
-                        disp_pt_index = 
cdp.spin_lock_nu1_list.index(cdp.spin_lock_nu1[key])
-                    field_index = 0
-                    if hasattr(cdp, 'frqs'):
-                        field_index = fields.index(cdp.frqs[keys])
-
-                    # The values.
-                    if sim_index == None:
-                        values[spin_index, field_index, disp_pt_index] = 
spin.r2eff[key]
-                    else:
-                        values[spin_index, field_index, disp_pt_index] = 
spin.r2eff_sim[key][sim_index]
-
-                    # The errors.
-                    errors[spin_index, field_index, disp_pt_index] = 
spin.r2eff_err[key]
-
-            # No R2eff/R1rho data for the spin cluster.
-            if not data_flag:
-                raise RelaxError("No R2eff/R1rho data could be found for the 
spin cluster %s." % spin_ids)
+            # The R2eff/R1rho data.
+            values, errors = return_r2eff_arrays(spins=spins, 
spin_ids=spin_ids, fields=fields, field_count=field_count)
 
             # Create the initial parameter vector.
             param_vector = assemble_param_vector(spins=spins)
@@ -1052,7 +1009,7 @@
                     print("Unconstrained grid search size: %s (constraints 
may decrease this size).\n" % grid_size)
 
             # Initialise the function to minimise.
-            model = Dispersion(model=cdp.model, 
num_params=param_num(spins=spins), num_spins=spin_num, num_frq=field_count, 
num_disp_points=cdp.dispersion_points, values=values, errors=errors, 
cpmg_frqs=return_cpmg_frqs(ref_flag=False), 
spin_lock_nu1=return_spin_lock_nu1(ref_flag=False), 
scaling_matrix=scaling_matrix)
+            model = Dispersion(model=cdp.model, 
num_params=param_num(spins=spins), num_spins=len(spins), num_frq=field_count, 
num_disp_points=cdp.dispersion_points, values=values, errors=errors, 
cpmg_frqs=return_cpmg_frqs(ref_flag=False), 
spin_lock_nu1=return_spin_lock_nu1(ref_flag=False), 
scaling_matrix=scaling_matrix)
 
             # Grid search.
             if search('^[Gg]rid', min_algor):

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=19667&r1=19666&r2=19667&view=diff
==============================================================================
--- branches/relax_disp/specific_analyses/relax_disp/disp_data.py (original)
+++ branches/relax_disp/specific_analyses/relax_disp/disp_data.py Mon May  6 
16:16:23 2013
@@ -22,6 +22,9 @@
 
 # Module docstring.
 """Functions for handling relaxation dispersion data within the relax data 
store."""
+
+# Python module imports.
+from numpy import float64, zeros
 
 # relax module imports.
 from lib.errors import RelaxError, RelaxNoSpectraError
@@ -313,6 +316,82 @@
     return spin.intensities[key]
 
 
+def return_r2eff_arrays(spins=None, spin_ids=None, fields=None, 
field_count=None, sim_index=None):
+    """Return numpy arrays of the R2eff/R1rho values and errors.
+
+    @keyword spins:         The list of spin containers in the cluster.
+    @type spins:            list of SpinContainer instances
+    @keyword spin_ids:      The list of spin IDs for the cluster.
+    @type spin_ids:         list of str
+    @keyword fields:        The list of spectrometer field strengths.
+    @type fields:           list of float
+    @keyword field_count:   The number of spectrometer field strengths.  
This may not be equal to the length of the fields list as the user may not 
have set the field strength.
+    @type field_count:      int
+    @keyword sim_index:     The index of the simulation to return the data 
of.  This should be None if the normal data is required.
+    @type sim_index:        None or int
+    @return:                The numpy array structure of the R2eff/R1rho 
values and the structure for the errors.  For each structure, the first 
dimension corresponds to the spins of a spin block, the second to the 
spectrometer field strength, and the third is the dispersion points.
+    @rtype:                 numpy rank-3 float array, numpy rank-3 float 
array
+    """
+
+    # The spin count.
+    spin_num = len(spins)
+
+    # Initialise the data structures for the target function.
+    values = zeros((spin_num, field_count, cdp.dispersion_points), float64)
+    errors = zeros((spin_num, field_count, cdp.dispersion_points), float64)
+
+    # Pack the R2eff/R1rho data.
+    data_flag = False
+    for spin_index in range(spin_num):
+        # Alias the spin.
+        spin = spins[spin_index]
+
+        # No data.
+        if not hasattr(spin, 'r2eff'):
+            continue
+        data_flag = True
+
+        # The keys.
+        keys = list(spin.r2eff.keys())
+
+        # Loop over the R2eff data.
+        for key in keys:
+            # Reference in the fixed time experiments.
+            if cdp.exp_type in FIXED_TIME_EXP:
+                if cdp.exp_type in CPMG_EXP and cdp.cpmg_frqs[key] == None:
+                    continue
+                if cdp.exp_type in R1RHO_EXP and cdp.spin_lock_nu1[key] == 
None:
+                    continue
+
+            # The indices.
+            disp_pt_index = 0
+            if cdp.exp_type in CPMG_EXP:
+                disp_pt_index = cdp.cpmg_frqs_list.index(cdp.cpmg_frqs[key])
+            elif cdp.exp_type in R1RHO_EXP:
+                disp_pt_index = 
cdp.spin_lock_nu1_list.index(cdp.spin_lock_nu1[key])
+            if cdp.exp_type in FIXED_TIME_EXP:
+                disp_pt_index -= 1
+            field_index = 0
+            if hasattr(cdp, 'frq'):
+                field_index = fields.index(cdp.frq[key])
+
+            # The values.
+            if sim_index == None:
+                values[spin_index, field_index, disp_pt_index] = 
spin.r2eff[key]
+            else:
+                values[spin_index, field_index, disp_pt_index] = 
spin.r2eff_sim[key][sim_index]
+
+            # The errors.
+            errors[spin_index, field_index, disp_pt_index] = 
spin.r2eff_err[key]
+
+    # No R2eff/R1rho data for the spin cluster.
+    if not data_flag:
+        raise RelaxError("No R2eff/R1rho data could be found for the spin 
cluster %s." % spin_ids)
+
+    # Return the structures.
+    return values, errors
+
+
 def return_key(frq=None, point=None, time=None):
     """Return the key corresponding to the spectrometer frequency, 
dispersion point, and relaxation time.
 




Related Messages


Powered by MHonArc, Updated Tue May 07 12:40:02 2013