Package specific_analyses :: Package frame_order :: Module data
[hide private]
[frames] | no frames]

Source Code for Module specific_analyses.frame_order.data

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2009-2011,2013-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  """Module for handling the frame order data in the relax data store.""" 
 24   
 25  # Python module imports. 
 26  from numpy import array, float64, zeros 
 27  from warnings import warn 
 28   
 29  # relax module imports. 
 30  from lib.errors import RelaxError 
 31  from lib.frame_order.variables import MODEL_DOUBLE_ROTOR, MODEL_RIGID 
 32  from lib.warnings import RelaxWarning 
 33  from lib.geometry.rotations import euler_to_R_zyz 
 34  from pipe_control import pipes 
 35  from pipe_control.interatomic import interatomic_loop 
 36  from pipe_control.mol_res_spin import spin_loop 
 37  from pipe_control.pipes import check_pipe 
 38  from specific_analyses.frame_order.checks import check_model, check_pivot 
 39   
 40   
41 -def base_data_types():
42 """Determine all the base data types. 43 44 The base data types can include:: 45 - 'rdc', residual dipolar couplings. 46 - 'pcs', pseudo-contact shifts. 47 48 @return: A list of all the base data types. 49 @rtype: list of str 50 """ 51 52 # Array of data types. 53 list = [] 54 55 # RDC search. 56 for interatom in interatomic_loop(selection1=domain_moving()): 57 if hasattr(interatom, 'rdc'): 58 list.append('rdc') 59 break 60 61 # PCS search. 62 for spin in spin_loop(selection=domain_moving()): 63 if hasattr(spin, 'pcs'): 64 list.append('pcs') 65 break 66 67 # No data is present. 68 if not list: 69 raise RelaxError("Neither RDCs nor PCSs are present.") 70 71 # Return the list. 72 return list
73 74
75 -def domain_moving():
76 """Return the spin ID string corresponding to the moving domain. 77 78 @return: The spin ID string defining the moving domain. 79 @rtype: str 80 """ 81 82 # Check that the domain is defined. 83 if not hasattr(cdp, 'domain'): 84 raise RelaxError("No domains have been defined. Please use the domain user function.") 85 86 # Only support for 2 domains. 87 if len(cdp.domain) > 2: 88 raise RelaxError("Only two domains are supported in the frame order analysis.") 89 90 # Reference domain not set yet. 91 if not hasattr(cdp, 'ref_domain'): 92 raise RelaxError("The reference non-moving domain has not been specified.") 93 94 # Loop over the domains. 95 for id in cdp.domain: 96 # Reference domain. 97 if id == cdp.ref_domain: 98 continue 99 100 # Return the ID. 101 return cdp.domain[id]
102 103
104 -def generate_pivot(order=1, sim_index=None, pipe_name=None, pdb_limit=False):
105 """Create and return the given pivot. 106 107 @keyword order: The pivot number with 1 corresponding to the first pivot, 2 to the second, etc. 108 @type order: int 109 @keyword sim_index: The optional Monte Carlo simulation index. If provided, the pivot for the given simulation will be returned instead. 110 @type sim_index: None or int 111 @keyword pipe_name: The data pipe 112 @type pipe_name: str 113 @keyword pdb_limit: A flag which if True will cause the coordinate to be between -1000 and 1000. 114 @type pdb_limit: bool 115 @return: The give pivot point. 116 @rtype: numpy 3D rank-1 float64 array 117 """ 118 119 # Checks. 120 check_pipe(pipe_name) 121 check_pivot(pipe_name=pipe_name) 122 check_model(pipe_name=pipe_name) 123 124 # The data pipe. 125 if pipe_name == None: 126 pipe_name = pipes.cdp_name() 127 128 # Get the data pipe. 129 dp = pipes.get_pipe(pipe_name) 130 131 # Initialise. 132 pivot = None 133 134 # The double rotor parameterisation. 135 if dp.model in [MODEL_DOUBLE_ROTOR]: 136 # The 2nd pivot point (the centre of the frame). 137 if sim_index != None and hasattr(dp, 'pivot_x_sim'): 138 pivot_2nd = array([dp.pivot_x_sim[sim_index], dp.pivot_y_sim[sim_index], dp.pivot_z_sim[sim_index]], float64) 139 else: 140 pivot_2nd = array([dp.pivot_x, dp.pivot_y, dp.pivot_z], float64) 141 142 # Generate the first pivot. 143 if order == 1: 144 # The eigenframe. 145 frame = zeros((3, 3), float64) 146 if sim_index != None and hasattr(dp, 'pivot_disp_sim'): 147 euler_to_R_zyz(dp.eigen_alpha_sim[sim_index], dp.eigen_beta_sim[sim_index], dp.eigen_gamma_sim[sim_index], frame) 148 pivot_disp = dp.pivot_disp_sim[sim_index] 149 else: 150 euler_to_R_zyz(dp.eigen_alpha, dp.eigen_beta, dp.eigen_gamma, frame) 151 pivot_disp = dp.pivot_disp 152 153 # The 1st pivot. 154 pivot = pivot_2nd + frame[:, 2] * pivot_disp 155 156 # Alias the 2nd pivot. 157 elif order == 2: 158 pivot = pivot_2nd 159 160 # All other models. 161 elif order == 1: 162 if sim_index != None and hasattr(dp, 'pivot_x_sim'): 163 pivot = array([dp.pivot_x_sim[sim_index], dp.pivot_y_sim[sim_index], dp.pivot_z_sim[sim_index]], float64) 164 else: 165 pivot = array([dp.pivot_x, dp.pivot_y, dp.pivot_z], float64) 166 167 # PDB limits. 168 if pivot is not None and pdb_limit: 169 # The original pivot, as text. 170 orig_pivot = "[%.3f, %.3f, %.3f]" % (pivot[0], pivot[1], pivot[2]) 171 172 # Check each coordinate. 173 out = False 174 for i in range(3): 175 if pivot[i] <= -900.0: 176 pivot[i] = -900.0 177 out = True 178 elif pivot[i] > 9900.0: 179 pivot[i] = 9900.0 180 out = True 181 182 # Failure. 183 if out: 184 new_pivot = "[%.3f, %.3f, %.3f]" % (pivot[0], pivot[1], pivot[2]) 185 warn(RelaxWarning("The pivot point %s is outside of the PDB coordinate limits of [-999.999, 9999.999], less a 100 Angstrom buffer, shifting to %s." % (orig_pivot, new_pivot))) 186 187 # Return the pivot. 188 return pivot
189 190
191 -def pivot_fixed():
192 """Determine if the pivot is fixed or not. 193 194 @return: The answer to the question. 195 @rtype: bool 196 """ 197 198 # A pivot point is not supported by the model. 199 if cdp.model in [MODEL_RIGID]: 200 return True 201 202 # No PCS data, so the pivot cannot be optimised. 203 if not hasattr(cdp, 'pcs_ids') or len(cdp.pcs_ids) == 0: 204 return True 205 206 # The fixed flag is not set. 207 if hasattr(cdp, 'pivot_fixed') and not cdp.pivot_fixed: 208 return False 209 210 # The point is fixed. 211 return True
212 213
214 -def tensor_loop(red=False):
215 """Generator method for looping over the full or reduced tensors. 216 217 @keyword red: A flag which if True causes the reduced tensors to be returned, and if False 218 the full tensors are returned. 219 @type red: bool 220 @return: The tensor index and the tensor. 221 @rtype: (int, AlignTensorData instance) 222 """ 223 224 # Number of tensor pairs. 225 n = len(cdp.align_tensors.reduction) 226 227 # Alias. 228 data = cdp.align_tensors 229 list = data.reduction 230 231 # Full or reduced index. 232 if red: 233 index = 1 234 else: 235 index = 0 236 237 # Loop over the reduction list. 238 for i in range(n): 239 yield i, data[list[i][index]]
240