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

Source Code for Module specific_analyses.hybrid

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