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

Source Code for Module specific_fns.hybrid

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