Package generic_fns :: Module eliminate
[hide private]
[frames] | no frames]

Source Code for Module generic_fns.eliminate

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2003-2005, 2007-2009 Edward d'Auvergne                        # 
  4  #                                                                             # 
  5  # This file is part of the program relax.                                     # 
  6  #                                                                             # 
  7  # relax is free software; you can redistribute it and/or modify               # 
  8  # it under the terms of the GNU General Public License as published by        # 
  9  # the Free Software Foundation; either version 2 of the License, or           # 
 10  # (at your option) any later version.                                         # 
 11  #                                                                             # 
 12  # relax is distributed in the hope that it will be useful,                    # 
 13  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
 14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
 15  # GNU General Public License for more details.                                # 
 16  #                                                                             # 
 17  # You should have received a copy of the GNU General Public License           # 
 18  # along with relax; if not, write to the Free Software                        # 
 19  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   # 
 20  #                                                                             # 
 21  ############################################################################### 
 22   
 23  # Module docstring. 
 24  """Module implementing the mathematical modelling step of model elimination.""" 
 25   
 26  # relax module imports. 
 27  from generic_fns import pipes 
 28  from relax_errors import RelaxError 
 29  from specific_fns.setup import get_specific_fn 
 30   
 31   
 32   
33 -def eliminate(function=None, args=None):
34 """Model elimination. 35 36 @keyword function: A user supplied function for model elimination. This function should accept 37 five arguments, a string defining a certain parameter, the value of the 38 parameter, the minimisation instance (ie the residue index if the model 39 is residue specific), and the function arguments. If the model is rejected, 40 the function should return True, otherwise it should return False. The 41 function will be executed multiple times, once for each parameter of the model. 42 @type function: function 43 @param args: The arguments to be passed to the user supplied function. 44 @type args: tuple 45 """ 46 47 # Test if the current data pipe exists. 48 pipes.test() 49 50 # Specific eliminate, parameter names, parameter values, number of instances, and deselect function setup. 51 eliminate = get_specific_fn('eliminate', cdp.pipe_type) 52 model_loop = get_specific_fn('model_loop', cdp.pipe_type) 53 get_param_names = get_specific_fn('get_param_names', cdp.pipe_type) 54 get_param_values = get_specific_fn('get_param_values', cdp.pipe_type) 55 deselect = get_specific_fn('deselect', cdp.pipe_type) 56 57 # Determine if simulations are active. 58 if hasattr(cdp, 'sim_state') and cdp.sim_state == True: 59 sim_state = True 60 else: 61 sim_state = False 62 63 64 # Get the number of instances and loop over them. 65 for model_info in model_loop(): 66 # Model elimination. 67 #################### 68 69 if not sim_state: 70 # Get the parameter names and values. 71 names = get_param_names(model_info) 72 values = get_param_values(model_info) 73 74 # No data. 75 if names == None or values == None: 76 continue 77 78 # Test that the names and values vectors are of equal length. 79 if len(names) != len(values): 80 raise RelaxError("The names vector " + repr(names) + " is of a different length to the values vector " + repr(values) + ".") 81 82 # Loop over the parameters. 83 flag = False 84 for j in xrange(len(names)): 85 # Eliminate function. 86 if eliminate(names[j], values[j], model_info, args): 87 flag = True 88 89 # Deselect. 90 if flag: 91 deselect(model_info) 92 93 94 # Simulation elimination. 95 ######################### 96 97 else: 98 # Loop over the simulations. 99 for j in xrange(cdp.sim_number): 100 # Get the parameter names and values. 101 names = get_param_names(model_info) 102 values = get_param_values(model_info, sim_index=j) 103 104 # No data. 105 if names == None or values == None: 106 continue 107 108 # Test that the names and values vectors are of equal length. 109 if len(names) != len(values): 110 raise RelaxError("The names vector " + repr(names) + " is of a different length to the values vector " + repr(values) + ".") 111 112 # Loop over the parameters. 113 flag = False 114 for k in xrange(len(names)): 115 # Eliminate function. 116 if eliminate(names[k], values[k], model_info, args, sim=j): 117 flag = True 118 119 # Deselect. 120 if flag: 121 deselect(model_info, sim_index=j)
122