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