1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 """The data pipe objects of the relax data store."""
24
25
26 from re import match
27
28
29 from data_store.align_tensor import AlignTensorList
30 from data_store.diff_tensor import DiffTensorData
31 from data_store.exp_info import ExpInfo
32 from data_store.interatomic import InteratomList
33 from data_store.mol_res_spin import MoleculeList
34 from data_store.prototype import Prototype
35 from data_store.relax_xml import fill_object_contents, node_value_to_python, xml_to_object
36 from lib.errors import RelaxFromXMLNotEmptyError
37 from lib.structure.internal.object import Internal
38
39
41 """Class containing all the program data."""
42
44 """Set up all the PipeContainer data structures."""
45
46
47 self.mol = MoleculeList()
48
49
50 self.interatomic = InteratomList()
51
52
53 self.pipe_type = None
54
55
56 self.hybrid_pipes = []
57
58
60 """The string representation of the object.
61
62 Rather than using the standard Python conventions (either the string representation of the
63 value or the "<...desc...>" notation), a rich-formatted description of the object is given.
64 """
65
66
67 text = "The data pipe storage object.\n"
68
69
70 spec_obj = ['exp_info', 'mol', 'interatomic', 'diff_tensor', 'structure']
71
72
73 text = text + "\n"
74 text = text + "Objects:\n"
75 for name in dir(self):
76
77 if name == 'mol':
78 text = text + " mol: The molecule list (for the storage of the spin system specific data)\n"
79
80
81 if name == 'interatomic':
82 text = text + " interatomic: The interatomic data list (for the storage of the inter-spin system data)\n"
83
84
85 if name == 'diff_tensor':
86 text = text + " diff_tensor: The Brownian rotational diffusion tensor data object\n"
87
88
89 if name == 'structure':
90 text = text + " structure: The 3D molecular data object\n"
91
92
93 if name == 'exp_info':
94 text = text + " exp_info: The data container for experimental information\n"
95
96
97 if name in list(self.__class__.__dict__.keys()):
98 continue
99
100
101 if match("^_", name) or name in spec_obj:
102 continue
103
104
105 text = text + " " + name + ": " + repr(getattr(self, name)) + "\n"
106
107
108 return text
109
110
112 """Method for converting old data structures to the new ones.
113
114 @keyword file_version: The relax XML version of the XML file.
115 @type file_version: int
116 """
117
118
119 self._back_compat_hook_ri_data()
120
121
123 """Converting the old relaxation data structures to the new ones."""
124
125
126 if not (hasattr(cdp, 'frq_labels') and hasattr(cdp, 'noe_r1_table') and hasattr(cdp, 'remap_table')):
127 return
128
129
130 cdp.ri_ids = []
131 cdp.ri_type = {}
132 frq = {}
133
134
135 for i in range(cdp.num_ri):
136
137 ri_id = "%s_%s" % (cdp.ri_labels[i], cdp.frq_labels[cdp.remap_table[i]])
138
139
140 if ri_id in cdp.ri_ids:
141
142 for j in range(100):
143
144 new_id = "%s_%s" % (ri_id, j)
145
146
147 if not new_id in cdp.ri_ids:
148 ri_id = new_id
149 break
150
151
152 cdp.ri_ids.append(ri_id)
153
154
155 cdp.ri_type[ri_id] = cdp.ri_labels[i]
156
157
158 frq[ri_id] = cdp.frq[cdp.remap_table[i]]
159
160
161 del cdp.frq
162 del cdp.frq_labels
163 del cdp.noe_r1_table
164 del cdp.num_frq
165 del cdp.num_ri
166 del cdp.remap_table
167 del cdp.ri_labels
168
169
170 cdp.frq = frq
171
172
173 - def from_xml(self, pipe_node, file_version=None, dir=None):
174 """Read a pipe container XML element and place the contents into this pipe.
175
176 @param pipe_node: The data pipe XML node.
177 @type pipe_node: xml.dom.minidom.Element instance
178 @keyword file_version: The relax XML version of the XML file.
179 @type file_version: int
180 @keyword dir: The name of the directory containing the results file (needed for loading external files).
181 @type dir: str
182 """
183
184
185 if not self.is_empty():
186 raise RelaxFromXMLNotEmptyError(self.__class__.__name__)
187
188
189 global_node = pipe_node.getElementsByTagName('global')[0]
190 xml_to_object(global_node, self, file_version=file_version)
191
192
193 self._back_compat_hook(file_version)
194
195
196 hybrid_node = pipe_node.getElementsByTagName('hybrid')[0]
197 pipes_node = hybrid_node.getElementsByTagName('pipes')[0]
198 setattr(self, 'hybrid_pipes', node_value_to_python(pipes_node.childNodes[0]))
199
200
201 exp_info_nodes = pipe_node.getElementsByTagName('exp_info')
202 if exp_info_nodes:
203
204 self.exp_info = ExpInfo()
205
206
207 self.exp_info.from_xml(exp_info_nodes[0], file_version=file_version)
208
209
210 diff_tensor_nodes = pipe_node.getElementsByTagName('diff_tensor')
211 if diff_tensor_nodes:
212
213 self.diff_tensor = DiffTensorData()
214
215
216 self.diff_tensor.from_xml(diff_tensor_nodes[0], file_version=file_version)
217
218
219 align_tensor_nodes = pipe_node.getElementsByTagName('align_tensors')
220 if align_tensor_nodes:
221
222 self.align_tensors = AlignTensorList()
223
224
225 self.align_tensors.from_xml(align_tensor_nodes[0], file_version=file_version)
226
227
228 interatom_nodes = pipe_node.getElementsByTagName('interatomic')
229 self.interatomic.from_xml(interatom_nodes, file_version=file_version)
230
231
232 mol_nodes = pipe_node.getElementsByTagName('mol')
233 self.mol.from_xml(mol_nodes, file_version=file_version)
234
235
236 str_nodes = pipe_node.getElementsByTagName('structure')
237 if str_nodes:
238
239 fail = False
240 self.structure = Internal()
241
242
243 if not fail:
244 self.structure.from_xml(str_nodes[0], dir=dir, file_version=file_version)
245
246
248 """Method for testing if the data pipe is empty.
249
250 @return: True if the data pipe is empty, False otherwise.
251 @rtype: bool
252 """
253
254
255 if hasattr(self, 'structure'):
256 return False
257
258
259 if not self.mol.is_empty():
260 return False
261
262
263 if not self.interatomic.is_empty():
264 return False
265
266
267 if self.hybrid_pipes:
268 return False
269
270
271 for name in dir(self):
272
273 if name in ['mol', 'interatomic', 'pipe_type', 'hybrid_pipes']:
274 continue
275
276
277 if name in list(self.__class__.__dict__.keys()):
278 continue
279
280
281 if match("^_", name):
282 continue
283
284
285 return False
286
287
288 return True
289
290
291 - def to_xml(self, doc, element, pipe_type=None):
292 """Create a XML element for the current data pipe.
293
294 @param doc: The XML document object.
295 @type doc: xml.dom.minidom.Document instance
296 @param element: The XML element to add the pipe XML element to.
297 @type element: XML element object
298 @keyword pipe_type: The type of the pipe being converted to XML.
299 @type pipe_type: str
300 """
301
302
303 global_element = doc.createElement('global')
304 element.appendChild(global_element)
305 global_element.setAttribute('desc', 'Global data located in the top level of the data pipe')
306 fill_object_contents(doc, global_element, object=self, blacklist=['align_tensors', 'diff_tensor', 'exp_info', 'interatomic', 'hybrid_pipes', 'mol', 'pipe_type', 'structure'] + list(self.__class__.__dict__.keys()))
307
308
309 self.xml_create_hybrid_element(doc, element)
310
311
312 if hasattr(self, 'exp_info'):
313 self.exp_info.to_xml(doc, element)
314
315
316 if hasattr(self, 'diff_tensor'):
317 self.diff_tensor.to_xml(doc, element)
318
319
320 if hasattr(self, 'align_tensors'):
321 self.align_tensors.to_xml(doc, element)
322
323
324 self.mol.to_xml(doc, element, pipe_type=pipe_type)
325
326
327 self.interatomic.to_xml(doc, element, pipe_type=pipe_type)
328
329
330 if hasattr(self, 'structure'):
331 self.structure.to_xml(doc, element)
332
333
335 """Create an XML element for the data pipe hybridisation information.
336
337 @param doc: The XML document object.
338 @type doc: xml.dom.minidom.Document instance
339 @param element: The element to add the hybridisation info to.
340 @type element: XML element object
341 """
342
343
344 hybrid_element = doc.createElement('hybrid')
345 element.appendChild(hybrid_element)
346
347
348 hybrid_element.setAttribute('desc', 'Data pipe hybridisation information')
349
350
351 list_element = doc.createElement('pipes')
352 hybrid_element.appendChild(list_element)
353
354
355 text_val = doc.createTextNode(str(self.hybrid_pipes))
356 list_element.appendChild(text_val)
357