root / prepareQMX / qmxWRITE.py @ 16
Historique | Voir | Annoter | Télécharger (2,9 ko)
1 |
#!/usr/bin/env python
|
---|---|
2 |
|
3 |
# GRAPHICAL interface for setup of QMX calculations
|
4 |
#
|
5 |
# Torsten Kerber, ENS LYON: 2011, 07, 11
|
6 |
#
|
7 |
# This work is supported by Award No. UK-C0017, made by King Abdullah
|
8 |
# University of Science and Technology (KAUST)
|
9 |
|
10 |
import StringIO |
11 |
|
12 |
def writeData(stream, definitions): |
13 |
stream.write("#!/usr/bin/env python\n")
|
14 |
keys=['import']
|
15 |
|
16 |
arrImports=[] |
17 |
for definition in definitions: |
18 |
strClass=definition.getValue('class')
|
19 |
strImport=definition.getValue('import')
|
20 |
|
21 |
if (strClass is not '' and strImport is not ''): |
22 |
s='from '+strImport+' import '+strClass+'\n' |
23 |
if not s in arrImports: |
24 |
stream.write(s) |
25 |
arrImports.append(s) |
26 |
|
27 |
stream.write("\n")
|
28 |
for name in ['high-level', 'low-level', 'hybrid']: |
29 |
for definition in definitions: |
30 |
if definition.system.lower() != name:
|
31 |
continue
|
32 |
strSystem=definition.system.lower().replace("-", "_") |
33 |
strClass=definition.getValue('class')
|
34 |
strOptions=definition.getValue('class.options')
|
35 |
|
36 |
if (strClass is not ''): |
37 |
stream.write(strSystem+'='+strClass+'('+strOptions+')\n') |
38 |
|
39 |
stream.write("\n")
|
40 |
|
41 |
extraOptions = ''
|
42 |
for name in ['cluster', 'system', 'embed']: |
43 |
for definition in definitions: |
44 |
if definition.system.lower() != name:
|
45 |
continue
|
46 |
strSystem=definition.system.lower() |
47 |
strClass=definition.getValue('class')
|
48 |
strOptions=definition.getValue('class.options')
|
49 |
|
50 |
if (strClass is not ''): |
51 |
if name is 'embed': |
52 |
if strOptions is not '': |
53 |
strOptions += ', '
|
54 |
strOptions += extraOptions |
55 |
stream.write(strSystem+'='+strClass+"("+strOptions+")\n") |
56 |
|
57 |
if name is 'cluster' and definition.name is 'CLUSTER': |
58 |
stream.write(strSystem+'=['+strOptions+']'+'\n') |
59 |
extraOptions='cluster_pos=False'
|
60 |
|
61 |
if name is 'embed': |
62 |
strOptions=definition.getValue('set_calculator')
|
63 |
stream.write(strSystem+'.set_calculator('+strOptions+')\n') |
64 |
|
65 |
stream.write("\n")
|
66 |
for definition in definitions: |
67 |
if (definition.system.lower() == 'job'): |
68 |
strSystem=definition.system.lower() |
69 |
strClass=definition.getValue('class')
|
70 |
strOptions=definition.getValue('class.options')
|
71 |
if (strOptions is not ''): |
72 |
strOptions = ', ' + strOptions
|
73 |
|
74 |
if (strClass is not ''): |
75 |
stream.write(strSystem+'='+strClass+'(embed'+strOptions+')\n') |
76 |
|
77 |
strSystem=definition.system.lower() |
78 |
strMethod=definition.getValue('method')
|
79 |
strOptions=definition.getValue('method.options')
|
80 |
stream.write(strSystem+'.'+strMethod+'('+strOptions+')\n') |