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 manipulating data pipes."""
25
26
27
28 import __builtin__
29 import sys
30
31
32 from data import Relax_data_store; ds = Relax_data_store()
33 from dep_check import C_module_exp_fn, scipy_module
34 from relax_errors import RelaxError, RelaxNoPipeError, RelaxPipeError
35 from status import Status; status = Status()
36
37
38
39 VALID_TYPES = ['ct', 'frame order', 'jw', 'hybrid', 'mf', 'N-state', 'noe', 'relax_fit']
40 PIPE_DESC = {
41 'ct': 'Consistency testing',
42 'frame order': 'Frame Order theories',
43 'jw': 'Reduced spectral density mapping',
44 'hybrid': 'Special hybrid pipe',
45 'mf': 'Model-free analysis',
46 'N-state': 'N-state model of domain motions',
47 'noe': 'Steady state NOE calculation',
48 'relax_fit': 'Relaxation curve fitting'
49 }
50 PIPE_DESC_LIST = []
51 for name in VALID_TYPES:
52 PIPE_DESC_LIST.append(PIPE_DESC[name])
53
54
55 -def copy(pipe_from=None, pipe_to=None):
56 """Copy the contents of the source data pipe to a new target data pipe.
57
58 If the 'pipe_from' argument is None then the current data pipe is assumed as the source. The
59 data pipe corresponding to 'pipe_to' cannot exist.
60
61 @param pipe_from: The name of the source data pipe to copy the data from.
62 @type pipe_from: str
63 @param pipe_to: The name of the target data pipe to copy the data to.
64 @type pipe_to: str
65 """
66
67
68 if pipe_to in list(ds.keys()):
69 raise RelaxPipeError(pipe_to)
70
71
72 status.pipe_lock.acquire(sys._getframe().f_code.co_name)
73 try:
74
75 if pipe_from == None:
76 pipe_from = cdp_name()
77
78
79 ds[pipe_to] = ds[pipe_from].__clone__()
80
81
82 finally:
83 status.pipe_lock.release(sys._getframe().f_code.co_name)
84
85
86 status.observers.pipe_alteration.notify()
87
88
89 -def create(pipe_name=None, pipe_type=None, switch=True):
90 """Create a new data pipe.
91
92 The current data pipe will be changed to this new data pipe.
93
94
95 @keyword pipe_name: The name of the new data pipe.
96 @type pipe_name: str
97 @keyword pipe_type: The new data pipe type which can be one of the following:
98 'ct': Consistency testing,
99 'frame order': The Frame Order theories.
100 'jw': Reduced spectral density mapping,
101 'hybrid': The hybridised data pipe.
102 'mf': Model-free analysis,
103 'N-state': N-state model of domain dynamics,
104 'noe': Steady state NOE calculation,
105 'relax_fit': Relaxation curve fitting,
106 'relax_disp': Relaxation dispersion,
107 @type pipe_type: str
108 @keyword switch: If True, this new pipe will be switched to, otherwise the current data pipe will remain as is.
109 @type switch: bool
110 """
111
112
113 if not pipe_type in VALID_TYPES:
114 raise RelaxError("The data pipe type " + repr(pipe_type) + " is invalid and must be one of the strings in the list " + repr(VALID_TYPES) + ".")
115
116
117 if pipe_type == 'relax_fit' and not C_module_exp_fn:
118 raise RelaxError("Relaxation curve fitting is not available. Try compiling the C modules on your platform.")
119
120
121 if pipe_type == 'frame order' and not scipy_module:
122 raise RelaxError("The frame order analysis is not available. Please install the scipy Python package.")
123
124
125 status.pipe_lock.acquire(sys._getframe().f_code.co_name)
126 try:
127
128 ds.add(pipe_name=pipe_name, pipe_type=pipe_type, switch=switch)
129
130
131 finally:
132 status.pipe_lock.release(sys._getframe().f_code.co_name)
133
134
136 """Return the name of the current data pipe.
137
138 @return: The name of the current data pipe.
139 @rtype: str
140 """
141
142 return ds.current_pipe
143
144
146 """Delete a data pipe.
147
148 @param pipe_name: The name of the data pipe to delete.
149 @type pipe_name: str
150 """
151
152
153 status.pipe_lock.acquire(sys._getframe().f_code.co_name)
154 try:
155
156 if pipe_name != None:
157
158 test(pipe_name)
159
160
161 pipes = [pipe_name]
162
163
164 else:
165 pipes = ds.keys()
166
167
168 for pipe in pipes:
169
170 del ds[pipe]
171
172
173 if ds.current_pipe == pipe:
174 ds.current_pipe = None
175 __builtin__.cdp = None
176
177
178 finally:
179 status.pipe_lock.release(sys._getframe().f_code.co_name)
180
181
182 status.observers.pipe_alteration.notify()
183
184
186 """Print the details of all the data pipes."""
187
188
189 status.pipe_lock.acquire(sys._getframe().f_code.co_name)
190 try:
191
192 print(("%-20s%-20s%-20s" % ("Data pipe name", "Data pipe type", "Current")))
193
194
195 for pipe_name in ds:
196
197 current = ''
198 if pipe_name == cdp_name():
199 current = '*'
200
201
202 print("%-20s%-20s%-20s" % ("'"+pipe_name+"'", get_type(pipe_name), current))
203
204
205 finally:
206 status.pipe_lock.release(sys._getframe().f_code.co_name)
207
208
210 """Return a data pipe.
211
212 @keyword name: The name of the data pipe to return. If None, the current data pipe is
213 returned.
214 @type name: str or None
215 @return: The current data pipe.
216 @rtype: PipeContainer instance
217 """
218
219
220 if name == None:
221 name = cdp_name()
222
223
224 test(name)
225
226 return ds[name]
227
228
230 """Return the type of the data pipe.
231
232 @keyword name: The name of the data pipe. If None, the current data pipe is used.
233 @type name: str or None
234 @return: The current data pipe type.
235 @rtype: str
236 """
237
238
239 if name == None:
240 name = cdp_name()
241
242
243 pipe = get_pipe(name)
244
245 return pipe.pipe_type
246
247
249 """Determine if the relax data store contains the data pipe.
250
251 @param name: The name of the data pipe.
252 @type name: str
253 @return: True if the data pipe exists, False otherwise.
254 @rtype: bool
255 """
256
257
258 if name in ds:
259 return True
260 else:
261 return False
262
263
265 """Generator function for looping over and yielding the data pipes.
266
267 @keyword name: A flag which if True will cause the name of the pipe to be returned.
268 @type name: bool
269 @return: The data pipes, and optionally the pipe names.
270 @rtype: PipeContainer instance or tuple of PipeContainer instance and str if name=True
271 """
272
273
274 status.pipe_lock.acquire(sys._getframe().f_code.co_name)
275 try:
276
277 for key in list(ds.keys()):
278
279 if name:
280 yield ds[key], key
281
282
283 else:
284 yield ds[key]
285
286
287 finally:
288 status.pipe_lock.release(sys._getframe().f_code.co_name)
289
290
292 """Return the list of all data pipes.
293
294 @return: The list of data pipes.
295 @rtype: list of str
296 """
297
298 return list(ds.keys())
299
300
302 """Switch the current data pipe to the given data pipe.
303
304 @param pipe_name: The name of the data pipe to switch to.
305 @type pipe_name: str
306 """
307
308
309 status.pipe_lock.acquire(sys._getframe().f_code.co_name)
310 try:
311
312 test(pipe_name)
313
314
315 ds.current_pipe = pipe_name
316 __builtin__.cdp = get_pipe()
317
318
319 finally:
320 status.pipe_lock.release(sys._getframe().f_code.co_name)
321
322
323 status.observers.pipe_alteration.notify()
324
325
326 -def test(pipe_name=None):
327 """Function for testing the existence of the current or supplied data pipe.
328
329 @param pipe_name: The name of the data pipe to switch to.
330 @type pipe_name: str
331 @return: The answer to the question of whether the pipe exists.
332 @rtype: Boolean
333 """
334
335
336 if pipe_name == None:
337
338 pipe_name = cdp_name()
339
340
341 if pipe_name == None:
342 raise RelaxNoPipeError
343
344
345 if pipe_name not in ds:
346 raise RelaxNoPipeError(pipe_name)
347