Révision 13

prepareQMX/prepareQMX.new.py (revision 13)
1
#!/usr/bin/env python
2

  
3
# command line 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
#---------------------------------------------------------------------------------------------------
11
import os, sys
12
from copy import deepcopy
13
from optparse import OptionParser
14

  
15
#---------------------------------------------------------------------------------------------------
16
from qmxEMBED import embedDefinitions
17
from qmxJOB  import jobDefinitions
18
from qmxSTR  import strDefinitions
19
from qmxCALC import calcDefinitions, QmxCalcDefinition
20

  
21
from qmxWRITE import writeData
22

  
23
#---------------------------------------------------------------------------------------------------
24
#---------------------------------------------------------------------------------------------------
25
#---------------------------------------------------------------------------------------------------
26
def getline(section, subsection, lines):
27
    nline = -1
28
    for iline in xrange(len(lines)):
29
        if lines[iline][0].strip() == subsection:
30
            if nline != -1:
31
                sys.stderr.write("section: <"+section+separator+subsection+"> has been definied more than once\n")
32
                sys.exit(1)
33
            nline = iline
34
    if nline == -1:
35
        return None
36
    return lines[nline][1].strip()
37

  
38
#---------------------------------------------------------------------------------------------------
39
def analyzeSection(definitions, section, lines):
40
    line = getline(section, "program", lines)
41
    if line is None:
42
        print "section <" + section + "> does not contain program"
43
        sys.exit(1)
44
        
45
    myDefinition = None
46
    for definition in definitions:
47
        if definition.name == line:
48
            myDefinition = deepcopy(definition)
49
            break
50
            
51
    if myDefinition is None:
52
        print "the program <" + line + "> is not defined for the section <" + section + ">"
53
        sys.exit(1)
54
        
55
    myDefinition.system = section
56

  
57
    subsections = []
58
    for line in lines:
59
        subsections.append(line[0].strip().lower())
60

  
61
    for subsection in subsections:
62
        line = getline(section, subsection, lines)
63
        if line is None:
64
            print "input error in <"+section+"."+subsection+">"
65
            sys.exit(1)
66
        if subsection == "program":
67
            continue
68
        if subsection == "options":
69
            subsection = 'class.options'
70
        
71
        myDefinition.keywords[subsection] = line    
72
        print subsection, myDefinition.keywords[subsection]
73
    
74
    return myDefinition
75

  
76
#---------------------------------------------------------------------------------------------------
77
#--- setting default values ------------------------------------------------------------------------
78
#---------------------------------------------------------------------------------------------------
79

  
80
#define separators
81
separator=":"
82
subseparator="."
83
lineseparator="\n"
84

  
85
#--- parse arguments -------------------------------------------------------------------------------
86
#parse arguments (python 2.6)
87
parser = OptionParser()
88
parser.add_option("-i", "--infile",  dest="inputFile",  help="specifies the input file", metavar="FILE", default="qmx.in")
89
parser.add_option("-o", "--outfile", dest="outputFile", help="specifies the output file", metavar="FILE")
90
parser.add_option("-f", action="store_true", dest="overwrite")
91
(options, args) = parser.parse_args()
92

  
93
#--- check wether output file exists ---------------------------------------------------------------
94
if options.outputFile is not None and os.path.exists(options.outputFile) and not options.overwrite:
95
    sys.stderr.write(lineseparator+"the output file <"+options.outputFile+"> already exists"+lineseparator)
96
    sys.exit(1)
97

  
98
#--- read intput file ------------------------------------------------------------------------------
99
file=open(options.inputFile, "r")
100
lines = file.readlines()
101
file.close()
102

  
103
#--- remove comments -------------------------------------------------------------------------------
104
for iline in xrange(len(lines)):
105
    lines[iline] = lines[iline].split("#")[0]    
106

  
107
#--- collect data in class -------------------------------------------------------------------------
108
definitions=[]
109
definitions.append(QmxCalcDefinition())
110

  
111
#--- analyze the input file ------------------------------------------------------------------------
112
for section in "high-level", "low-level", "cluster", "system", "job":
113
    #search lines for section
114
    lines_section=[]
115
    for line in lines:
116
        line = line.split(separator)
117
        if line[0].find(section) >= 0:
118
            line[0] = line[0].replace(section+subseparator, "")
119
            lines_section.append(line)
120

  
121
    #calculators
122
    if section == "high-level" or section == "low-level":
123
        definitions.append(analyzeSection(calcDefinitions, section, lines_section))
