1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 """Module for the reading of Bruker Dynamics Centre (DC) files."""
24
25
26 from re import search, split
27
28
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
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
47 rx = 1.0 / float(data[0])
48
49
50 rx_err = float(data[1]) / float(data[2])
51
52
53 rx_err = rx**2 * rx_err
54
55
56 return rx, rx_err
57
58
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
67 res_num = None
68
69
70 row = split('([0-9]+)', data)
71
72
73 for j in range(len(row)):
74 try:
75 res_num = int(row[j])
76 except ValueError:
77 pass
78
79
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
95 pipes.test()
96
97
98 if not exists_mol_res_spin_data():
99 raise RelaxNoSequenceError
100
101
102 file_handle = open_read_file(file, dir)
103 lines = file_handle.readlines()
104 file_handle.close()
105
106
107 values = []
108 errors = []
109 res_nums = []
110 int_type = None
111
112
113 in_ri_data = False
114 for line in lines:
115
116 row = split("\t", line)
117
118
119 for j in range(len(row)):
120 row[j] = row[j].strip()
121
122
123 if len(row) == 0:
124 continue
125
126
127 if row[0] == 'generated by:':
128 version = row[1]
129
130
131 if row[0] == 'Systematic error estimation of data:':
132
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
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
146 elif row[0] == 'Proton frequency[MHz]:':
147 frq = float(row[1]) * 1e6
148
149
150 elif row[0] == 'SECTION:' and row[1] == 'results':
151 in_ri_data = True
152
153
154 elif in_ri_data:
155
156 if row[0] == 'Peak name':
157
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
167 continue
168
169
170 res_nums.append(get_res_num(row[0]))
171
172
173 if ri_type != 'NOE':
174
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
182 values.append(rx)
183 errors.append(rx_err)
184
185
186 elif row[0] == 'Temperature (K):':
187
188 pass
189
190
191 elif row[0] == 'Labelling:':
192
193 isotope = row[1]
194
195
196 set_spin_isotope(isotope=isotope, force=None)
197
198
199 name = split('([A-Z]+)', row[1])[1]
200 name_spin(name=name, force=None)
201
202
203 elif row[0] == 'Used integrals:':
204
205 if row[1] == 'peak intensities':
206 int_type = 'height'
207
208
209 if row[1] == 'area integral':
210 int_type = 'volume'
211
212
213 atom_name = element_from_isotope(isotope)
214 for i in range(len(res_nums)):
215 res_nums[i] += '@' + atom_name
216
217
218 pack_data(ri_id, ri_type, frq, values, errors, spin_ids=res_nums)
219
220
221 peak_intensity_type(ri_id=ri_id, type=int_type)
222
223
224 software_select('Bruker DC', version=version)
225