Package specific_analyses :: Module hybrid
[hide private]
[frames] | no frames]

Source Code for Module specific_analyses.hybrid

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2006-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  """Analysis specific code for the hybridisation of different data pipes.""" 
 24   
 25  # relax module imports. 
 26  from lib.errors import RelaxError, RelaxNoSequenceError, RelaxPipeError, RelaxSequenceError 
 27  from pipe_control import pipes 
 28  from pipe_control.mol_res_spin import exists_mol_res_spin_data 
 29  from pipe_control.sequence import compare_sequence 
 30   
 31   
32 -class Hybrid:
33 """Class containing function specific to hybrid models.""" 34
35 - def _hybridise(self, hybrid=None, pipe_list=None):
36 """Create the hybrid data pipe. 37 38 @keyword hybrid: The name of the new hybrid data pipe. 39 @type hybrid: str 40 @keyword pipe_list: The list of data pipes that the hybrid is composed of. 41 @type pipe_list: list of str 42 """ 43 44 # Test if the hybrid data pipe already exists. 45 if hybrid in pipes.pipe_names(): 46 raise RelaxPipeError(hybrid) 47 48 # Loop over the pipes to be hybridised and check them. 49 pipe_type = pipes.get_type(pipe_list[0]) 50 for pipe in pipe_list: 51 # Switch to the data pipe. 52 pipes.switch(pipe) 53 54 # Test if the pipe exists. 55 pipes.test() 56 57 # Check that the pipe types match. 58 if pipes.get_type() != pipe_type: 59 raise RelaxError("The data pipe types do not match.") 60 61 # Test if sequence data is loaded. 62 if not exists_mol_res_spin_data(): 63 raise RelaxNoSequenceError 64 65 # Check that the sequence data matches in all pipes. 66 for i in range(1, len(pipe_list)): 67 compare_sequence(pipe_list[0], pipe_list[1]) 68 69 # Create the data pipe. 70 pipes.create(pipe_name=hybrid, pipe_type='hybrid') 71 72 # Store the pipe list forming the hybrid. 73 cdp.hybrid_pipes = pipe_list
74 75
76 - def duplicate_data(self, pipe_from=None, pipe_to=None, model_info=None, global_stats=False, verbose=True):
77 """Duplicate the data specific to a single hybrid data pipe. 78 79 @keyword pipe_from: The data pipe to copy the data from. 80 @type pipe_from: str 81 @keyword pipe_to: The data pipe to copy the data to. 82 @type pipe_to: str 83 @keyword model_info: The model information from model_info(). 84 @type model_info: int 85 @keyword global_stats: The global statistics flag. 86 @type global_stats: bool 87 @keyword verbose: A flag which if True will cause info to be printed out. 88 @type verbose: bool 89 """ 90 91 # First create the pipe_to data pipe, if it doesn't exist, but don't switch to it. 92 if not pipes.has_pipe(pipe_to): 93 pipes.create(pipe_to, pipe_type='hybrid', switch=False) 94 95 # Get the data pipes. 96 dp_from = pipes.get_pipe(pipe_from) 97 dp_to = pipes.get_pipe(pipe_to) 98 99 # Test that the target data pipe has no sequence loaded. 100 if not exists_mol_res_spin_data(pipe_to): 101 raise RelaxSequenceError(pipe_to) 102 103 # Duplicate the hybrid pipe list data structure. 104 dp_to.hybrid_pipes = dp_from.hybrid_pipes
105 106
107 - def model_desc(self, model_info):
108 """Return a description of the model. 109 110 @param model_info: The model information from the model_loop(). This is unused. 111 @type model_info: int 112 @return: The model description. 113 @rtype: str 114 """ 115 116 return "hybrid model"
117 118
119 - def model_loop(self):
120 """Dummy generator method - this should be a global model!""" 121 122 yield 0
123 124
125 - def model_type(self):
126 """Method stating that this is a global model.""" 127 128 return 'global'
129 130
131 - def model_statistics(self, model_info=None, spin_id=None, global_stats=None):
132 """Return the k, n, and chi2 model statistics of the hybrid. 133 134 k - number of parameters. 135 n - number of data points. 136 chi2 - the chi-squared value. 137 138 139 @keyword model_index: The model index. This is zero for the global models or equal to the 140 global spin index (which covers the molecule, residue, and spin 141 indices). This originates from the model_loop(). 142 @type model_index: int 143 @keyword spin_id: The spin identification string. Either this or the instance keyword 144 argument must be supplied. 145 @type spin_id: None or str 146 @keyword global_stats: A parameter which determines if global or local statistics are 147 returned. If None, then the appropriateness of global or local 148 statistics is automatically determined. 149 @type global_stats: None or bool 150 @return: The optimisation statistics, in tuple format, of the number of 151 parameters (k), the number of data points (n), and the chi-squared 152 value (chi2). 153 @rtype: tuple of int, int, float 154 """ 155 156 # Bad argument combination. 157 if model_info == None and spin_id == None: 158 raise RelaxError("Either the model_info or spin_id argument must be supplied.") 159 elif model_info != None and spin_id != None: 160 raise RelaxError("The model_info arg " + repr(model_info) + " and spin_id arg " + repr(spin_id) + " clash. Only one should be supplied.") 161 162 # Initialise. 163 k_total = 0 164 n_total = 0 165 chi2_total = 0.0 166 167 # Specific setup. 168 for pipe in cdp.hybrid_pipes: 169 # Switch to the data pipe. 170 pipes.switch(pipe) 171 172 # Specific model statistics and number of instances functions. 173 model_statistics = setup.get_specific_fn('model_stats', pipes.get_type(pipe)) 174 175 # Loop over the instances. 176 #for i in range(num): 177 # Get the statistics. 178 k, n, chi2 = model_statistics(model_info=model_info, spin_id=spin_id, global_stats=global_stats) 179 180 # Bad stats. 181 if k == None or n == None or chi2 == None: 182 continue 183 184 # Sum the stats. 185 k_total = k_total + k 186 n_total = n_total + n 187 chi2_total = chi2_total + chi2 188 189 # Return the totals. 190 return k_total, n_total, chi2_total
191 192
193 - def num_instances(self):
194 """Return the number of instances, which for hybrids is always 1. 195 196 @return: The number of instances. 197 @rtype: int 198 """ 199 200 return 1
201 202
203 - def skip_function(self, model_info):
204 """Dummy function. 205 206 @param model_info: The model index from model_loop(). 207 @type model_info: int 208 @return: True if the data should be skipped, False otherwise. 209 @rtype: bool 210 """ 211 212 # Don't skip data. 213 return False
214