124
        
125
    #structures (atoms)
126
    if section == "cluster" or section == "system":
127
        definitions.append(analyzeSection(strDefinitions, section, lines_section))
128
        
129
    #job
130
    if section == "job":
131
        definitions.append(analyzeSection(jobDefinitions, section, lines_section))
132
        
133
    #embed
134
    if section == "embed":
135
        definitions.append(analyzeSection(embedDefinitions, section, lines_section))
136

  
137
output = None
138
if options.outputFile is None:
139
    output=sys.stdout
140
else:
141
    output=open(options.outputFile, "w")
142
    
143
writeData(output, definitions)
144
output.close()
145

  
146

  
147

  
148

  
149

  
150

  
151

  
152
#
153
##--- write header ----------------------------------------------------------------------------------
154
#output.write("#!/usr/bin/env python\n")
155
#
156
##--- write import lines ----------------------------------------------------------------------------
157
#xlines=[]
158
#for data in data_collection:
159
#    value = data.str_import
160
#    if value is None or value in xlines:
161
#        continue
162
#    xlines.append(value)
163
#    output.write(value+lineseparator)
164
#output.write(lineseparator)
165
#
166
##--- define the methods ----------------------------------------------------------------------------
167
#for system in 'high', 'low':
168
#    for data in data_collection:
169
#        if data.__name__ == system+"-level":
170
#            output.write(system+"Level = "+data.str_class+"("+data.str_option+")"+lineseparator)
171
#output.write(lineseparator)
172
#
173
##--- qmx class (substraction scheme ----------------------------------------------------------------
174
#for data in data_collection:
175
#    if data.__name__ == "qmx":
176
#        output.write("qmx = "+data.str_class+"("+data.str_option+")"+lineseparator)
177
#output.write(lineseparator)
178
#
179
##--- read all the systems --------------------------------------------------------------------------
180
#for system in "cluster", "system":
181
#    for data in data_collection:
182
#        if data.__name__ == system:
183
#            if data.str_structure is None:
184
#                continue
185
#            output.write(system+" = "+data.str_class+"(\""+data.str_structure+"\")"+lineseparator)
186
#output.write(lineseparator)
187
#
188
##--- embeding class --------------------------------------------------------------------------------
189
#for data in data_collection:
190
#    if data.__name__ == "embed":
191
#        output.write("embed = "+data.str_class+"("+data.str_option+")"+lineseparator)
192
#        for method in data.str_methods:
193
#            output.write("embed."+method+lineseparator)
194
#output.write(lineseparator)
195
#
196
##--- dynamics class --------------------------------------------------------------------------------
197
#for data in data_collection:
198
#    if data.__name__ == "dynamics":
199
#        output.write("dyn="+data.str_class+"(embed)"+lineseparator)
200
#        output.write("dyn.run("+data.str_option+")"+lineseparator)
201
#
202
#
203
#
204
#
205
#
206
#def getline(section, subsection, lines):
207
#    nline = -1
208
#    for iline in xrange(len(lines)):
209
#        if lines[iline][0].strip() == subsection:
210
#            if nline != -1:
211
#                sys.stderr.write("section: <"+section+separator+subsection+"> has been definied more than once\n")
212
#                sys.exit(1)
213
#            nline = iline
214
#    if nline == -1:
215
#        return None
216
#    return lines[nline][1].strip()
217
#
218
##def analyzeAtoms(section, lines):
219
##    data = Data(section)
220
##    line = getline(section, "program", lines)
221
##    if line is None:
222
##        line=""
223
##    if line.lower() == "turbomole":
224
##        data.str_import = "from ase.io.turbomole import read_turbomole"
225
##        data.str_class = "read_turbomole"
226
##    elif line.lower() == "vasp":
227
##        data.str_import = "from ase.io.vasp import read_vasp"
228
##        data.str_class = "read_vasp"
229
##        
230
##    data.str_structure = getline(section, "structure", lines)
231
##    return data
232
##
233
##def analyzeCalculator(section, lines):
234
##    data = Data(section)
235
##    #read programs
236
##    line = getline(section, "program", lines)
237
##    if line.lower() == "turbomole":
238
##        data.str_import = "from ase.calculators.turbomole import Turbomole"
239
##        data.str_class = "Turbomole"
240
##    elif line.lower() == "vasp":
241
##        data.str_import = "from ase.calculators.vasp import Vasp"
242
##        data.str_class = "Vasp"
243
##    
244
##    str = getline(section, "class", lines)
245
##    if str is not None:
246
##        data.str_class = str
247
##
248
##    str = getline(section, "import", lines)
249
##    if str is not None:
250
##        data.str_import = str
251
##
252
##    str = getline(section, "options", lines)
253
##    if str is not None:
254
##        data.str_option = str
255
##    return data
256
##
257
##def analyzeDynamics(section, lines):
258
##    data = Data(section)
259
##    line = getline(section, "method", lines)
260
##    if line.lower() == "optimizer":
261
##        data.str_import = "from ase.optimize import QuasiNewton"
262
##        data.str_class = "QuasiNewton"
263
##    return data
264

  
prepareQMX/prepareQMX.py (revision 13)
1 1
#!/usr/bin/env python
2

  
3
# command line 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
#---------------------------------------------------------------------------------------------------
2 11
import os, sys
12
from copy import deepcopy
3 13
from optparse import OptionParser
4 14

  
5
class Data:
6
    def __init__(self, name):
