mailr25900 - /trunk/auto_analyses/relax_disp_repeat_cpmg.py


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

Header


Content

Posted by tlinnet on September 18, 2014 - 17:46:
Author: tlinnet
Date: Thu Sep 18 17:46:44 2014
New Revision: 25900

URL: http://svn.gna.org/viewcvs/relax?rev=25900&view=rev
Log:
Reordered functions in repeated analysis protocol.

Task #7826 (https://gna.org/task/index.php?7826): Write an python class for 
the repeated analysis of dispersion data.

Modified:
    trunk/auto_analyses/relax_disp_repeat_cpmg.py

Modified: trunk/auto_analyses/relax_disp_repeat_cpmg.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/auto_analyses/relax_disp_repeat_cpmg.py?rev=25900&r1=25899&r2=25900&view=diff
==============================================================================
--- trunk/auto_analyses/relax_disp_repeat_cpmg.py       (original)
+++ trunk/auto_analyses/relax_disp_repeat_cpmg.py       Thu Sep 18 17:46:44 
2014
@@ -449,6 +449,9 @@
                 else:
                     self.interpreter.results.write(file=resfile, dir=path, 
force=force)
 
+                # Show selected spins
+                self.interpreter.spin.display()
+
 
     def select_spin(self, spin_id=None, methods=None, model=None, 
model_from=None, analysis=None, analysis_from=None, list_glob_ini=None, 
force=False):
         """Method to select spins for a pipe."""
@@ -493,10 +496,12 @@
                 else:
                     self.interpreter.results.write(file=resfile, dir=path, 
force=force)
 
-
-    def r20_from_min_r2eff(self, spin_id=None, methods=None, model=None, 
model_from=None, analysis=None, analysis_from=None, list_glob_ini=None, 
force=False):
-        """Will set the grid R20 values from the minimum R2eff values 
through the r20_from_min_r2eff user function.
-        This will speed up the grid search with a factor 
GRID_INC^(Nr_spec_freq). For a CPMG experiment with two fields and standard 
GRID_INC=21, the speed-up is a factor 441."""
+                # Show selected spins
+                self.interpreter.spin.display()
+
+
+    def value_set(self, spin_id=None, val=None, param=None, methods=None, 
model=None, model_from=None, analysis=None, analysis_from=None, 
list_glob_ini=None, force=False):
+        """Use value.set on all pipes."""
 
         # Set default
         if model_from == None:
@@ -523,13 +528,13 @@
                     self.interpreter.pipe.switch(pipe_name)
 
                 # Print
