@@ -26,7 +26,7 @@ IState_Charge::~IState_Charge()
2626{
2727}
2828
29- // for gamma only
29+ // For gamma_only
3030void IState_Charge::begin (Gint_Gamma& gg,
3131 double ** rho,
3232 const ModuleBase::matrix& wg,
@@ -41,36 +41,35 @@ void IState_Charge::begin(Gint_Gamma& gg,
4141 const int bigpw_nbz,
4242 const bool gamma_only_local,
4343 const int nbands_istate,
44- const std::vector<int >& out_band_kb ,
44+ const std::vector<int >& out_pchg ,
4545 const int nbands,
4646 const double nelec,
4747 const int nspin,
4848 const int nlocal,
4949 const std::string& global_out_dir,
50- const int my_rank,
5150 std::ofstream& ofs_warning,
5251 const UnitCell* ucell_in,
5352 Grid_Driver* GridD_in,
5453 const K_Vectors& kv)
5554{
5655 ModuleBase::TITLE (" IState_Charge" , " begin" );
5756
58- std::cout << " Perform |psi(i)|^2 for selected bands (band-decomposed charge densities, gamma only)." << std::endl;
57+ std::cout << " Calculate |psi(i)|^2 for selected bands (band-decomposed charge densities, gamma only)."
58+ << std::endl;
5959
60+ // Determine the mode based on the input parameters
6061 int mode = 0 ;
61- if (nbands_istate > 0 && static_cast <int >(out_band_kb.size ()) == 0 )
62+ // mode = 1: select bands below and above the Fermi surface using parameter `nbands_istate`
63+ if (nbands_istate > 0 && static_cast <int >(out_pchg.size ()) == 0 )
6264 {
6365 mode = 1 ;
6466 }
65- else if (static_cast <int >(out_band_kb.size ()) > 0 )
67+ // mode = 2: select bands directly using parameter `out_pchg`
68+ else if (static_cast <int >(out_pchg.size ()) > 0 )
6669 {
67- // If out_band_kb (bands_to_print) is not empty, set mode to 2
70+ // If out_pchg is not empty, set mode to 2
6871 mode = 2 ;
69- std::cout << " Notice: INPUT parameter `nbands_istate` overwritten by `bands_to_print`!" << std::endl;
70- }
71- else
72- {
73- mode = 3 ;
72+ std::cout << " Notice: INPUT parameter `nbands_istate` overwritten by `out_pchg`!" << std::endl;
7473 }
7574
7675 // if ucell is odd, it's correct,
@@ -81,7 +80,7 @@ void IState_Charge::begin(Gint_Gamma& gg,
8180 std::cout << " number of occupied bands = " << fermi_band << std::endl;
8281
8382 // Set this->bands_picked_ according to the mode
84- select_bands (nbands_istate, out_band_kb , nbands, nelec, mode, fermi_band);
83+ select_bands (nbands_istate, out_pchg , nbands, nelec, mode, fermi_band);
8584
8685 for (int ib = 0 ; ib < nbands; ++ib)
8786 {
@@ -174,13 +173,12 @@ void IState_Charge::begin(Gint_k& gk,
174173 const int bigpw_nbz,
175174 const bool gamma_only_local,
176175 const int nbands_istate,
177- const std::vector<int >& out_band_kb ,
176+ const std::vector<int >& out_pchg ,
178177 const int nbands,
179178 const double nelec,
180179 const int nspin,
181180 const int nlocal,
182181 const std::string& global_out_dir,
183- const int my_rank,
184182 std::ofstream& ofs_warning,
185183 UnitCell* ucell_in,
186184 Grid_Driver* GridD_in,
@@ -191,18 +189,18 @@ void IState_Charge::begin(Gint_k& gk,
191189{
192190 ModuleBase::TITLE (" IState_Charge" , " begin" );
193191
194- std::cout << " Perform |psi(i)|^2 for selected bands (band-decomposed charge densities, multi-k)." << std::endl;
192+ std::cout << " Calculate |psi(i)|^2 for selected bands (band-decomposed charge densities, multi-k)." << std::endl;
195193
196194 int mode = 0 ;
197- if (nbands_istate > 0 && static_cast <int >(out_band_kb .size ()) == 0 )
195+ if (nbands_istate > 0 && static_cast <int >(out_pchg .size ()) == 0 )
198196 {
199197 mode = 1 ;
200198 }
201- else if (static_cast <int >(out_band_kb .size ()) > 0 )
199+ else if (static_cast <int >(out_pchg .size ()) > 0 )
202200 {
203- // If out_band_kb (bands_to_print) is not empty, set mode to 2
201+ // If out_pchg is not empty, set mode to 2
204202 mode = 2 ;
205- std::cout << " Notice: INPUT parameter `nbands_istate` overwritten by `bands_to_print `!" << std::endl;
203+ std::cout << " Notice: INPUT parameter `nbands_istate` overwritten by `out_pchg `!" << std::endl;
206204 }
207205 else
208206 {
@@ -214,7 +212,7 @@ void IState_Charge::begin(Gint_k& gk,
214212 std::cout << " number of occupied bands = " << fermi_band << std::endl;
215213
216214 // Set this->bands_picked_ according to the mode
217- select_bands (nbands_istate, out_band_kb , nbands, nelec, mode, fermi_band);
215+ select_bands (nbands_istate, out_pchg , nbands, nelec, mode, fermi_band);
218216
219217 for (int ib = 0 ; ib < nbands; ++ib)
220218 {
@@ -322,13 +320,7 @@ void IState_Charge::begin(Gint_k& gk,
322320 {
323321 rho_save_pointers[i] = rho_save[i].data ();
324322 }
325- srho.begin (is,
326- rho_save_pointers.data (),
327- rhog,
328- ngmc,
329- nullptr ,
330- rho_pw,
331- ucell_in->symm );
323+ srho.begin (is, rho_save_pointers.data (), rhog, ngmc, nullptr , rho_pw, ucell_in->symm );
332324 }
333325
334326 std::cout << " Writing cube files..." ;
@@ -368,7 +360,7 @@ void IState_Charge::begin(Gint_k& gk,
368360}
369361
370362void IState_Charge::select_bands (const int nbands_istate,
371- const std::vector<int >& out_band_kb ,
363+ const std::vector<int >& out_pchg ,
372364 const int nbands,
373365 const double nelec,
374366 const int mode,
@@ -382,6 +374,7 @@ void IState_Charge::select_bands(const int nbands_istate,
382374 this ->bands_picked_ .resize (nbands);
383375 ModuleBase::GlobalFunc::ZEROS (bands_picked_.data (), nbands);
384376
377+ // mode = 1: select bands below and above the Fermi surface using parameter `nbands_istate`
385378 if (mode == 1 )
386379 {
387380 bands_below = nbands_istate;
@@ -404,33 +397,28 @@ void IState_Charge::select_bands(const int nbands_istate,
404397 }
405398 }
406399 }
400+ // mode = 2: select bands directly using parameter `out_pchg`
407401 else if (mode == 2 )
408402 {
409- // Check if length of out_band_kb is valid
410- if (static_cast <int >(out_band_kb .size ()) > nbands)
403+ // Check if length of out_pchg is valid
404+ if (static_cast <int >(out_pchg .size ()) > nbands)
411405 {
412- ModuleBase::WARNING_QUIT (
413- " IState_Charge::select_bands" ,
414- " The number of bands specified by `bands_to_print` in the INPUT file exceeds `nbands`!" );
406+ ModuleBase::WARNING_QUIT (" IState_Charge::select_bands" ,
407+ " The number of bands specified by `out_pchg` in the INPUT file exceeds `nbands`!" );
415408 }
416- // Check if all elements in out_band_kb are 0 or 1
417- for (int value: out_band_kb )
409+ // Check if all elements in out_pchg are 0 or 1
410+ for (int value: out_pchg )
418411 {
419412 if (value != 0 && value != 1 )
420413 {
421- ModuleBase::WARNING_QUIT (
422- " IState_Charge::select_bands" ,
423- " The elements of `bands_to_print` must be either 0 or 1. Invalid values found!" );
414+ ModuleBase::WARNING_QUIT (" IState_Charge::select_bands" ,
415+ " The elements of `out_pchg` must be either 0 or 1. Invalid values found!" );
424416 }
425417 }
426- // Fill bands_picked_ with values from out_band_kb
418+ // Fill bands_picked_ with values from out_pchg
427419 // Remaining bands are already set to 0
428- const int length = std::min (static_cast <int >(out_band_kb.size ()), nbands);
429- for (int i = 0 ; i < length; ++i)
430- {
431- // out_band_kb rely on function parse_expression
432- bands_picked_[i] = out_band_kb[i];
433- }
420+ const int length = std::min (static_cast <int >(out_pchg.size ()), nbands);
421+ std::copy (out_pchg.begin (), out_pchg.begin () + length, bands_picked_.begin ());
434422
435423 // Check if there are selected bands below the Fermi surface
436424 bool has_below = false ;
@@ -485,7 +473,7 @@ void IState_Charge::select_bands(const int nbands_istate,
485473}
486474
487475#ifdef __MPI
488- // for gamma only
476+ // For gamma_only
489477void IState_Charge::idmatrix (const int & ib,
490478 const int nspin,
491479 const double & nelec,
0 commit comments