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

Source Code for Module pipe_control.eliminate

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2003-2013 Edward d'Auvergne                                   # 
  4  #                                                                             # 
  5  # This file is part of the program relax (http://www.nmr-relax.com).          # 
  6  #                                                                             # 
  7  # This program 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 3 of the License, or           # 
 10  # (at your option) any later version.                                         # 
 11  #                                                                             # 
 12  # This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.       # 
 19  #                                                                             # 
 20  ############################################################################### 
 21   
 22  # Module docstring. 
 23  """Module implementing the mathematical modelling step of model elimination.""" 
 24   
 25  # relax module imports. 
 26  from lib.errors import RelaxError 
 27  from pipe_control import pipes 
 28  from specific_analyses.setup import get_specific_fn 
 29   
 30   
 31   
32 -def eliminate(function=None, args=None):
33 """Model elimination. 34 35 @keyword function: A user supplied function for model elimination. This function should accept 36 five arguments, a string defining a certain parameter, the value of the 37 parameter, the minimisation instance (ie the residue index if the model 38 is residue specific), and the function arguments. If the model is rejected, 39 the function should return True, otherwise it should return False. The 40 function will be executed multiple times, once for each parameter of the model. 41 @type function: function 42 @param args: The arguments to be passed to the user supplied function. 43 @type args: tuple 44 """ 45 46 # Test if the current data pipe exists. 47 pipes.test() 48 49 # Specific eliminate, parameter names, parameter values, number of instances, and deselect function setup. 50 eliminate = get_specific_fn('eliminate', cdp.pipe_type) 51 model_loop = get_specific_fn('model_loop', cdp.pipe_type) 52 get_param_names = get_specific_fn('get_param_names', cdp.pipe_type) 53 get_param_values = get_specific_fn('get_param_values', cdp.pipe_type) 54 deselect = get_specific_fn('deselect', cdp.pipe_type) 55 56 # Determine if simulations are active. 57 if hasattr(cdp, 'sim_state') and cdp.sim_state == True: 58 sim_state = True 59 else: 60 sim_state = False 61 62 63 # Get the number of instances and loop over them. 64 for model_info in model_loop(): 65 # Model elimination. 66 #################### 67 68 if not sim_state: 69 # Get the parameter names and values. 70 names = get_param_names(model_info) 71 values = get_param_values(model_info) 72 73 # No data. 74 if names == None or values == None: 75 continue 76 77 # Test that the names and values vectors are of equal length. 78 if len(names) != len(values): 79 raise RelaxError("The names vector " + repr(names) + " is of a different length to the values vector " + repr(values) + ".") 80 81 # Loop over the parameters. 82 flag = False 83 for j in range(len(names)): 84 # Eliminate function. 85 if eliminate(names[j], values[j], model_info, args): 86 flag = True 87 88 # Deselect. 89 if flag: 90 deselect(model_info) 91 92 93 # Simulation elimination. 94 ######################### 95 96 else: 97 # Loop over the simulations. 98 for j in range(cdp.sim_number): 99 # Get the parameter names and values. 100 names = get_param_names(model_info) 101 values = get_param_values(model_info, sim_index=j) 102 103 # No data. 104 if names == None or values == None: 105 continue 106 107 # Test that the names and values vectors are of equal length. 108 if len(names) != len(values): 109 raise RelaxError("The names vector " + repr(names) + " is of a different length to the values vector " + repr(values) + ".") 110 111 # Loop over the parameters. 112 flag = False 113 for k in range(len(names)): 114 # Eliminate function. 115 if eliminate(names[k], values[k], model_info, args, sim=j): 116 flag = True 117 118 # Deselect. 119 if flag: 120 deselect(model_info, sim_index=j)
121