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

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