mailr25103 - /trunk/auto_analyses/relax_disp.py


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

Header


Content

Posted by tlinnet on August 20, 2014 - 18:09:
Author: tlinnet
Date: Wed Aug 20 18:09:29 2014
New Revision: 25103

URL: http://svn.gna.org/viewcvs/relax?rev=25103&view=rev
Log:
Rewrote the logic of the key-word 'optimise_r2eff' in the auto analyses of 
relax disp.

If R2eff result file exist in the 'pre_run_dir', this is loaded.

If the results contain both values, and errors, then no optimisation is 
performed on the R2eff model.
Unless the 'optimise_r2eff' flag is raised, which is not standard.

Modified:
    trunk/auto_analyses/relax_disp.py

Modified: trunk/auto_analyses/relax_disp.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/auto_analyses/relax_disp.py?rev=25103&r1=25102&r2=25103&view=diff
==============================================================================
--- trunk/auto_analyses/relax_disp.py   (original)
+++ trunk/auto_analyses/relax_disp.py   Wed Aug 20 18:09:29 2014
@@ -51,7 +51,7 @@
     opt_func_tol = 1e-25
     opt_max_iterations = int(1e7)
 
-    def __init__(self, pipe_name=None, pipe_bundle=None, results_dir=None, 
models=[MODEL_R2EFF], grid_inc=11, mc_sim_num=500, exp_mc_sim_num=None, 
modsel='AIC', pre_run_dir=None, optimise_pre_run_r2eff=True, 
insignificance=0.0, numeric_only=False, mc_sim_all_models=False, 
eliminate=True, set_grid_r20=False):
+    def __init__(self, pipe_name=None, pipe_bundle=None, results_dir=None, 
models=[MODEL_R2EFF], grid_inc=11, mc_sim_num=500, exp_mc_sim_num=None, 
modsel='AIC', pre_run_dir=None, optimise_r2eff=False, insignificance=0.0, 
numeric_only=False, mc_sim_all_models=False, eliminate=True, 
set_grid_r20=False):
         """Perform a full relaxation dispersion analysis for the given list 
of models.
 
         @keyword pipe_name:                 The name of the data pipe 
containing all of the data for the analysis.
@@ -72,8 +72,8 @@
         @type modsel:                       str
         @keyword pre_run_dir:               The optional directory 
containing the dispersion auto-analysis results from a previous run.  The 
optimised parameters from these previous results will be used as the starting 
point for optimisation rather than performing a grid search.  This is 
essential for when large spin clusters are specified, as a grid search 
becomes prohibitively expensive with clusters of three or more spins.  At 
some point a RelaxError will occur because the grid search is impossibly 
large.  For the cluster specific parameters, i.e. the populations of the 
states and the exchange parameters, an average value will be used as the 
starting point.  For all other parameters, the R20 values for each spin and 
magnetic field, as well as the parameters related to the chemical shift 
difference dw, the optimised values of the previous run will be directly 
copied.
         @type pre_run_dir:                  None or str
-        @keyword optimise_pre_run_r2eff:    Flag to specify if the read 
previous R2eff results should be optimised.  For R1rho models where the error 
of R2eff values are determined by Monte-Carlo simulations, it can be valuable 
to make an initial R2eff run with a high number of Monte-Carlo simulations.  
Any subsequent model analysis can then be based on these R2eff values, 
without optimising the R2eff values. 
-        @type optimise_pre_run_r2eff:       bool
+        @keyword optimise_r2eff:            Flag to specify if the read 
previous R2eff results should be optimised.  For R1rho models where the error 
of R2eff values are determined by Monte-Carlo simulations, it can be valuable 
to make an initial R2eff run with a high number of Monte-Carlo simulations.  
Any subsequent model analysis can then be based on these R2eff values, 
without optimising the R2eff values.
+        @type optimise_r2eff:               bool
         @keyword insignificance:            The R2eff/R1rho value in rad/s 
by which to judge insignificance.  If the maximum difference between two 
points on all dispersion curves for a spin is less than this value, that spin 
will be deselected.  This does not affect the 'No Rex' model.  Set this value 
to 0.0 to use all data.  The value will be passed on to the 
relax_disp.insignificance user function.
         @type insignificance:               float
         @keyword numeric_only:              The class of models to use in 
the model selection.  The default of False allows all dispersion models to be 
used in the analysis (no exchange, the analytic models and the numeric 
models).  The value of True will activate a pure numeric solution - the 
analytic models will be optimised, as they are very useful for replacing the 
grid search for the numeric models, but the final model selection will not 
include them.
@@ -105,7 +105,7 @@
         self.exp_mc_sim_num = exp_mc_sim_num
         self.modsel = modsel
         self.pre_run_dir = pre_run_dir
-        self.optimise_pre_run_r2eff = optimise_pre_run_r2eff
+        self.optimise_r2eff = optimise_r2eff
         self.insignificance = insignificance
         self.set_grid_r20 = set_grid_r20
         self.numeric_only = numeric_only
@@ -431,21 +431,63 @@
                         self.interpreter.value.set(param=param, index=None)
 
         # Minimise.
+        do_minimise = False
         if model == MODEL_R2EFF:
-            if self.optimise_pre_run_r2eff:
-                self.interpreter.minimise.execute('simplex', 
func_tol=self.opt_func_tol, max_iter=self.opt_max_iterations, 
constraints=True)
-            else:
+            # Check if all spins contains 'r2eff and it associated error.
+            has_r2eff = False
+
+            # Loop over all spins.
+            for cur_spin, spin_id in spin_loop(return_id=True, 
skip_desel=True):
+                # Check 'r2eff'
+                if hasattr(cur_spin, 'r2eff') and hasattr(cur_spin, 
'r2eff_err'):
+                    has_r2eff = True
+                else:
+                    has_r2eff = False
+                    break
+
+            # Skip optimisation, if 'r2eff' + 'r2eff_err' is present and 
flag for forcing optimisation is not raised.
+            if has_r2eff and not self.optimise_r2eff:
                 pass
-        else:
+
+            # Do optimisation, if 'r2eff' + 'r2eff_err' is present and flag 
for forcing optimisation is raised.
+            elif has_r2eff and self.optimise_r2eff:
+                do_minimise = True
+
+            # Optimise, if no R2eff and error is present.
+            elif not has_r2eff:
+                do_minimise = True
+
+        else:
+            do_minimise = True
+
+        # Do the minimisation.
+        if do_minimise:
             self.interpreter.minimise.execute('simplex', 
func_tol=self.opt_func_tol, max_iter=self.opt_max_iterations, 
constraints=True)
-
 
         # Model elimination.
         if self.eliminate:
             self.interpreter.eliminate()
 
         # Monte Carlo simulations.
-        if self.mc_sim_all_models or len(self.models) < 2 or (model == 
MODEL_R2EFF and self.optimise_pre_run_r2eff):
+        do_monte_carlo = False
+        if model == MODEL_R2EFF:
+            # Skip optimisation, if 'r2eff' + 'r2eff_err' is present and 
flag for forcing optimisation is not raised.
+            if has_r2eff and not self.optimise_r2eff:
+                pass
+
+            # Do optimisation, if 'r2eff' + 'r2eff_err' is present and flag 
for forcing optimisation is raised.
+            elif has_r2eff and self.optimise_r2eff:
+                do_monte_carlo = True
+
+            # Optimise, if no R2eff and error is present.
+            elif not has_r2eff:
+                do_monte_carlo = True
+
+        elif self.mc_sim_all_models or len(self.models) < 2:
+            do_monte_carlo = True
+
+        # Do Monte Carlo simulations.
+        if do_monte_carlo:
             if model == MODEL_R2EFF and self.exp_mc_sim_num != None:
                 
self.interpreter.monte_carlo.setup(number=self.exp_mc_sim_num)
             else:




Related Messages


Powered by MHonArc, Updated Wed Aug 20 18:20:02 2014