mailr26075 - in /branches/frame_order_cleanup: ./ auto_analyses/relax_disp_repeat_cpmg.py test_suite/system_tests/relax_disp.py


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

Header


Content

Posted by edward on September 26, 2014 - 19:14:
Author: bugman
Date: Fri Sep 26 19:14:41 2014
New Revision: 26075

URL: http://svn.gna.org/viewcvs/relax?rev=26075&view=rev
Log:
Merged revisions 26057 via svnmerge from 
svn+ssh://bugman@xxxxxxxxxxx/svn/relax/trunk

........
  r26057 | tlinnet | 2014-09-26 13:06:40 +0200 (Fri, 26 Sep 2014) | 3 lines
  
  Implemented the writing out of parameter values between comparison of NI 
level.
  
  Task #7826 (https://gna.org/task/index.php?7826): Write an python class for 
the repeated analysis of dispersion data.
........

Modified:
    branches/frame_order_cleanup/   (props changed)
    branches/frame_order_cleanup/auto_analyses/relax_disp_repeat_cpmg.py
    branches/frame_order_cleanup/test_suite/system_tests/relax_disp.py

Propchange: branches/frame_order_cleanup/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Fri Sep 26 19:14:41 2014
@@ -1 +1 @@
-/trunk:1-26017,26043-26056
+/trunk:1-26017,26043-26057

Modified: branches/frame_order_cleanup/auto_analyses/relax_disp_repeat_cpmg.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/frame_order_cleanup/auto_analyses/relax_disp_repeat_cpmg.py?rev=26075&r1=26074&r2=26075&view=diff
==============================================================================
--- branches/frame_order_cleanup/auto_analyses/relax_disp_repeat_cpmg.py      
  (original)
+++ branches/frame_order_cleanup/auto_analyses/relax_disp_repeat_cpmg.py      
  Fri Sep 26 19:14:41 2014
@@ -1691,6 +1691,7 @@
         res_dic = {}
         res_dic['method'] = method
         res_dic['selection'] = selection
+        res_dic['analysis'] = analysis
 
         for glob_ini in list_glob_ini:
             # Check previous, and get the pipe name.
@@ -1764,7 +1765,7 @@
         return res_dic
 
 
-    def plot_min_corr(self, corr_data, show=False):
+    def plot_min_corr(self, corr_data, show=False, write_stats=False):
         # Define figure.
         # Nr of columns is number of datasets.
         nr_cols = len(corr_data)
@@ -1773,6 +1774,7 @@
         glob_ini_0 = glob_inis_0[0]
         params_list = data_xy_0[0][str(glob_ini_0)]['params']['params_list']
         nr_rows = len(params_list)
+        analysis = data_xy_0[0]['analysis']
 
         # Define figure
         fig, axises = plt.subplots(nrows=nr_rows, ncols=nr_cols)
@@ -1780,6 +1782,9 @@
 
         # axises is a tuple with number of elements corresponding to number 
of rows.
         # Each sub-tuple contains axis for each column.
+
+        # For writing out stats.
+        data_dic = OrderedDict()
 
         # Loop over the rows.
         for i, row_axises in enumerate(axises):
@@ -1797,6 +1802,15 @@
                 y = data_y[str(glob_ini_y)]['params'][param]
                 np = len(y)
 
+                # Linear a, with no intercept.
+                a = sum(x * y) / sum(x**2)
+                min_xy = min(concatenate((x,y)))
+                max_xy = max(concatenate((x,y)))
+
+                dx = (max_xy - min_xy) / np
+                x_arange = arange(min_xy, max_xy + dx, dx)
+                y_arange = a * x_arange
+
                 ax.plot(x, x, 'o', label='%s vs. %s' % (method_x, method_x))
                 ax.plot(x, y, '.', label='%s vs. %s' % (method_y, method_x) )
 
@@ -1814,20 +1828,116 @@
                     ax.ticklabel_format(style='sci', axis='x', 
scilimits=(0,0))
                     ax.ticklabel_format(style='sci', axis='y', 
scilimits=(0,0))
 
