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