Author: bugman Date: Sun Jun 24 17:28:28 2007 New Revision: 3309 URL: http://svn.gna.org/viewcvs/relax?rev=3309&view=rev Log: Automatic looping in the full_analysis.py script. In response to the post by Douglas Kojetin <douglas dot kojetin att gmail dot com> at https://mail.gna.org/public/relax-users/2007-06/msg00002.html, I have added the ability to automatically loop over the optimisation rounds of the full_analysis.py script until convergence. This is not turned on automatically by default as it is likely to require a bit of debugging. Modified: 1.3/sample_scripts/full_analysis.py Modified: 1.3/sample_scripts/full_analysis.py URL: http://svn.gna.org/viewcvs/relax/1.3/sample_scripts/full_analysis.py?rev=3309&r1=3308&r2=3309&view=diff ============================================================================== --- 1.3/sample_scripts/full_analysis.py (original) +++ 1.3/sample_scripts/full_analysis.py Sun Jun 24 17:28:28 2007 @@ -136,6 +136,8 @@ # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. MC_NUM = 200 +# Automatic looping over all rounds until convergence. +CONV_LOOP = 0 class Main: @@ -167,85 +169,90 @@ ############################# elif DIFF_MODEL == 'sphere' or DIFF_MODEL == 'prolate' or DIFF_MODEL == 'oblate' or DIFF_MODEL == 'ellipsoid': - # Determine which round of optimisation to do (init, round_1, round_2, etc). - self.round = self.determine_rnd(model=DIFF_MODEL) - - - # Inital round of optimisation for diffusion models MII to MV. - if self.round == 0: - # Base directory to place files into. - self.base_dir = DIFF_MODEL + '/init/' - - # Run name. - name = DIFF_MODEL - - # Create the run. - run.create(name, 'mf') - - # Load the local tm diffusion model MI results. - results.read(run=name, file='results', dir='local_tm/aic') - - # Remove the tm parameter. - model_free.remove_tm(run=name) - - # Load the PDB file and calculate the unit vectors parallel to the XH bond. - structure.read_pdb(name, PDB_FILE) - structure.vectors(name, heteronuc='N', proton='H') - - # Add an arbitrary diffusion tensor which will be optimised. - if DIFF_MODEL == 'sphere': - diffusion_tensor.init(name, 10e-9, fixed=0) - inc = 11 - elif DIFF_MODEL == 'prolate': - diffusion_tensor.init(name, (10e-9, 0, 0, 0), spheroid_type='prolate', fixed=0) - inc = 11 - elif DIFF_MODEL == 'oblate': - diffusion_tensor.init(name, (10e-9, 0, 0, 0), spheroid_type='oblate', fixed=0) - inc = 11 - elif DIFF_MODEL == 'ellipsoid': - diffusion_tensor.init(name, (10e-09, 0, 0, 0, 0, 0), fixed=0) - inc = 6 - - # Minimise just the diffusion tensor. - fix(name, 'all_res') - grid_search(name, inc=inc) - minimise(MIN_ALGOR, run=name) - - # Write the results. - results.write(run=name, file='results', dir=self.base_dir, force=1) - - - # Normal round of optimisation for diffusion models MII to MV. - else: - # Base directory to place files into. - self.base_dir = DIFF_MODEL + '/round_' + `self.round` + '/' - - # Load the optimised diffusion tensor from either the previous round. - self.load_tensor() - - # Sequential optimisation of all model-free models (function must be modified to suit). - self.multi_model() - - # Create the final run (for model selection and final optimisation). - name = 'final' - run.create(name, 'mf') - - # Model selection. - self.model_selection(run=name, dir=self.base_dir + 'aic') - - # Final optimisation of all diffusion and model-free parameters. - fix(name, 'all', fixed=0) - - # Minimise all parameters. - minimise(MIN_ALGOR, run=name) - - # Write the results. - dir = self.base_dir + 'opt' - results.write(run=name, file='results', dir=dir, force=1) - - # Test for convergence. - self.convergence(run=name) - + # Loop until convergence if CONV_LOOP is set, otherwise just loop once. + # This looping could be made much cleaner by removing the dependence on the determine_rnd() function. + while 1: + # Determine which round of optimisation to do (init, round_1, round_2, etc). + self.round = self.determine_rnd(model=DIFF_MODEL) + + # Inital round of optimisation for diffusion models MII to MV. + if self.round == 0: + # Base directory to place files into. + self.base_dir = DIFF_MODEL + '/init/' + + # Run name. + name = DIFF_MODEL + + # Create the run. + run.create(name, 'mf') + + # Load the local tm diffusion model MI results. + results.read(run=name, file='results', dir='local_tm/aic') + + # Remove the tm parameter. + model_free.remove_tm(run=name) + + # Load the PDB file and calculate the unit vectors parallel to the XH bond. + structure.read_pdb(name, PDB_FILE) + structure.vectors(name, heteronuc='N', proton='H') + + # Add an arbitrary diffusion tensor which will be optimised. + if DIFF_MODEL == 'sphere': + diffusion_tensor.init(name, 10e-9, fixed=0) + inc = 11 + elif DIFF_MODEL == 'prolate': + diffusion_tensor.init(name, (10e-9, 0, 0, 0), spheroid_type='prolate', fixed=0) + inc = 11 + elif DIFF_MODEL == 'oblate': + diffusion_tensor.init(name, (10e-9, 0, 0, 0), spheroid_type='oblate', fixed=0) + inc = 11 + elif DIFF_MODEL == 'ellipsoid': + diffusion_tensor.init(name, (10e-09, 0, 0, 0, 0, 0), fixed=0) + inc = 6 + + # Minimise just the diffusion tensor. + fix(name, 'all_res') + grid_search(name, inc=inc) + minimise(MIN_ALGOR, run=name) + + # Write the results. + results.write(run=name, file='results', dir=self.base_dir, force=1) + + + # Normal round of optimisation for diffusion models MII to MV. + else: + # Base directory to place files into. + self.base_dir = DIFF_MODEL + '/round_' + `self.round` + '/' + + # Load the optimised diffusion tensor from either the previous round. + self.load_tensor() + + # Sequential optimisation of all model-free models (function must be modified to suit). + self.multi_model() + + # Create the final run (for model selection and final optimisation). + name = 'final' + run.create(name, 'mf') + + # Model selection. + self.model_selection(run=name, dir=self.base_dir + 'aic') + + # Final optimisation of all diffusion and model-free parameters. + fix(name, 'all', fixed=0) + + # Minimise all parameters. + minimise(MIN_ALGOR, run=name) + + # Write the results. + dir = self.base_dir + 'opt' + results.write(run=name, file='results', dir=dir, force=1) + + # Test for convergence. + converged = self.convergence(run=name) + + # Break out of the infinite while loop if automatic looping is not activated or if convergence has occurred. + if converged or not CONV_LOOP: + break # Final run. @@ -441,8 +448,10 @@ print "\nConvergence:" if chi2_converged and models_converged and params_converged: print " [ Yes ]" + return 1 else: print " [ No ]" + return 0 def determine_rnd(self, model=None):