-                # If r2 or dw parameter, do a straight line:
-                if param in PARAMS_R20 + ['dw']:
-                    # Linear a, with no intercept.
-                    a = sum(x * y) / sum(x**2)
-                    min_xy = min(concatenate((x,y)))
-                    max_xy = max(concatenate((x,y)))
-
-                    dx = (max_xy - min_xy) / 10
-                    x_arange = arange(min_xy, max_xy + dx, dx)
-                    y_arange = a * x_arange
-                    ax.plot(x_arange, x_arange, 'b--')
-                    ax.plot(x_arange, y_arange, 'g--')
+                ## If r2 or dw parameter, do a straight line:
+                #if param in PARAMS_R20 + ['dw']:
+
+                #    ax.plot(x_arange, x_arange, 'b--')
+                #    ax.plot(x_arange, y_arange, 'g--')
+
+                # Do a straight line for all.
+                ax.plot(x_arange, x_arange, 'b--')
+                ax.plot(x_arange, y_arange, 'g--')
+
+                # Store to data dic
+                method_xy_NI = "%s_%s_%s%s_%s%s" % (analysis, param, 
method_x, glob_ini_x, method_y, glob_ini_y)
+                data_dic[method_xy_NI] = []
+
+                # Add to data.
+                for k, x_k in enumerate(x):
+                    y_k = y[k]
+                    x_arange_k = x_arange[k]
+                    y_arange_k = y_arange[k]
+                    data_dic[method_xy_NI].append(["%3.5f"%x_k, "%3.5f"%y_k, 
"%3.5f"%x_arange_k, "%3.5f"%y_arange_k])
 
         plt.tight_layout()
+
+        # Loop over columns for writing data.
+        # Write to file.
+        if write_stats:
+            # Re-order the data.
+            headings_all = []
+            method_xy_NI_all = []
+            # Loop over the columns.
+            for j in range(nr_cols):
+                headings_j = []
+                method_xy_NI_j = []
+                # Loop over rows
+                for i in range(nr_rows):
+                    # Extract from lists.
+                    data, methods, glob_inis = corr_data[j]
+                    method_x, method_y = methods
+                    glob_ini_x, glob_ini_y = glob_inis
+                    param = params_list[i]
+
+                    # Add to headings
+                    method_x_NI = "%s_%s_%s%s" % (analysis, param, method_x, 
glob_ini_x)
+                    method_y_NI = "%s_%s_%s%s" % (analysis, param, method_y, 
glob_ini_y)
+                    method_x_NI_lin = "%s_%s_lin_%s%s" % (analysis, param, 
method_x, glob_ini_x)
+                    method_y_NI_lin = "%s_%s_lin_%s%s" % (analysis, param, 
method_y, glob_ini_y)
+                    headings_j = headings_j + [method_x_NI, method_y_NI, 
method_x_NI_lin, method_y_NI_lin]
+
+                    method_xy_NI = "%s_%s_%s%s_%s%s" % (analysis, param, 
method_x, glob_ini_x, method_y, glob_ini_y)
+                    method_xy_NI_j.append(method_xy_NI)
+
+                headings_all.append(headings_j)
+                method_xy_NI_all.append(method_xy_NI_j)
+
+            # Loop over the columns.
+            for j, headings_j in enumerate(headings_all):
+                method_xy_NI_j = method_xy_NI_all[j]
+
+                data_w = []
+                method_xy_NI_r2 = method_xy_NI_j[0]
+                data_r2 = data_dic[method_xy_NI_r2]
+
+                # Loop over the rows of data.
+                for k, data_r2_k in enumerate(data_r2):
+                    data_row = data_r2_k
+                    # Loop over the columns.
+                    for method_xy_NI in method_xy_NI_j[1:]:
+                        data_param = data_dic[method_xy_NI]
+
+                        try:
+                            data_param_row = data_param[k]
+                        except IndexError:
+                            data_param_row = len(data_param[0]) * ['0.0']
+
+                        data_row = data_row + data_param_row
+
+                    data_w.append(data_row)
+
+                # Define file name.
+                data, methods, glob_inis = corr_data[j]
+                data_x, data_y = data
+                method_x, method_y = methods
+                glob_ini_x, glob_ini_y = glob_inis
+
+                # Get the spin selection for correlation.
+                selection = data_x['selection']
+
+                file_name_ini = '%s_%s_%s_%s_%s' % (analysis, method_x, 
glob_ini_x, method_y, glob_ini_y)
+                if selection == None:
+                    file_name_ini = file_name_ini + '_all'
+                else:
+                    file_name_ini = file_name_ini + '_sel'
+
+                file_name = file_name_ini + '.txt'
+                path = self.results_dir
+
+                # save figure
+                # Write png.
+                png_file_name = file_name_ini + '.png'
+                png_file_path = get_file_path(file_name=png_file_name, 
dir=path)
+                plt.savefig(png_file_path, bbox_inches='tight')
+
+                # Write file
+                file_obj, file_path = open_write_file(file_name=file_name, 
dir=path, force=True, compress_type=0, verbosity=1, return_path=True)
+
+                # Write data.
+                write_data(out=file_obj, headings=headings_j, data=data_w)
+
+                # Close file.
+                file_obj.close()
 
         if show:
             plt.show()