7
        self.__name__ = name
8
        self.str_option = ""
9
        self.str_import = None
10
        self.str_class  = None
11
        self.str_methods = []
12
        self.str_structure = None
13
                
14
    def __str__(self):
15
       return self.__name__
15
#---------------------------------------------------------------------------------------------------
16
from qmxEMBED import embedDefinitions
17
from qmxJOB  import jobDefinitions
18
from qmxSTR  import strDefinitions
19
from qmxCALC import calcDefinitions, QmxCalcDefinition
16 20

  
21
from qmxWRITE import writeData
22

  
23
#---------------------------------------------------------------------------------------------------
24
#---------------------------------------------------------------------------------------------------
25
#---------------------------------------------------------------------------------------------------
17 26
def getline(section, subsection, lines):
18 27
    nline = -1
19 28
    for iline in xrange(len(lines)):
......
26 35
        return None
27 36
    return lines[nline][1].strip()
28 37

  
29
def analyzeAtoms(section, lines):
30
    data = Data(section)
38
#---------------------------------------------------------------------------------------------------
39
def analyzeSection(definitions, section, lines):
31 40
    line = getline(section, "program", lines)
32 41
    if line is None:
33
        line=""
34
    if line.lower() == "turbomole":
35
        data.str_import = "from ase.io.turbomole import read_turbomole"
36
        data.str_class = "read_turbomole"
37
    elif line.lower() == "vasp":
38
        data.str_import = "from ase.io.vasp import read_vasp"
39
        data.str_class = "read_vasp"
42
        print "section <" + section + "> does not contain program"
43
        sys.exit(1)
40 44
        
41
    data.str_structure = getline(section, "structure", lines)
42
    return data
45
    myDefinition = None
46
    for definition in definitions:
47
        if definition.name == line:
48
            myDefinition = deepcopy(definition)
49
            break
50
            
51
    if myDefinition is None:
52
        print "the program <" + line + "> is not defined for the section <" + section + ">"
53
        sys.exit(1)
54
        
55
    myDefinition.system = section
43 56

  
44
def analyzeCalculator(section, lines):
45
    data = Data(section)
46
    #read programs
47
    line = getline(section, "program", lines)
48
    if line.lower() == "turbomole":
49
        data.str_import = "from ase.calculators.turbomole import Turbomole"
50
        data.str_class = "Turbomole"
51
    elif line.lower() == "vasp":
52
        data.str_import = "from ase.calculators.vasp import Vasp"
53
        data.str_class = "Vasp"
57
    subsections = []
58
    for line in lines:
59
        subsections.append(line[0].strip().lower())
60

  
61
    for subsection in subsections:
62
        line = getline(section, subsection, lines)
63
        if line is None:
64
            print "input error in <"+section+"."+subsection+">"
65
            sys.exit(1)
66
        if subsection == "program":
67
            continue
68
        if subsection == "options":
69
            subsection = 'class.options'
70
        
71
        myDefinition.keywords[subsection] = line    
72
        print subsection, myDefinition.keywords[subsection]
54 73
    
55
    str = getline(section, "class", lines)
56
    if str is not None:
57
        data.str_class = str
74
    return myDefinition
58 75

  
59
    str = getline(section, "import", lines)
60
    if str is not None:
61
        data.str_import = str
62

  
63
    str = getline(section, "options", lines)
64
    if str is not None:
65
        data.str_option = str
66
    return data
67

  
68
def analyzeDynamics(section, lines):
69
    data = Data(section)
