Statistiques
| Révision :

root / prepareQMX / qmxWRITE.py @ 10

Historique | Voir | Annoter | Télécharger (2,71 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', 'qmx']:
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
    for name in ['system', 'cluster', 'embed']:
41
        for definition in definitions:
42
            if definition.system.lower() != name:
43
                continue
44
            strSystem=definition.system.lower()
45
            strClass=definition.getValue('class')
46
            strOptions=definition.getValue('class.options')
47

    
48
            if (strClass is not ''):
49
                stream.write(strSystem+'='+strClass+"('"+strOptions+"')\n")
50
                
51
            if name is 'embed':
52
                strMethod=definition.getValue('method')
53
                strOptions=definition.getValue('method.options')
54
                stream.write(strSystem+'.'+strMethod+'('+strOptions+')\n')
55

    
56
                strOptions=definition.getValue('calculator')
57
                stream.write(strSystem+'.set_calculator('+strOptions+')\n')
58
        
59
    stream.write("\n")
60
    for definition in definitions:
61
        if (definition.system.lower() == 'job'):
62
            strSystem=definition.system.lower()
63
            strClass=definition.getValue('class')
64
            strOptions=definition.getValue('class.options')
65
            if (strOptions is not ''):
66
                strOptions = ', ' + strOptions
67
            
68
            if (strClass is not ''):
69
                stream.write(strSystem+'='+strClass+'(embed'+strOptions+')\n')
70

    
71
            strSystem=definition.system.lower()
72
            strMethod=definition.getValue('method')
73
            strOptions=definition.getValue('method.options')
74
            stream.write(strSystem+'.'+strMethod+'('+strOptions+')\n')