Modified: branches/frame_order_cleanup/test_suite/system_tests/relax_disp.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/frame_order_cleanup/test_suite/system_tests/relax_disp.py?rev=26075&r1=26074&r2=26075&view=diff
==============================================================================
--- branches/frame_order_cleanup/test_suite/system_tests/relax_disp.py  
(original)
+++ branches/frame_order_cleanup/test_suite/system_tests/relax_disp.py  Fri 
Sep 26 19:14:41 2014
@@ -6123,8 +6123,97 @@
                     for i, data_i in enumerate(data):
                         print(i, data_i)
 
-        # Do minimisation.
-        if False:
+
+        # Do minimisation individual.
+        if True:
+            methods = ['FT', 'MDD']
+            # Now calculate R2eff.
+            RDR.calc_r2eff(methods=methods, list_glob_ini=[128, 126])
+
+            min_methods = [['FT'], ['MDD']]
+            min_list_glob_ini = [[128], range(126, 130, 2)[::-1]]
+
+            #min_methods = [['FT']]
+            #min_list_glob_ini = [[128]]
+            #selection = ':2,3'
+            selection = None
+
+            for i, methods in enumerate(min_methods):
+                list_glob_ini = min_list_glob_ini[i]
+
+                if True:
+                    # First get data.
+                    if True:
+                        # First load all data.
+                        RDR.calc_r2eff(methods=methods, 
list_glob_ini=list_glob_ini)
+
+                    # Then set R20
+                    if True:
+                        # Set R20 from min R2eff in preparation for Grid 
search.
+                        RDR.r20_from_min_r2eff(methods=methods, 
model=MODEL_CR72, model_from=MODEL_R2EFF, analysis='grid_setup_ind', 
analysis_from='int', list_glob_ini=list_glob_ini, force=True)
+
+                    # Check and print parameters.
+                    if True:
+                        # Print for pipe name
+                        method = methods[0]
+                        glob_ini = list_glob_ini[0]
+
+                        test_pipe_name = RDR.name_pipe(method=method, 
model=MODEL_CR72, analysis='grid_setup_ind', glob_ini=glob_ini)
+                        RDR.spin_display_params(pipe_name=test_pipe_name)
+
+                    # Then Grid search.
+                    if True:
+                        # Do Grid search.
+                        RDR.minimise_grid_search(inc=4, verbosity=1, 
methods=methods, model=MODEL_CR72, analysis='grid_setup_ind', 
list_glob_ini=list_glob_ini, force=True)
+
+                # Then Minimise.
+                if True:
+                    # Minimise
+                    RDR.opt_max_iterations = int(1e2)
+                    RDR.minimise_execute(methods=methods, model=MODEL_CR72, 
analysis='min_ind', analysis_from='grid_setup_ind', 
list_glob_ini=list_glob_ini, force=True)
+
+                #print asd
+
+        # Plot statistics.
+        # Try plot some minimisation correlations.
+        if True:
+            selection = None
+            # Collect param values.
+            analysis = 'min_ind'
+            min_ft_sel = RDR.col_min(method='FT', model=MODEL_CR72, 
analysis=analysis, list_glob_ini=[128], selection=selection)
+            min_mdd_sel = RDR.col_min(method='MDD', model=MODEL_CR72, 
analysis=analysis, list_glob_ini=range(126, 130, 2)[::-1], 
selection=selection)
+
+            fig1 = [[min_ft_sel, min_mdd_sel], ['FT', 'MDD'], [128, 128]]
+            fig2 = [[min_ft_sel, min_mdd_sel], ['FT', 'MDD'], [128, 126]]
+            corr_data = [fig1, fig2]
+
+            write_stats = True
+            RDR.plot_min_corr(corr_data=corr_data, show=False, 
write_stats=write_stats)
+
+            # Open stat file.
+            if write_stats:
+                for i, corr_data_i in enumerate(corr_data):
+                    data, methods, glob_inis = corr_data[i]
+                    data_x, data_y = data
+                    method_x, method_y = methods
+                    glob_ini_x, glob_ini_y = glob_inis
+
+                    file_name_ini = '%s_%s_%s_%s_%s' % (analysis, method_x, 
glob_ini_x, method_y, glob_ini_y)
+
+                    if selection == None:
+                        file_name = file_name_ini + '_all.txt'
+                    else:
+                        file_name = file_name_ini + '_sel.txt'
+                    path = RDR.results_dir
+                    data = extract_data(file=file_name, dir=path)
+
+                    # Loop over the lines.
+                    for i, data_i in enumerate(data):
+                        print(i, data_i)
+
+
+        # Do minimisation clustered.
+        if True:
             methods = ['FT', 'MDD']
             # Now calculate R2eff.
             RDR.calc_r2eff(methods=methods, list_glob_ini=[128, 126])
