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