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