-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_cube
More file actions
executable file
·82 lines (63 loc) · 1.92 KB
/
create_cube
File metadata and controls
executable file
·82 lines (63 loc) · 1.92 KB
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/env -S uv run --script
import argparse
from tempfile import NamedTemporaryFile
import subprocess
import re
import sys
# edit this template for fine tuning
template = """\
1 # select type:
1 # MO
5 # select output format:
7 # cube
4 # select resolution
{grid} # ngrid
2 # select orbital number
{index} # orbital index
10 # create file
11 # quit program"""
def call_orca_plot(orb_idx, gbw, grid):
"call orca_plot for orbitals orb_idx with operator spin on file gbw with grid"
with NamedTemporaryFile(mode="w+") as f: # only write temporary file
content = template.format(grid=grid, index=orb_idx)
f.write(content)
f.seek(0) # reset file pointer for reading
subprocess.run(["orca_plot", gbw, "-i"], stdin=f, stdout=subprocess.DEVNULL)
print(
"INFO: Plotted orbital {} from {} using grid {}".format(
orb_idx, gbw, grid
)
)
def expand_range(inp_str):
inp_split = inp_str.split("-")
int_list = list(range(int(inp_split[0]), int(inp_split[1]) + 1))
str_list = [str(i) for i in int_list]
return str_list
def convert_list(inp_str):
inp_split = inp_str.split(",")
res_list = []
for i in inp_split:
if "-" in i:
res_list.extend(expand_range(i))
else:
res_list.append(i)
return res_list
def run():
parser = argparse.ArgumentParser(description="create cube from gbw")
parser.add_argument("orca_gbw", metavar="ORCA_GBW", help="ORCA gbw file")
parser.add_argument(
"-g", "--grid", metavar="N", default=60, help="number of grid points"
)
parser.add_argument(
"--index",
nargs='+',
type=str,
help="A list of MO's to plot (space-separated)"
)
args = parser.parse_args()
grid = args.grid
gbw = args.orca_gbw
for i in args.index:
call_orca_plot(orb_idx=i, gbw=gbw, grid=grid)
if __name__ == "__main__":
run()