70
    line = getline(section, "method", lines)
71
    if line.lower() == "optimizer":
72
        data.str_import = "from ase.optimize import QuasiNewton"
73
        data.str_class = "QuasiNewton"
74
    return data
75

  
76
#---------------------------------------------------------------------------------------------------
76 77
#--- setting default values ------------------------------------------------------------------------
78
#---------------------------------------------------------------------------------------------------
79

  
77 80
#define separators
78 81
separator=":"
79 82
subseparator="."
......
87 90
parser.add_option("-f", action="store_true", dest="overwrite")
88 91
(options, args) = parser.parse_args()
89 92

  
93
#--- check wether output file exists ---------------------------------------------------------------
94
if options.outputFile is not None and os.path.exists(options.outputFile) and not options.overwrite:
95
    sys.stderr.write(lineseparator+"the output file <"+options.outputFile+"> already exists"+lineseparator)
96
    sys.exit(1)
97

  
98
#--- read intput file ------------------------------------------------------------------------------
90 99
file=open(options.inputFile, "r")
91 100
lines = file.readlines()
92 101
file.close()
93 102

  
94

  
95
#--- split intput file -----------------------------------------------------------------------------
96

  
97 103
#--- remove comments -------------------------------------------------------------------------------
98 104
for iline in xrange(len(lines)):
99 105
    lines[iline] = lines[iline].split("#")[0]    
100 106

  
101 107
#--- collect data in class -------------------------------------------------------------------------
102
data_collection=[]
108
definitions=[]
109
definitions.append(QmxCalcDefinition())
103 110

  
104
#--- settings for QMX class ------------------------------------------------------------------------
105
data = Data("qmx")
106
data.str_class = "Qmx"
107
data.str_import = "from ase.calculators.qmx import Qmx"
108
data.str_option = "highLevel, lowLevel"
109

  
110
data_collection.append(data)
111

  
112
#--- settings for Embed class ----------------------------------------------------------------------
113
data = Data("embed")
114
data.str_class = "Embed"
115
data.str_import = "from ase.embed import Embed"
116
data.str_option = "system, cluster"
117
data.str_methods = ["embed()", "set_calculator(qmx)"]
118

  
119
data_collection.append(data)
120

  
121

  
122 111
#--- analyze the input file ------------------------------------------------------------------------
123
for section in "high-level", "low-level", "cluster", "system", "dynamics":
112
for section in "high-level", "low-level", "cluster", "system", "job":
124 113
    #search lines for section
125 114
    lines_section=[]
126 115
    for line in lines:
......
128 117
        if line[0].find(section) >= 0:
129 118
            line[0] = line[0].replace(section+subseparator, "")
130 119
            lines_section.append(line)
131
    
120

  
132 121
    #calculators
133 122
    if section == "high-level" or section == "low-level":
134
        data_collection.append(analyzeCalculator(section, lines_section))
123
        definitions.append(analyzeSection(calcDefinitions, section, lines_section))
135 124
        
136
    #systems
125
    #structures (atoms)
137 126
    if section == "cluster" or section == "system":
138
        data_collection.append(analyzeAtoms(section, lines_section))
127
        definitions.append(analyzeSection(strDefinitions, section, lines_section))
139 128
        
140
    #dynamics
141
    if section == "dynamics":
142
        data_collection.append(analyzeDynamics(section, lines_section))
129
    #job
130
    if section == "job":
131
        definitions.append(analyzeSection(jobDefinitions, section, lines_section))
132
        
133
    #embed
134
    if section == "embed":
135
        definitions.append(analyzeSection(embedDefinitions, section, lines_section))
143 136

  
144
#--- write output file -----------------------------------------------------------------------------
145
if options.outputFile is not None and os.path.exists(options.outputFile) and not options.overwrite:
146
    sys.stderr.write(lineseparator+"the output file <"+options.outputFile+"> already exists"+lineseparator)
147
    sys.exit(1)
148

  
149 137
output = None
150 138
if options.outputFile is None:
151 139
    output=sys.stdout
152 140
else:
153 141
    output=open(options.outputFile, "w")
154

  
155
#--- write header ----------------------------------------------------------------------------------
156
output.write("#!/usr/bin/env python\n")
157

  
158
#--- write import lines ----------------------------------------------------------------------------
159
xlines=[]
160
for data in data_collection:
161
    value = data.str_import
162
    if value is None or value in xlines:
163
        continue