-                subtitle(file=sys.stdout, text="Set grid r20 for pipe='%s'" 
% (pipe_name), prespace=3)
+                subtitle(file=sys.stdout, text="For param '%s' set value 
'%3.2f' for pipe='%s'" % (param, val, pipe_name), prespace=3)
 
                 # Select the model.
                 self.interpreter.relax_disp.select_model(model)
 
-                # Set r20 from min r2eff.
-                self.interpreter.relax_disp.r20_from_min_r2eff(force=True)
+                # Set value
+                self.interpreter.value.set(val=val, param=param, 
spin_id=spin_id)
 
                 # Save results, and store the current settings dic to pipe.
                 cdp.settings = self.settings
@@ -541,9 +546,13 @@
                 else:
                     self.interpreter.results.write(file=resfile, dir=path, 
force=force)
 
-
-    def value_set(self, spin_id=None, val=None, param=None, methods=None, 
model=None, model_from=None, analysis=None, analysis_from=None, 
list_glob_ini=None, force=False):
-        """Use value.set on all pipes."""
+                # Print for pipe name
+                self.spin_display_params(pipe_name=pipe_name)
+
+
+    def r20_from_min_r2eff(self, spin_id=None, methods=None, model=None, 
model_from=None, analysis=None, analysis_from=None, list_glob_ini=None, 
force=False):
+        """Will set the grid R20 values from the minimum R2eff values 
through the r20_from_min_r2eff user function.
+        This will speed up the grid search with a factor 
GRID_INC^(Nr_spec_freq). For a CPMG experiment with two fields and standard 
GRID_INC=21, the speed-up is a factor 441."""
 
         # Set default
         if model_from == None:
@@ -570,10 +579,13 @@
                     self.interpreter.pipe.switch(pipe_name)
 
                 # Print
-                subtitle(file=sys.stdout, text="For param '%s' set value 
'%3.2f' for pipe='%s'" % (param, val, pipe_name), prespace=3)
-
-                # Set value
-                self.interpreter.value.set(val=val, param=param, 
spin_id=spin_id)
+                subtitle(file=sys.stdout, text="Set grid r20 for pipe='%s'" 
% (pipe_name), prespace=3)
+
+                # Select the model.
+                self.interpreter.relax_disp.select_model(model)
+
+                # Set r20 from min r2eff.
+                self.interpreter.relax_disp.r20_from_min_r2eff(force=True)
 
                 # Save results, and store the current settings dic to pipe.
                 cdp.settings = self.settings
@@ -585,6 +597,9 @@
                 else:
                     self.interpreter.results.write(file=resfile, dir=path, 
force=force)
 
+                # Print for pipe name
+                self.spin_display_params(pipe_name=pipe_name)
+
 
     def minimise_grid_search(self, inc=11, verbosity=0, methods=None, 
model=None, model_from=None, analysis=None, analysis_from=None, 
list_glob_ini=None, force=False):
         """Use value.set on all pipes."""
@@ -605,6 +620,11 @@
                 # Check previous, and get the pipe name.
                 found, pipe_name, resfile, path = 
self.check_previous_result(method=self.method, model=model, 
analysis=analysis, glob_ini=glob_ini, bundle=self.method)
 
+                # Try from analysis
+                if not found:
+                    # Check previous, and get the pipe name.
+                    found, pipe_name, resfile, path = 
self.check_previous_result(method=self.method, model=model, 
analysis=analysis_from, glob_ini=glob_ini, bundle=self.method)
+
                 if not found:
                     # If previous pipe not found, then create it.
                     model_from_pipe_name = 
self.name_pipe(method=self.method, model=model_from, analysis=analysis_from, 
glob_ini=glob_ini)
@@ -648,6 +668,12 @@
 
                 # Save results, and store the current settings dic to pipe.
                 cdp.settings = self.settings
+
+                # Define new pipe names.
+                pipe_name = self.name_pipe(method=self.method, model=model, 
analysis=analysis, glob_ini=glob_ini)
+                resfile = pipe_name.replace(" ", "_")
+                model_path = model.replace(" ", "_")
+                path = self.results_dir+sep+model_path
 
                 if found and not force:
                     file_path = get_file_path(file_name=resfile, dir=path)
@@ -656,9 +682,12 @@
                 else:
                     self.interpreter.results.write(file=resfile, dir=path, 
force=force)
 
-
-    def minimise_execute(self, verbosity=1, methods=None, model=None, 
model_from=None, analysis=None, analysis_from=None, list_glob_ini=None, 
force=False):
-        """Use value.set on all pipes."""
+                # Print for pipe name
+                self.spin_display_params(pipe_name=pipe_name)
+
+
+    def cluster_spins(self, spin_id=None, methods=None, model=None, 
model_from=None, analysis=None, analysis_from=None, list_glob_ini=None, 
force=False):
+        """Method to select spins for a pipe."""
 
         # Set default
         if model_from == None:
@@ -680,6 +709,58 @@
                     # If previous pipe not found, then create it.
                     model_from_pipe_name = 
self.name_pipe(method=self.method, model=model_from, analysis=analysis_from, 
glob_ini=glob_ini)
 
+                    # Copy pipe and switch.
+                    
self.interpreter.pipe.copy(pipe_from=model_from_pipe_name, pipe_to=pipe_name, 
bundle_to=self.method)
+                    self.interpreter.pipe.switch(pipe_name)
+
+                # Print
+                subtitle(file=sys.stdout, text="Cluster spins '%s' for 
pipe='%s'" % (spin_id, pipe_name), prespace=3)
+
+                # Select spins.
+                self.interpreter.relax_disp.cluster(cluster_id='sel', 
spin_id=spin_id)
+
+                # Save results, and store the current settings dic to pipe.
+                cdp.settings = self.settings
+
+                if found and not force:
+                    file_path = get_file_path(file_name=resfile, dir=path)
+                    text = "The file '%s' already exists.  Set the force 
flag to True to overwrite." % (file_path)
+                    warn(RelaxWarning(text))
+                else:
+                    self.interpreter.results.write(file=resfile, dir=path, 
force=force)
+
+            # print clustered spins
+            print("Clustered spins are:", cdp.clustering)
+
+
+    def minimise_execute(self, verbosity=1, methods=None, model=None, 
model_from=None, analysis=None, analysis_from=None, list_glob_ini=None, 
force=False):
+        """Use value.set on all pipes."""
+
+        # Set default
+        if model_from == None:
+            model_from = model
+        if analysis_from == None:
+            analysis_from = analysis
+
+        # Loop over the methods.
+        for method in methods:
+            # Change the self key.
+            self.set_self(key='method', value=method)
+
+            # Loop over the glob ini:
+            for glob_ini in list_glob_ini:
+                # Check previous, and get the pipe name.
+                found, pipe_name, resfile, path = 
self.check_previous_result(method=self.method, model=model, 
analysis=analysis, glob_ini=glob_ini, bundle=self.method)
+
+                # Try from analysis
+                if not found:
+                    # Check previous, and get the pipe name.
+                    found, pipe_name, resfile, path = 
self.check_previous_result(method=self.method, model=model, 
analysis=analysis_from, glob_ini=glob_ini, bundle=self.method)
+
+                if not found:
+                    # If previous pipe not found, then create it.
+                    model_from_pipe_name = 
self.name_pipe(method=self.method, model=model_from, analysis=analysis_from, 
glob_ini=glob_ini)
+
                     # Check if pipe exists. If not, try grid pipe.
                     if not pipes.has_pipe(model_from_pipe_name):
                         model_from_pipe_name = 
self.name_pipe(method=self.method, model=model_from, analysis='grid', 
glob_ini=glob_ini)
@@ -696,6 +777,25 @@
 
                 # Do the minimisation.
                 self.interpreter.minimise.execute(min_algor=self.min_algor, 
func_tol=self.opt_func_tol, max_iter=self.opt_max_iterations, 
constraints=self.constraints, scaling=True, verbosity=verbosity)
+
+                # Save results, and store the current settings dic to pipe.
+                cdp.settings = self.settings
+
+                # Define new pipe names.
+                pipe_name = self.name_pipe(method=self.method, model=model, 
analysis=analysis, glob_ini=glob_ini)
+                resfile = pipe_name.replace(" ", "_")
+                model_path = model.replace(" ", "_")
+                path = self.results_dir+sep+model_path
+
+                if found and not force:
+                    file_path = get_file_path(file_name=resfile, dir=path)
+                    text = "The file '%s' already exists.  Set the force 
flag to True to overwrite." % (file_path)
+                    warn(RelaxWarning(text))
+                else:
+                    self.interpreter.results.write(file=resfile, dir=path, 
force=force)
+
+                # Print for pipe name
+                self.spin_display_params(pipe_name=pipe_name)
 
 
     def name_pipe(self, method, model, analysis, glob_ini, clusterid=None):
@@ -771,9 +871,46 @@
         """Display parameters for model in pipe."""
 
 
-        # Switch to the pipe.
-        if pipes.cdp_name() != pipe_name:
-            self.interpreter.pipe.switch(pipe_name)
+        # First check if the pipe already exists. Then switch to it.
+        if pipes.has_pipe(pipe_name):
+            # Switch to the pipe.
+            if pipes.cdp_name() != pipe_name:
+                print("Detected the presence of previous '%s' pipe - 
switching to it." % pipe_name)
+                self.interpreter.pipe.switch(pipe_name)
+
+        else:
+            # The result file.
+            pipe_name_split = pipe_name.split("_-_")
+            method = pipe_name_split[0]
+            model = pipe_name_split[1]
+            analysis = pipe_name_split[2]
+            bundle = method
+
+            model_path = model.replace(" ", "_")
+            path = self.results_dir+sep+model_path
+            # The result file.
+            resfile = pipe_name.replace(" ", "_")
+
+            # Check that results do not already exist - i.e. a previous run 
was interrupted.
+            path1 = get_file_path(file_name=resfile, dir=path)
+            path2 = path1 + '.bz2'
+            path3 = path1 + '.gz'
+
+            #print("Path to R2eff file is: %s"%path1)
+            if access(path1, F_OK) or access(path2, F_OK) or access(path2, 
F_OK):
+                # Printout.
+                print("Detected the presence of results files for the '%s' 
pipe - loading these instead of performing optimisation for a second time." % 
pipe_name)
+
+                # Create a data new pipe and switch to it.
+                self.interpreter.pipe.create(pipe_name=pipe_name, 
pipe_type=self.pipe_type, bundle=bundle)
+                self.interpreter.pipe.switch(pipe_name)
+
+                # Load the results.
+                self.interpreter.results.read(file=resfile, dir=path)
+
+                # Set found to True
+                found = True
+
 
         # Start dic.
         my_dic = {}
@@ -814,7 +951,10 @@
                         my_dic[spin_id][param] = {}
 
                         # Get the Value.
-                        param_val = deepcopy(getattr(cur_spin, 
param)[param_key])
+                        if len(getattr(cur_spin, param)) == 0:
+                            param_val = None
+                        else:
+                            param_val = deepcopy(getattr(cur_spin, 
param)[param_key])
                         my_dic[spin_id][param][param_key] = param_val
 
                         # Add information to data.




Related Messages


Powered by MHonArc, Updated Thu Sep 18 18:00:03 2014