Package generic_fns :: Module bruker
[hide private]
[frames] | no frames]

Source Code for Module generic_fns.bruker

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2011-2012 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  # Module docstring. 
 24  """Module for the reading of Bruker Dynamics Centre (DC) files.""" 
 25   
 26  # Python module imports. 
 27  from re import search, split 
 28  from string import strip 
 29   
 30  # relax module imports. 
 31  from generic_fns import pipes 
 32  from generic_fns import value 
 33  from generic_fns.exp_info import software_select 
 34  from generic_fns.mol_res_spin import exists_mol_res_spin_data, name_spin, spin_loop 
 35  from generic_fns.relax_data import pack_data, peak_intensity_type 
 36  from relax_errors import RelaxError 
 37  from relax_io import open_read_file 
 38   
 39   
40 -def convert_relax_data(data):
41 """Determine the relaxation data from the given DC data. 42 43 @param data: The list of Tx, Tx error, and scaling factor for a given residue from the DC file. 44 @type data: list of str 45 """ 46 47 # Convert the value from Tx to Rx. 48 rx = 1.0 / float(data[0]) 49 50 # Remove the scaling. 51 rx_err = float(data[1]) / float(data[2]) 52 53 # Convert the Tx error to an Rx error. 54 rx_err = rx**2 * rx_err 55 56 # Return the value and error. 57 return rx, rx_err
58 59
60 -def get_res_num(data):
61 """Determine the residue number from the given DC data. 62 63 @param data: The list of residue info, split by whitespace, from the DC file. 64 @type data: list of str 65 """ 66 67 # Init. 68 res_num = None 69 70 # Split the data. 71 row = split('([0-9]+)', data) 72 73 # Loop over the new list. 74 for j in range(len(row)): 75 try: 76 res_num = int(row[j]) 77 except ValueError: 78 pass 79 80 # Return the value. 81 return ":%s" % res_num
82 83
84 -def read(ri_id=None, file=None, dir=None):
85 """Read the DC data file and place all the data into the relax data store. 86 87 @keyword ri_id: The relaxation data ID string. 88 @type ri_id: str 89 @keyword file: The name of the file to open. 90 @type file: str 91 @keyword dir: The directory containing the file (defaults to the current directory if None). 92 @type dir: str or None 93 """ 94 95 # Test if the current pipe exists. 96 pipes.test() 97 98 # Test if sequence data is loaded. 99 if not exists_mol_res_spin_data(): 100 raise RelaxNoSequenceError 101 102 # Extract the data from the file. 103 file_handle = open_read_file(file, dir) 104 lines = file_handle.readlines() 105 file_handle.close() 106 107 # Init. 108 values = [] 109 errors = [] 110 res_nums = [] 111 int_type = None 112 113 # Loop over the data. 114 in_ri_data = False 115 for line in lines: 116 # Split the line. 117 row = split("\t", line) 118 119 # Strip the rubbish. 120 for j in range(len(row)): 121 row[j] = strip(row[j]) 122 123 # Empty line. 124 if len(row) == 0: 125 continue 126 127 # The DC version. 128 if row[0] == 'generated by:': 129 version = row[1] 130 131 # Check for bad errors. 132 if row[0] == 'Systematic error estimation of data:': 133 # Badness. 134 if row[1] == 'worst case per peak scenario': 135 raise RelaxError("The errors estimation method \"worst case per peak scenario\" is not suitable for model-free analysis. Please go back to the DC and switch to \"average variance calculation\".") 136 137 # The data type. 138 if row[0] == 'Project:': 139 if search('T1', row[1]): 140 ri_type = 'R1' 141 elif search('T2', row[1]): 142 ri_type = 'R2' 143 elif search('NOE', row[1]): 144 ri_type = 'NOE' 145 146 # Get the frequency, converting to Hz. 147 elif row[0] == 'Proton frequency[MHz]:': 148 frq = float(row[1]) * 1e6 149 150 # Inside the relaxation data section. 151 elif row[0] == 'SECTION:' and row[1] == 'results': 152 in_ri_data = True 153 154 # The relaxation data. 155 elif in_ri_data: 156 # Skip the header. 157 if row[0] == 'Peak name': 158 continue 159 160 # The residue info. 161 res_nums.append(get_res_num(row[0])) 162 163 # Get the relaxation data. 164 if ri_type != 'NOE': 165 #rx, rx_err = convert_relax_data(row[3:]) 166 rx = float(row[-2]) 167 rx_err = float(row[-1]) 168 else: 169 rx = float(row[-3]) 170 rx_err = float(row[-2]) 171 172 # Append the data. 173 values.append(rx) 174 errors.append(rx_err) 175 176 # The temperature. 177 elif row[0] == 'Temperature (K):': 178 # Set the value (not implemented yet). 179 pass 180 181 # The labelling. 182 elif row[0] == 'Labelling:': 183 # Set the heteronucleus value. 184 value.set(row[1], 'heteronuc_type') 185 186 # Name the spins. 187 name = split('([A-Z]+)', row[1])[1] 188 name_spin(name=name) 189 190 # The integration method. 191 elif row[0] == 'Used integrals:': 192 # Peak heights. 193 if row[1] == 'peak intensities': 194 int_type = 'height' 195 196 # Peak volumes: 197 if row[1] == 'area integral': 198 int_type = 'volume' 199 200 # Pack the data. 201 pack_data(ri_id, ri_type, frq, values, errors, spin_ids=res_nums) 202 203 # Set the integration method. 204 peak_intensity_type(ri_id=ri_id, type=int_type) 205 206 # Set the DC as used software. 207 software_select('Bruker DC', version=version)
208