From 9072dcf3475ff6180aeb690442ceba63b6424fd6 Mon Sep 17 00:00:00 2001 From: sunliang98 <1700011430@pku.edu.cn> Date: Sat, 11 Oct 2025 14:46:00 +0800 Subject: [PATCH 1/3] Fix: Resolve the output of Eband --- source/source_esolver/esolver_ks.cpp | 30 ++++++++++++++-------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/source/source_esolver/esolver_ks.cpp b/source/source_esolver/esolver_ks.cpp index 9e1299907b..d219e19a0f 100644 --- a/source/source_esolver/esolver_ks.cpp +++ b/source/source_esolver/esolver_ks.cpp @@ -308,23 +308,23 @@ template void ESolver_KS::iter_finish(UnitCell& ucell, const int istep, int& iter, bool &conv_esolver) { + //---------------------------------------------------------------- + // 1) print out band gap + //---------------------------------------------------------------- + if (PARAM.inp.out_bandgap) + { + if (!PARAM.globalv.two_fermi) + { + this->pelec->cal_bandgap(); + } + else + { + this->pelec->cal_bandgap_updw(); + } + } + if(iter % PARAM.inp.out_freq_elec == 0) { - //---------------------------------------------------------------- - // 1) print out band gap - //---------------------------------------------------------------- - if (PARAM.inp.out_bandgap) - { - if (!PARAM.globalv.two_fermi) - { - this->pelec->cal_bandgap(); - } - else - { - this->pelec->cal_bandgap_updw(); - } - } - //---------------------------------------------------------------- // 2) print out eigenvalues and occupations //---------------------------------------------------------------- From 377091c59ffd553f872fb05c365a124d59183eac Mon Sep 17 00:00:00 2001 From: sunliang98 <1700011430@pku.edu.cn> Date: Sat, 11 Oct 2025 14:54:49 +0800 Subject: [PATCH 2/3] Refactor: Remove the input parameter `out_bandgap` --- docs/advanced/input_files/input-main.md | 9 -------- docs/advanced/interface/TB2J.md | 1 - examples/03_spin_polarized/ATOM/INPUT | 1 - examples/19_dftu/NiO/INPUT | 1 - examples/relax/pw_output/INPUT | 1 - source/source_esolver/esolver_ks.cpp | 15 +++++------- source/source_estate/elecstate_print.cpp | 23 ++++++++----------- .../test/elecstate_print_test.cpp | 3 --- .../module_parameter/input_parameter.h | 1 - source/source_io/read_input_item_output.cpp | 6 ----- tests/01_PW/078_PW_S2_elec_add/INPUT | 1 - tests/01_PW/209_PW_DFTHALF/INPUT | 3 --- 12 files changed, 16 insertions(+), 49 deletions(-) diff --git a/docs/advanced/input_files/input-main.md b/docs/advanced/input_files/input-main.md index 47670d1735..08212b1099 100644 --- a/docs/advanced/input_files/input-main.md +++ b/docs/advanced/input_files/input-main.md @@ -147,7 +147,6 @@ - [out\_band](#out_band) - [out\_proj\_band](#out_proj_band) - [out\_stru](#out_stru) - - [out\_bandgap](#out_bandgap) - [out\_level](#out_level) - [out\_alllog](#out_alllog) - [out\_mat\_hs](#out_mat_hs) @@ -1827,14 +1826,6 @@ These variables are used to control the output of properties. - **Description**: Whether to output structure files per ionic step in geometry relaxation calculations into `OUT.${suffix}/STRU_ION${istep}_D`, where `${istep}` is the ionic step. - **Default**: False -### out_bandgap - -- **Type**: Boolean -- **Description**: Whether to print the bandgap per electronic iteration into `OUT.${suffix}/running_${calculation}.log`. The value of bandgaps can be obtained by searching for the keyword: - - [nupdown](#nupdown) > 0: `E_bandgap_up` and `E_bandgap_dw` - - [nupdown](#nupdown) = 0: `E_bandgap` -- **Default**: False - ### out_level - **Type**: String diff --git a/docs/advanced/interface/TB2J.md b/docs/advanced/interface/TB2J.md index 8a2d731557..2848d4b573 100644 --- a/docs/advanced/interface/TB2J.md +++ b/docs/advanced/interface/TB2J.md @@ -66,7 +66,6 @@ out_mul 1 #Parameters (4.Relaxation) ks_solver genelpa scf_nmax 200 -out_bandgap 0 #Parameters (5.LCAO) basis_type lcao diff --git a/examples/03_spin_polarized/ATOM/INPUT b/examples/03_spin_polarized/ATOM/INPUT index 11b933d8a4..108f21d13e 100644 --- a/examples/03_spin_polarized/ATOM/INPUT +++ b/examples/03_spin_polarized/ATOM/INPUT @@ -46,7 +46,6 @@ cal_force 1 cal_stress 1 out_stru 1 # print STRU in OUT out_chg 0 # print CHG or not -out_bandgap 1 # if bandgap and mul out, chg will out out_mul 1 # print Mulliken charge and mag of atom in mulliken.txt # out_wfc_lcao 1 # out_interval 1 diff --git a/examples/19_dftu/NiO/INPUT b/examples/19_dftu/NiO/INPUT index cccad64e87..1094ff534f 100644 --- a/examples/19_dftu/NiO/INPUT +++ b/examples/19_dftu/NiO/INPUT @@ -28,7 +28,6 @@ dft_plus_u 1 orbital_corr 2 2 -1 hubbard_u 5.0 5.0 0.0 -out_bandgap 1 out_chg 1 out_mul 1 diff --git a/examples/relax/pw_output/INPUT b/examples/relax/pw_output/INPUT index 7f77f31358..152e3d66ed 100644 --- a/examples/relax/pw_output/INPUT +++ b/examples/relax/pw_output/INPUT @@ -37,7 +37,6 @@ out_dos 1 # dos.txt g out_elf 1 # elf.txt out_band 1 # eig.txt out_stru 1 # g -out_bandgap 1 out_app_flag 0 diff --git a/source/source_esolver/esolver_ks.cpp b/source/source_esolver/esolver_ks.cpp index d219e19a0f..4768f6afd1 100644 --- a/source/source_esolver/esolver_ks.cpp +++ b/source/source_esolver/esolver_ks.cpp @@ -311,16 +311,13 @@ void ESolver_KS::iter_finish(UnitCell& ucell, const int istep, int& i //---------------------------------------------------------------- // 1) print out band gap //---------------------------------------------------------------- - if (PARAM.inp.out_bandgap) + if (!PARAM.globalv.two_fermi) { - if (!PARAM.globalv.two_fermi) - { - this->pelec->cal_bandgap(); - } - else - { - this->pelec->cal_bandgap_updw(); - } + this->pelec->cal_bandgap(); + } + else + { + this->pelec->cal_bandgap_updw(); } if(iter % PARAM.inp.out_freq_elec == 0) diff --git a/source/source_estate/elecstate_print.cpp b/source/source_estate/elecstate_print.cpp index 584b34fe6c..a04efc7563 100644 --- a/source/source_estate/elecstate_print.cpp +++ b/source/source_estate/elecstate_print.cpp @@ -276,20 +276,17 @@ void print_etot(const Magnetism& magnet, } // print out the band gap if needed - if (PARAM.inp.out_bandgap) + if (!PARAM.globalv.two_fermi) { - if (!PARAM.globalv.two_fermi) - { - titles.push_back("E_bandgap"); - energies_Ry.push_back(elec.bandgap); - } - else - { - titles.push_back("E_bandgap_up"); - energies_Ry.push_back(elec.bandgap_up); - titles.push_back("E_bandgap_dw"); - energies_Ry.push_back(elec.bandgap_dw); - } + titles.push_back("E_bandgap"); + energies_Ry.push_back(elec.bandgap); + } + else + { + titles.push_back("E_bandgap_up"); + energies_Ry.push_back(elec.bandgap_up); + titles.push_back("E_bandgap_dw"); + energies_Ry.push_back(elec.bandgap_dw); } energies_eV.resize(energies_Ry.size()); std::transform(energies_Ry.begin(), energies_Ry.end(), energies_eV.begin(), [](double ener) { diff --git a/source/source_estate/test/elecstate_print_test.cpp b/source/source_estate/test/elecstate_print_test.cpp index 3a016d5ab6..53dcbb0c58 100644 --- a/source/source_estate/test/elecstate_print_test.cpp +++ b/source/source_estate/test/elecstate_print_test.cpp @@ -135,7 +135,6 @@ TEST_F(ElecStatePrintTest, PrintEtot) PARAM.input.efield_flag = true; PARAM.input.gate_flag = true; PARAM.sys.two_fermi = true; - PARAM.input.out_bandgap = true; GlobalV::MY_RANK = 0; PARAM.input.basis_type = "pw"; PARAM.input.nspin = 2; @@ -221,7 +220,6 @@ TEST_F(ElecStatePrintTest, PrintEtotColorS2) PARAM.input.efield_flag = true; PARAM.input.gate_flag = true; PARAM.sys.two_fermi = true; - PARAM.input.out_bandgap = true; PARAM.input.nspin = 2; GlobalV::MY_RANK = 0; @@ -251,7 +249,6 @@ TEST_F(ElecStatePrintTest, PrintEtotColorS4) PARAM.input.efield_flag = true; PARAM.input.gate_flag = true; PARAM.sys.two_fermi = true; - PARAM.input.out_bandgap = true; PARAM.input.nspin = 4; PARAM.input.noncolin = true; GlobalV::MY_RANK = 0; diff --git a/source/source_io/module_parameter/input_parameter.h b/source/source_io/module_parameter/input_parameter.h index a8dd6d63bb..0991e42ecf 100644 --- a/source/source_io/module_parameter/input_parameter.h +++ b/source/source_io/module_parameter/input_parameter.h @@ -379,7 +379,6 @@ struct Input_para std::string out_level = "ie"; ///< control the output information. std::vector out_dmr = {0, 8}; ///< output density matrix in real space DM(R) std::vector out_dmk = {0, 8}; ///< output density matrix in reciprocal space DM(k) - bool out_bandgap = false; ///< QO added for bandgap printing std::vector out_mat_hs = {0, 8}; ///< output H matrix and S matrix in local basis. std::vector out_mat_tk = {0, 8}; ///< output T(k) matrix in local basis. std::vector out_mat_l = {0, 8}; ///< output L matrix in local basis. diff --git a/source/source_io/read_input_item_output.cpp b/source/source_io/read_input_item_output.cpp index a1d7d764ff..3fd805cfb7 100644 --- a/source/source_io/read_input_item_output.cpp +++ b/source/source_io/read_input_item_output.cpp @@ -235,12 +235,6 @@ void ReadInput::item_output() sync_intvec(input.out_dmr, 2, 0); this->add_item(item); } - { - Input_Item item("out_bandgap"); - item.annotation = "if true, print out bandgap"; - read_sync_bool(input.out_bandgap); - this->add_item(item); - } { Input_Item item("out_mat_hs"); item.annotation = "output H and S matrix (with precision 8)"; diff --git a/tests/01_PW/078_PW_S2_elec_add/INPUT b/tests/01_PW/078_PW_S2_elec_add/INPUT index 4590bf72d7..d894338da8 100644 --- a/tests/01_PW/078_PW_S2_elec_add/INPUT +++ b/tests/01_PW/078_PW_S2_elec_add/INPUT @@ -28,7 +28,6 @@ mixing_type plain mixing_beta 0.7 nupdown 1.0 -out_bandgap 1 cal_force 1 cal_stress 1 diff --git a/tests/01_PW/209_PW_DFTHALF/INPUT b/tests/01_PW/209_PW_DFTHALF/INPUT index a1f94218d7..5737d3b48b 100644 --- a/tests/01_PW/209_PW_DFTHALF/INPUT +++ b/tests/01_PW/209_PW_DFTHALF/INPUT @@ -26,7 +26,4 @@ mixing_beta 0.7 dft_functional PBE -#OUT -out_bandgap true - pw_seed 1 From d7e9da348e4c3f80f0af892ff4e7638d126ed7e7 Mon Sep 17 00:00:00 2001 From: sunliang98 <1700011430@pku.edu.cn> Date: Mon, 13 Oct 2025 18:38:43 +0800 Subject: [PATCH 3/3] Refactor: Replace PARAM.inp.nbands with this->ekb.nc in bandgap calculations --- source/source_estate/elecstate_energy.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/source/source_estate/elecstate_energy.cpp b/source/source_estate/elecstate_energy.cpp index 471dd0df00..bb4c471bd2 100644 --- a/source/source_estate/elecstate_energy.cpp +++ b/source/source_estate/elecstate_energy.cpp @@ -16,7 +16,8 @@ void ElecState::cal_bandgap() this->bandgap = 0.0; return; } - int nbands = PARAM.inp.nbands; + // int nbands = PARAM.inp.nbands; + int nbands = this->ekb.nc; int nks = this->klist->get_nks(); double homo = this->ekb(0, 0); double lumo = this->ekb(0, nbands - 1); @@ -47,7 +48,8 @@ void ElecState::cal_bandgap_updw() this->bandgap_dw = 0.0; return; } - int nbands = PARAM.inp.nbands; + // int nbands = PARAM.inp.nbands; + int nbands = this->ekb.nc; int nks = this->klist->get_nks(); double homo_up = this->ekb(0, 0); double lumo_up = this->ekb(0, nbands - 1);