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

Source Code for Module pipe_control.eliminate

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2003-2014 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.api import return_api 
 29   
 30   
31 -def eliminate(function=None, args=None):
32 """Model elimination. 33 34 @keyword function: A user supplied function for model elimination. This function should accept 35 five arguments, a string defining a certain parameter, the value of the 36 parameter, the minimisation instance (ie the residue index if the model 37 is residue specific), and the function arguments. If the model is rejected, 38 the function should return True, otherwise it should return False. The 39 function will be executed multiple times, once for each parameter of the model. 40 @type function: function 41 @param args: The arguments to be passed to the user supplied function. 42 @type args: tuple 43 """ 44 45 # Test if the current data pipe exists. 46 pipes.test() 47 48 # The specific analysis API object. 49 api = return_api() 50 51 # Determine if simulations are active. 52 if hasattr(cdp, 'sim_state') and cdp.sim_state == True: 53 sim_state = True 54 else: 55 sim_state = False 56 57 58 # Get the number of instances and loop over them. 59 for model_info in api.model_loop(): 60 # Model elimination. 61 #################### 62 63 if not sim_state: 64 # Get the parameter names and values. 65 names = api.get_param_names(model_info) 66 values = api.get_param_values(model_info) 67 68 # No data. 69 if names == None or values == None: 70 continue 71 72 # Test that the names and values vectors are of equal length. 73 if len(names) != len(values): 74 raise RelaxError("The names vector " + repr(names) + " is of a different length to the values vector " + repr(values) + ".") 75 76 # Loop over the parameters. 77 flag = False 78 for j in range(len(names)): 79 # Eliminate function. 80 if api.eliminate(names[j], values[j], model_info, args): 81 flag = True 82 83 # Deselect. 84 if flag: 85 api.deselect(model_info) 86 87 88 # Simulation elimination. 89 ######################### 90 91 else: 92 # Loop over the simulations. 93 for j in range(cdp.sim_number): 94 # Get the parameter names and values. 95 names = api.get_param_names(model_info) 96 values = api.get_param_values(model_info, sim_index=j) 97 98 # No data. 99 if names == None or values == None: 100 continue 101 102 # Test that the names and values vectors are of equal length. 103 if len(names) != len(values): 104 raise RelaxError("The names vector " + repr(names) + " is of a different length to the values vector " + repr(values) + ".") 105 106 # Loop over the parameters. 107 flag = False 108 for k in range(len(names)): 109 # Eliminate function. 110 if api.eliminate(names[k], values[k], model_info, args, sim=j): 111 flag = True 112 113 # Deselect. 114 if flag: 115 api.deselect(model_info, sim_index=j)
116