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