Skip to content

Commit e3c756e

Browse files
committed
parse grad from 131.0 file as well plus new test
1 parent 7370ccf commit e3c756e

File tree

6 files changed

+695
-12
lines changed

6 files changed

+695
-12
lines changed

atomate/qchem/firetasks/parse_outputs.py

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -100,23 +100,47 @@ def run_task(self, fw_spec):
100100
grad_file = os.path.join(calc_dir, "scratch/GRAD.gz")
101101
elif os.path.exists(os.path.join(calc_dir, "scratch/GRAD")):
102102
grad_file = os.path.join(calc_dir, "scratch/GRAD")
103+
elif os.path.exists(os.path.join(calc_dir, "131.0.gz")):
104+
grad_file = os.path.join(calc_dir, "131.0.gz")
105+
elif os.path.exists(os.path.join(calc_dir, "131.0")):
106+
grad_file = os.path.join(calc_dir, "131.0")
107+
elif os.path.exists(os.path.join(calc_dir, "scratch/131.0.gz")):
108+
grad_file = os.path.join(calc_dir, "scratch/131.0.gz")
109+
elif os.path.exists(os.path.join(calc_dir, "scratch/131.0")):
110+
grad_file = os.path.join(calc_dir, "scratch/131.0")
103111

104112
if grad_file is None:
105113
task_doc["warnings"]["grad_file_missing"] = True
106114
else:
107115
grad = []
108-
with zopen(grad_file, mode="rt", encoding="ISO-8859-1") as f:
109-
lines = f.readlines()
110-
for line in lines:
111-
split_line = line.split()
112-
if len(split_line) == 3:
113-
grad.append(
114-
[
115-
float(split_line[0]),
116-
float(split_line[1]),
117-
float(split_line[2]),
118-
]
119-
)
116+
if grad_file[-5:] == "131.0" or grad_file[-8:] == "131.0.gz":
117+
tmp_grad_data = []
118+
with zopen(grad_file, mode="rb") as file:
119+
binary = file.read()
120+
for ii in range(int(len(binary)/8)):
121+
tmp_grad_data.append(struct.unpack("d",binary[ii*8:(ii+1)*8])[0])
122+
grad = []
123+
for ii in range(int(len(tmp_grad_data)/3)):
124+
grad.append(
125+
[
126+
float(tmp_grad_data[ii*3]),
127+
float(tmp_grad_data[ii*3+1]),
128+
float(tmp_grad_data[ii*3+2])
129+
]
130+
)
131+
else:
132+
with zopen(grad_file, mode="rt", encoding="ISO-8859-1") as f:
133+
lines = f.readlines()
134+
for line in lines:
135+
split_line = line.split()
136+
if len(split_line) == 3:
137+
grad.append(
138+
[
139+
float(split_line[0]),
140+
float(split_line[1]),
141+
float(split_line[2]),
142+
]
143+
)
120144
task_doc["output"]["precise_gradients"] = grad
121145
if os.path.exists(os.path.join(calc_dir, "scratch")):
122146
shutil.rmtree(os.path.join(calc_dir, "scratch"))

atomate/qchem/firetasks/tests/test_parse_outputs.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717

1818

1919
class TestParseOutputQChem(AtomateTest):
20+
def setUp(self, lpad=False):
21+
super().setUp(lpad=False)
22+
23+
def tearDown(self):
24+
pass
25+
2026
def test_parse_grad_good(self):
2127
my_calc_dir = os.path.join(module_dir, "..", "..", "test_files","parse_grad_good")
2228
ft = QChemToDb(calc_dir=my_calc_dir, parse_grad_file=True)
@@ -28,6 +34,17 @@ def test_parse_grad_good(self):
2834
self.assertEqual(task_doc["output"]["precise_gradients"][-1], [0.0014495621906601, -0.0018570062958895, 0.0012478282193499])
2935
os.remove(os.path.join(my_calc_dir, "task.json"))
3036

