9
9
from fireworks import FWorker
10
10
from fireworks .core .rocket_launcher import rapidfire
11
11
12
- from atomate .common .powerups import powerup_by_kwargs
12
+ from atomate .vasp .powerups import use_fake_vasp
13
13
from atomate .vasp .workflows .presets .core import wf_raman_spectra
14
14
from atomate .utils .testing import AtomateTest
15
15
16
16
from pymatgen .util .testing import PymatgenTest
17
17
18
- __author__ = " Kiran Mathew"
19
-
18
+ __author__ = ' Kiran Mathew'
19
+
20
20
21
21
module_dir = os .path .join (os .path .dirname (os .path .abspath (__file__ )))
22
22
db_dir = os .path .join (module_dir , ".." , ".." , ".." , "common" , "test_files" )
23
23
ref_dir = os .path .join (module_dir , ".." , ".." , "test_files" )
24
24
25
- DEBUG_MODE = (
26
- False # If true, retains the database and output dirs at the end of the test
27
- )
28
- VASP_CMD = (
29
- None # If None, runs a "fake" VASP. Otherwise, runs VASP with this command...
30
- )
25
+ DEBUG_MODE = False # If true, retains the database and output dirs at the end of the test
26
+ VASP_CMD = None # If None, runs a "fake" VASP. Otherwise, runs VASP with this command...
31
27
32
28
33
29
class TestRamanWorkflow (AtomateTest ):
30
+
34
31
def setUp (self ):
35
32
super (TestRamanWorkflow , self ).setUp ()
36
33
self .struct_si = PymatgenTest .get_structure ("Si" )
37
- self .raman_config = {
38
- "MODES" : [0 , 1 ],
39
- "STEP_SIZE" : 0.005 ,
40
- "VASP_CMD" : ">>vasp_cmd<<" ,
41
- "DB_FILE" : ">>db_file<<" ,
42
- }
34
+ self .raman_config = {"MODES" : [0 , 1 ], "STEP_SIZE" : 0.005 ,
35
+ "VASP_CMD" : ">>vasp_cmd<<" , "DB_FILE" : ">>db_file<<" }
43
36
self .wf = wf_raman_spectra (self .struct_si , self .raman_config )
44
37
45
38
def _simulate_vasprun (self , wf ):
46
39
reference_dir = os .path .abspath (os .path .join (ref_dir , "raman_wf" ))
47
- si_ref_dirs = {
48
- "structure optimization" : os .path .join (reference_dir , "1" ),
49
- "static dielectric" : os .path .join (reference_dir , "2" ),
50
- "raman_0_-0.005" : os .path .join (reference_dir , "6" ),
51
- "raman_0_0.005" : os .path .join (reference_dir , "5" ),
52
- "raman_1_-0.005" : os .path .join (reference_dir , "4" ),
53
- "raman_1_0.005" : os .path .join (reference_dir , "3" ),
54
- }
55
- return powerup_by_kwargs (
56
- wf , use_fake_vasp = {"ref_dirs" : si_ref_dirs , "params_to_check" : ["ENCUT" ]}
57
- )
58
- # return use_fake_vasp(wf, si_ref_dirs, params_to_check=["ENCUT"])
40
+ si_ref_dirs = {"structure optimization" : os .path .join (reference_dir , "1" ),
41
+ "static dielectric" : os .path .join (reference_dir , "2" ),
42
+ "raman_0_-0.005" : os .path .join (reference_dir , "6" ),
43
+ "raman_0_0.005" : os .path .join (reference_dir , "5" ),
44
+ "raman_1_-0.005" : os .path .join (reference_dir , "4" ),
45
+ "raman_1_0.005" : os .path .join (reference_dir , "3" )}
46
+ return use_fake_vasp (wf , si_ref_dirs , params_to_check = ["ENCUT" ])
59
47
60
48
def _check_run (self , d , mode ):
61
- if mode not in [
62
- "structure optimization" ,
63
- "static dielectric" ,
64
- "raman_0_0.005" ,
65
- "raman analysis" ,
66
- ]:
49
+ if mode not in ["structure optimization" , "static dielectric" ,
50
+ "raman_0_0.005" , "raman analysis" ]:
67
51
raise ValueError ("Invalid mode!" )
68
52
69
53
if mode not in ["raman analysis" ]:
70
54
self .assertEqual (d ["formula_pretty" ], "Si" )
71
55
self .assertEqual (d ["formula_anonymous" ], "A" )
72
56
self .assertEqual (d ["nelements" ], 1 )
73
57
self .assertEqual (d ["state" ], "successful" )
74
- self .assertAlmostEqual (
75
- d ["calcs_reversed" ][0 ]["output" ]["structure" ]["lattice" ]["a" ], 3.867 , 2
76
- )
58
+ self .assertAlmostEqual (d ["calcs_reversed" ][0 ]["output" ]["structure" ]["lattice" ]["a" ], 3.867 , 2 )
77
59
78
60
if mode in ["structure optimization" ]:
79
61
self .assertAlmostEqual (d ["output" ]["energy" ], - 10.850 , 2 )
80
62
self .assertAlmostEqual (d ["output" ]["energy_per_atom" ], - 5.425 , 2 )
81
63
82
64
elif mode in ["static dielectric" ]:
83
- epsilon = [
84
- [13.23245131 , - 1.98e-06 , - 1.4e-06 ],
85
- [- 1.98e-06 , 13.23245913 , 8.38e-06 ],
86
- [- 1.4e-06 , 8.38e-06 , 13.23245619 ],
87
- ]
88
- np .testing .assert_allclose (
89
- epsilon , d ["output" ]["epsilon_static" ], rtol = 1e-5
90
- )
65
+ epsilon = [[13.23245131 , - 1.98e-06 , - 1.4e-06 ],
66
+ [- 1.98e-06 , 13.23245913 , 8.38e-06 ],
67
+ [- 1.4e-06 , 8.38e-06 , 13.23245619 ]]
68
+ np .testing .assert_allclose (epsilon , d ["output" ]["epsilon_static" ], rtol = 1e-5 )
91
69
92
70
elif mode in ["raman_0_0.005" ]:
93
- epsilon = [
94
- [13.16509632 , 0.00850098 , 0.00597267 ],
95
- [0.00850097 , 13.25477303 , - 0.02979572 ],
96
- [0.00597267 , - 0.0297953 , 13.28883867 ],
97
- ]
98
- np .testing .assert_allclose (
99
- epsilon , d ["output" ]["epsilon_static" ], rtol = 1e-5
100
- )
71
+ epsilon = [[13.16509632 , 0.00850098 , 0.00597267 ],
72
+ [0.00850097 , 13.25477303 , - 0.02979572 ],
73
+ [0.00597267 , - 0.0297953 , 13.28883867 ]]
74
+ np .testing .assert_allclose (epsilon , d ["output" ]["epsilon_static" ], rtol = 1e-5 )
101
75
102
76
elif mode in ["raman analysis" ]:
103
- freq = [
104
- 82.13378641656142 ,
105
- 82.1337379843688 ,
106
- 82.13373236539397 ,
107
- 3.5794336040310436e-07 ,
108
- 3.872360276932139e-07 ,
109
- 1.410955723105983e-06 ,
110
- ]
77
+ freq = [82.13378641656142 , 82.1337379843688 , 82.13373236539397 ,
78
+ 3.5794336040310436e-07 , 3.872360276932139e-07 , 1.410955723105983e-06 ]
111
79
np .testing .assert_allclose (freq , d ["frequencies" ], rtol = 1e-5 )
112
- raman_tensor = {
113
- "0" : [
114
- [- 0.14893062387265346 , 0.01926196125448702 , 0.013626954435454657 ],
115
- [0.019262321540910236 , 0.03817444467845385 , - 0.06614541890150054 ],
116
- [0.013627229948601821 , - 0.06614564143135017 , 0.11078513986463052 ],
117
- ],
118
- "1" : [
119
- [- 0.021545749071077102 , - 0.12132200642389818 , - 0.08578776196143767 ],
120
- [- 0.12131975993142007 , - 0.00945267872479081 , - 0.004279822490713417 ],
121
- [- 0.08578678706847546 , - 0.004279960247327641 , 0.032660281203217366 ],
122
- ],
123
- }
124
- np .testing .assert_allclose (
125
- raman_tensor ["0" ], d ["raman_tensor" ]["0" ], rtol = 1e-5
126
- )
127
- np .testing .assert_allclose (
128
- raman_tensor ["1" ], d ["raman_tensor" ]["1" ], rtol = 1e-5
129
- )
80
+ raman_tensor = {'0' : [[- 0.14893062387265346 , 0.01926196125448702 , 0.013626954435454657 ],
81
+ [0.019262321540910236 , 0.03817444467845385 , - 0.06614541890150054 ],
82
+ [0.013627229948601821 , - 0.06614564143135017 , 0.11078513986463052 ]],
83
+ '1' : [[- 0.021545749071077102 , - 0.12132200642389818 , - 0.08578776196143767 ],
84
+ [- 0.12131975993142007 , - 0.00945267872479081 , - 0.004279822490713417 ],
85
+ [- 0.08578678706847546 , - 0.004279960247327641 , 0.032660281203217366 ]]}
86
+ np .testing .assert_allclose (raman_tensor ["0" ], d ["raman_tensor" ]["0" ], rtol = 1e-5 )
87
+ np .testing .assert_allclose (raman_tensor ["1" ], d ["raman_tensor" ]["1" ], rtol = 1e-5 )
130
88
131
89
def test_wf (self ):
132
90
self .wf = self ._simulate_vasprun (self .wf )
133
91
134
92
self .assertEqual (len (self .wf .fws ), len (self .raman_config ["MODES" ]) * 2 + 3 )
135
93
136
94
self .lp .add_wf (self .wf )
137
- rapidfire (
138
- self .lp , fworker = FWorker (env = {"db_file" : os .path .join (db_dir , "db.json" )})
139
- )
95
+ rapidfire (self .lp , fworker = FWorker (env = {"db_file" : os .path .join (db_dir , "db.json" )}))
140
96
141
97
# check relaxation
142
- d = self .get_task_collection ().find_one (
143
- {"task_label" : "structure optimization" }
144
- )
98
+ d = self .get_task_collection ().find_one ({"task_label" : "structure optimization" })
145
99
self ._check_run (d , mode = "structure optimization" )
146
100
147
101
# check phonon DFPT calculation
@@ -157,7 +111,7 @@ def test_wf(self):
157
111
self ._check_run (d , mode = "raman analysis" )
158
112
159
113
wf = self .lp .get_wf_by_fw_id (1 )
160
- self .assertTrue (all ([s == " COMPLETED" for s in wf .fw_states .values ()]))
114
+ self .assertTrue (all ([s == ' COMPLETED' for s in wf .fw_states .values ()]))
161
115
162
116
163
117
if __name__ == "__main__" :
0 commit comments