Skip to content

Commit ce43f6c

Browse files
authored
Merge pull request #47 from ahxbcn/develop
Tests for plotting band with ABACUS calculation using PW basis
2 parents 4a0b3b5 + 7b34174 commit ce43f6c

5 files changed

Lines changed: 129 additions & 2 deletions

File tree

src/abacusagent/modules/band.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,4 +402,4 @@ def abacus_cal_band(abacus_inputs_dir: Path,
402402
else:
403403
raise ValueError(f"Calculation mode {mode} not in ('pyatb', 'nscf')")
404404
except Exception as e:
405-
return {'messsage': f"Calculating band failed: {e}"}
405+
return {'message': f"Calculating band failed: {e}"}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
INPUT_PARAMETERS
2+
calculation scf
3+
ecutwfc 100
4+
scf_thr 1e-05
5+
scf_nmax 100
6+
smearing_method gauss
7+
smearing_sigma 0.015
8+
mixing_type broyden
9+
mixing_beta 0.2
10+
basis_type pw
11+
ks_solver dav_subspace
12+
kspacing 0.20
13+
nspin 2
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
INPUT_PARAMETERS
2+
suffix Si
3+
ntype 1
4+
pseudo_dir ./
5+
orbital_dir ./
6+
nspin 1
7+
ecutwfc 100
8+
scf_thr 1e-8
9+
basis_type pw
10+
ks_solver dav_subspace
11+
calculation scf
12+
kspacing 0.14
13+
14+
smearing_method gaussian
15+
smearing_sigma 0.00001

tests/integrate_test/data/ref_results.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,24 @@
6262
"band_gap": 0.0
6363
}
6464
},
65+
"test_abacus_cal_band_pyatb_pw":
66+
{
67+
"result": {
68+
"message": "Calculating band failed: Pyatb mode is not supported for PW basis. Please use 'nscf' mode instead."
69+
}
70+
},
71+
"test_abacus_cal_band_nscf_pw_nspin1":
72+
{
73+
"result": {
74+
"band_gap": 0.5583
75+
}
76+
},
77+
"test_abacus_cal_band_nscf_pw_nspin2":
78+
{
79+
"result": {
80+
"band_gap": 0.0
81+
}
82+
},
6583
"test_abacus_dos_run_species":
6684
{
6785
"result": {

tests/integrate_test/test_band.py

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
initilize_test_env()
1111

1212
class TestAbacusCalBand(unittest.TestCase):
13+
"""
14+
Test tool function abacus_cal_band while ABACUS calculation uses LCAO basis.
15+
"""
1316
def setUp(self):
1417
self.test_dir = tempfile.TemporaryDirectory()
1518
self.addCleanup(self.test_dir.cleanup)
@@ -84,14 +87,92 @@ def test_abacus_cal_band_nscf_nspin1(self):
8487

8588
def test_abacus_cal_band_nscf_nspin2(self):
8689
"""
87-
Test plot band structure in NSCF mode in nspin=1 case
90+
Test plot band structure in NSCF mode in nspin=2 case
91+
"""
92+
test_func_name = inspect.currentframe().f_code.co_name
93+
ref_results = load_test_ref_result(test_func_name)
94+
95+
test_work_dir = self.test_path / test_func_name
96+
shutil.copytree(self.abacus_inputs_dir_fe_bcc_prim, test_work_dir)
97+
shutil.copy2(self.fe_stru_band, test_work_dir / "STRU")
98+
99+
outputs = abacus_cal_band(test_work_dir, mode='nscf')
100+
101+
band_calc_dir = outputs['band_calc_dir']
102+
band_picture = outputs['band_picture']
103+
self.assertIsInstance(band_calc_dir, get_path_type())
104+
self.assertIsInstance(band_picture, get_path_type())
105+
self.assertAlmostEqual(outputs['band_gap'], ref_results['band_gap'], places=4)
106+
107+
class TestAbacusCalBandPw(unittest.TestCase):
108+
"""
109+
Test tool function abacus_cal_band while ABACUS calculation uses PW basis.
110+
"""
111+
def setUp(self):
112+
self.test_dir = tempfile.TemporaryDirectory()
113+
self.addCleanup(self.test_dir.cleanup)
114+
self.test_path = Path(self.test_dir.name)
115+
self.abacus_inputs_dir_si_prim = Path(__file__).parent / 'abacus_inputs_dirs/Si-prim/'
116+
self.abacus_inputs_dir_fe_bcc_prim = Path(__file__).parent / 'abacus_inputs_dirs/Fe-BCC-prim/'
117+
self.si_stru_band = self.abacus_inputs_dir_si_prim / "STRU_band"
118+
self.input_pw_si = self.abacus_inputs_dir_si_prim / "INPUT_pw"
119+
self.fe_stru_band = self.abacus_inputs_dir_fe_bcc_prim / "STRU_band"
120+
self.input_pw_fe= self.abacus_inputs_dir_fe_bcc_prim / "INPUT_pw"
121+
122+
self.original_cwd = os.getcwd()
123+
os.chdir(self.test_path)
124+
125+
def tearDown(self):
126+
os.chdir(self.original_cwd)
127+
128+
def test_abacus_cal_band_pyatb_pw(self):
129+
"""
130+
Test plot band structure in PYATB mode using PW basis. Should return a message.
131+
"""
132+
test_func_name = inspect.currentframe().f_code.co_name
133+
ref_results = load_test_ref_result(test_func_name)
134+
135+
test_work_dir = self.test_path / test_func_name
136+
shutil.copytree(self.abacus_inputs_dir_si_prim, test_work_dir)
137+
shutil.copy2(self.si_stru_band, test_work_dir / "STRU")
138+
shutil.copy2(self.input_pw_si, test_work_dir / "INPUT")
139+
140+
outputs = abacus_cal_band(test_work_dir, mode='pyatb')
141+
print(outputs)
142+
self.assertEqual(outputs['message'], ref_results['message'])
143+
144+
def test_abacus_cal_band_nscf_pw_nspin1(self):
145+
"""
146+
Test plot band structure in NSCF mode using PW basis in nspin=1 case
147+
"""
148+
test_func_name = inspect.currentframe().f_code.co_name
149+
ref_results = load_test_ref_result(test_func_name)
150+
151+
test_work_dir = self.test_path / test_func_name
152+
shutil.copytree(self.abacus_inputs_dir_si_prim, test_work_dir)
153+
shutil.copy2(self.si_stru_band, test_work_dir / "STRU")
154+
shutil.copy2(self.input_pw_si, test_work_dir / "INPUT")
155+
156+
outputs = abacus_cal_band(test_work_dir, mode='nscf')
157+
print(outputs)
158+
159+
band_calc_dir = outputs['band_calc_dir']
160+
band_picture = outputs['band_picture']
161+
self.assertIsInstance(band_calc_dir, get_path_type())
162+
self.assertIsInstance(band_picture, get_path_type())
163+
self.assertAlmostEqual(outputs['band_gap'], ref_results['band_gap'], places=4)
164+
165+
def test_abacus_cal_band_nscf_pw_nspin2(self):
166+
"""
167+
Test plot band structure in NSCF mode using PW basis in nspin=2 case
88168
"""
89169
test_func_name = inspect.currentframe().f_code.co_name
90170
ref_results = load_test_ref_result(test_func_name)
91171

92172
test_work_dir = self.test_path / test_func_name
93173
shutil.copytree(self.abacus_inputs_dir_fe_bcc_prim, test_work_dir)
94174
shutil.copy2(self.fe_stru_band, test_work_dir / "STRU")
175+
shutil.copy2(self.input_pw_fe, test_work_dir / "INPUT")
95176

96177
outputs = abacus_cal_band(test_work_dir, mode='nscf')
97178

0 commit comments

Comments
 (0)