-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathorca.py
401 lines (350 loc) · 10.4 KB
/
orca.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
"""
/******************************************************************************
This source file is part of the Avogadro project.
This source code is released under the New BSD License, (the "License").
******************************************************************************/
"""
import argparse
import json
import sys
# Some globals:
targetName = "ORCA"
debug = False
def getOptions():
userOptions = {"tabName": "Basic"}
userOptions["Title"] = {
"type": "string",
"default": "",
"toolTip": "Title of the input file",
}
userOptions["Processor Cores"] = {
"type": "integer",
"default": 1,
"minimum": 1,
}
userOptions["Memory"] = {
"type": "integer",
"default": 16,
"minimum": 1,
}
userOptions["Calculation Type"] = {
"type": "stringList",
"default": 1,
"values": [
"Single Point",
"Geometry Optimization",
"Frequencies",
"Transition State",
"Dynamics",
],
"toolTip": "Type of calculation to perform",
}
userOptions["Print Molecular Orbitals"] = {
"type": "boolean",
"default": False,
}
userOptions["Theory"] = {
"type": "stringList",
"default": 7,
"values": [
"HF",
"MP2",
"CCSD",
"CCSD(T)",
"BLYP",
"PBE",
"PBE0",
"revPBE",
"B3LYP",
"B97-3C",
"M06L",
"M062X",
"wB97X-D3",
],
}
userOptions["RI Approximation"] = {
"type": "stringList",
"default": 0,
"values": ["None", "NORI", "RIJK", "RIJONX", "RIJCOSX"],
}
userOptions["Dispersion Correction"] = {
"type": "stringList",
"default": 0,
"values": ["None", "D3ZERO", "D3BJ", "D4"],
"toolTip": "Any added dispersion corrections",
"hide": True,
}
userOptions["Basis"] = {
"type": "stringList",
"default": 8,
"values": [
"6-31G(d)",
"cc-pVDZ",
"cc-pVTZ",
"cc-pVQZ",
"aug-cc-pVDZ",
"aug-cc-pVTZ",
"aug-cc-pVQZ",
"def2-SVP",
"def2-TZVP",
"def2-QZVP",
"def2-TZVPP",
"def2-QZVPP",
"def2-TZVPPD",
"def2-QZVPPD",
"ma-def2-SVP",
"ma-def2-TZVP",
"ma-def2-QZVP",
],
"toolTip": "Gaussian basis set",
}
userOptions["Solvation"] = {
"type": "stringList",
"default": 0,
"values": [
"None (gas)",
"-",
"Water",
"Acetonitrile",
"Acetone",
"Ethanol",
"Methanol",
"CCl4",
"CH2Cl2",
"Chloroform",
"DMSO",
"DMF",
"Hexane",
"Toluene",
"Pyridine",
"THF",
"Toluene",
],
"toolTip": "Solvent Model",
}
userOptions["Solvation Type"] = {
"type": "stringList",
"default": 0,
"values": ["CPCM", "SMD"],
"toolTip": "Solvent model",
}
userOptions["Filename Base"] = {
"type": "string",
"default": "job",
}
userOptions["Charge"] = {
"type": "integer",
"default": 0,
"minimum": -9,
"maximum": 9,
"toolTip": "Total charge of the system",
}
userOptions["Multiplicity"] = {
"type": "integer",
"default": 1,
"minimum": 1,
"maximum": 6,
"toolTip": "Total spin multiplicity of the system",
}
userOptions["AutoAux"] = {
"type": "boolean",
"default": False,
"toolTip": "Automatically select auxiliary basis set",
}
aimdOptions = {"tabName": "Dynamics"}
aimdOptions["AIMD TimeStep"] = {
"type": "string",
"default": "0.5_fs",
}
aimdOptions["AIMD Initvel"] = {
"type": "string",
"default": "350",
}
aimdOptions["AIMD Thermostat Temp"] = {
"type": "integer",
"default": 300,
"maximum": 1000,
"minimum": 0,
}
aimdOptions["AIMD Thermostat Time"] = {
"type": "string",
"default": "10_fs",
}
aimdOptions["AIMD RunTime"] = {
"type": "integer",
"default": 200,
}
opts = {"userOptions": [userOptions, aimdOptions]}
return opts
def generateInputFile(opts):
# Extract options:
title = opts["Title"]
calculate = opts["Calculation Type"]
theory = opts["Theory"]
basis = opts["Basis"]
charge = opts["Charge"]
multiplicity = opts["Multiplicity"]
nCores = int(opts["Processor Cores"])
memory = int((opts["Memory"] * 1024) / nCores)
solvtype = opts["Solvation Type"]
solvent = opts["Solvation"]
mos = opts["Print Molecular Orbitals"]
autoaux = opts["AutoAux"]
disp = opts["Dispersion Correction"]
ri = opts["RI Approximation"]
auxbasis = "None"
rijbasis = {
"6-31G(d)": "AutoAux",
"cc-pVDZ": "Def2/J",
"cc-pVTZ": "Def2/J",
"cc-pVQZ": "Def2/J",
"aug-cc-pVDZ": "AutoAux",
"aug-cc-pVTZ": "AutoAux",
"aug-cc-pVQZ": "AutoAux",
"def2-SVP": "Def2/J",
"def2-TZVP": "Def2/J",
"def2-QZVP": "Def2/J",
"def2-TZVPP": "Def2/J",
"def2-QZVPP": "Def2/J",
"def2-TZVPPD": "AutoAux",
"def2-QZVPPD": "AutoAux",
"ma-def2-SVP": "AutoAux",
"ma-def2-TZVP": "AutoAux",
"ma-def2-QZVP": "AutoAux",
}
rijkbasis = {
"6-31G(d)": "AutoAux",
"cc-pVDZ": "cc-pVDZ/JK",
"cc-pVTZ": "cc-pVTZ/JK",
"cc-pVQZ": "cc-pVQZ/JK",
"aug-cc-pVDZ": "aug-cc-pVDZ/JK",
"aug-cc-pVTZ": "aug-cc-pVTZ/JK",
"aug-cc-pVQZ": "aug-cc-pVQZ/JK",
"def2-SVP": "Def2/JK",
"def2-TZVP": "Def2/JK",
"def2-QZVP": "Def2/JK",
"def2-TZVPP": "Def2/JK",
"def2-QZVPP": "Def2/JK",
"def2-TZVPPD": "aug-cc-pVTZ/JK",
"def2-QZVPPD": "aug-cc-pVQZ/JK",
"ma-def2-SVP": "aug-cc-pVDZ/JK",
"ma-def2-TZVP": "aug-cc-pVTZ/JK",
"ma-def2-QZVP": "aug-cc-pVQZ/JK",
}
# Convert to code-specific strings
calcStr = ""
if calculate == "Single Point":
calcStr = "SP"
elif calculate == "Geometry Optimization":
calcStr = "Opt"
elif calculate == "Frequencies":
calcStr = "Opt Freq"
elif calculate == "Dynamics":
calcStr = "MD"
elif calculate == "Transition State":
calcStr = "OptTS"
else:
raise Exception("Unhandled calculation type: %s" % calculate)
solvation = ""
if not "None" in opts["Solvation"] and solvtype == "CPCM":
solvation = "CPCM(" + solvent + ")"
elif not "None" in opts["Solvation"] and solvtype == "SMD":
solvation = "CPCM"
if disp == "None":
disp = ""
else:
disp = " " + disp
if ri in ["None"]:
autoaux = False
ri = ""
# see https://discuss.avogadro.cc/t/orca-input-generator-does-not-print-nori-when-selected/5489
elif ri in ["NORI"]:
autoaux = False
ri = " " + ri
else:
if ri in ["RIJONX", "RIJCOSX"]:
auxbasis = rijbasis[basis]
else:
auxbasis = rijkbasis[basis]
ri = " " + ri
if autoaux == True:
auxbasis = "AutoAux"
if auxbasis != "None":
basis = basis + " " + auxbasis
theory = theory + disp + ri
# put the pieces together
code = f"{calcStr} {theory} {basis} {solvation}"
output = ""
output += "# avogadro generated ORCA file\n"
output += "# " + title + "\n"
output += "# \n"
output += f"! {code}\n\n"
output += "%maxcore " + str(memory) + "\n\n"
output += "%pal\n"
output += " nprocs " + str(nCores) + "\n"
output += "end\n\n"
if not "None" in opts["Solvation"] and solvtype == "SMD":
output += "%cpcm\n"
output += " smd true\n"
output += ' SMDSolvent "' + solvent + '"\n'
output += "end\n\n"
if calcStr == "MD":
output += "%md\n"
output += " timestep " + opts["AIMD TimeStep"] + "\n"
output += " initvel " + opts["AIMD Initvel"] + "_k\n"
output += (
" thermostat berendsen "
+ str(opts["AIMD Thermostat Temp"])
+ "_k timecon "
+ opts["AIMD Thermostat Time"]
+ "\n"
)
output += ' dump position stride 1 filename "trajectory.xyz"\n'
output += " run " + str(opts["AIMD RunTime"]) + "\n"
output += "end\n\n"
if mos == True:
output += "%output\n"
output += " print[p_mos] 1\n"
output += " print[p_basis] 2\n"
output += "end\n\n"
output += f"* xyz {charge} {multiplicity}\n"
output += "$$coords:___Sxyz$$\n"
output += "*\n\n\n"
return output
def generateInput():
# Read options from stdin
stdinStr = sys.stdin.read()
# Parse the JSON strings
opts = json.loads(stdinStr)
# Generate the input file
inp = generateInputFile(opts["options"])
# Basename for input files:
baseName = opts["options"]["Filename Base"]
# Prepare the result
result = {}
# Input file text -- will appear in the same order in the GUI as they are
# listed in the array:
files = []
files.append({"filename": "%s.inp" % baseName, "contents": inp})
if debug:
files.append({"filename": "debug_info", "contents": stdinStr})
result["files"] = files
# Specify the main input file. This will be used by MoleQueue to determine
# the value of the $$inputFileName$$ and $$inputFileBaseName$$ keywords.
result["mainFile"] = "%s.inp" % baseName
return result
if __name__ == "__main__":
parser = argparse.ArgumentParser("Generate a %s input file." % targetName)
parser.add_argument("--debug", action="store_true")
parser.add_argument("--print-options", action="store_true")
parser.add_argument("--generate-input", action="store_true")
parser.add_argument("--display-name", action="store_true")
parser.add_argument("--lang", nargs="?", default="en")
args = vars(parser.parse_args())
debug = args["debug"]
if args["display_name"]:
print(targetName)
if args["print_options"]:
print(json.dumps(getOptions()))
elif args["generate_input"]:
print(json.dumps(generateInput()))