1
1
import os
2
2
import shutil
3
- import unittest
4
3
5
- from pymatgen .core import Molecule
6
- from pymatgen .io .qchem .inputs import QCInput
4
+ from monty .serialization import loadfn
7
5
8
6
from atomate .qchem .firetasks .parse_outputs import QChemToDb
9
7
from atomate .utils .testing import AtomateTest
10
8
11
- from monty .serialization import loadfn
12
-
13
9
__author__ = "Samuel Blau"
14
10
15
11
@@ -24,62 +20,122 @@ def tearDown(self):
24
20
pass
25
21
26
22
def test_parse_grad_good (self ):
27
- my_calc_dir = os .path .join (module_dir , ".." , ".." , "test_files" ,"parse_grad_good" )
23
+ my_calc_dir = os .path .join (
24
+ module_dir , ".." , ".." , "test_files" , "parse_grad_good"
25
+ )
28
26
ft = QChemToDb (calc_dir = my_calc_dir , parse_grad_file = True )
29
27
ft .run_task ({})
30
- task_doc = loadfn (os .path .join (my_calc_dir ,"task.json" ))
28
+ task_doc = loadfn (os .path .join (my_calc_dir , "task.json" ))
31
29
self .assertEqual (task_doc ["output" ]["final_energy" ], - 274.6893362188 )
32
30
self .assertEqual (len (task_doc ["output" ]["precise_gradients" ]), 10 )
33
- self .assertEqual (task_doc ["output" ]["precise_gradients" ][0 ], [0.0090906486788787 , 0.016150932052898 , 0.0054568671405536 ])
34
- self .assertEqual (task_doc ["output" ]["precise_gradients" ][- 1 ], [0.0014495621906601 , - 0.0018570062958895 , 0.0012478282193499 ])
31
+ self .assertEqual (
32
+ task_doc ["output" ]["precise_gradients" ][0 ],
33
+ [0.0090906486788787 , 0.016150932052898 , 0.0054568671405536 ],
34
+ )
35
+ self .assertEqual (
36
+ task_doc ["output" ]["precise_gradients" ][- 1 ],
37
+ [0.0014495621906601 , - 0.0018570062958895 , 0.0012478282193499 ],
38
+ )
35
39
os .remove (os .path .join (my_calc_dir , "task.json" ))
36
40
37
41
def test_parse_grad_131 (self ):
38
- my_calc_dir = os .path .join (module_dir , ".." , ".." , "test_files" ,"tmqm_grad_pcm" )
42
+ my_calc_dir = os .path .join (
43
+ module_dir , ".." , ".." , "test_files" , "tmqm_grad_pcm"
44
+ )
39
45
ft = QChemToDb (calc_dir = my_calc_dir , parse_grad_file = True )
40
46
ft .run_task ({})
41
- task_doc = loadfn (os .path .join (my_calc_dir ,"task.json" ))
47
+ task_doc = loadfn (os .path .join (my_calc_dir , "task.json" ))
42
48
self .assertEqual (task_doc ["output" ]["final_energy" ], - 2791.8404057999 )
43
49
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 ])
50
+ self .assertEqual (
51
+ task_doc ["output" ]["precise_gradients" ][0 ],
52
+ [- 2.7425178677332305e-05 , 1.8017443772144412e-06 , - 2.3689773769176685e-06 ],
53
+ )
54
+ self .assertEqual (
55
+ task_doc ["output" ]["precise_gradients" ][- 1 ],
56
+ [0.0028753270363098644 , - 0.000392640066359285 , 0.004405091870637312 ],
57
+ )
46
58
os .remove (os .path .join (my_calc_dir , "task.json" ))
47
59
48
60
def test_parse_grad_bad (self ):
49
- my_calc_dir = os .path .join (module_dir , ".." , ".." , "test_files" ,"parse_grad_bad" )
61
+ my_calc_dir = os .path .join (
62
+ module_dir , ".." , ".." , "test_files" , "parse_grad_bad"
63
+ )
50
64
ft = QChemToDb (calc_dir = my_calc_dir , parse_grad_file = True )
51
65
ft .run_task ({})
52
- task_doc = loadfn (os .path .join (my_calc_dir ,"task.json" ))
66
+ task_doc = loadfn (os .path .join (my_calc_dir , "task.json" ))
53
67
self .assertEqual (task_doc ["warnings" ]["grad_file_missing" ], True )
54
68
os .remove (os .path .join (my_calc_dir , "task.json" ))
55
69
56
70
57
71
class TestParseOutputQChem_hess (AtomateTest ):
58
72
def setUp (self , lpad = False ):
59
- os .makedirs (os .path .join (module_dir , ".." , ".." , "test_files" , "freq_save_hess" , "scratch" ))
73
+ os .makedirs (
74
+ os .path .join (
75
+ module_dir , ".." , ".." , "test_files" , "freq_save_hess" , "scratch"
76
+ )
77
+ )
60
78
shutil .copyfile (
61
- os .path .join (module_dir , ".." , ".." , "test_files" , "freq_save_hess" , "BUP_scratch" , "132.0" ),
62
- os .path .join (module_dir , ".." , ".." , "test_files" , "freq_save_hess" , "scratch" , "132.0" ),
79
+ os .path .join (
80
+ module_dir ,
81
+ ".." ,
82
+ ".." ,
83
+ "test_files" ,
84
+ "freq_save_hess" ,
85
+ "BUP_scratch" ,
86
+ "132.0" ,
87
+ ),
88
+ os .path .join (
89
+ module_dir ,
90
+ ".." ,
91
+ ".." ,
92
+ "test_files" ,
93
+ "freq_save_hess" ,
94
+ "scratch" ,
95
+ "132.0" ,
96
+ ),
63
97
)
64
98
shutil .copyfile (
65
- os .path .join (module_dir , ".." , ".." , "test_files" , "freq_save_hess" , "BUP_scratch" , "HESS" ),
66
- os .path .join (module_dir , ".." , ".." , "test_files" , "freq_save_hess" , "scratch" , "HESS" ),
99
+ os .path .join (
100
+ module_dir ,
101
+ ".." ,
102
+ ".." ,
103
+ "test_files" ,
104
+ "freq_save_hess" ,
105
+ "BUP_scratch" ,
106
+ "HESS" ,
107
+ ),
108
+ os .path .join (
109
+ module_dir ,
110
+ ".." ,
111
+ ".." ,
112
+ "test_files" ,
113
+ "freq_save_hess" ,
114
+ "scratch" ,
115
+ "HESS" ,
116
+ ),
67
117
)
68
118
super ().setUp (lpad = False )
69
119
70
120
def test_parse_hess (self ):
71
- my_calc_dir = os .path .join (module_dir , ".." , ".." , "test_files" ,"freq_save_hess" )
121
+ my_calc_dir = os .path .join (
122
+ module_dir , ".." , ".." , "test_files" , "freq_save_hess"
123
+ )
72
124
ft = QChemToDb (calc_dir = my_calc_dir , parse_hess_file = True )
73
125
ft .run_task ({})
74
- task_doc = loadfn (os .path .join (my_calc_dir ,"task.json" ))
126
+ task_doc = loadfn (os .path .join (my_calc_dir , "task.json" ))
75
127
self .assertEqual (task_doc ["output" ]["final_energy" ], - 151.3244603665 )
76
- self .assertEqual (task_doc ["output" ]["hess_data" ]["scratch/132.0" ][0 ],0.12636293260949633 )
77
- self .assertEqual (task_doc ["output" ]["hess_data" ]["scratch/132.0" ][- 2 ],- 0.2025032138024329 )
78
- self .assertEqual (task_doc ["output" ]["hess_data" ]["scratch/HESS" ][- 2 ], ' -0.175476533300377 -0.202503213802433 0.205623571433770 \n ' )
128
+ self .assertEqual (
129
+ task_doc ["output" ]["hess_data" ]["scratch/132.0" ][0 ], 0.12636293260949633
130
+ )
131
+ self .assertEqual (
132
+ task_doc ["output" ]["hess_data" ]["scratch/132.0" ][- 2 ], - 0.2025032138024329
133
+ )
134
+ self .assertEqual (
135
+ task_doc ["output" ]["hess_data" ]["scratch/HESS" ][- 2 ],
136
+ " -0.175476533300377 -0.202503213802433 0.205623571433770 \n " ,
137
+ )
79
138
os .remove (os .path .join (my_calc_dir , "task.json" ))
80
139
81
140
def tearDown (self ):
82
141
pass
83
-
84
- if __name__ == "__main__" :
85
- unittest .main ()
0 commit comments