1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 import sys
24
25
28 """Class containing functions for reading and writing data."""
29
30 self.relax = relax
31
32
33 - def copy(self, run1=None, run2=None, sim=None):
34 """Function for copying all results from run1 to run2."""
35
36
37 if not run1 in self.relax.data.run_names:
38 raise RelaxNoRunError, run1
39
40
41 if not run2 in self.relax.data.run_names:
42 raise RelaxNoRunError, run2
43
44
45 function_type = self.relax.data.run_types[self.relax.data.run_names.index(run1)]
46
47
48 copy = self.relax.specific_setup.setup('copy', function_type, raise_error=0)
49
50
51 copy(run1=run1, run2=run2, sim=sim)
52
53
54 - def display(self, run=None, format='columnar'):
55 """Function for displaying the results."""
56
57
58 if not run in self.relax.data.run_names:
59 raise RelaxNoRunError, run
60
61
62 function_type = self.relax.data.run_types[self.relax.data.run_names.index(run)]
63
64
65 if format == 'xml':
66 format = 'XML'
67 self.write_function = self.relax.specific_setup.setup('write_xml_results', function_type, raise_error=0)
68 elif format == 'columnar':
69 self.write_function = self.relax.specific_setup.setup('write_columnar_results', function_type, raise_error=0)
70 else:
71 raise RelaxError, "Unknown format " + `format` + "."
72
73
74 if not self.write_function:
75 raise RelaxError, "The " + format + " format is not currently supported for " + self.relax.specific_setup.get_string(function_type) + "."
76
77
78 self.write_function(sys.stdout, run)
79
80
81 - def read(self, run=None, file='results', directory=None, file_data=None, format='columnar', print_flag=1):
82 """Function for reading the data out of a file."""
83
84
85 if not run in self.relax.data.run_names:
86 raise RelaxNoRunError, run
87
88
89 function_type = self.relax.data.run_types[self.relax.data.run_names.index(run)]
90
91
92 if format == 'xml':
93 format = 'XML'
94 self.read_function = self.relax.specific_setup.setup('read_xml_results', function_type)
95 elif format == 'columnar':
96 self.read_function = self.relax.specific_setup.setup('read_columnar_results', function_type)
97 else:
98 raise RelaxError, "Unknown format " + `format` + "."
99
100
101 if not self.read_function:
102 raise RelaxError, "The " + format + " format is not currently supported for " + self.relax.specific_setup.get_string(function_type) + "."
103
104
105 if directory == 'run':
106 directory = run
107
108
109 for data_name in dir(self.relax.data):
110
111 data = getattr(self.relax.data, data_name)
112
113
114 if not hasattr(data, 'has_key'):
115 continue
116
117
118 if data.has_key(run):
119 raise RelaxError, "Data corresponding to the run " + `run` + " exists."
120
121
122 file_data = self.relax.IO.extract_data(file_name=file, dir=directory, file_data=file_data)
123
124
125 file_data = self.relax.IO.strip(file_data)
126
127
128 if not file_data:
129 raise RelaxFileEmptyError
130
131
132 self.read_function(run, file_data, print_flag)
133
134
135 - def write(self, run=None, file="results", directory=None, force=0, format='columnar', compress_type=1, print_flag=1):
136 """Create the results file."""
137
138
139 if not run in self.relax.data.run_names:
140 raise RelaxNoRunError, run
141
142
143 if directory == 'run':
144 directory = run
145
146
147 function_type = self.relax.data.run_types[self.relax.data.run_names.index(run)]
148
149
150 if format == 'xml':
151 format = 'XML'
152 self.write_function = self.relax.specific_setup.setup('write_xml_results', function_type, raise_error=0)
153 elif format == 'columnar':
154 self.write_function = self.relax.specific_setup.setup('write_columnar_results', function_type, raise_error=0)
155 else:
156 raise RelaxError, "Unknown format " + `format` + "."
157
158
159 if not self.write_function:
160 raise RelaxError, "The " + format + " format is not currently supported for " + self.relax.specific_setup.get_string(function_type) + "."
161
162
163 results_file = self.relax.IO.open_write_file(file_name=file, dir=directory, force=force, compress_type=compress_type, print_flag=print_flag)
164
165
166 self.write_function(results_file, run)
167
168
169 results_file.close()
170