@@ -6148,23 +6237,19 @@
                     # Then select spins.
                     if True:
                         # Deselect all spins.
-                        #RDR.deselect_all(methods=methods, model='setup', 
model_from=MODEL_R2EFF, analysis='grid_setup', analysis_from='int', 
list_glob_ini=list_glob_ini)
                         RDR.deselect_all(methods=methods, model='setup', 
model_from=MODEL_R2EFF, analysis='grid_setup', analysis_from='int', 
list_glob_ini=list_glob_ini, force=True)
                 
-                        #RDR.select_spin(spin_id=selection, methods=methods, 
model='setup', analysis='grid_setup', list_glob_ini=list_glob_ini)
                         RDR.select_spin(spin_id=selection, methods=methods, 
model='setup', analysis='grid_setup', list_glob_ini=list_glob_ini, force=True)
                 
                     # Then preset values.
                     if True:
                         # Set k_AB for Grid search.
-                        #RDR.value_set(methods=methods, val=1000., 
param='kex', model=MODEL_CR72, model_from='setup', analysis='grid_setup', 
list_glob_ini=list_glob_ini)
                         RDR.value_set(methods=methods, val=1000., 
param='kex', model=MODEL_CR72, model_from='setup', analysis='grid_setup', 
list_glob_ini=list_glob_ini, force=True)
                         RDR.value_set(methods=methods, val=0.95, param='pA', 
model=MODEL_CR72, model_from='setup', analysis='grid_setup', 
list_glob_ini=list_glob_ini, force=True)
                 
                     # Then set R20
                     if True:
                         # Set R20 from min R2eff in preparation for Grid 
search.
-                        #RDR.r20_from_min_r2eff(methods=methods, 
model=MODEL_CR72, analysis='grid_setup', list_glob_ini=list_glob_ini)
                         RDR.r20_from_min_r2eff(methods=methods, 
model=MODEL_CR72, analysis='grid_setup', list_glob_ini=list_glob_ini, 
force=True)
                 
                     # Check and print parameters.
@@ -6179,38 +6264,54 @@
                     # Then Grid search.
                     if True:
                         # Do Grid search.
