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 manipulating data pipes."""
24
25
26 import sys
27
28
29 from compat import builtins
30 from data import Relax_data_store; ds = Relax_data_store()
31 from dep_check import C_module_exp_fn, scipy_module
32 from relax_errors import RelaxError, RelaxNoPipeError, RelaxPipeError
33 from relax_io import write_data
34 from status import Status; status = Status()
35
36
37
38 VALID_TYPES = ['ct', 'frame order', 'jw', 'hybrid', 'mf', 'N-state', 'noe', 'relax_fit']
39 PIPE_DESC = {
40 'ct': 'Consistency testing',
41 'frame order': 'Frame Order theories',
42 'jw': 'Reduced spectral density mapping',
43 'hybrid': 'Special hybrid pipe',
44 'mf': 'Model-free analysis',
45 'N-state': 'N-state model or ensemble analysis',
46 'noe': 'Steady state NOE calculation',
47 'relax_fit': 'Relaxation curve fitting'
48 }
49 PIPE_DESC_LIST = []
50 for name in VALID_TYPES:
51 PIPE_DESC_LIST.append(PIPE_DESC[name])
52
53
54 -def bundle(bundle=None, pipe=None):
55 """Add the data pipe to the given bundle, created the bundle as needed.
56
57 @keyword bundle: The name of the data pipe bundle.
58 @type bundle: str
59 @keyword pipe: The name of the data pipe to add to the bundle.
60 @type pipe: str
61 """
62
63
64 test(pipe)
65
66
67 for key in ds.pipe_bundles.keys():
68 if pipe in ds.pipe_bundles[key]:
69 raise RelaxError("The data pipe is already within the '%s' bundle." % key)
70
71
72 if bundle not in ds.pipe_bundles.keys():
73 ds.pipe_bundles[bundle] = []
74
75
76 ds.pipe_bundles[bundle].append(pipe)
77
78
79 status.observers.pipe_alteration.notify()
80
81
83 """Return the list of all data pipe bundles.
84
85 @return: The list of data pipe bundles.
86 @rtype: list of str
87 """
88
89 return list(ds.pipe_bundles.keys())
90
91
93 """Change the type of the current data pipe.
94
95 @keyword pipe_type: The new data pipe type which can be one of the following:
96 'ct': Consistency testing,
97 'frame order': The Frame Order theories.
98 'jw': Reduced spectral density mapping,
99 'hybrid': The hybridised data pipe.
100 'mf': Model-free analysis,
101 'N-state': N-state model of domain dynamics,
102 'noe': Steady state NOE calculation,
103 'relax_fit': Relaxation curve fitting,
104 'relax_disp': Relaxation dispersion,
105 @type pipe_type: str
106 """
107
108
109 check_type(pipe_type)
110
111
112 cdp.pipe_type = pipe_type
113
114
115 -def copy(pipe_from=None, pipe_to=None, bundle_to=None):
116 """Copy the contents of the source data pipe to a new target data pipe.
117
118 If the 'pipe_from' argument is None then the current data pipe is assumed as the source. The
119 data pipe corresponding to 'pipe_to' cannot exist.
120
121 @param pipe_from: The name of the source data pipe to copy the data from.
122 @type pipe_from: str
123 @param pipe_to: The name of the target data pipe to copy the data to.
124 @type pipe_to: str
125 @keyword bundle_to: The optional data pipe bundle to associate the new data pipe with.
126 @type bundle_to: str or None
127 """
128
129
130 if pipe_to in list(ds.keys()):
131 raise RelaxPipeError(pipe_to)
132
133
134 if pipe_from == None and pipe_to == None:
135 raise RelaxError("The pipe_from and pipe_to arguments cannot both be set to None.")
136
137
138 status.pipe_lock.acquire(sys._getframe().f_code.co_name)
139 try:
140
141 if pipe_from == None:
142 pipe_from = cdp_name()
143
144
145 ds[pipe_to] = ds[pipe_from].__clone__()
146
147
148 if bundle_to:
149 bundle(bundle=bundle_to, pipe=pipe_to)
150
151
152 finally:
153 status.pipe_lock.release(sys._getframe().f_code.co_name)
154
155
156 status.observers.pipe_alteration.notify()
157
158
159 -def create(pipe_name=None, pipe_type=None, bundle=None, switch=True):
160 """Create a new data pipe.
161
162 The current data pipe will be changed to this new data pipe.
163
164
165 @keyword pipe_name: The name of the new data pipe.
166 @type pipe_name: str
167 @keyword pipe_type: The new data pipe type which can be one of the following:
168 'ct': Consistency testing,
169 'frame order': The Frame Order theories.
170 'jw': Reduced spectral density mapping,
171 'hybrid': The hybridised data pipe.
172 'mf': Model-free analysis,
173 'N-state': N-state model of domain dynamics,
174 'noe': Steady state NOE calculation,
175 'relax_fit': Relaxation curve fitting,
176 'relax_disp': Relaxation dispersion,
177 @type pipe_type: str
178 @keyword bundle: The optional data pipe bundle to associate the data pipe with.
179 @type bundle: str or None
180 @keyword switch: If True, this new pipe will be switched to, otherwise the current data pipe will remain as is.
181 @type switch: bool
182 """
183
184
185 check_type(pipe_type)
186
187
188 status.pipe_lock.acquire(sys._getframe().f_code.co_name)
189 try:
190
191 ds.add(pipe_name=pipe_name, pipe_type=pipe_type, bundle=bundle, switch=switch)
192
193
194 finally:
195 status.pipe_lock.release(sys._getframe().f_code.co_name)
196
197
199 """Check the validity of the given data pipe type.
200
201 @keyword pipe_type: The data pipe type to check.
202 @type pipe_type: str
203 @raises RelaxError: If the data pipe type is invalid or the required Python modules are missing.
204 """
205
206
207 if not pipe_type in VALID_TYPES:
208 raise RelaxError("The data pipe type " + repr(pipe_type) + " is invalid and must be one of the strings in the list " + repr(VALID_TYPES) + ".")
209
210
211 if pipe_type == 'relax_fit' and not C_module_exp_fn:
212 raise RelaxError("Relaxation curve fitting is not available. Try compiling the C modules on your platform.")
213
214
215 if pipe_type == 'frame order' and not scipy_module:
216 raise RelaxError("The frame order analysis is not available. Please install the scipy Python package.")
217
218
220 """Return the name of the current data pipe.
221
222 @return: The name of the current data pipe.
223 @rtype: str
224 """
225
226 return ds.current_pipe
227
228
230 """Print the name of the current data pipe."""
231
232 print(cdp_name())
233
234
236 """Delete a data pipe.
237
238 @param pipe_name: The name of the data pipe to delete.
239 @type pipe_name: str
240 """
241
242
243 status.pipe_lock.acquire(sys._getframe().f_code.co_name)
244 try:
245
246 if pipe_name != None:
247
248 test(pipe_name)
249
250
251 pipes = [pipe_name]
252
253
254 else:
255 pipes = ds.keys()
256
257
258 for pipe in pipes:
259
260 bundle = get_bundle(pipe)
261 if bundle:
262
263 ds.pipe_bundles[bundle].remove(pipe)
264
265
266 if ds.pipe_bundles[bundle] == []:
267 ds.pipe_bundles.pop(bundle)
268
269
270 del ds[pipe]
271
272
273 if ds.current_pipe == pipe:
274 ds.current_pipe = None
275 builtins.cdp = None
276
277
278 finally:
279 status.pipe_lock.release(sys._getframe().f_code.co_name)
280
281
282 status.observers.pipe_alteration.notify()
283
284
286 """Print the details of all the data pipes."""
287
288
289 status.pipe_lock.acquire(sys._getframe().f_code.co_name)
290 try:
291
292 data = []
293 for pipe_name in ds:
294
295 current = ''
296 if pipe_name == cdp_name():
297 current = '*'
298
299
300 data.append([repr(pipe_name), get_type(pipe_name), repr(get_bundle(pipe_name)), current])
301
302
303 finally:
304 status.pipe_lock.release(sys._getframe().f_code.co_name)
305
306
307 write_data(out=sys.stdout, headings=["Data pipe name", "Data pipe type", "Bundle", "Current"], data=data)
308
309
311 """Return the name of the bundle that the given pipe belongs to.
312
313 @keyword pipe: The name of the data pipe to find the bundle of.
314 @type pipe: str
315 @return: The name of the bundle that the pipe is located in.
316 @rtype: str or None
317 """
318
319
320 test(pipe)
321
322
323 for key in ds.pipe_bundles.keys():
324 if pipe in ds.pipe_bundles[key]:
325 return key
326
327
329 """Return a data pipe.
330
331 @keyword name: The name of the data pipe to return. If None, the current data pipe is
332 returned.
333 @type name: str or None
334 @return: The current data pipe.
335 @rtype: PipeContainer instance
336 """
337
338
339 if name == None:
340 name = cdp_name()
341
342
343 test(name)
344
345 return ds[name]
346
347
349 """Return the type of the data pipe.
350
351 @keyword name: The name of the data pipe. If None, the current data pipe is used.
352 @type name: str or None
353 @return: The current data pipe type.
354 @rtype: str
355 """
356
357
358 if name == None:
359 name = cdp_name()
360
361
362 pipe = get_pipe(name)
363
364 return pipe.pipe_type
365
366
368 """Determine if the relax data store contains the data pipe bundle.
369
370 @keyword bundle: The name of the data pipe bundle.
371 @type bundle: str
372 @return: The answer to the question.
373 @rtype: bool
374 """
375
376
377 if bundle in ds.pipe_bundles.keys():
378 return True
379 else:
380 return False
381
382
384 """Determine if the relax data store contains the data pipe.
385
386 @param name: The name of the data pipe.
387 @type name: str
388 @return: True if the data pipe exists, False otherwise.
389 @rtype: bool
390 """
391
392
393 if name in ds:
394 return True
395 else:
396 return False
397
398
400 """Generator function for looping over and yielding the data pipes.
401
402 @keyword name: A flag which if True will cause the name of the pipe to be returned.
403 @type name: bool
404 @return: The data pipes, and optionally the pipe names.
405 @rtype: PipeContainer instance or tuple of PipeContainer instance and str if name=True
406 """
407
408
409 status.pipe_lock.acquire(sys._getframe().f_code.co_name)
410 try:
411
412 for key in list(ds.keys()):
413
414 if name:
415 yield ds[key], key
416
417
418 else:
419 yield ds[key]
420
421
422 except:
423 status.pipe_lock.release(sys._getframe().f_code.co_name)
424 raise
425 status.pipe_lock.release(sys._getframe().f_code.co_name)
426
427
429 """Return the list of all data pipes.
430
431 @keyword bundle: If supplied, the pipe names will be restricted to those of the bundle.
432 @type bundle: str or None
433 @return: The list of data pipes.
434 @rtype: list of str
435 """
436
437
438 names = []
439 pipes = sorted(ds.keys())
440
441
442 for pipe in pipes:
443
444 if bundle and get_bundle(pipe) != bundle:
445 continue
446
447
448 names.append(pipe)
449
450
451 return names
452
453
455 """Switch the current data pipe to the given data pipe.
456
457 @param pipe_name: The name of the data pipe to switch to.
458 @type pipe_name: str
459 """
460
461
462 status.pipe_lock.acquire(sys._getframe().f_code.co_name)
463 try:
464
465 test(pipe_name)
466
467
468 ds.current_pipe = pipe_name
469 builtins.cdp = get_pipe()
470
471
472 finally:
473 status.pipe_lock.release(sys._getframe().f_code.co_name)
474
475
476 status.observers.pipe_alteration.notify()
477
478
479 -def test(pipe_name=None):
480 """Function for testing the existence of the current or supplied data pipe.
481
482 @param pipe_name: The name of the data pipe to switch to.
483 @type pipe_name: str
484 @return: The answer to the question of whether the pipe exists.
485 @rtype: Boolean
486 """
487
488
489 if pipe_name == None:
490
491 pipe_name = cdp_name()
492
493
494 if pipe_name == None:
495 raise RelaxNoPipeError
496
497
498 if pipe_name not in ds:
499 raise RelaxNoPipeError(pipe_name)
500