1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 from Numeric import Float64, array, zeros
25 from time import asctime, localtime
26
27
30 """The space mapping base class."""
31
32
34 """Function for creating the OpenDX .cfg program configuration file."""
35
36
37 print "\nCreating the OpenDX .cfg program configuration file."
38
39
40 config_file = self.relax.IO.open_write_file(file_name=self.file+".cfg", dir=self.dir, force=1)
41
42
43 text = self.config_text()
44
45
46 config_file.write(text)
47
48
49 config_file.close()
50
51
53 """Function for creating the OpenDX .general file."""
54
55
56 print "\nCreating the OpenDX .general file."
57
58
59 general_file = self.relax.IO.open_write_file(file_name=self.file+".general", dir=self.dir, force=1)
60
61
62 text = self.general_text()
63
64
65 general_file.write(text)
66
67
68 general_file.close()
69
70
72 """Function for creating the map."""
73
74
75 print "\nCreating the map."
76
77
78 map_file = self.relax.IO.open_write_file(file_name=self.file, dir=self.dir, force=1)
79
80
81 self.map_text(map_file)
82
83
84 map_file.close()
85
86
88 """Function for creating a sphere at a given position within the 3D map.
89
90 The formula used to calculate the coordinate position is:
91
92 V - L
93 coord = Inc * -----
94 U - L
95
96 where:
97 V is the coordinate or parameter value.
98 L is the lower bound value.
99 U is the upper bound value.
100 Inc is the number of increments.
101
102 Both a data file and .general file will be created.
103 """
104
105
106 print "\nCreating the OpenDX .general and data files for the given point."
107
108
109 point_file = self.relax.IO.open_write_file(file_name=self.point_file, dir=self.dir, force=1)
110 point_file_general = self.relax.IO.open_write_file(file_name=self.point_file+".general", dir=self.dir, force=1)
111
112
113 coords = self.inc * (self.point - self.bounds[:, 0]) / (self.bounds[:, 1] - self.bounds[:, 0])
114 for i in xrange(self.n):
115 point_file.write("%-15.5g" % coords[i])
116 point_file.write("1\n")
117
118
119 text = self.point_text()
120
121
122 point_file_general.write(text)
123
124
125 point_file.close()
126 point_file_general.close()
127
128
130 """Function for creating the OpenDX .net program file."""
131
132
133 print "\nCreating the OpenDX .net program file."
134
135
136 program_file = self.relax.IO.open_write_file(file_name=self.file+".net", dir=self.dir, force=1)
137
138
139 self.map_axes()
140
141
142 self.corners = "{[0"
143 for i in xrange(self.n - 1):
144 self.corners = self.corners + " 0"
145 self.corners = self.corners + "] [" + `self.inc`
146 for i in xrange(self.n - 1):
147 self.corners = self.corners + " " + `self.inc`
148 self.corners = self.corners + "]}"
149
150
151 self.sphere_size = `0.025 * (self.inc + 1.0)`
152
153
154 text = self.program_text()
155
156
157 program_file.write(text)
158
159
160 program_file.close()
161
162
164 """Function for creating a date string."""
165
166 self.date = asctime(localtime())
167
168
170 """Function for retrieving the parameter names."""
171
172
173 self.param_names = []
174
175
176 for i in xrange(self.n):
177
178 name = self.return_data_name(self.params[i])
179
180
181 if self.function_type == 'mf':
182
183 diff_name = self.relax.generic.diffusion_tensor.return_data_name(self.params[i])
184
185
186 if diff_name:
187 name = diff_name
188
189
190 self.diff_params[i] = 1
191
192
193 if not name:
194 raise RelaxUnknownParamError, self.params[i]
195
196
197 self.param_names.append(name)
198
199
201 """Function for creating labels, tick locations, and tick values for an OpenDX map."""
202
203
204 self.labels = "{"
205 self.tick_locations = []
206 self.tick_values = []
207 loc_inc = float(self.inc) / float(self.axis_incs)
208
209
210 for i in xrange(self.n):
211
212 factor = self.return_conversion_factor[i](self.param_names[i])
213
214
215 units = self.return_units[i](self.param_names[i])
216
217
218 if units:
219 self.labels = self.labels + "\"" + self.params[i] + " (" + units + ")\""
220 else:
221 self.labels = self.labels + "\"" + self.params[i] + "\""
222
223 if i < self.n - 1:
224 self.labels = self.labels + " "
225 else:
226 self.labels = self.labels + "}"
227
228
229 vals = self.bounds[i, 0] / factor
230 val_inc = (self.bounds[i, 1] - self.bounds[i, 0]) / (self.axis_incs * factor)
231
232 string = ""
233 for j in xrange(self.axis_incs + 1):
234 string = string + "\"" + "%.2f" % vals + "\" "
235 vals = vals + val_inc
236 self.tick_values.append("{" + string + "}")
237
238
239 string = ""
240 val = 0.0
241 for j in xrange(self.axis_incs + 1):
242 string = string + " " + `val`
243 val = val + loc_inc
244 self.tick_locations.append("{" + string + " }")
245
246
247 - def map_space(self, run, params, res_num, index, inc, lower, upper, axis_incs, file, dir, point, point_file, remap):
248 """Generic function for mapping a space."""
249
250
251
252
253
254 self.function_type = self.relax.data.run_types[self.relax.data.run_names.index(run)]
255
256
257 self.run = run
258 self.params = params
259 self.res_num = res_num
260 self.index = index
261 self.n = len(params)
262 self.inc = inc
263 self.axis_incs = axis_incs
264 self.file = file
265 self.dir = dir
266 self.point_file = point_file
267 self.remap = remap
268
269
270 self.calculate = self.relax.specific_setup.setup('calculate', self.function_type)
271 self.model_stats = self.relax.specific_setup.setup('model_stats', self.function_type)
272 self.return_data_name = self.relax.specific_setup.setup('return_data_name', self.function_type)
273 self.map_bounds = []
274 self.return_conversion_factor = []
275 self.return_units = []
276 for i in xrange(self.n):
277 self.map_bounds.append(self.relax.specific_setup.setup('map_bounds', self.function_type))
278 self.return_conversion_factor.append(self.relax.specific_setup.setup('return_conversion_factor', self.function_type))
279 self.return_units.append(self.relax.specific_setup.setup('return_units', self.function_type))
280
281
282 self.diff_params = zeros(self.n)
283
284
285 self.get_param_names()
286
287
288 for i in xrange(self.n):
289 if self.diff_params[i]:
290 self.map_bounds[i] = self.relax.generic.diffusion_tensor.map_bounds
291 self.return_conversion_factor[i] = self.relax.generic.diffusion_tensor.return_conversion_factor
292 self.return_units[i] = self.relax.generic.diffusion_tensor.return_units
293
294
295 if point != None:
296 self.point = array(point, Float64)
297 self.num_points = 1
298 else:
299 self.num_points = 0
300
301
302 self.bounds = zeros((self.n, 2), Float64)
303 for i in xrange(self.n):
304
305 bounds = self.map_bounds[i](self.run, self.param_names[i])
306
307
308 if not bounds:
309 raise RelaxError, "No bounds for the parameter " + `self.params[i]` + " could be determined."
310
311
312 self.bounds[i] = bounds
313
314
315 if lower != None:
316 self.bounds[:, 0] = array(lower, Float64)
317
318
319 if upper != None:
320 self.bounds[:, 1] = array(upper, Float64)
321
322
323 self.step_size = zeros(self.n, Float64)
324 self.step_size = (self.bounds[:, 1] - self.bounds[:, 0]) / self.inc
325
326
327
328
329
330
331 self.get_date()
332
333
334 self.create_program()
335
336
337 self.create_config()
338
339
340 self.create_general()
341
342
343 if self.num_points == 1:
344 self.create_point()
345
346
347 self.create_map()
348