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 lib.errors import RelaxError
30 from lib.io import open_read_file
31
32
34 """Determine the relaxation data from the given DC data.
35
36 @param data: The list of Tx, Tx error, and scaling factor for a given residue from the DC file.
37 @type data: list of str
38 """
39
40
41 rx = 1.0 / float(data[0])
42
43
44 rx_err = float(data[1]) / float(data[2])
45
46
47 rx_err = rx**2 * rx_err
48
49
50 return rx, rx_err
51
52
54 """Determine the residue number from the given DC data.
55
56 @param data: The list of residue info, split by whitespace, from the DC file.
57 @type data: list of str
58 """
59
60
61 res_num = None
62
63
64 row = split('([0-9]+)', data)
65
66
67 for j in range(len(row)):
68 try:
69 res_num = int(row[j])
70 except ValueError:
71 pass
72
73
74 return ":%s" % res_num
75
76
78 """Parse the DC data file and return the extracted data.
79
80 @keyword file: The name of the file to open.
81 @type file: str
82 @keyword dir: The directory containing the file (defaults to the current directory if None).
83 @type dir: str or None
84 @return: The data from the Bruker Dynamics Centre file. This includes the values, the errors, the residue numbers, the integration type, the field strength frequency, the relaxation data type, the isotope, the spin name, and the BDC version number.
85 @rtype: list of float, list of float, list of int, str, float, str, str, str, str
86 """
87
88
89 file_handle = open_read_file(file, dir)
90 lines = file_handle.readlines()
91 file_handle.close()
92
93
94 values = []
95 errors = []
96 res_nums = []
97 int_type = None
98 isotope = None
99 spin_name = None
100
101
102 in_ri_data = False
103 for line in lines:
104
105 row = split("\t", line)
106
107
108 for j in range(len(row)):
109 row[j] = row[j].strip()
110
111
112 if len(row) == 0 or row == ['']:
113 continue
114
115
116 if row[0] == 'generated by:':
117 version = row[1]
118
119
120 if row[0] == 'Systematic error estimation of data:':
121
122 if row[1] == 'worst case per peak scenario':
123 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\".")
124
125
126 if row[0] == 'Project:':
127 if search('T1', row[1]):
128 ri_type = 'R1'
129 elif search('T2', row[1]):
130 ri_type = 'R2'
131 elif search('NOE', row[1]):
132 ri_type = 'NOE'
133
134
135 elif row[0] == 'Proton frequency[MHz]:':
136 frq = float(row[1]) * 1e6
137
138
139 elif row[0] == 'SECTION:' and row[1] == 'results':
140 in_ri_data = True
141
142
143 elif in_ri_data:
144
145 if row[0] == 'Peak name':
146
147 pdc_file = False
148 if ri_type == 'R1' and not search('R1', line):
149 pdc_file = True
150 elif ri_type == 'R2' and not search('R2', line):
151 pdc_file = True
152 if pdc_file:
153 raise RelaxError("The old Protein Dynamics Center (PDC) files are not supported")
154
155
156 continue
157
158
159 res_nums.append(get_res_num(row[0]))
160
161
162 if ri_type != 'NOE':
163
164 rx = float(row[-2])
165 rx_err = float(row[-1])
166 else:
167 rx = float(row[-3])
168 rx_err = float(row[-2])
169
170
171 values.append(rx)
172 errors.append(rx_err)
173
174
175 elif row[0] == 'Temperature (K):':
176
177 pass
178
179
180 elif row[0] == 'Labelling:':
181
182 isotope = row[1]
183
184
185 spin_name = split('([A-Z]+)', row[1])[1]
186
187
188 elif row[0] == 'Used integrals:':
189
190 if row[1] == 'peak intensities':
191 int_type = 'height'
192
193
194 if row[1] == 'area integral':
195 int_type = 'volume'
196
197
198 return values, errors, res_nums, int_type, frq, ri_type, spin_name, isotope, version
199