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

Source Code for Module specific_analyses.n_state_model.data

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2007-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  """The N-state model or structural ensemble analysis base data handling.""" 
 24   
 25  # Python module imports. 
 26  from numpy.linalg import norm 
 27   
 28  # relax module imports. 
 29  from lib.errors import RelaxError 
 30  from pipe_control.interatomic import interatomic_loop 
 31  from pipe_control.mol_res_spin import return_spin, spin_loop 
 32   
 33   
34 -def base_data_types():
35 """Determine all the base data types. 36 37 The base data types can include:: 38 - 'rdc', residual dipolar couplings. 39 - 'pcs', pseudo-contact shifts. 40 - 'noesy', NOE restraints. 41 - 'tensor', alignment tensors. 42 43 @return: A list of all the base data types. 44 @rtype: list of str 45 """ 46 47 # Array of data types. 48 list = [] 49 50 # RDC search. 51 for interatom in interatomic_loop(): 52 if hasattr(interatom, 'rdc'): 53 list.append('rdc') 54 break 55 56 # PCS search. 57 for spin in spin_loop(): 58 if hasattr(spin, 'pcs'): 59 list.append('pcs') 60 break 61 62 # Alignment tensor search. 63 if not ('rdc' in list or 'pcs' in list) and hasattr(cdp, 'align_tensors'): 64 list.append('tensor') 65 66 # NOESY data search. 67 if hasattr(cdp, 'noe_restraints'): 68 list.append('noesy') 69 70 # No data is present. 71 if not list: 72 raise RelaxError("Neither RDC, PCS, NOESY nor alignment tensor data is present.") 73 74 # Return the list. 75 return list
76 77
78 -def calc_ave_dist(atom1, atom2, exp=1):
79 """Calculate the average distances. 80 81 The formula used is:: 82 83 _N_ 84 / 1 \ \ 1/exp 85 <r> = | - > |p1i - p2i|^exp | 86 \ N /__ / 87 i 88 89 where i are the members of the ensemble, N is the total number of structural models, and p1 90 and p2 at the two atom positions. 91 92 93 @param atom1: The atom identification string of the first atom. 94 @type atom1: str 95 @param atom2: The atom identification string of the second atom. 96 @type atom2: str 97 @keyword exp: The exponent used for the averaging, e.g. 1 for linear averaging and -6 for 98 r^-6 NOE averaging. 99 @type exp: int 100 @return: The average distance between the two atoms. 101 @rtype: float 102 """ 103 104 # Get the spin containers. 105 spin1 = return_spin(atom1) 106 spin2 = return_spin(atom2) 107 108 # Loop over each model. 109 num_models = len(spin1.pos) 110 ave_dist = 0.0 111 for i in range(num_models): 112 # Distance to the minus sixth power. 113 dist = norm(spin1.pos[i] - spin2.pos[i]) 114 ave_dist = ave_dist + dist**(exp) 115 116 # Average. 117 ave_dist = ave_dist / num_models 118 119 # The exponent. 120 ave_dist = ave_dist**(1.0/exp) 121 122 # Return the average distance. 123 return ave_dist
124 125
126 -def num_data_points():
127 """Determine the number of data points used in the model. 128 129 @return: The number, n, of data points in the model. 130 @rtype: int 131 """ 132 133 # Determine the data type. 134 data_types = base_data_types() 135 136 # Init. 137 n = 0 138 139 # Spin loop. 140 for spin in spin_loop(): 141 # Skip deselected spins. 142 if not spin.select: 143 continue 144 145 # PCS data (skipping array elements set to None). 146 if 'pcs' in data_types: 147 if hasattr(spin, 'pcs'): 148 for pcs in spin.pcs: 149 if isinstance(pcs, float): 150 n = n + 1 151 152 # Interatomic data loop. 153 for interatom in interatomic_loop(): 154 # RDC data (skipping array elements set to None). 155 if 'rdc' in data_types: 156 if hasattr(interatom, 'rdc'): 157 for rdc in interatom.rdc: 158 if isinstance(rdc, float): 159 n = n + 1 160 161 # Alignment tensors. 162 if 'tensor' in data_types: 163 n = n + 5*len(cdp.align_tensors) 164 165 # Return the value. 166 return n
167 168
169 -def tensor_loop(red=False):
170 """Generator method for looping over the full or reduced tensors. 171 172 @keyword red: A flag which if True causes the reduced tensors to be returned, and if False 173 the full tensors are returned. 174 @type red: bool 175 @return: The tensor index and the tensor. 176 @rtype: (int, AlignTensorData instance) 177 """ 178 179 # Number of tensor pairs. 180 n = len(cdp.align_tensors.reduction) 181 182 # Alias. 183 data = cdp.align_tensors 184 list = data.reduction 185 186 # Full or reduced index. 187 if red: 188 index = 1 189 else: 190 index = 0 191 192 # Loop over the reduction list. 193 for i in range(n): 194 yield i, data[list[i][index]]
195