-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdriver.py
144 lines (129 loc) · 6.29 KB
/
driver.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
"""
RSHtune - Driver.
Driver script for the RSHtune package
DependenciesL os, sys, argparse, RSHtune (on PYTHONPATH)
"""
import os
import sys
import RSHtune as tune
import argparse as argp
def dryRun(inputFile: str, dir: str = "",
multiplicities: list[int] = []) -> None:
"""Navigate to a directory and analyze tuning files already present."""
if dir != "":
os.chdir(dir)
_dirContents = os.listdir('.')
_omega = {float(i.split("_")[0].split('w')[1])/1000 for i in _dirContents
if i.split(".")[-1] == "out"
and f"{i.split('_')[0]}_neutral.out" in _dirContents
and f"{i.split('_')[0]}_anion.out" in _dirContents
and f"{i.split('_')[0]}_cation.out" in _dirContents}
print(f"#omega J_OT\n{22*'#'}")
for _o in sorted(list(_omega)):
if multiplicities != []:
tuning_run = tune.QchemTuning(fname=inputFile,
omega=_o,
nthreads=1,
neutralSpMlt=multiplicities[0],
anionSpMlt=multiplicities[1],
cationSpMlt=multiplicities[2],
loggerLevel="WARNING")
else:
tuning_run = tune.QchemTuning(fname=inputFile,
omega=_o,
nthreads=1,
loggerLevel="WARNING")
try:
tuning_run.parseOutput()
tuning_run.calculateOptimalTuning()
print(f"{_o:.3f} {tuning_run.data['tuning']['JOT']:.4E}")
except ValueError:
print(f"{_o:.3f} ERROR")
def singlePoint(inputFile: str, nthreads: int,
omega: float, dir: str = "",
multiplicities: list[int] = []) -> None:
"""Run a single tuning calculation for a given value of omega."""
if dir != "":
os.chdir(dir)
if multiplicities != []:
tuning_run = tune.QchemTuning(fname=inputFile,
omega=omega,
nthreads=nthreads,
neutralSpMlt=multiplicities[0],
anionSpMlt=multiplicities[1],
cationSpMlt=multiplicities[2],
loggerLevel="WARNING")
else:
tuning_run = tune.QchemTuning(fname=inputFile,
omega=omega,
nthreads=nthreads,
loggerLevel="WARNING")
print(f"#omega J_OT\n{22*'#'}")
tuning_run.runCalculations()
try:
tuning_run.parseOutput()
tuning_run.calculateOptimalTuning()
print(f"{omega:.3f} {tuning_run.data['tuning']['JOT']:.4E}")
except ValueError:
print(f"{omega:.3f} ERROR")
def rangeTuning(inputFile: str, nthreads: int,
omega: list, dir: str = "",
multiplicities: list[int] = []) -> None:
"""Run a series of tuning calculation over a range of omega."""
if dir != "":
os.chdir(dir)
print(f"#omega J_OT\n{22*'#'}")
for _o in omega:
if multiplicities != []:
tuning_run = tune.QchemTuning(fname=inputFile,
omega=_o,
nthreads=nthreads,
neutralSpMlt=multiplicities[0],
anionSpMlt=multiplicities[1],
cationSpMlt=multiplicities[2],
loggerLevel="WARNING")
else:
tuning_run = tune.QchemTuning(fname=inputFile,
omega=_o,
nthreads=nthreads,
loggerLevel="WARNING")
tuning_run.runCalculations()
try:
tuning_run.parseOutput()
tuning_run.calculateOptimalTuning()
print(f"""{_o:.3f} {tuning_run.data['tuning']['JOT']:.4E}""")
except ValueError:
print(f"""{_o:.3f} ERROR""")
if __name__ == "__main__":
"""Invoke a tuning instance using arguments from the command line."""
parser = argp.ArgumentParser(description="""Driver for the RSHtune package
for tuning RSH functionals using QChem.""")
parser.add_argument("--inputFile", type=str, required=True, metavar="file",
help="NEUTRAL calculation input file. Respects --dir!")
parser.add_argument("--numThreads", type=int, default=1,
metavar="int", help="Number of CPU threads for Qchem.")
parser.add_argument("--omega", type=float, default=None,
metavar="float", help="Single value for omega.")
parser.add_argument("--omegaRange", type=float, nargs="*",
metavar="float", help="Range of omega values.")
parser.add_argument("--dir", type=str, default="", metavar="dir",
help="Working directory if different to CWD.")
parser.add_argument("--multiplicities", nargs=3, type=int, default=[],
metavar="int int int",
help="Spin-multiplicities: neutral anion cation.")
parser.add_argument("--dry", action="store_true", default=False,
help="Analyze files present in directory.")
args = parser.parse_args()
if args.dry:
print(f"# Printing completed tuning runs in directory <{args.dir}>")
dryRun(args.inputFile, args.dir, args.multiplicities)
if args.omega and args.omegaRange:
sys.exit("Choose either --omega or --omegaRange")
if args.omega:
print(f"# Single point tuning claculation at omega={args.omega}.")
singlePoint(args.inputFile, args.numThreads, args.omega, args.dir,
args.multiplicities)
if args.omegaRange:
print(f"# Tuning calculations over range omega={args.omegaRange}.")
rangeTuning(args.inputFile, args.numThreads, args.omegaRange, args.dir,
args.multiplicities)