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

Source Code for Module specific_fns.hybrid

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