From 788092dee25a6b294fcb25993acc1ebef9885047 Mon Sep 17 00:00:00 2001 From: AsTonyshment Date: Sun, 31 Mar 2024 14:15:52 +0800 Subject: [PATCH 1/6] Add INPUT param out_band_index --- source/module_io/input.h | 1 + 1 file changed, 1 insertion(+) diff --git a/source/module_io/input.h b/source/module_io/input.h index 91f5347c20..27534ad784 100644 --- a/source/module_io/input.h +++ b/source/module_io/input.h @@ -48,6 +48,7 @@ class Input int ntype; // number of atom types int nbands; // number of bands int nbands_istate; // number of bands around fermi level for get_pchg calculation. + std::string out_band_index; // specify which bands to calculate for get_pchg calculation, formalism similar to ocp_set. int pw_seed; // random seed for initializing wave functions qianrui 2021-8-12 bool init_vel; // read velocity from STRU or not liuyu 2021-07-14 From da0a72b30e59522390d7af1be495e0cba69e1aa4 Mon Sep 17 00:00:00 2001 From: AsTonyshment Date: Sun, 7 Apr 2024 14:11:20 +0800 Subject: [PATCH 2/6] Add INPUT param out_band_index --- source/module_io/input.cpp | 6 ++++++ source/module_io/input.h | 2 +- source/module_io/write_input.cpp | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/source/module_io/input.cpp b/source/module_io/input.cpp index 9588132f25..8e64509f4e 100644 --- a/source/module_io/input.cpp +++ b/source/module_io/input.cpp @@ -162,6 +162,7 @@ void Input::Default(void) nbands_sto = 256; nbndsto_str = "256"; nbands_istate = 5; + out_band_index = ""; pw_seed = 1; emin_sto = 0.0; emax_sto = 0.0; @@ -783,6 +784,10 @@ bool Input::Read(const std::string& fn) // if (nbands_istate < 0) // ModuleBase::WARNING_QUIT("Input", "NBANDS_ISTATE must > 0"); } + else if (strcmp("out_band_index", word) == 0) + { + getline(ifs, out_band_index); + } else if (strcmp("nche_sto", word) == 0) // Chebyshev expansion order { read_value(ifs, nche_sto); @@ -3248,6 +3253,7 @@ void Input::Bcast() Parallel_Common::bcast_int(nbands); Parallel_Common::bcast_int(nbands_sto); Parallel_Common::bcast_int(nbands_istate); + Parallel_Common::bcast_string(out_band_index); for (int i = 0; i < 3; i++) { Parallel_Common::bcast_double(kspacing[i]); diff --git a/source/module_io/input.h b/source/module_io/input.h index 27534ad784..aaed2cadaf 100644 --- a/source/module_io/input.h +++ b/source/module_io/input.h @@ -48,7 +48,7 @@ class Input int ntype; // number of atom types int nbands; // number of bands int nbands_istate; // number of bands around fermi level for get_pchg calculation. - std::string out_band_index; // specify which bands to calculate for get_pchg calculation, formalism similar to ocp_set. + std::string out_band_index; // specify the bands to be calculated in the get_pchg calculation, formalism similar to ocp_set. int pw_seed; // random seed for initializing wave functions qianrui 2021-8-12 bool init_vel; // read velocity from STRU or not liuyu 2021-07-14 diff --git a/source/module_io/write_input.cpp b/source/module_io/write_input.cpp index 5974a54003..9d14179478 100644 --- a/source/module_io/write_input.cpp +++ b/source/module_io/write_input.cpp @@ -60,6 +60,7 @@ void Input::Print(const std::string &fn) const "nbands_istate", nbands_istate, "number of bands around Fermi level for get_pchg calulation"); + ModuleBase::GlobalFunc::OUTP(ofs, "out_band_index", out_band_index, "specify the bands to be calculated in the get_pchg calculation"); ModuleBase::GlobalFunc::OUTP(ofs, "symmetry", symmetry, "the control of symmetry"); ModuleBase::GlobalFunc::OUTP(ofs, "init_vel", init_vel, "read velocity from STRU or not"); ModuleBase::GlobalFunc::OUTP(ofs, From da644dab25b0361c4bcc1123d5621399b9988ccf Mon Sep 17 00:00:00 2001 From: AsTonyshment Date: Mon, 8 Apr 2024 22:02:33 +0800 Subject: [PATCH 3/6] Add INPUT param out_band_index --- docs/advanced/input_files/input-main.md | 24 +++-- source/module_base/global_variable.cpp | 1 + source/module_base/global_variable.h | 1 + .../module_esolver/esolver_ks_lcao_elec.cpp | 2 + source/module_io/input_conv.cpp | 3 + source/module_io/istate_charge.cpp | 101 ++++++++++++++---- source/module_io/istate_charge.h | 15 ++- source/module_io/test/input_conv_test.cpp | 3 +- source/module_io/test/input_test_para.cpp | 1 + 9 files changed, 120 insertions(+), 31 deletions(-) diff --git a/docs/advanced/input_files/input-main.md b/docs/advanced/input_files/input-main.md index e2a9504c0e..208199aab3 100644 --- a/docs/advanced/input_files/input-main.md +++ b/docs/advanced/input_files/input-main.md @@ -64,7 +64,6 @@ - [basis\_type](#basis_type) - [ks\_solver](#ks_solver) - [nbands](#nbands) - - [nbands\_istate](#nbands_istate) - [nspin](#nspin) - [smearing\_method](#smearing_method) - [smearing\_sigma](#smearing_sigma) @@ -154,6 +153,8 @@ - [restart\_save](#restart_save) - [restart\_load](#restart_load) - [rpa](#rpa) + - [nbands\_istate](#nbands_istate) + - [out\_band\_index](#out_band_index) - [Density of states](#density-of-states) - [dos\_edelta\_ev](#dos_edelta_ev) - [dos\_sigma](#dos_sigma) @@ -936,13 +937,6 @@ calculations. - nspin=2: max(1.2\*nelec_spin, nelec_spin + 10), in which nelec_spin = max(nelec_spin_up, nelec_spin_down) - nspin=4: max(1.2\*nelec, nelec + 20) -### nbands_istate - -- **Type**: Integer -- **Availability**: Only used when `calculation = get_wf` or `calculation = get_pchg`. -- **Description**: The number of bands around the Fermi level you would like to calculate. `get_wf` means to calculate the envelope functions of wave functions $\Psi_{i}=\Sigma_{\mu}C_{i\mu}\Phi_{\mu}$, where $\Psi_{i}$ is the ith wave function with the band index $i$ and $\Phi_{\mu}$ is the localized atomic orbital set. `get_pchg` means to calculate the density of each wave function $|\Psi_{i}|^{2}$. Specifically, suppose we have highest occupied bands at 100th wave functions. And if you set this variable to 5, it will print five wave functions from 96th to 105th. But before all this can be carried out, the wave functions coefficients should be first calculated and written into a file by setting the flag `out_wfc_lcao = 1`. -- **Default**: 5 - ### nspin - **Type**: Integer @@ -1680,6 +1674,20 @@ These variables are used to control the output of properties. - **Description**: Generate output files used in rpa calculations. - **Default**: False +### nbands_istate + +- **Type**: Integer +- **Availability**: Only used when `calculation = get_wf` or `calculation = get_pchg`. +- **Description**: The number of bands around the Fermi level you would like to calculate. `get_wf` means to calculate the envelope functions of wave functions $\Psi_{i}=\Sigma_{\mu}C_{i\mu}\Phi_{\mu}$, where $\Psi_{i}$ is the ith wave function with the band index $i$ and $\Phi_{\mu}$ is the localized atomic orbital set. `get_pchg` means to calculate the density of each wave function $|\Psi_{i}|^{2}$. Specifically, suppose we have highest occupied bands at 100th wave functions. And if you set this variable to 5, it will print five wave functions from 96th to 105th. But before all this can be carried out, the wave functions coefficients should be first calculated and written into a file by setting the flag `out_wfc_lcao = 1`. +- **Default**: 5 + +### out_band_index + +- **Type**: String +- **Availability**: Only used when `calculation = get_pchg`. +- **Description**: Specifies the bands to calculate the charge density for, using a space-separated string of 0s and 1s, providing a more flexible selection compared to `nbands_istate`. Each digit in the string corresponds to a band, starting from the first band. A `1` indicates that the charge density should be calculated for that band, while a `0` means the band will be ignored. The parameter allows a compact and flexible notation (similar to [`ocp_set`](#ocp_set)), for example the syntax `1 4*0 5*1 0` is used to denote the selection of bands: `1` means calculate for the first band, `4*0` skips the next four bands, `5*1` means calculate for the following five bands, and the final `0` skips the next band. It's essential that the total count of bands does not exceed the total number of bands (`nbands`); otherwise, it results in an error, and the process exits. The input string must contain only numbers and the asterisk (`*`) for repetition, ensuring correct format and intention of band selection. +- **Default**: none + [back to top](#full-list-of-input-keywords) ## Density of states diff --git a/source/module_base/global_variable.cpp b/source/module_base/global_variable.cpp index b6ed81f361..d7a74dc826 100644 --- a/source/module_base/global_variable.cpp +++ b/source/module_base/global_variable.cpp @@ -20,6 +20,7 @@ namespace GlobalV //---------------------------------------------------------- int NBANDS = 0; int NBANDS_ISTATE = 0; // default number. +std::string OUT_BAND_INDEX = "none"; // default output bands index. int NLOCAL = 0; // total number of local basis. double KSPACING[3] = {0.0,0.0,0.0}; diff --git a/source/module_base/global_variable.h b/source/module_base/global_variable.h index a504307ce2..3e4a1bacad 100644 --- a/source/module_base/global_variable.h +++ b/source/module_base/global_variable.h @@ -20,6 +20,7 @@ namespace GlobalV extern int NBANDS; extern int NBANDS_ISTATE; // 1.05 // mohan add 2011-03-22 +extern std::string OUT_BAND_INDEX; extern int NLOCAL; // 1.1 // mohan add 2009-05-29 extern double KSPACING[3]; diff --git a/source/module_esolver/esolver_ks_lcao_elec.cpp b/source/module_esolver/esolver_ks_lcao_elec.cpp index e16774c6f1..e975514017 100644 --- a/source/module_esolver/esolver_ks_lcao_elec.cpp +++ b/source/module_esolver/esolver_ks_lcao_elec.cpp @@ -398,6 +398,8 @@ void ESolver_KS_LCAO::othercalculation(const int istep) GlobalV::NBANDS, GlobalV::nelec, GlobalV::NSPIN, + GlobalV::NLOCAL, + GlobalV::OUT_BAND_INDEX, GlobalV::global_out_dir, GlobalV::MY_RANK, GlobalV::ofs_warning); diff --git a/source/module_io/input_conv.cpp b/source/module_io/input_conv.cpp index e18661e7f0..d5c6fc0f4b 100644 --- a/source/module_io/input_conv.cpp +++ b/source/module_io/input_conv.cpp @@ -305,6 +305,9 @@ void Input_Conv::Convert(void) GlobalV::MIN_DIST_COEF = INPUT.min_dist_coef; GlobalV::NBANDS = INPUT.nbands; GlobalV::NBANDS_ISTATE = INPUT.nbands_istate; + + GlobalV::OUT_BAND_INDEX = INPUT.out_band_index; + GlobalV::device_flag = psi::device::get_device_flag(INPUT.device, INPUT.ks_solver, INPUT.basis_type); if (GlobalV::device_flag == "gpu") diff --git a/source/module_io/istate_charge.cpp b/source/module_io/istate_charge.cpp index 24736da213..393381aa66 100644 --- a/source/module_io/istate_charge.cpp +++ b/source/module_io/istate_charge.cpp @@ -6,6 +6,7 @@ #include "module_base/parallel_common.h" #include "module_base/scalapack_connector.h" #include "module_hamilt_pw/hamilt_pwdft/global.h" +#include "module_io/input_conv.h" #include "module_io/rho_io.h" IState_Charge::IState_Charge(psi::Psi* psi_gamma_in, Local_Orbital_Charge& loc_in) @@ -26,6 +27,8 @@ void IState_Charge::begin(Gint_Gamma& gg, const int nbands, const double nelec, const int nspin, + const int nlocal, + const std::string& out_band_index, const std::string& global_out_dir, const int my_rank, std::ofstream& ofs_warning) @@ -40,25 +43,34 @@ void IState_Charge::begin(Gint_Gamma& gg, } int mode = 0; - if (nbands_istate > 0) + if (nbands_istate > 0 && out_band_index.empty()) + { mode = 1; - else + } + else if (!out_band_index.empty()) + { + // If OUT_BAND_INDEX is not empty, set mode to 2 mode = 2; + std::cout << " Notice: INPUT parameter `nbands_istate` overwritten by `out_band_index`!" << std::endl; + } + else + { + mode = 3; + } int fermi_band = 0; int bands_below = 0; int bands_above = 0; + std::vector out_band_kb; + Input_Conv::parse_expression(out_band_index, out_band_kb); // (2) cicle: - // (2.1) calculate the selected density matrix - // from wave functions. - // (2.2) carry out the grid integration to - // get the charge density. - this->bands_picked = new int[nbands]; - ModuleBase::GlobalFunc::ZEROS(bands_picked, nbands); + // (2.1) calculate the selected density matrix from wave functions. + // (2.2) carry out the grid integration to get the charge density. + this->bands_picked_.resize(nbands); + ModuleBase::GlobalFunc::ZEROS(bands_picked_.data(), nbands); // (1) - // (1.2) read in LOWF_GAMMA.dat std::cout << " number of electrons = " << nelec << std::endl; @@ -74,24 +86,72 @@ void IState_Charge::begin(Gint_Gamma& gg, bands_below = nbands_istate; bands_above = nbands_istate; - std::cout << " plot band decomposed charge density below fermi surface with " << bands_below << " bands." + std::cout << " Plot band decomposed charge density below Fermi surface with " << bands_below << " bands." << std::endl; - std::cout << " plot band decomposed charge density above fermi surface with " << bands_above << " bands." + std::cout << " Plot band decomposed charge density above Fermi surface with " << bands_above << " bands." << std::endl; - for (int ib = 0; ib < nbands; ib++) + for (int ib = 0; ib < nbands; ++ib) { if (ib >= fermi_band - bands_below) { if (ib < fermi_band + bands_above) { - bands_picked[ib] = 1; + bands_picked_[ib] = 1; } } } } else if (mode == 2) + { + // Check if length of out_band_kb is valid + if (static_cast(out_band_kb.size()) > nbands) + { + ModuleBase::WARNING_QUIT( + "IState_Charge::begin", + "The number of bands specified by `out_band_index` in the INPUT file exceeds `nbands`!"); + } + // Check if all elements in bands_picked_ are 0 or 1 + for (int value: out_band_kb) + { + if (value != 0 && value != 1) + { + ModuleBase::WARNING_QUIT( + "IState_Charge::begin", + "The elements of `out_band_index` must be either 0 or 1. Invalid values found!"); + } + } + // Fill bands_picked_ with values from out_band_kb, converting to int + // Remaining bands are already set to 0 + int length = std::min(static_cast(out_band_kb.size()), nbands); + for (int i = 0; i < length; ++i) + { + // out_band_kb rely on function parse_expression from input_conv.cpp + // Initially designed for ocp_set, which can be double + bands_picked_[i] = static_cast(out_band_kb[i]); + } + + std::cout << " Plot band decomposed charge density below the Fermi surface: band "; + for (int i = 0; i + 1 <= fermi_band; ++i) + { + if (bands_picked_[i] == 1) + { + std::cout << i + 1 << " "; + } + } + std::cout << std::endl; + std::cout << " Plot band decomposed charge density above the Fermi surface: band "; + for (int i = fermi_band; i < nbands; ++i) + { + if (bands_picked_[i] == 1) + { + std::cout << i + 1 << " "; + } + } + std::cout << std::endl; + } + else if (mode == 3) { bool stop = false; std::stringstream ss; @@ -109,14 +169,14 @@ void IState_Charge::begin(Gint_Gamma& gg, // int band_index; for (int ib = 0; ib < nbands; ++ib) { - ModuleBase::GlobalFunc::READ_VALUE(ifs, bands_picked[ib]); + ModuleBase::GlobalFunc::READ_VALUE(ifs, bands_picked_[ib]); } } } #ifdef __MPI Parallel_Common::bcast_bool(stop); - Parallel_Common::bcast_int(bands_picked, GlobalV::NBANDS); + Parallel_Common::bcast_int(bands_picked_.data(), nbands); #endif if (stop) { @@ -125,9 +185,9 @@ void IState_Charge::begin(Gint_Gamma& gg, } } - for (int ib = 0; ib < nbands; ib++) + for (int ib = 0; ib < nbands; ++ib) { - if (bands_picked[ib]) + if (bands_picked_[ib]) { std::cout << " Perform band decomposed charge density for band " << ib + 1 << std::endl; @@ -135,10 +195,10 @@ void IState_Charge::begin(Gint_Gamma& gg, // band, whenever it is occupied or not. #ifdef __MPI - this->idmatrix(ib, pelec, GlobalV::NSPIN, GlobalV::nelec, GlobalV::NLOCAL); + this->idmatrix(ib, pelec, nspin, nelec, nlocal); #endif // (2) zero out of charge density array. - for (int is = 0; is < nspin; is++) + for (int is = 0; is < nspin; ++is) { ModuleBase::GlobalFunc::ZEROS(pelec->charge->rho[is], rhopw->nrxx); } @@ -151,7 +211,7 @@ void IState_Charge::begin(Gint_Gamma& gg, std::stringstream ssc; ssc << global_out_dir << "BAND" << ib + 1; // 0 means definitely output charge density. - for (int is = 0; is < nspin; is++) + for (int is = 0; is < nspin; ++is) { ssc << "_SPIN" << is << "_CHG.cube"; const double ef_tmp = pelec->eferm.get_efval(is); @@ -176,7 +236,6 @@ void IState_Charge::begin(Gint_Gamma& gg, } } - delete[] bands_picked; return; } diff --git a/source/module_io/istate_charge.h b/source/module_io/istate_charge.h index b786736514..1a2535d0ce 100644 --- a/source/module_io/istate_charge.h +++ b/source/module_io/istate_charge.h @@ -11,6 +11,14 @@ #include "module_hamilt_lcao/module_gint/gint_gamma.h" #include "module_psi/psi.h" +/** + * @brief Manages the computation of the charge density for different bands. + * + * This class is responsible for initializing and managing the + * charge state computation process, offering functionality to + * calculate and plot the decomposed charge density below and above + * the Fermi surface based on specified bands. + */ class IState_Charge { public: @@ -31,14 +39,19 @@ class IState_Charge const int nbands, const double nelec, const int nspin, + const int nlocal, + const std::string& out_band_index, const std::string& global_out_dir, const int my_rank, std::ofstream& ofs_warning); private: - int* bands_picked; + std::vector bands_picked_; #ifdef __MPI + /** + * @brief Calculates the density matrix for a given band and spin. + */ void idmatrix(const int& ib, elecstate::ElecState* pelec, const int nspin, const double nelec, const int nlocal); #endif psi::Psi* psi_gamma; diff --git a/source/module_io/test/input_conv_test.cpp b/source/module_io/test/input_conv_test.cpp index eebc50d91a..fad821917d 100644 --- a/source/module_io/test/input_conv_test.cpp +++ b/source/module_io/test/input_conv_test.cpp @@ -45,6 +45,7 @@ TEST_F(InputConvTest, Conv) EXPECT_DOUBLE_EQ(GlobalV::MIN_DIST_COEF,0.2); EXPECT_EQ(GlobalV::NBANDS, 8); EXPECT_EQ(GlobalV::NBANDS_ISTATE,5); + EXPECT_EQ(GlobalV::OUT_BAND_INDEX, INPUT.out_band_index); EXPECT_EQ(GlobalV::device_flag,"cpu"); EXPECT_EQ(GlobalV::KPAR,1); EXPECT_EQ(GlobalV::NSTOGROUP,1); @@ -460,7 +461,7 @@ TEST_F(InputConvTest,parse ) EXPECT_EQ(module_tddft::Evolve_elec::td_vext_dire_case.size(), 0); } -TEST_F(InputConvTest,parse2 ) +TEST_F(InputConvTest, parse2) { INPUT.Default(); std::string input_file = "./support/INPUT"; diff --git a/source/module_io/test/input_test_para.cpp b/source/module_io/test/input_test_para.cpp index 4a661bf582..a0c3e2883f 100644 --- a/source/module_io/test/input_test_para.cpp +++ b/source/module_io/test/input_test_para.cpp @@ -48,6 +48,7 @@ TEST_F(InputParaTest, Bcast) EXPECT_EQ(INPUT.nbands, 0); EXPECT_EQ(INPUT.nbands_sto, 256); EXPECT_EQ(INPUT.nbands_istate, 5); + EXPECT_EQ(INPUT.out_band_index, ""); EXPECT_EQ(INPUT.pw_seed, 1); EXPECT_EQ(INPUT.emin_sto, 0.0); EXPECT_EQ(INPUT.emax_sto, 0.0); From bee6e06b391a66977c729eeadd6616396437bdd5 Mon Sep 17 00:00:00 2001 From: AsTonyshment Date: Tue, 9 Apr 2024 11:01:29 +0800 Subject: [PATCH 4/6] Fix extra spacing within in doc --- docs/advanced/input_files/input-main.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/advanced/input_files/input-main.md b/docs/advanced/input_files/input-main.md index 208199aab3..d420c60022 100644 --- a/docs/advanced/input_files/input-main.md +++ b/docs/advanced/input_files/input-main.md @@ -1678,7 +1678,7 @@ These variables are used to control the output of properties. - **Type**: Integer - **Availability**: Only used when `calculation = get_wf` or `calculation = get_pchg`. -- **Description**: The number of bands around the Fermi level you would like to calculate. `get_wf` means to calculate the envelope functions of wave functions $\Psi_{i}=\Sigma_{\mu}C_{i\mu}\Phi_{\mu}$, where $\Psi_{i}$ is the ith wave function with the band index $i$ and $\Phi_{\mu}$ is the localized atomic orbital set. `get_pchg` means to calculate the density of each wave function $|\Psi_{i}|^{2}$. Specifically, suppose we have highest occupied bands at 100th wave functions. And if you set this variable to 5, it will print five wave functions from 96th to 105th. But before all this can be carried out, the wave functions coefficients should be first calculated and written into a file by setting the flag `out_wfc_lcao = 1`. +- **Description**: The number of bands around the Fermi level you would like to calculate. `get_wf` means to calculate the envelope functions of wave functions $\Psi_{i}=\Sigma_{\mu}C_{i\mu}\Phi_{\mu}$, where $\Psi_{i}$ is the ith wave function with the band index $i$ and $\Phi_{\mu}$ is the localized atomic orbital set. `get_pchg` means to calculate the density of each wave function $|\Psi_{i}|^{2}$. Specifically, suppose we have highest occupied bands at 100th wave functions. And if you set this variable to 5, it will print five wave functions from 96th to 105th. But before all this can be carried out, the wave functions coefficients should be first calculated and written into a file by setting the flag `out_wfc_lcao = 1`. - **Default**: 5 ### out_band_index From a95f79c8b3ad2e2e2cf1e46538aa4e2ded16713d Mon Sep 17 00:00:00 2001 From: AsTonyshment Date: Fri, 12 Apr 2024 01:18:55 +0800 Subject: [PATCH 5/6] Fix several bugs of band-decomposed charge densities using PW basis set --- source/module_base/global_variable.cpp | 1 - source/module_base/global_variable.h | 1 - .../module_esolver/esolver_ks_lcao_elec.cpp | 1 - source/module_esolver/esolver_ks_pw.cpp | 72 +++++++++++++++---- source/module_io/input.cpp | 50 +------------ source/module_io/input.h | 12 +++- source/module_io/input_conv.cpp | 2 - source/module_io/istate_charge.cpp | 6 +- source/module_io/istate_charge.h | 1 - source/module_io/test/input_conv_test.cpp | 1 - source/module_io/test/input_test_para.cpp | 2 +- source/module_io/write_input.cpp | 2 +- 12 files changed, 77 insertions(+), 74 deletions(-) diff --git a/source/module_base/global_variable.cpp b/source/module_base/global_variable.cpp index 29e4f106bd..b9ceb358da 100644 --- a/source/module_base/global_variable.cpp +++ b/source/module_base/global_variable.cpp @@ -20,7 +20,6 @@ namespace GlobalV //---------------------------------------------------------- int NBANDS = 0; int NBANDS_ISTATE = 0; // default number. -std::string OUT_BAND_INDEX = "none"; // default output bands index. int NLOCAL = 0; // total number of local basis. double KSPACING[3] = {0.0,0.0,0.0}; diff --git a/source/module_base/global_variable.h b/source/module_base/global_variable.h index 3e4a1bacad..a504307ce2 100644 --- a/source/module_base/global_variable.h +++ b/source/module_base/global_variable.h @@ -20,7 +20,6 @@ namespace GlobalV extern int NBANDS; extern int NBANDS_ISTATE; // 1.05 // mohan add 2011-03-22 -extern std::string OUT_BAND_INDEX; extern int NLOCAL; // 1.1 // mohan add 2009-05-29 extern double KSPACING[3]; diff --git a/source/module_esolver/esolver_ks_lcao_elec.cpp b/source/module_esolver/esolver_ks_lcao_elec.cpp index 9379d5ee9e..5eeaaa2e63 100644 --- a/source/module_esolver/esolver_ks_lcao_elec.cpp +++ b/source/module_esolver/esolver_ks_lcao_elec.cpp @@ -409,7 +409,6 @@ void ESolver_KS_LCAO::others(const int istep) GlobalV::nelec, GlobalV::NSPIN, GlobalV::NLOCAL, - GlobalV::OUT_BAND_INDEX, GlobalV::global_out_dir, GlobalV::MY_RANK, GlobalV::ofs_warning); diff --git a/source/module_esolver/esolver_ks_pw.cpp b/source/module_esolver/esolver_ks_pw.cpp index d5e7b9a195..b3ca6fb2c4 100644 --- a/source/module_esolver/esolver_ks_pw.cpp +++ b/source/module_esolver/esolver_ks_pw.cpp @@ -7,6 +7,7 @@ #include "module_io/write_istate_info.h" #include "module_io/write_wfc_pw.h" #include "module_io/output_log.h" +#include "module_io/input_conv.h" //--------------temporary---------------------------- #include "module_elecstate/module_charge/symmetry_rho.h" @@ -1023,36 +1024,81 @@ void ESolver_KS_PW::after_scf(const int istep) this->psi[0].size()); } - if(INPUT.band_print_num > 0) + // Get out_band_index through public function of INPUT (returns a const pointer to string) + std::string out_band_index = *INPUT.get_out_band_index(); + if(!out_band_index.empty()) { - std::complex * wfcr = new std::complex[this->pw_rho->nxyz]; - double * rho_band = new double [this->pw_rho->nxyz]; - for(int i = 0; i < this->pw_rho->nxyz; i++) + std::vector out_band_kb; + Input_Conv::parse_expression(out_band_index, out_band_kb); + + // bands_picked is a vector of 0s and 1s, where 1 means the band is picked to output + std::vector bands_picked; + bands_picked.resize(this->kspw_psi->get_nbands()); + ModuleBase::GlobalFunc::ZEROS(bands_picked.data(), this->kspw_psi->get_nbands()); + + // Check if length of out_band_kb is valid + if (static_cast(out_band_kb.size()) > this->kspw_psi->get_nbands()) + { + ModuleBase::WARNING_QUIT( + "ESolver_KS_PW::after_scf", + "The number of bands specified by `out_band_index` in the INPUT file exceeds `nbands`!"); + } + + // Check if all elements in bands_picked are 0 or 1 + for (int value: out_band_kb) + { + if (value != 0 && value != 1) + { + ModuleBase::WARNING_QUIT( + "ESolver_KS_PW::after_scf", + "The elements of `out_band_index` must be either 0 or 1. Invalid values found!"); + } + } + + // Fill bands_picked with values from out_band_kb, converting to int + // Remaining bands are already set to 0 + int length = std::min(static_cast(out_band_kb.size()), this->kspw_psi->get_nbands()); + for (int i = 0; i < length; ++i) { - rho_band[i] = 0.0; + // out_band_kb rely on function parse_expression from input_conv.cpp + // Initially designed for ocp_set, which can be double + bands_picked[i] = static_cast(out_band_kb[i]); } - for(int i = 0; i < INPUT.band_print_num; i++) + std::complex* wfcr = new std::complex[this->pw_rho->nxyz]; + double* rho_band = new double[this->pw_rho->nxyz]; + + for (int ib = 0; ib < this->kspw_psi->get_nbands(); ++ib) { - int ib = INPUT.bands_to_print[i]; - for(int ik = 0; ik < this->kv.nks; ik++) + // Skip the loop iteration if bands_picked[ib] is 0 + if (!bands_picked[ib]) + { + continue; + } + + for (int i = 0; i < this->pw_rho->nxyz; i++) + { + // Initialize rho_band to zero for each band + rho_band[i] = 0.0; + } + + for (int ik = 0; ik < this->kv.nks; ik++) { this->psi->fix_k(ik); - this->pw_wfc->recip_to_real(this->ctx,&psi[0](ib,0),wfcr,ik); + this->pw_wfc->recip_to_real(this->ctx, &psi[0](ib, 0), wfcr, ik); double w1 = static_cast(this->kv.wk[ik] / GlobalC::ucell.omega); - for(int i = 0; i < this->pw_rho->nxyz; i++) + for (int i = 0; i < this->pw_rho->nxyz; i++) { rho_band[i] += std::norm(wfcr[i]) * w1; } } std::stringstream ssc; - ssc << GlobalV::global_out_dir << "band" << ib << ".cube"; + ssc << GlobalV::global_out_dir << "band" << ib + 1 << ".cube"; // band index starts from 1 - ModuleIO::write_rho - ( + ModuleIO::write_rho( #ifdef __MPI this->pw_big->bz, this->pw_big->nbz, diff --git a/source/module_io/input.cpp b/source/module_io/input.cpp index e7d9b60258..65f4a0a26f 100644 --- a/source/module_io/input.cpp +++ b/source/module_io/input.cpp @@ -162,7 +162,7 @@ void Input::Default(void) nbands_sto = 256; nbndsto_str = "256"; nbands_istate = 5; - out_band_index = ""; + out_band_index_ = ""; pw_seed = 1; emin_sto = 0.0; emax_sto = 0.0; @@ -333,8 +333,6 @@ void Input::Default(void) out_bandgap = 0; // QO added for bandgap printing - band_print_num = 0; - deepks_out_labels = 0; // caoyu added 2020-11-24, mohan added 2021-01-03 deepks_scf = 0; deepks_bandgap = 0; @@ -787,7 +785,7 @@ bool Input::Read(const std::string& fn) } else if (strcmp("out_band_index", word) == 0) { - getline(ifs, out_band_index); + getline(ifs, out_band_index_); } else if (strcmp("nche_sto", word) == 0) // Chebyshev expansion order { @@ -1356,14 +1354,6 @@ bool Input::Read(const std::string& fn) { read_bool(ifs, out_chg); } - else if (strcmp("band_print_num", word) == 0) - { - read_value(ifs, band_print_num); - } - else if (strcmp("bands_to_print", word) == 0) - { - ifs.ignore(150, '\n'); - } else if (strcmp("out_dm", word) == 0) { read_bool(ifs, out_dm); @@ -2421,29 +2411,6 @@ bool Input::Read(const std::string& fn) ModuleBase::WARNING_QUIT("Input", "The ntype in INPUT is not equal to the ntype counted in STRU, check it."); } - if(band_print_num > 0) - { - bands_to_print.resize(band_print_num); - ifs.clear(); - ifs.seekg(0); // move to the beginning of the file - ifs.rdstate(); - while (ifs.good()) - { - ifs >> word1; - if (ifs.eof() != 0) - break; - strtolower(word1, word); // convert uppercase std::string to lower case; word1 --> word - - if (strcmp("bands_to_print", word) == 0) - { - for(int i = 0; i < band_print_num; i ++) - { - ifs >> bands_to_print[i]; - } - } - } - } - //---------------------------------------------------------- // DFT+U Xin Qu added on 2020-10-29 //---------------------------------------------------------- @@ -3261,7 +3228,7 @@ void Input::Bcast() Parallel_Common::bcast_int(nbands); Parallel_Common::bcast_int(nbands_sto); Parallel_Common::bcast_int(nbands_istate); - Parallel_Common::bcast_string(out_band_index); + Parallel_Common::bcast_string(out_band_index_); for (int i = 0; i < 3; i++) { Parallel_Common::bcast_double(kspacing[i]); @@ -3631,17 +3598,6 @@ void Input::Bcast() Parallel_Common::bcast_bool(restart_save); // Peize Lin add 2020.04.04 Parallel_Common::bcast_bool(restart_load); // Peize Lin add 2020.04.04 - Parallel_Common::bcast_int(band_print_num); - if(GlobalV::MY_RANK != 0) - { - bands_to_print.resize(band_print_num); - } - - for(int i = 0; i < band_print_num; i++) - { - Parallel_Common::bcast_int(bands_to_print[i]); - } - //----------------------------------------------------------------------------------- // DFT+U (added by Quxin 2020-10-29) //----------------------------------------------------------------------------------- diff --git a/source/module_io/input.h b/source/module_io/input.h index 55214f9405..35afe85db0 100644 --- a/source/module_io/input.h +++ b/source/module_io/input.h @@ -48,7 +48,7 @@ class Input int ntype; // number of atom types int nbands; // number of bands int nbands_istate; // number of bands around fermi level for get_pchg calculation. - std::string out_band_index; // specify the bands to be calculated in the get_pchg calculation, formalism similar to ocp_set. + int pw_seed; // random seed for initializing wave functions qianrui 2021-8-12 bool init_vel; // read velocity from STRU or not liuyu 2021-07-14 @@ -263,8 +263,6 @@ class Input bool out_chg; // output charge density. 0: no; 1: yes bool out_dm; // output density matrix. bool out_dm1; - int band_print_num; - std::vector bands_to_print; int out_pot; // yes or no int out_wfc_pw; // 0: no; 1: txt; 2: dat bool out_wfc_r; // 0: no; 1: yes @@ -641,6 +639,8 @@ class Input int count_ntype(const std::string &fn); // sunliang add 2022-12-06 + std::string out_band_index_; // specify the bands to be calculated in the get_pchg calculation, formalism similar to ocp_set. + public: template static void read_value(std::ifstream &ifs, T &var) { @@ -698,6 +698,12 @@ class Input typename std::enable_if::value, T>::type cast_string(const std::string& str) { return str; } void strtolower(char *sa, char *sb); void read_bool(std::ifstream &ifs, bool &var); + + // Return the const string pointer of private member out_band_index_ + const std::string* get_out_band_index() const + { + return &out_band_index_; + } }; extern Input INPUT; diff --git a/source/module_io/input_conv.cpp b/source/module_io/input_conv.cpp index e0e27ddc89..c232ca1a03 100644 --- a/source/module_io/input_conv.cpp +++ b/source/module_io/input_conv.cpp @@ -306,8 +306,6 @@ void Input_Conv::Convert(void) GlobalV::NBANDS = INPUT.nbands; GlobalV::NBANDS_ISTATE = INPUT.nbands_istate; - GlobalV::OUT_BAND_INDEX = INPUT.out_band_index; - GlobalV::device_flag = psi::device::get_device_flag(INPUT.device, INPUT.ks_solver, INPUT.basis_type); if (GlobalV::device_flag == "gpu") diff --git a/source/module_io/istate_charge.cpp b/source/module_io/istate_charge.cpp index 393381aa66..4c2d65c8e9 100644 --- a/source/module_io/istate_charge.cpp +++ b/source/module_io/istate_charge.cpp @@ -28,7 +28,6 @@ void IState_Charge::begin(Gint_Gamma& gg, const double nelec, const int nspin, const int nlocal, - const std::string& out_band_index, const std::string& global_out_dir, const int my_rank, std::ofstream& ofs_warning) @@ -42,6 +41,9 @@ void IState_Charge::begin(Gint_Gamma& gg, ModuleBase::WARNING_QUIT("IState_Charge::begin", "Only available for GAMMA_ONLY_LOCAL now."); } + // Get out_band_index through public function of INPUT (returns a const pointer to string) + std::string out_band_index = *INPUT.get_out_band_index(); + int mode = 0; if (nbands_istate > 0 && out_band_index.empty()) { @@ -49,7 +51,7 @@ void IState_Charge::begin(Gint_Gamma& gg, } else if (!out_band_index.empty()) { - // If OUT_BAND_INDEX is not empty, set mode to 2 + // If out_band_index is not empty, set mode to 2 mode = 2; std::cout << " Notice: INPUT parameter `nbands_istate` overwritten by `out_band_index`!" << std::endl; } diff --git a/source/module_io/istate_charge.h b/source/module_io/istate_charge.h index 1a2535d0ce..bb525aad8d 100644 --- a/source/module_io/istate_charge.h +++ b/source/module_io/istate_charge.h @@ -40,7 +40,6 @@ class IState_Charge const double nelec, const int nspin, const int nlocal, - const std::string& out_band_index, const std::string& global_out_dir, const int my_rank, std::ofstream& ofs_warning); diff --git a/source/module_io/test/input_conv_test.cpp b/source/module_io/test/input_conv_test.cpp index fad821917d..5c38c5745d 100644 --- a/source/module_io/test/input_conv_test.cpp +++ b/source/module_io/test/input_conv_test.cpp @@ -45,7 +45,6 @@ TEST_F(InputConvTest, Conv) EXPECT_DOUBLE_EQ(GlobalV::MIN_DIST_COEF,0.2); EXPECT_EQ(GlobalV::NBANDS, 8); EXPECT_EQ(GlobalV::NBANDS_ISTATE,5); - EXPECT_EQ(GlobalV::OUT_BAND_INDEX, INPUT.out_band_index); EXPECT_EQ(GlobalV::device_flag,"cpu"); EXPECT_EQ(GlobalV::KPAR,1); EXPECT_EQ(GlobalV::NSTOGROUP,1); diff --git a/source/module_io/test/input_test_para.cpp b/source/module_io/test/input_test_para.cpp index 0861229c91..9dac0c7b8e 100644 --- a/source/module_io/test/input_test_para.cpp +++ b/source/module_io/test/input_test_para.cpp @@ -48,7 +48,7 @@ TEST_F(InputParaTest, Bcast) EXPECT_EQ(INPUT.nbands, 0); EXPECT_EQ(INPUT.nbands_sto, 256); EXPECT_EQ(INPUT.nbands_istate, 5); - EXPECT_EQ(INPUT.out_band_index, ""); + EXPECT_EQ(*INPUT.get_out_band_index(), ""); EXPECT_EQ(INPUT.pw_seed, 1); EXPECT_EQ(INPUT.emin_sto, 0.0); EXPECT_EQ(INPUT.emax_sto, 0.0); diff --git a/source/module_io/write_input.cpp b/source/module_io/write_input.cpp index b4a5f1ff0c..59e4340d84 100644 --- a/source/module_io/write_input.cpp +++ b/source/module_io/write_input.cpp @@ -60,7 +60,7 @@ void Input::Print(const std::string &fn) const "nbands_istate", nbands_istate, "number of bands around Fermi level for get_pchg calulation"); - ModuleBase::GlobalFunc::OUTP(ofs, "out_band_index", out_band_index, "specify the bands to be calculated in the get_pchg calculation"); + ModuleBase::GlobalFunc::OUTP(ofs, "out_band_index", out_band_index_, "specify the bands to be calculated in the get_pchg calculation"); ModuleBase::GlobalFunc::OUTP(ofs, "symmetry", symmetry, "the control of symmetry"); ModuleBase::GlobalFunc::OUTP(ofs, "init_vel", init_vel, "read velocity from STRU or not"); ModuleBase::GlobalFunc::OUTP(ofs, From badbdcb9d60ffe6b14e14f9b78b0721a86b2a9f2 Mon Sep 17 00:00:00 2001 From: AsTonyshment Date: Fri, 12 Apr 2024 01:41:53 +0800 Subject: [PATCH 6/6] Change INPUT param from out_band_index to bands_to_print and modified the corresponding docs --- docs/advanced/input_files/input-main.md | 26 +++++------------------ source/module_esolver/esolver_ks_pw.cpp | 12 +++++------ source/module_io/input.cpp | 8 +++---- source/module_io/input.h | 8 +++---- source/module_io/istate_charge.cpp | 18 ++++++++-------- source/module_io/test/input_test_para.cpp | 2 +- source/module_io/write_input.cpp | 2 +- 7 files changed, 30 insertions(+), 46 deletions(-) diff --git a/docs/advanced/input_files/input-main.md b/docs/advanced/input_files/input-main.md index ea69702991..657bc37945 100644 --- a/docs/advanced/input_files/input-main.md +++ b/docs/advanced/input_files/input-main.md @@ -147,14 +147,12 @@ - [out\_app\_flag](#out_app_flag) - [out\_ndigits](#out_ndigits) - [out\_interval](#out_interval) - - [band\_print\_num](#band_print_num) - - [bands\_to\_print](#bands_to_print) - [out\_element\_info](#out_element_info) - [restart\_save](#restart_save) - [restart\_load](#restart_load) - [rpa](#rpa) - [nbands\_istate](#nbands_istate) - - [out\_band\_index](#out_band_index) + - [bands\_to\_print](#bands_to_print) - [Density of states](#density-of-states) - [dos\_edelta\_ev](#dos_edelta_ev) - [dos\_sigma](#dos_sigma) @@ -414,7 +412,7 @@ These variables are used to control general system parameters. - relax: do structure relaxation calculation, one can use `relax_nmax` to decide how many ionic relaxations you want - cell-relax: do variable-cell relaxation calculation - nscf: do the non self-consistent electronic structure calculations. For this option, you need a charge density file. For nscf calculations with planewave basis set, pw_diag_thr should be <= 1e-3 - - get_pchg: For LCAO basis. Please see the explanation for variable `nbands_istate` + - get_pchg: For LCAO basis. Please see the explanation for variable `nbands_istate` and `bands_to_print` - get_wf: Envelope function for LCAO basis. Please see the explanation for variable `nbands_istate` - md: molecular dynamics - test_memory : checks memory required for the calculation. The number is not quite reliable, please use it with care @@ -1629,20 +1627,6 @@ These variables are used to control the output of properties. - **Description**: Control the interval for printing Mulliken population analysis, $r(R)$, $H(R)$, $S(R)$, $T(R)$, $dH(R)$, $H(k)$, $S(k)$ and $wfc(k)$ matrices during molecular dynamics calculations. Check input parameters [out_mul](#out_mul), [out_mat_r](#out_mat_r), [out_mat_hs2](#out_mat_hs2), [out_mat_t](#out_mat_t), [out_mat_dh](#out_mat_dh), [out_mat_hs](#out_mat_hs) and [out_wfc_lcao](#out_wfc_lcao) for more information, respectively. - **Default**: 1 -### band_print_num - -- **Type**: Integer -- **Availability**: PW basis -- **Description**: If you want to plot a partial charge density contributed from some chosen bands. `band_print_num` define the number of band list. The result can be found in "band*.cube". -- **Default**: 0 - -### bands_to_print - -- **Type**: vector -- **Availability**: band_print_num > 0 -- **Description**: define which band you want to choose for partial charge density. -- **Default**: [] - ### out_element_info - **Type**: Boolean @@ -1678,14 +1662,14 @@ These variables are used to control the output of properties. ### nbands_istate - **Type**: Integer -- **Availability**: Only used when `calculation = get_wf` or `calculation = get_pchg`. +- **Availability**: Only for LCAO, used when `calculation = get_wf` or `calculation = get_pchg`. - **Description**: The number of bands around the Fermi level you would like to calculate. `get_wf` means to calculate the envelope functions of wave functions $\Psi_{i}=\Sigma_{\mu}C_{i\mu}\Phi_{\mu}$, where $\Psi_{i}$ is the ith wave function with the band index $i$ and $\Phi_{\mu}$ is the localized atomic orbital set. `get_pchg` means to calculate the density of each wave function $|\Psi_{i}|^{2}$. Specifically, suppose we have highest occupied bands at 100th wave functions. And if you set this variable to 5, it will print five wave functions from 96th to 105th. But before all this can be carried out, the wave functions coefficients should be first calculated and written into a file by setting the flag `out_wfc_lcao = 1`. - **Default**: 5 -### out_band_index +### bands_to_print - **Type**: String -- **Availability**: Only used when `calculation = get_pchg`. +- **Availability**: For both PW and LCAO. When `basis_type = lcao`, only used when `calculation = get_pchg`. - **Description**: Specifies the bands to calculate the charge density for, using a space-separated string of 0s and 1s, providing a more flexible selection compared to `nbands_istate`. Each digit in the string corresponds to a band, starting from the first band. A `1` indicates that the charge density should be calculated for that band, while a `0` means the band will be ignored. The parameter allows a compact and flexible notation (similar to [`ocp_set`](#ocp_set)), for example the syntax `1 4*0 5*1 0` is used to denote the selection of bands: `1` means calculate for the first band, `4*0` skips the next four bands, `5*1` means calculate for the following five bands, and the final `0` skips the next band. It's essential that the total count of bands does not exceed the total number of bands (`nbands`); otherwise, it results in an error, and the process exits. The input string must contain only numbers and the asterisk (`*`) for repetition, ensuring correct format and intention of band selection. - **Default**: none diff --git a/source/module_esolver/esolver_ks_pw.cpp b/source/module_esolver/esolver_ks_pw.cpp index b3ca6fb2c4..24a1d3f189 100644 --- a/source/module_esolver/esolver_ks_pw.cpp +++ b/source/module_esolver/esolver_ks_pw.cpp @@ -1024,12 +1024,12 @@ void ESolver_KS_PW::after_scf(const int istep) this->psi[0].size()); } - // Get out_band_index through public function of INPUT (returns a const pointer to string) - std::string out_band_index = *INPUT.get_out_band_index(); - if(!out_band_index.empty()) + // Get bands_to_print through public function of INPUT (returns a const pointer to string) + std::string bands_to_print = *INPUT.get_bands_to_print(); + if(!bands_to_print.empty()) { std::vector out_band_kb; - Input_Conv::parse_expression(out_band_index, out_band_kb); + Input_Conv::parse_expression(bands_to_print, out_band_kb); // bands_picked is a vector of 0s and 1s, where 1 means the band is picked to output std::vector bands_picked; @@ -1041,7 +1041,7 @@ void ESolver_KS_PW::after_scf(const int istep) { ModuleBase::WARNING_QUIT( "ESolver_KS_PW::after_scf", - "The number of bands specified by `out_band_index` in the INPUT file exceeds `nbands`!"); + "The number of bands specified by `bands_to_print` in the INPUT file exceeds `nbands`!"); } // Check if all elements in bands_picked are 0 or 1 @@ -1051,7 +1051,7 @@ void ESolver_KS_PW::after_scf(const int istep) { ModuleBase::WARNING_QUIT( "ESolver_KS_PW::after_scf", - "The elements of `out_band_index` must be either 0 or 1. Invalid values found!"); + "The elements of `bands_to_print` must be either 0 or 1. Invalid values found!"); } } diff --git a/source/module_io/input.cpp b/source/module_io/input.cpp index 65f4a0a26f..5cce4bf474 100644 --- a/source/module_io/input.cpp +++ b/source/module_io/input.cpp @@ -162,7 +162,7 @@ void Input::Default(void) nbands_sto = 256; nbndsto_str = "256"; nbands_istate = 5; - out_band_index_ = ""; + bands_to_print_ = ""; pw_seed = 1; emin_sto = 0.0; emax_sto = 0.0; @@ -783,9 +783,9 @@ bool Input::Read(const std::string& fn) // if (nbands_istate < 0) // ModuleBase::WARNING_QUIT("Input", "NBANDS_ISTATE must > 0"); } - else if (strcmp("out_band_index", word) == 0) + else if (strcmp("bands_to_print", word) == 0) { - getline(ifs, out_band_index_); + getline(ifs, bands_to_print_); } else if (strcmp("nche_sto", word) == 0) // Chebyshev expansion order { @@ -3228,7 +3228,7 @@ void Input::Bcast() Parallel_Common::bcast_int(nbands); Parallel_Common::bcast_int(nbands_sto); Parallel_Common::bcast_int(nbands_istate); - Parallel_Common::bcast_string(out_band_index_); + Parallel_Common::bcast_string(bands_to_print_); for (int i = 0; i < 3; i++) { Parallel_Common::bcast_double(kspacing[i]); diff --git a/source/module_io/input.h b/source/module_io/input.h index 35afe85db0..79f337b3b6 100644 --- a/source/module_io/input.h +++ b/source/module_io/input.h @@ -639,7 +639,7 @@ class Input int count_ntype(const std::string &fn); // sunliang add 2022-12-06 - std::string out_band_index_; // specify the bands to be calculated in the get_pchg calculation, formalism similar to ocp_set. + std::string bands_to_print_; // specify the bands to be calculated in the get_pchg calculation, formalism similar to ocp_set. public: template static void read_value(std::ifstream &ifs, T &var) @@ -699,10 +699,10 @@ class Input void strtolower(char *sa, char *sb); void read_bool(std::ifstream &ifs, bool &var); - // Return the const string pointer of private member out_band_index_ - const std::string* get_out_band_index() const + // Return the const string pointer of private member bands_to_print_ + const std::string* get_bands_to_print() const { - return &out_band_index_; + return &bands_to_print_; } }; diff --git a/source/module_io/istate_charge.cpp b/source/module_io/istate_charge.cpp index 4c2d65c8e9..8fe4a170d5 100644 --- a/source/module_io/istate_charge.cpp +++ b/source/module_io/istate_charge.cpp @@ -41,19 +41,19 @@ void IState_Charge::begin(Gint_Gamma& gg, ModuleBase::WARNING_QUIT("IState_Charge::begin", "Only available for GAMMA_ONLY_LOCAL now."); } - // Get out_band_index through public function of INPUT (returns a const pointer to string) - std::string out_band_index = *INPUT.get_out_band_index(); + // Get bands_to_print through public function of INPUT (returns a const pointer to string) + std::string bands_to_print = *INPUT.get_bands_to_print(); int mode = 0; - if (nbands_istate > 0 && out_band_index.empty()) + if (nbands_istate > 0 && bands_to_print.empty()) { mode = 1; } - else if (!out_band_index.empty()) + else if (!bands_to_print.empty()) { - // If out_band_index is not empty, set mode to 2 + // If bands_to_print is not empty, set mode to 2 mode = 2; - std::cout << " Notice: INPUT parameter `nbands_istate` overwritten by `out_band_index`!" << std::endl; + std::cout << " Notice: INPUT parameter `nbands_istate` overwritten by `bands_to_print`!" << std::endl; } else { @@ -64,7 +64,7 @@ void IState_Charge::begin(Gint_Gamma& gg, int bands_below = 0; int bands_above = 0; std::vector out_band_kb; - Input_Conv::parse_expression(out_band_index, out_band_kb); + Input_Conv::parse_expression(bands_to_print, out_band_kb); // (2) cicle: // (2.1) calculate the selected density matrix from wave functions. @@ -112,7 +112,7 @@ void IState_Charge::begin(Gint_Gamma& gg, { ModuleBase::WARNING_QUIT( "IState_Charge::begin", - "The number of bands specified by `out_band_index` in the INPUT file exceeds `nbands`!"); + "The number of bands specified by `bands_to_print` in the INPUT file exceeds `nbands`!"); } // Check if all elements in bands_picked_ are 0 or 1 for (int value: out_band_kb) @@ -121,7 +121,7 @@ void IState_Charge::begin(Gint_Gamma& gg, { ModuleBase::WARNING_QUIT( "IState_Charge::begin", - "The elements of `out_band_index` must be either 0 or 1. Invalid values found!"); + "The elements of `bands_to_print` must be either 0 or 1. Invalid values found!"); } } // Fill bands_picked_ with values from out_band_kb, converting to int diff --git a/source/module_io/test/input_test_para.cpp b/source/module_io/test/input_test_para.cpp index 9dac0c7b8e..0ba90d9076 100644 --- a/source/module_io/test/input_test_para.cpp +++ b/source/module_io/test/input_test_para.cpp @@ -48,7 +48,7 @@ TEST_F(InputParaTest, Bcast) EXPECT_EQ(INPUT.nbands, 0); EXPECT_EQ(INPUT.nbands_sto, 256); EXPECT_EQ(INPUT.nbands_istate, 5); - EXPECT_EQ(*INPUT.get_out_band_index(), ""); + EXPECT_EQ(*INPUT.get_bands_to_print(), ""); EXPECT_EQ(INPUT.pw_seed, 1); EXPECT_EQ(INPUT.emin_sto, 0.0); EXPECT_EQ(INPUT.emax_sto, 0.0); diff --git a/source/module_io/write_input.cpp b/source/module_io/write_input.cpp index 59e4340d84..bbfcd1547c 100644 --- a/source/module_io/write_input.cpp +++ b/source/module_io/write_input.cpp @@ -60,7 +60,7 @@ void Input::Print(const std::string &fn) const "nbands_istate", nbands_istate, "number of bands around Fermi level for get_pchg calulation"); - ModuleBase::GlobalFunc::OUTP(ofs, "out_band_index", out_band_index_, "specify the bands to be calculated in the get_pchg calculation"); + ModuleBase::GlobalFunc::OUTP(ofs, "bands_to_print", bands_to_print_, "specify the bands to be calculated in the get_pchg calculation"); ModuleBase::GlobalFunc::OUTP(ofs, "symmetry", symmetry, "the control of symmetry"); ModuleBase::GlobalFunc::OUTP(ofs, "init_vel", init_vel, "read velocity from STRU or not"); ModuleBase::GlobalFunc::OUTP(ofs,