37+
def test_parse_grad_131(self):
38+
my_calc_dir = os.path.join(module_dir, "..", "..", "test_files","tmqm_grad_pcm")
39+
ft = QChemToDb(calc_dir=my_calc_dir, parse_grad_file=True)
40+
ft.run_task({})
41+
task_doc = loadfn(os.path.join(my_calc_dir,"task.json"))
42+
self.assertEqual(task_doc["output"]["final_energy"], -2791.8404057999)
43+
self.assertEqual(len(task_doc["output"]["precise_gradients"]), 25)
44+
self.assertEqual(task_doc["output"]["precise_gradients"][0], [-2.7425178677332305e-05, 1.8017443772144412e-06, -2.3689773769176685e-06])
45+
self.assertEqual(task_doc["output"]["precise_gradients"][-1], [0.0028753270363098644, -0.000392640066359285, 0.004405091870637312])
46+
os.remove(os.path.join(my_calc_dir, "task.json"))
47+
3148
def test_parse_grad_bad(self):
3249
my_calc_dir = os.path.join(module_dir, "..", "..", "test_files","parse_grad_bad")
3350
ft = QChemToDb(calc_dir=my_calc_dir, parse_grad_file=True)
600 Bytes
Binary file not shown.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash -l
2+
#SBATCH --qos=condo_blau
3+
#SBATCH -p lr6
4+
#SBATCH --time=24:00:00
5+
#SBATCH --nodes=1
6+
#SBATCH --ntasks-per-node=40
7+
#SBATCH --account=lr_blau
8+
##SBATCH -C lr6_m192
9+
##SBATCH --mem=185G
10+
#SBATCH -J direct
11+
12+
module load qchem/6.0.2
13+
export QCTHREADS=40
14+
export OMP_NUM_THREADS=40
15+
export QCSCRATCH=/global/home/groups/lr_mp/smblau/direct_testing/tmqm_grad_pcm
16+
export QCLOCALSCR=/tmp
17+
export KMP_INIT_AT_FORK=FALSE
18+
export NBOEXE=/clusterfs/mp/software/nbo7/bin/nbo7.i4.exe
19+
rm -rf /tmp/scratch
20+
qchem -save -nt 40 mol.qin mol.out scratch
21+
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
$molecule
2+
0 3
3+
Ni -1.8682000000 2.3072000000 5.1235000000
4+
S -3.6919000000 3.1368000000 6.1126000000
5+
N -0.8026000000 3.5955000000 6.5021000000
6+
H -0.1140000000 3.0689000000 7.0512000000
7+
H -0.2749000000 4.2751000000 5.9396000000
8+
N -1.6162000000 4.3303000000 7.4160000000
9+
N -3.7322000000 4.8417000000 8.0960000000
10+
H -4.7165000000 4.7293000000 7.9269000000
11+
C -2.8846000000 4.1812000000 7.2902000000
12+
C -3.2583000000 5.7554000000 9.1029000000
13+
H -2.6430000000 6.5323000000 8.6440000000
14+
H -4.1028000000 6.2091000000 9.6123000000
15+
H -2.6383000000 5.2197000000 9.8239000000
16+
S -0.0445000000 1.4776000000 4.1344000000
17+
C -0.8520000000 0.4332000000 2.9568000000
18+
N -2.1204000000 0.2841000000 2.8310000000
19+
N -2.9332000000 1.0188000000 3.7449000000
20+
H -3.6227000000 1.5457000000 3.1956000000
21+
H -3.4618000000 0.3391000000 4.3076000000
22+
N -0.0041000000 -0.2271000000 2.1513000000
23+
H 0.9799000000 -0.1149000000 2.3200000000
24+
C -0.4781000000 -1.1407000000 1.1442000000
25+
H -1.0938000000 -1.9182000000 1.6032000000
26+
H 0.3666000000 -1.5949000000 0.6345000000
27+
H -1.0984000000 -0.6051000000 0.4229000000
28+
$end
29+
30+
$rem
31+
job_type = force
32+
basis = def2-svpd
33+
max_scf_cycles = 100
34+
gen_scfman = true
35+
xc_grid = 3
36+
thresh = 14
37+
s2thresh = 16
38+
scf_algorithm = gdm
39+
scf_convergence = 6
40+
resp_charges = false
41+
symmetry = false
42+
sym_ignore = true
43+
method = wb97mv
44+
ecp = def2-ecp
45+
solvent_method = pcm
46+
$end
47+
48+
$pcm
49+
heavypoints 194
50+
hpoints 194
51+
radii uff
52+
theory cpcm
53+
vdwscale 1.1
54+
$end
55+
56+
$solvent
57+
dielectric 3.0
58+
$end

0 commit comments

Comments
 (0)