-
Notifications
You must be signed in to change notification settings - Fork 0
/
wavejam.py
executable file
·82 lines (69 loc) · 2.55 KB
/
wavejam.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
#!/usr/bin/python3
"""Convert wavefunction files using MultiWFN."""
import argparse
from functools import partial
import os
import subprocess
def convert(infile, outfile):
"""Convert wavefunction files.
Parameters
----------
infile, outfile : str
"""
inbase, inext = os.path.splitext(infile)
inext = inext[1:]
outbase, outext = os.path.splitext(outfile)
outext = outext[1:]
if inext == "gbw":
if outext == "mkl":
p = subprocess.run(
["orca_2mkl", inbase, "-mkl"], stdout=subprocess.PIPE
)
elif outext == "molden":
p = subprocess.run(
["orca_2mkl", inbase, "-molden"], stdout=subprocess.PIPE
)
os.rename(f"{inbase}.molden.input", outfile)
elif inext == "mkl":
if outext == "gbw":
p = subprocess.run(
["orca_2mkl", inbase, "-gbw"], stdout=subprocess.PIPE
)
else:
# TODO(schneiderfelipe): convert to pdb using OpenBabel? If possible,
# the result is improved, but use the code below if something fails.
selector = """100 // Other functions (Part 1)
2 // Export various files...
{code} // Output current wavefunction as...
{outfile}
0 // Return
q // Exit program gracefully"""
input = {
"pdb": partial(selector.format, code="1"),
"xyz": partial(selector.format, code="2"),
"chg": partial(selector.format, code="3"),
"wfx": partial(selector.format, code="4"),
"wfn": partial(selector.format, code="5"),
"molden": partial(selector.format, code="6"),
"fch": partial(selector.format, code="7"),
"47": partial(selector.format, code="8"),
"mkl": partial(selector.format, code="9"),
}
p = subprocess.run(
["Multiwfn", infile],
stdout=subprocess.PIPE,
input=input[outext](outfile=outfile),
encoding="ascii",
)
# os.rename(f"{inbase}.{outext}", outfile)
if p.returncode:
raise ValueError(f"conversion {p.args} failed: {p.stdout}")
def main():
"""Run main procedure."""
parser = argparse.ArgumentParser()
parser.add_argument("infile")
parser.add_argument("-O", "--outfile", help="specify the output file")
args = parser.parse_args()
convert(args.infile, args.outfile)
if __name__ == "__main__":
main()