0
|
1 import os
|
|
2 import sys
|
|
3 import tempfile
|
|
4
|
12
|
5 from icqsol.shapes.icqShapeManager import ShapeManager
|
|
6 from icqsol.bem.icqLaplaceMatrices import LaplaceMatrices
|
|
7
|
6
|
8 PLY = 'ply'
|
5
|
9 POLYDATA = 'POLYDATA'
|
6
|
10 VTK = 'vtk'
|
5
|
11
|
0
|
12
|
5
|
13 def asbool(val):
|
|
14 return str(val).lower() in ['yes', 'true']
|
0
|
15
|
5
|
16
|
|
17 def get_format_and_type(galaxy_ext):
|
0
|
18 # Define the output file format and type.
|
|
19 format = None
|
|
20 datatype = None
|
5
|
21 if galaxy_ext in ['vtkascii', 'vtkbinary']:
|
6
|
22 format = VTK
|
5
|
23 elif galaxy_ext in ['plyascii', 'plybinary']:
|
6
|
24 format = PLY
|
5
|
25 if galaxy_ext in ['vtkascii', 'plyascii']:
|
0
|
26 datatype = 'ascii'
|
5
|
27 elif galaxy_ext in ['vtkbinary', 'plybinary']:
|
0
|
28 datatype = 'binary'
|
|
29 return format, datatype
|
|
30
|
5
|
31
|
|
32 def get_input_file_path(tmp_dir, input_file, format):
|
0
|
33 """
|
|
34 iCqSol uses file extensions (e.g., .ply, .vtk) when reading and
|
|
35 writing files, so the Galaxy dataset naming convention of
|
|
36 setting all file extensions as .dat must be handled.
|
|
37 """
|
5
|
38 file_path = get_temporary_file_path(tmp_dir, format)
|
0
|
39 # Remove the file so we can create a symlink.
|
5
|
40 os.remove(file_path)
|
|
41 os.symlink(input_file, file_path)
|
0
|
42 return file_path
|
|
43
|
5
|
44
|
12
|
45 def get_laplace_solver(shape_data, max_edge_length=float('inf')):
|
|
46 return LaplaceMatrices(shape_data, max_edge_length=max_edge_length)
|
|
47
|
|
48
|
|
49 def get_shape_manager(format, dataset_type):
|
|
50 # Instantiate a ShapeManager.
|
|
51 if format == VTK:
|
|
52 return ShapeManager(file_format=format, vtk_dataset_type=dataset_type)
|
|
53 else:
|
|
54 return ShapeManager(file_format=format)
|
|
55
|
|
56
|
5
|
57 def get_temp_dir(prefix='tmp-vtk-', dir=None):
|
0
|
58 """
|
|
59 Return a temporary directory.
|
|
60 """
|
5
|
61 return tempfile.mkdtemp(prefix=prefix, dir=dir)
|
0
|
62
|
5
|
63
|
|
64 def get_tempfilename(dir=None, suffix=None):
|
0
|
65 """
|
|
66 Return a temporary file name.
|
|
67 """
|
10
|
68 if suffix is None:
|
|
69 s = None
|
|
70 elif suffix.startswith('.'):
|
|
71 s = suffix
|
|
72 else:
|
|
73 s = '.%s' % suffix
|
|
74 fd, name = tempfile.mkstemp(suffix=s, dir=dir)
|
5
|
75 os.close(fd)
|
0
|
76 return name
|
|
77
|
5
|
78
|
|
79 def get_temporary_file_path(tmp_dir, file_extension):
|
0
|
80 """
|
|
81 Return the path to a temporary file with a valid VTK format
|
|
82 file extension.
|
|
83 """
|
5
|
84 return get_tempfilename(tmp_dir, file_extension)
|
|
85
|
0
|
86
|
5
|
87 def stop_err(msg):
|
|
88 sys.stderr.write("%s\n" % msg)
|
0
|
89 sys.exit()
|