164
    xlines.append(value)
165
    output.write(value+lineseparator)
166
output.write(lineseparator)
167

  
168
#--- define the methods ----------------------------------------------------------------------------
169
for system in 'high', 'low':
170
    for data in data_collection:
171
        if data.__name__ == system+"-level":
172
            output.write(system+"Level = "+data.str_class+"("+data.str_option+")"+lineseparator)
173
output.write(lineseparator)
174

  
175
#--- qmx class (substraction scheme ----------------------------------------------------------------
176
for data in data_collection:
177
    if data.__name__ == "qmx":
178
        output.write("qmx = "+data.str_class+"("+data.str_option+")"+lineseparator)
179
output.write(lineseparator)
180

  
181
#--- read all the systems --------------------------------------------------------------------------
182
for system in "cluster", "system":
183
    for data in data_collection:
184
        if data.__name__ == system:
185
            if data.str_structure is None:
186
                continue
187
            output.write(system+" = "+data.str_class+"(\""+data.str_structure+"\")"+lineseparator)
188
output.write(lineseparator)
189

  
190
#--- embeding class --------------------------------------------------------------------------------
191
for data in data_collection:
192
    if data.__name__ == "embed":
193
        output.write("embed = "+data.str_class+"("+data.str_option+")"+lineseparator)
194
        for method in data.str_methods:
195
            output.write("embed."+method+lineseparator)
196
output.write(lineseparator)
197

  
198
#--- dynamics class --------------------------------------------------------------------------------
199
for data in data_collection:
200
    if data.__name__ == "dynamics":
201
        output.write("dyn="+data.str_class+"(embed)"+lineseparator)
202
        output.write("dyn.run("+data.str_option+")"+lineseparator)
203

  
142
    
143
writeData(output, definitions)
204 144
output.close()
205
sys.exit(0)
145

  
prepareQMX/prepareQMX.GUI.py (revision 13)
123 123
        self.frames.append(frame)
124 124

  
125 125
        icol+=1
126
        for label in ['High-Level', 'Low-Level']:
126
        for label in ['Low-Level', 'High-Level']:
127 127
            def_list=calcDefinitions
128 128
            frame=MyLabelFrame(self, bigFrame, label, def_list, None)
129 129
            frame.doLayout()
......
152 152

  
153 153
        frame = Frame(self)
154 154

  
155
        image = PhotoImage(file="exit.gif")
156
        buttonExit=Button(frame, image=image, command=self.quit)
157
        buttonExit.image = image
155
        #image = PhotoImage(file="exit.gif")
156
        buttonExit=Button(frame, text="Quit!", command=self.quit)
157
        #buttonExit.image = image
158 158
        buttonExit.grid(row=1, column = 1, rowspan=2, sticky= W+E+N+S)
159 159
        
160 160
        buttonSave=Button(frame, text='save settings', state=DISABLED)
ase/embed.py (revision 13)
1
"""
2
This module is the EMBED module for ASE
3
implemented by T. Kerber
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

  
1 11
import math
2 12
from ase import Atom, Atoms
3 13
from ase.data import covalent_radii, atomic_numbers
ase/calculators/mopac.py (revision 13)
1 1
"""
2
This module is the MOPAC module for ASE, 
3
based on the PyMD MOPAC Module by R. Bulo, 
2
This module is the MOPAC module for ASE, based on the PyMD MOPAC Module by R. Bulo, 
4 3
implemented by T. Kerber
5 4

  
6
2011, ENS Lyon
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)
7 9
"""
8 10
import commands
9 11
import numpy as np
10 12

  
11
from copy import deepcopy
12

  
13 13
from ase.atoms import Atoms
14 14
from ase.units import kcal, mol
15 15
from ase.calculators.general import Calculator
ase/calculators/qmx.py (revision 13)
1
""" This is a QM:MM embedded system for ASE
1
"""
2
This module is the EMBED module for ASE
3
implemented by T. Kerber
2 4

  
3
torsten.kerber@ens-lyon.fr
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)
4 9
"""
5

  
6 10
import ase
7 11
import ase.atoms
8 12
import numpy as np
ase/calculators/turbomole.py (revision 13)
1
"""This module defines an ASE interface to Turbomole
2
http://www.turbomole.com/
3 1
"""
2
This module is the EMBED module for ASE
3
implemented by T. Kerber
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
"""
4 10
import os, sys, string
5 11

  
6 12
from ase.units import Hartree, Bohr

Formats disponibles : Unified diff