-                        #RDR.minimise_grid_search(inc=200, verbosity=1, 
methods=methods, model=MODEL_CR72, analysis='grid', 
analysis_from='grid_setup', list_glob_ini=list_glob_ini)
                         RDR.minimise_grid_search(inc=200, verbosity=1, 
methods=methods, model=MODEL_CR72, analysis='grid', 
analysis_from='grid_setup', list_glob_ini=list_glob_ini, force=True)
                 
                     # Then cluster spins.
                     if True:
-                        #RDR.cluster_spins(spin_id=selection, 
methods=methods, model=MODEL_CR72, analysis='grid', 
list_glob_ini=list_glob_ini)
                         RDR.cluster_spins(spin_id=selection, 
methods=methods, model=MODEL_CR72, analysis='grid', 
list_glob_ini=list_glob_ini, force=True)
             
                 # Then Minimise.
                 if True:
                     # Minimise
                     RDR.opt_max_iterations = int(1e2)
-                    #RDR.minimise_execute(methods=methods, model=MODEL_CR72, 
analysis='min', analysis_from='grid', list_glob_ini=list_glob_ini, force=True)
                     RDR.minimise_execute(methods=methods, model=MODEL_CR72, 
analysis='min', analysis_from='grid', list_glob_ini=list_glob_ini, 
force=False)
-
-                #print asd
 
         # Plot statistics.
         # Try plot some minimisation correlations.
-        if False:
-            # Collect r2eff values.
-            min_ft_sel = RDR.col_min(method='FT', model=MODEL_CR72, 
analysis='min', list_glob_ini=[128], selection=None)
-            min_mdd_sel = RDR.col_min(method='MDD', model=MODEL_CR72, 
analysis='min', list_glob_ini=range(126, 130, 2)[::-1], selection=None)
-
-            fig1 = [[min_ft_sel, min_mdd_sel], ['FT', 'MDD'], [128, 126]]
-            fig2 = [[min_mdd_sel, min_mdd_sel], ['MDD', 'MDD'], [128, 126]]
+        if True:
+            selection = ':2,3'
+            # Collect param values.
+            analysis = 'min'
+            min_ft_sel = RDR.col_min(method='FT', model=MODEL_CR72, 
analysis=analysis, list_glob_ini=[128], selection=selection)
+            min_mdd_sel = RDR.col_min(method='MDD', model=MODEL_CR72, 
analysis=analysis, list_glob_ini=range(126, 130, 2)[::-1], 
selection=selection)
+
+            fig1 = [[min_ft_sel, min_mdd_sel], ['FT', 'MDD'], [128, 128]]
+            fig2 = [[min_ft_sel, min_mdd_sel], ['FT', 'MDD'], [128, 126]]
             corr_data = [fig1, fig2]
 
-            RDR.plot_min_corr(corr_data=corr_data, show=False)
-
-        # Print the pipes.
-        #display(sort=True, rev=True)
+            write_stats = True
+            RDR.plot_min_corr(corr_data=corr_data, show=False, 
write_stats=write_stats)
+
+            # Open stat file.
+            if write_stats:
+                for i, corr_data_i in enumerate(corr_data):
+                    data, methods, glob_inis = corr_data[i]
+                    data_x, data_y = data
+                    method_x, method_y = methods
+                    glob_ini_x, glob_ini_y = glob_inis
+
+                    file_name_ini = '%s_%s_%s_%s_%s' % (analysis, method_x, 
glob_ini_x, method_y, glob_ini_y)
+
+                    if selection == None:
+                        file_name = file_name_ini + '_all.txt'
+                    else:
+                        file_name = file_name_ini + '_sel.txt'
+                    path = RDR.results_dir
+                    data = extract_data(file=file_name, dir=path)
+
+                    # Loop over the lines.
+                    for i, data_i in enumerate(data):
+                        print(i, data_i)
 
 
     def test_r1rho_kjaergaard_auto(self):




Related Messages


Powered by MHonArc, Updated Fri Sep 26 19:20:03 2014