From bc9527ed8997ae6fb259495f9019fab5e2754408 Mon Sep 17 00:00:00 2001 From: mohanchen Date: Thu, 29 May 2025 09:07:21 +0800 Subject: [PATCH 01/19] add notes for the modified output file names, specify the names in the 3.10-LTS version --- docs/advanced/input_files/input-main.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/advanced/input_files/input-main.md b/docs/advanced/input_files/input-main.md index d91640bdb4..e78c7286d3 100644 --- a/docs/advanced/input_files/input-main.md +++ b/docs/advanced/input_files/input-main.md @@ -1638,6 +1638,7 @@ These variables are used to control the output of properties. In molecular dynamics calculations, the output frequency is controlled by [out_interval](#out_interval). - **Default**: 0 +- **NOTE**: In the 3.10-LTS version, the file names are SPIN1_POT.cube and SPIN1_POT_INI.cube, etc. ### out_dm @@ -1651,6 +1652,7 @@ These variables are used to control the output of properties. - nspin = 1: `dms1k1_nao.csr`, `dms1k2_nao.csr`, ...; - nspin = 2: `dms1k1_nao.csr`... and `dms2k1_nao.csr`... for the two spin channels. - **Default**: False +- **NOTE**: In the 3.10-LTS version, the file names are SPIN1_DM and SPIN2_DM, etc. ### out_dm1 @@ -1660,6 +1662,7 @@ These variables are used to control the output of properties. - nspin = 1: `dmrs1_nao.csr`; - nspin = 2: `dmrs1_nao.csr` and `dmrs2_nao.csr` for the two spin channels. - **Default**: False +- **NOTE**: In the 3.10-LTS version, the file names are data-DMR-sparse_SPIN0.csr and data-DMR-sparse_SPIN1.csr, etc. ### out_wfc_pw @@ -1672,6 +1675,7 @@ These variables are used to control the output of properties. - 2: (binary format) - non-gamma-only: `wfs1k1_pw.dat` or `wfs1k2_pw.dat`, .... - **Default**: 0 +- **NOTE**: In the 3.10-LTS version, the file names are OUT.${suffix}/WAVEFUNC${K}.dat, etc. ### out_wfc_lcao @@ -1689,7 +1693,8 @@ These variables are used to control the output of properties. The corresponding sequence of the orbitals can be seen in [Basis Set](../pp_orb.md#basis-set). Also controled by [out_interval](#out_interval) and [out_app_flag](#out_app_flag). -- **Default**: Flase +- **Default**: False +- **NOTE**: In the 3.10-LTS version, the file names are WFC_NAO_GAMMA1_ION1.txt and WFC_NAO_K1_ION1.txt, etc. ### out_dos From dab6d17010d34d165ff4c897ed931912dd7adc2c Mon Sep 17 00:00:00 2001 From: mohanchen Date: Thu, 29 May 2025 09:25:51 +0800 Subject: [PATCH 02/19] update the CHG file names in input-main.md and change the output file names of charge density --- docs/advanced/input_files/input-main.md | 20 +++++++++----------- source/module_esolver/esolver_fp.cpp | 7 ++++--- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/docs/advanced/input_files/input-main.md b/docs/advanced/input_files/input-main.md index e78c7286d3..6d553d4f34 100644 --- a/docs/advanced/input_files/input-main.md +++ b/docs/advanced/input_files/input-main.md @@ -608,7 +608,7 @@ These variables are used to control general system parameters. - **Description**: This variable is used for both plane wave set and localized orbitals set. It indicates the type of starting density. - atomic: the density is starting from the summation of the atomic density of single atoms. - - file: the density will be read in from a binary file `charge-density.dat` first. If it does not exist, the charge density will be read in from cube files. Besides, when you do `nspin=1` calculation, you only need the density file SPIN1_CHG.cube. However, if you do `nspin=2` calculation, you also need the density file SPIN2_CHG.cube. The density file should be output with these names if you set out_chg = 1 in INPUT file. + - file: the density will be read in from a binary file `charge-density.dat` first. If it does not exist, the charge density will be read in from cube files. Besides, when you do `nspin=1` calculation, you only need the density file chgs1.cube. However, if you do `nspin=2` calculation, you also need the density file chgs2.cube. The density file should be output with these names if you set out_chg = 1 in INPUT file. - wfc: the density will be calculated by wavefunctions and occupations. Wavefunctions are read in from binary files `wf*.dat` (see [out_wfc_pw](#out_wfc_pw)) while occupations are read in from file `istate.info`. - auto: Abacus first attempts to read the density from a file; if not found, it defaults to using atomic density. - **Default**: atomic @@ -742,7 +742,7 @@ These variables are used to control parameters related to input files. ### read_file_dir - **Type**: String -- **Description**: Indicates the location of files, such as electron density (`SPIN1_CHG.cube`), required as a starting point. +- **Description**: Location of files, such as the electron density (`chgs1.cube`), required as a starting point. - Example: './' implies the files to be read are located in the working directory. - **Default**: OUT.$suffix @@ -1602,13 +1602,10 @@ These variables are used to control the output of properties. - **Description**: The first integer controls whether to output the charge density on real space grids: - 1: Output the charge density (in Bohr^-3) on real space grids into the density files in the folder `OUT.${suffix}`. The files are named as: - - nspin = 1: SPIN1_CHG.cube; - - nspin = 2: SPIN1_CHG.cube, and SPIN2_CHG.cube; - - nspin = 4: SPIN1_CHG.cube, SPIN2_CHG.cube, SPIN3_CHG.cube, and SPIN4_CHG.cube. - - 2: On top of 1, also output the initial charge density. The files are named as: - - nspin = 1: SPIN1_CHG_INI.cube - - nspin = 2: SPIN1_CHG_INI.cube, and SPIN2_CHG_INI.cube; - - nspin = 4: SPIN1_CHG_INI.cube, SPIN2_CHG_INI.cube, SPIN3_CHG_INI.cube, and SPIN4_CHG_INI.cube. + - nspin = 1: `chgs1.cube`; + - nspin = 2: `chgs1.cube`, and `chgs2.cube`; + - nspin = 4: `chgs1.cube`, `chgs2.cube`, `chgs3.cube`, and `chgs4.cube`; + - 2: On top of 1, also output the initial charge density, the file names have suffix _ini, such as `chgs1_ini.cube`, etc. - -1: disable the charge density auto-back-up file `{suffix}-CHARGE-DENSITY.restart`, useful for large systems. The second integer controls the precision of the charge density output, if not given, will use `3` as default. For purpose restarting from this file and other high-precision involved calculation, recommend to use `10`. @@ -1616,10 +1613,11 @@ These variables are used to control the output of properties. --- The circle order of the charge density on real space grids is: x is the outer loop, then y and finally z (z is moving fastest). - If EXX(exact exchange) is calculated, (i.e. *[dft_fuctional](#dft_functional)==hse/hf/pbe0/scan0/opt_orb* or *[rpa](#rpa)==True*), the Hexx(R) files will be output in the folder `OUT.${suffix}` too, which can be read in NSCF calculation. + In EXX(exact exchange) calculations, (i.e. *[dft_fuctional](#dft_functional)==hse/hf/pbe0/scan0/opt_orb* or *[rpa](#rpa)==True*), the Hexx(R) files will be output in the folder `OUT.${suffix}` too, which can be read in NSCF calculation. - In molecular dynamics calculations, the output frequency is controlled by [out_interval](#out_interval). + In molecular dynamics simulations, the output frequency is controlled by [out_interval](#out_interval). - **Default**: 0 3 +- **NOTE**: In the 3.10-LTS version, the file names are SPIN1_CHG.cube and SPIN1_CHG_INI.cube, etc. ### out_pot diff --git a/source/module_esolver/esolver_fp.cpp b/source/module_esolver/esolver_fp.cpp index 95d0d11081..f32a389158 100644 --- a/source/module_esolver/esolver_fp.cpp +++ b/source/module_esolver/esolver_fp.cpp @@ -165,7 +165,7 @@ void ESolver_FP::after_scf(UnitCell& ucell, const int istep, const bool conv_eso for (int is = 0; is < PARAM.inp.nspin; is++) { this->pw_rhod->real2recip(this->chr.rho_save[is], this->chr.rhog_save[is]); - std::string fn =PARAM.globalv.global_out_dir + "/SPIN" + std::to_string(is + 1) + "_CHG.cube"; + std::string fn =PARAM.globalv.global_out_dir + "/chgs" + std::to_string(is + 1) + ".cube"; ModuleIO::write_vdata_palgrid(Pgrid, this->chr.rho_save[is], is, @@ -176,9 +176,10 @@ void ESolver_FP::after_scf(UnitCell& ucell, const int istep, const bool conv_eso &(ucell), PARAM.inp.out_chg[1], 1); + if (XC_Functional::get_ked_flag()) { - fn =PARAM.globalv.global_out_dir + "/SPIN" + std::to_string(is + 1) + "_TAU.cube"; + fn =PARAM.globalv.global_out_dir + "/taus" + std::to_string(is + 1) + ".cube"; ModuleIO::write_vdata_palgrid(Pgrid, this->chr.kin_r_save[is], is, @@ -339,7 +340,7 @@ void ESolver_FP::before_scf(UnitCell& ucell, const int istep) for (int is = 0; is < PARAM.inp.nspin; is++) { std::stringstream ss; - ss << PARAM.globalv.global_out_dir << "SPIN" << is + 1 << "_CHG_INI.cube"; + ss << PARAM.globalv.global_out_dir << "/chgs" << is + 1 << "_ini.cube"; ModuleIO::write_vdata_palgrid(this->Pgrid, this->chr.rho[is], is, From 050b85ebfc88281ac8f2a050b47c33c203b611ec Mon Sep 17 00:00:00 2001 From: mohanchen Date: Thu, 29 May 2025 09:30:41 +0800 Subject: [PATCH 03/19] add explanations for taus1.cube, etc. --- docs/advanced/input_files/input-main.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/advanced/input_files/input-main.md b/docs/advanced/input_files/input-main.md index 6d553d4f34..8a56cfd4c6 100644 --- a/docs/advanced/input_files/input-main.md +++ b/docs/advanced/input_files/input-main.md @@ -1605,7 +1605,11 @@ These variables are used to control the output of properties. - nspin = 1: `chgs1.cube`; - nspin = 2: `chgs1.cube`, and `chgs2.cube`; - nspin = 4: `chgs1.cube`, `chgs2.cube`, `chgs3.cube`, and `chgs4.cube`; - - 2: On top of 1, also output the initial charge density, the file names have suffix _ini, such as `chgs1_ini.cube`, etc. + Note that by using the Meta-GGA functional, additional files containing the kinetic energy density will be output with the following names: + - nspin = 1: `taus1.cube`; + - nspin = 2: `taus1.cube`, and `taus2.cube`; + - nspin = 4: `taus1.cube`, `taus2.cube`, `taus3.cube`, and `taus4.cube`; + - 2: On top of 1, also output the initial charge density files with a suffix name as '_ini', such as `taus1_ini.cube`, etc. - -1: disable the charge density auto-back-up file `{suffix}-CHARGE-DENSITY.restart`, useful for large systems. The second integer controls the precision of the charge density output, if not given, will use `3` as default. For purpose restarting from this file and other high-precision involved calculation, recommend to use `10`. From 5140b3ca83309b1e889f179dc53a62aa7459afdb Mon Sep 17 00:00:00 2001 From: mohanchen Date: Thu, 29 May 2025 09:44:18 +0800 Subject: [PATCH 04/19] change the file names for 203_PW_OK example --- .../203_PW_OK/{SPIN1_CHG.cube.ref => chgs1.cube.ref} | 0 .../203_PW_OK/{SPIN1_TAU.cube.ref => taus1.cube.ref} | 0 tests/integrate/tools/catch_properties.sh | 8 ++++---- 3 files changed, 4 insertions(+), 4 deletions(-) rename tests/01_PW/203_PW_OK/{SPIN1_CHG.cube.ref => chgs1.cube.ref} (100%) rename tests/01_PW/203_PW_OK/{SPIN1_TAU.cube.ref => taus1.cube.ref} (100%) diff --git a/tests/01_PW/203_PW_OK/SPIN1_CHG.cube.ref b/tests/01_PW/203_PW_OK/chgs1.cube.ref similarity index 100% rename from tests/01_PW/203_PW_OK/SPIN1_CHG.cube.ref rename to tests/01_PW/203_PW_OK/chgs1.cube.ref diff --git a/tests/01_PW/203_PW_OK/SPIN1_TAU.cube.ref b/tests/01_PW/203_PW_OK/taus1.cube.ref similarity index 100% rename from tests/01_PW/203_PW_OK/SPIN1_TAU.cube.ref rename to tests/01_PW/203_PW_OK/taus1.cube.ref diff --git a/tests/integrate/tools/catch_properties.sh b/tests/integrate/tools/catch_properties.sh index 705f118890..bc7f7a7bb9 100755 --- a/tests/integrate/tools/catch_properties.sh +++ b/tests/integrate/tools/catch_properties.sh @@ -376,10 +376,10 @@ fi #--------------------------------------- if ! test -z "$has_scan" && [ $has_scan == "scan" ] && \ ! test -z "$out_chg" && [ $out_chg == 1 ]; then - python3 $COMPARE_SCRIPT SPIN1_CHG.cube.ref OUT.autotest/SPIN1_CHG.cube 8 - echo "SPIN1_CHG.cube_pass $?" >>$1 - python3 $COMPARE_SCRIPT SPIN1_TAU.cube.ref OUT.autotest/SPIN1_TAU.cube 8 - echo "SPIN1_TAU.cube_pass $?" >>$1 + python3 $COMPARE_SCRIPT chgs1.cube.ref OUT.autotest/chgs1.cube 8 + echo "chgs1.cube_pass $?" >>$1 + python3 $COMPARE_SCRIPT taus1.cube.ref OUT.autotest/taus1.cube 8 + echo "taus1.cube_pass $?" >>$1 fi #--------------------------------------- From 69b23cf9875cbd3c9c9b8a5569bd9ff30aa8709f Mon Sep 17 00:00:00 2001 From: mohanchen Date: Thu, 29 May 2025 10:04:42 +0800 Subject: [PATCH 05/19] update read in charge density codes and tests --- .../module_charge/charge_init.cpp | 41 +++++++++++-------- .../{SPIN1_CHG.cube => chgs1.cube} | 0 2 files changed, 23 insertions(+), 18 deletions(-) rename tests/03_NAO_multik/16_NO_KP_OD/{SPIN1_CHG.cube => chgs1.cube} (100%) diff --git a/source/module_elecstate/module_charge/charge_init.cpp b/source/module_elecstate/module_charge/charge_init.cpp index c6942279d0..cb73ad5a86 100644 --- a/source/module_elecstate/module_charge/charge_init.cpp +++ b/source/module_elecstate/module_charge/charge_init.cpp @@ -28,8 +28,12 @@ void Charge::init_rho(elecstate::efermi& eferm_iout, { ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "init_chg", PARAM.inp.init_chg); + const int nspin = PARAM.inp.nspin; + assert(nspin>0); + std::cout << " START CHARGE : " << PARAM.inp.init_chg << std::endl; - //here we need to set the omega for the charge density + + // we need to set the omega for the charge density set_omega(&ucell.omega); this->pgrid = &pgrid; @@ -46,17 +50,17 @@ void Charge::init_rho(elecstate::efermi& eferm_iout, if (ModuleIO::read_rhog(binary.str(), rhopw, rhog)) { GlobalV::ofs_running << " Read electron density from file: " << binary.str() << std::endl; - for (int is = 0; is < PARAM.inp.nspin; ++is) + for (int is = 0; is < nspin; ++is) { rhopw->recip2real(rhog[is], rho[is]); } } else { - for (int is = 0; is < PARAM.inp.nspin; ++is) + for (int is = 0; is < nspin; ++is) { std::stringstream ssc; - ssc << PARAM.globalv.global_readin_dir << "SPIN" << is + 1 << "_CHG.cube"; + ssc << PARAM.globalv.global_readin_dir << "chgs" << is + 1 << ".cube"; if (ModuleIO::read_vdata_palgrid(pgrid, (PARAM.inp.esolver_type == "sdft" ? GlobalV::RANK_IN_BPGROUP : GlobalV::MY_RANK), GlobalV::ofs_running, @@ -103,7 +107,7 @@ void Charge::init_rho(elecstate::efermi& eferm_iout, { const std::string warn_msg = " WARNING: \"init_chg\" is enabled but ABACUS failed to read\n charge density from file.\n" - " Please check if there is SPINX_CHG.cube (X=1,...) or\n {suffix}-CHARGE-DENSITY.restart in the " + " Please check if there is chgsx.cube (x=1,2,etc.) or\n {suffix}-CHARGE-DENSITY.restart in the " "directory.\n"; std::cout << warn_msg; if (PARAM.inp.init_chg == "file") @@ -121,9 +125,9 @@ void Charge::init_rho(elecstate::efermi& eferm_iout, { GlobalV::ofs_running << " try to read kinetic energy density from file" << std::endl; // try to read charge from binary file first, which is the same as QE - std::vector> kin_g_space(PARAM.inp.nspin * this->ngmc, {0.0, 0.0}); + std::vector> kin_g_space(nspin * this->ngmc, {0.0, 0.0}); std::vector*> kin_g; - for (int is = 0; is < PARAM.inp.nspin; is++) + for (int is = 0; is < nspin; is++) { kin_g.push_back(kin_g_space.data() + is * this->ngmc); } @@ -133,14 +137,14 @@ void Charge::init_rho(elecstate::efermi& eferm_iout, if (ModuleIO::read_rhog(binary.str(), rhopw, kin_g.data())) { GlobalV::ofs_running << " Read in the kinetic energy density: " << binary.str() << std::endl; - for (int is = 0; is < PARAM.inp.nspin; ++is) + for (int is = 0; is < nspin; ++is) { rhopw->recip2real(kin_g[is], this->kin_r[is]); } } else { - for (int is = 0; is < PARAM.inp.nspin; is++) + for (int is = 0; is < nspin; is++) { std::stringstream ssc; ssc << PARAM.globalv.global_readin_dir << "SPIN" << is + 1 << "_TAU.cube"; @@ -175,16 +179,16 @@ void Charge::init_rho(elecstate::efermi& eferm_iout, } } - if (PARAM.inp.init_chg == "atomic" || read_error) // mohan add 2007-10-17 + if (PARAM.inp.init_chg == "atomic" || read_error) { if (read_error) { std::cout << " Charge::init_rho: use atomic initialization instead." << std::endl; } - this->atomic_rho(PARAM.inp.nspin, ucell.omega, rho, strucFac, ucell); + this->atomic_rho(nspin, ucell.omega, rho, strucFac, ucell); } - // wenfei 2021-7-29 : initial tau = 3/5 rho^2/3, Thomas-Fermi + // initial tau = 3/5 rho^2/3, Thomas-Fermi if (XC_Functional::get_ked_flag()) { if (PARAM.inp.init_chg == "atomic" || read_kin_error) @@ -194,11 +198,11 @@ void Charge::init_rho(elecstate::efermi& eferm_iout, std::cout << " Charge::init_rho: init kinetic energy density from rho." << std::endl; } const double fact = (3.0 / 5.0) * pow(3.0 * ModuleBase::PI * ModuleBase::PI, 2.0 / 3.0); - for (int is = 0; is < PARAM.inp.nspin; ++is) + for (int is = 0; is < nspin; ++is) { for (int ir = 0; ir < this->rhopw->nrxx; ++ir) { - kin_r[is][ir] = fact * pow(std::abs(rho[is][ir]) * PARAM.inp.nspin, 5.0 / 3.0) / PARAM.inp.nspin; + kin_r[is][ir] = fact * pow(std::abs(rho[is][ir]) * nspin, 5.0 / 3.0) / nspin; } } } @@ -207,7 +211,7 @@ void Charge::init_rho(elecstate::efermi& eferm_iout, // Peize Lin add 2020.04.04 if (GlobalC::restart.info_load.load_charge && !GlobalC::restart.info_load.load_charge_finish) { - for (int is = 0; is < PARAM.inp.nspin; ++is) + for (int is = 0; is < nspin; ++is) { try { @@ -217,7 +221,7 @@ void Charge::init_rho(elecstate::efermi& eferm_iout, { // try to load from the output of `out_chg` std::stringstream ssc; - ssc << PARAM.globalv.global_readin_dir << "SPIN" << is + 1 << "_CHG.cube"; + ssc << PARAM.globalv.global_readin_dir << "chgs" << is + 1 << ".cube"; if (ModuleIO::read_vdata_palgrid(pgrid, (PARAM.inp.esolver_type == "sdft" ? GlobalV::RANK_IN_BPGROUP : GlobalV::MY_RANK), GlobalV::ofs_running, @@ -225,12 +229,13 @@ void Charge::init_rho(elecstate::efermi& eferm_iout, this->rho[is], ucell.nat)) { - GlobalV::ofs_running << " Read in the electron density: " << ssc.str() << std::endl; + GlobalV::ofs_running << " Read in electron density: " << ssc.str() << std::endl; } } } GlobalC::restart.info_load.load_charge_finish = true; } + #ifdef __MPI this->init_chgmpi(); #endif @@ -248,7 +253,7 @@ void Charge::init_rho(elecstate::efermi& eferm_iout, PARAM.globalv.global_readin_dir, GlobalV::KPAR, GlobalV::MY_POOL, GlobalV::MY_RANK, GlobalV::NPROC_IN_POOL, GlobalV::RANK_IN_POOL, - PARAM.inp.nbands, PARAM.inp.nspin, PARAM.globalv.npol, + PARAM.inp.nbands, nspin, PARAM.globalv.npol, kv->get_nkstot(),kv->ik2iktot,kv->isk,GlobalV::ofs_running); } } diff --git a/tests/03_NAO_multik/16_NO_KP_OD/SPIN1_CHG.cube b/tests/03_NAO_multik/16_NO_KP_OD/chgs1.cube similarity index 100% rename from tests/03_NAO_multik/16_NO_KP_OD/SPIN1_CHG.cube rename to tests/03_NAO_multik/16_NO_KP_OD/chgs1.cube From 5cb73b5e5dec709b6282adfbca5c8ebf8d35008a Mon Sep 17 00:00:00 2001 From: mohanchen Date: Thu, 29 May 2025 10:06:27 +0800 Subject: [PATCH 06/19] fix example 050_PW_CHG_mismatch --- tests/01_PW/050_PW_CHG_mismatch/{SPIN1_CHG.cube => chgs1.cube} | 0 tests/01_PW/050_PW_CHG_mismatch/{SPIN2_CHG.cube => chgs2.cube} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename tests/01_PW/050_PW_CHG_mismatch/{SPIN1_CHG.cube => chgs1.cube} (100%) rename tests/01_PW/050_PW_CHG_mismatch/{SPIN2_CHG.cube => chgs2.cube} (100%) diff --git a/tests/01_PW/050_PW_CHG_mismatch/SPIN1_CHG.cube b/tests/01_PW/050_PW_CHG_mismatch/chgs1.cube similarity index 100% rename from tests/01_PW/050_PW_CHG_mismatch/SPIN1_CHG.cube rename to tests/01_PW/050_PW_CHG_mismatch/chgs1.cube diff --git a/tests/01_PW/050_PW_CHG_mismatch/SPIN2_CHG.cube b/tests/01_PW/050_PW_CHG_mismatch/chgs2.cube similarity index 100% rename from tests/01_PW/050_PW_CHG_mismatch/SPIN2_CHG.cube rename to tests/01_PW/050_PW_CHG_mismatch/chgs2.cube From 47f36c22782af0b9db065a1424a899921008862a Mon Sep 17 00:00:00 2001 From: mohanchen Date: Thu, 29 May 2025 10:12:32 +0800 Subject: [PATCH 07/19] update the file names of charge densities --- tests/01_PW/051_PW_OBOD_MemSaver/{SPIN1_CHG.cube => chgs1.cube} | 0 tests/01_PW/052_PW_OB/{SPIN1_CHG.cube => chgs1.cube} | 0 tests/01_PW/053_PW_OD/{SPIN1_CHG.cube => chgs1.cube} | 0 tests/01_PW/056_PW_IW/{SPIN1_CHG.cube => chgs1.cube} | 0 tests/01_PW/088_PW_OP_nscf/{SPIN1_CHG.cube => chgs1.cube} | 0 tests/01_PW/105_PW_W90/{SPIN1_CHG.cube => chgs1.cube} | 0 tests/03_NAO_multik/15_NO_KP_OB/{SPIN1_CHG.cube => chgs1.cube} | 0 .../03_NAO_multik/19_NO_KP_OH_nscf/{SPIN1_CHG.cube => chgs1.cube} | 0 .../23_NO_KP_OK/{SPIN1_CHG.cube.ref => chgs1.cube.ref} | 0 .../23_NO_KP_OK/{SPIN1_TAU.cube.ref => taus1.cube.ref} | 0 .../03_NAO_multik/35_NO_KP_MU_nscf/{SPIN1_CHG.cube => chgs1.cube} | 0 tests/03_NAO_multik/39_NO_OP_nscf/{SPIN1_CHG.cube => chgs1.cube} | 0 tests/06_SDFT/18_PW_NSCF_KG_100/{SPIN1_CHG.cube => chgs1.cube} | 0 tests/06_SDFT/20_PW_SDOS_MALL/{SPIN1_CHG.cube => chgs1.cube} | 0 tests/06_SDFT/21_PW_SKG_10D10S/{SPIN1_CHG.cube => chgs1.cube} | 0 .../102_NO_GO_deepks_nscf/{SPIN1_CHG.cube => chgs1.cube} | 0 .../102_NO_KP_deepks_nscf/{SPIN1_CHG.cube => chgs1.cube} | 0 17 files changed, 0 insertions(+), 0 deletions(-) rename tests/01_PW/051_PW_OBOD_MemSaver/{SPIN1_CHG.cube => chgs1.cube} (100%) rename tests/01_PW/052_PW_OB/{SPIN1_CHG.cube => chgs1.cube} (100%) rename tests/01_PW/053_PW_OD/{SPIN1_CHG.cube => chgs1.cube} (100%) rename tests/01_PW/056_PW_IW/{SPIN1_CHG.cube => chgs1.cube} (100%) rename tests/01_PW/088_PW_OP_nscf/{SPIN1_CHG.cube => chgs1.cube} (100%) rename tests/01_PW/105_PW_W90/{SPIN1_CHG.cube => chgs1.cube} (100%) rename tests/03_NAO_multik/15_NO_KP_OB/{SPIN1_CHG.cube => chgs1.cube} (100%) rename tests/03_NAO_multik/19_NO_KP_OH_nscf/{SPIN1_CHG.cube => chgs1.cube} (100%) rename tests/03_NAO_multik/23_NO_KP_OK/{SPIN1_CHG.cube.ref => chgs1.cube.ref} (100%) rename tests/03_NAO_multik/23_NO_KP_OK/{SPIN1_TAU.cube.ref => taus1.cube.ref} (100%) rename tests/03_NAO_multik/35_NO_KP_MU_nscf/{SPIN1_CHG.cube => chgs1.cube} (100%) rename tests/03_NAO_multik/39_NO_OP_nscf/{SPIN1_CHG.cube => chgs1.cube} (100%) rename tests/06_SDFT/18_PW_NSCF_KG_100/{SPIN1_CHG.cube => chgs1.cube} (100%) rename tests/06_SDFT/20_PW_SDOS_MALL/{SPIN1_CHG.cube => chgs1.cube} (100%) rename tests/06_SDFT/21_PW_SKG_10D10S/{SPIN1_CHG.cube => chgs1.cube} (100%) rename tests/09_DeePKS/102_NO_GO_deepks_nscf/{SPIN1_CHG.cube => chgs1.cube} (100%) rename tests/09_DeePKS/102_NO_KP_deepks_nscf/{SPIN1_CHG.cube => chgs1.cube} (100%) diff --git a/tests/01_PW/051_PW_OBOD_MemSaver/SPIN1_CHG.cube b/tests/01_PW/051_PW_OBOD_MemSaver/chgs1.cube similarity index 100% rename from tests/01_PW/051_PW_OBOD_MemSaver/SPIN1_CHG.cube rename to tests/01_PW/051_PW_OBOD_MemSaver/chgs1.cube diff --git a/tests/01_PW/052_PW_OB/SPIN1_CHG.cube b/tests/01_PW/052_PW_OB/chgs1.cube similarity index 100% rename from tests/01_PW/052_PW_OB/SPIN1_CHG.cube rename to tests/01_PW/052_PW_OB/chgs1.cube diff --git a/tests/01_PW/053_PW_OD/SPIN1_CHG.cube b/tests/01_PW/053_PW_OD/chgs1.cube similarity index 100% rename from tests/01_PW/053_PW_OD/SPIN1_CHG.cube rename to tests/01_PW/053_PW_OD/chgs1.cube diff --git a/tests/01_PW/056_PW_IW/SPIN1_CHG.cube b/tests/01_PW/056_PW_IW/chgs1.cube similarity index 100% rename from tests/01_PW/056_PW_IW/SPIN1_CHG.cube rename to tests/01_PW/056_PW_IW/chgs1.cube diff --git a/tests/01_PW/088_PW_OP_nscf/SPIN1_CHG.cube b/tests/01_PW/088_PW_OP_nscf/chgs1.cube similarity index 100% rename from tests/01_PW/088_PW_OP_nscf/SPIN1_CHG.cube rename to tests/01_PW/088_PW_OP_nscf/chgs1.cube diff --git a/tests/01_PW/105_PW_W90/SPIN1_CHG.cube b/tests/01_PW/105_PW_W90/chgs1.cube similarity index 100% rename from tests/01_PW/105_PW_W90/SPIN1_CHG.cube rename to tests/01_PW/105_PW_W90/chgs1.cube diff --git a/tests/03_NAO_multik/15_NO_KP_OB/SPIN1_CHG.cube b/tests/03_NAO_multik/15_NO_KP_OB/chgs1.cube similarity index 100% rename from tests/03_NAO_multik/15_NO_KP_OB/SPIN1_CHG.cube rename to tests/03_NAO_multik/15_NO_KP_OB/chgs1.cube diff --git a/tests/03_NAO_multik/19_NO_KP_OH_nscf/SPIN1_CHG.cube b/tests/03_NAO_multik/19_NO_KP_OH_nscf/chgs1.cube similarity index 100% rename from tests/03_NAO_multik/19_NO_KP_OH_nscf/SPIN1_CHG.cube rename to tests/03_NAO_multik/19_NO_KP_OH_nscf/chgs1.cube diff --git a/tests/03_NAO_multik/23_NO_KP_OK/SPIN1_CHG.cube.ref b/tests/03_NAO_multik/23_NO_KP_OK/chgs1.cube.ref similarity index 100% rename from tests/03_NAO_multik/23_NO_KP_OK/SPIN1_CHG.cube.ref rename to tests/03_NAO_multik/23_NO_KP_OK/chgs1.cube.ref diff --git a/tests/03_NAO_multik/23_NO_KP_OK/SPIN1_TAU.cube.ref b/tests/03_NAO_multik/23_NO_KP_OK/taus1.cube.ref similarity index 100% rename from tests/03_NAO_multik/23_NO_KP_OK/SPIN1_TAU.cube.ref rename to tests/03_NAO_multik/23_NO_KP_OK/taus1.cube.ref diff --git a/tests/03_NAO_multik/35_NO_KP_MU_nscf/SPIN1_CHG.cube b/tests/03_NAO_multik/35_NO_KP_MU_nscf/chgs1.cube similarity index 100% rename from tests/03_NAO_multik/35_NO_KP_MU_nscf/SPIN1_CHG.cube rename to tests/03_NAO_multik/35_NO_KP_MU_nscf/chgs1.cube diff --git a/tests/03_NAO_multik/39_NO_OP_nscf/SPIN1_CHG.cube b/tests/03_NAO_multik/39_NO_OP_nscf/chgs1.cube similarity index 100% rename from tests/03_NAO_multik/39_NO_OP_nscf/SPIN1_CHG.cube rename to tests/03_NAO_multik/39_NO_OP_nscf/chgs1.cube diff --git a/tests/06_SDFT/18_PW_NSCF_KG_100/SPIN1_CHG.cube b/tests/06_SDFT/18_PW_NSCF_KG_100/chgs1.cube similarity index 100% rename from tests/06_SDFT/18_PW_NSCF_KG_100/SPIN1_CHG.cube rename to tests/06_SDFT/18_PW_NSCF_KG_100/chgs1.cube diff --git a/tests/06_SDFT/20_PW_SDOS_MALL/SPIN1_CHG.cube b/tests/06_SDFT/20_PW_SDOS_MALL/chgs1.cube similarity index 100% rename from tests/06_SDFT/20_PW_SDOS_MALL/SPIN1_CHG.cube rename to tests/06_SDFT/20_PW_SDOS_MALL/chgs1.cube diff --git a/tests/06_SDFT/21_PW_SKG_10D10S/SPIN1_CHG.cube b/tests/06_SDFT/21_PW_SKG_10D10S/chgs1.cube similarity index 100% rename from tests/06_SDFT/21_PW_SKG_10D10S/SPIN1_CHG.cube rename to tests/06_SDFT/21_PW_SKG_10D10S/chgs1.cube diff --git a/tests/09_DeePKS/102_NO_GO_deepks_nscf/SPIN1_CHG.cube b/tests/09_DeePKS/102_NO_GO_deepks_nscf/chgs1.cube similarity index 100% rename from tests/09_DeePKS/102_NO_GO_deepks_nscf/SPIN1_CHG.cube rename to tests/09_DeePKS/102_NO_GO_deepks_nscf/chgs1.cube diff --git a/tests/09_DeePKS/102_NO_KP_deepks_nscf/SPIN1_CHG.cube b/tests/09_DeePKS/102_NO_KP_deepks_nscf/chgs1.cube similarity index 100% rename from tests/09_DeePKS/102_NO_KP_deepks_nscf/SPIN1_CHG.cube rename to tests/09_DeePKS/102_NO_KP_deepks_nscf/chgs1.cube From d22a573dceaf059ee513b125dba3b9136ae92cc3 Mon Sep 17 00:00:00 2001 From: mohanchen Date: Thu, 29 May 2025 10:15:04 +0800 Subject: [PATCH 08/19] update CHG files in support directories --- .../module_elecstate/test/support/{SPIN1_CHG.cube => chgs1.cube} | 0 .../module_io/test_serial/support/{SPIN1_CHG.cube => chgs1.cube} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename source/module_elecstate/test/support/{SPIN1_CHG.cube => chgs1.cube} (100%) rename source/module_io/test_serial/support/{SPIN1_CHG.cube => chgs1.cube} (100%) diff --git a/source/module_elecstate/test/support/SPIN1_CHG.cube b/source/module_elecstate/test/support/chgs1.cube similarity index 100% rename from source/module_elecstate/test/support/SPIN1_CHG.cube rename to source/module_elecstate/test/support/chgs1.cube diff --git a/source/module_io/test_serial/support/SPIN1_CHG.cube b/source/module_io/test_serial/support/chgs1.cube similarity index 100% rename from source/module_io/test_serial/support/SPIN1_CHG.cube rename to source/module_io/test_serial/support/chgs1.cube From a61e8f4cf2009af0fc8120eecb14f191f6d237b1 Mon Sep 17 00:00:00 2001 From: mohanchen Date: Thu, 29 May 2025 11:51:55 +0800 Subject: [PATCH 09/19] fix file names in rho_io_test.cpp --- source/module_io/test_serial/rho_io_test.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/source/module_io/test_serial/rho_io_test.cpp b/source/module_io/test_serial/rho_io_test.cpp index 086275c480..339da2ae3f 100644 --- a/source/module_io/test_serial/rho_io_test.cpp +++ b/source/module_io/test_serial/rho_io_test.cpp @@ -91,7 +91,7 @@ class RhoIOTest : public ::testing::Test TEST_F(RhoIOTest, Read) { int is = 0; - std::string fn = "./support/SPIN1_CHG.cube"; + std::string fn = "./support/chgs1.cube"; int nx = 36; int ny = 36; int nz = 36; @@ -117,9 +117,9 @@ TEST_F(RhoIOTest, Write) ucell->atoms[0].tau[1] = ModuleBase::Vector3(-0.75, 0.75, 0.75); ucell->atoms[0].ncpp.zv = 4; Parallel_Grid pgrid(nx, ny, nz, nz, nrxx, nz, 1); - ModuleIO::read_vdata_palgrid(pgrid, my_rank, ofs_running, "support/SPIN1_CHG.cube", rho[0], ucell->nat); + ModuleIO::read_vdata_palgrid(pgrid, my_rank, ofs_running, "support/chgs1.cube", rho[0], ucell->nat); ModuleIO::write_vdata_palgrid(pgrid, rho[0], 0, nspin, 0, "test_write_vdata_palgrid.cube", 0.461002, ucell, 11, 1); - EXPECT_EQ(system("diff -q test_write_vdata_palgrid.cube support/SPIN1_CHG.cube"), 0); + EXPECT_EQ(system("diff -q test_write_vdata_palgrid.cube support/chgs1.cube"), 0); } TEST_F(RhoIOTest, TrilinearInterpolate) @@ -130,7 +130,7 @@ TEST_F(RhoIOTest, TrilinearInterpolate) int nx_read = 36; int ny_read = 36; int nz_read = 36; - std::ifstream ifs("./support/SPIN1_CHG.cube"); + std::ifstream ifs("./support/chgs1.cube"); for (int i = 0; i < 8; ++i) { ifs.ignore(300, '\n'); @@ -190,7 +190,7 @@ struct CubeIOTest : public ::testing::Test std::vector atom_charge; std::vector> atom_pos; std::vector data_read; - const std::string fn = "./support/SPIN1_CHG.cube"; + const std::string fn = "./support/chgs1.cube"; }; @@ -236,5 +236,5 @@ TEST_F(CubeIOTest, WriteCube) dx, dy, dz, atom_type, atom_charge, atom_pos, data_read, 11); - EXPECT_EQ(system("diff -q test_write.cube ./support/SPIN1_CHG.cube"), 0); + EXPECT_EQ(system("diff -q test_write.cube ./support/chgs1.cube"), 0); } From 7ac520f577b601e9cad57c64e8616067cbacfeef Mon Sep 17 00:00:00 2001 From: mohanchen Date: Thu, 29 May 2025 14:46:53 +0800 Subject: [PATCH 10/19] update 203_PW_OK --- tests/01_PW/203_PW_OK/result.ref | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/01_PW/203_PW_OK/result.ref b/tests/01_PW/203_PW_OK/result.ref index a640192cac..1ebf74fa8d 100644 --- a/tests/01_PW/203_PW_OK/result.ref +++ b/tests/01_PW/203_PW_OK/result.ref @@ -1,5 +1,5 @@ etotref -213.3867238098172 etotperatomref -106.6933619049 -SPIN1_CHG.cube_pass 0 -SPIN1_TAU.cube_pass 0 +chgs1.cube_pass 0 +taus1.cube_pass 0 totaltimeref 0.84452 From fb3e91bed4432b555907b39fe5e6d734e4911054 Mon Sep 17 00:00:00 2001 From: mohanchen Date: Sat, 31 May 2025 20:36:31 +0800 Subject: [PATCH 11/19] update result.ref in 23_NO_KP_OK --- tests/03_NAO_multik/23_NO_KP_OK/result.ref | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/03_NAO_multik/23_NO_KP_OK/result.ref b/tests/03_NAO_multik/23_NO_KP_OK/result.ref index 2e58b04ad1..e62d956fce 100644 --- a/tests/03_NAO_multik/23_NO_KP_OK/result.ref +++ b/tests/03_NAO_multik/23_NO_KP_OK/result.ref @@ -1,5 +1,5 @@ etotref -196.4521105421520 etotperatomref -98.2260552711 -SPIN1_CHG.cube_pass 0 -SPIN1_TAU.cube_pass 0 +chgs1.cube_pass 0 +taus1.cube_pass 0 totaltimeref 0.62163 From 1f86f857f515206f8654505653268a8ac07fb8c9 Mon Sep 17 00:00:00 2001 From: mohanchen Date: Sat, 31 May 2025 21:59:49 +0800 Subject: [PATCH 12/19] delete redundant print_eigenvalues in elecstate_print.cpp, change the file name istate.info to eig.txt --- source/module_elecstate/elecstate_print.cpp | 92 ------------ source/module_elecstate/elecstate_print.h | 5 - .../test/elecstate_print_test.cpp | 57 -------- source/module_esolver/esolver_ks.cpp | 7 +- source/module_esolver/esolver_ks_lcao.cpp | 1 - source/module_esolver/esolver_ks_lcaopw.cpp | 1 - source/module_esolver/esolver_ks_pw.cpp | 1 - source/module_esolver/esolver_sdft_pw.cpp | 8 +- source/module_esolver/lcao_after_scf.cpp | 1 - source/module_esolver/pw_others.cpp | 1 - source/module_hsolver/hsolver_pw.cpp | 17 +-- source/module_io/write_istate_info.cpp | 132 ++++++++++-------- 12 files changed, 92 insertions(+), 231 deletions(-) diff --git a/source/module_elecstate/elecstate_print.cpp b/source/module_elecstate/elecstate_print.cpp index 09565e4b86..8959e997c8 100644 --- a/source/module_elecstate/elecstate_print.cpp +++ b/source/module_elecstate/elecstate_print.cpp @@ -148,98 +148,6 @@ void print_scf_iterinfo(const std::string& ks_solver, } std::cout << buf; } -/// @brief print and check for band energy and occupations -/// @param ofs -void print_eigenvalue(const ModuleBase::matrix& ekb, - const ModuleBase::matrix& wg, - const K_Vectors* klist, - std::ofstream& ofs) -{ - bool wrong = false; - const int nks = klist->get_nks(); - const int nkstot = klist->get_nkstot(); - for (int ik = 0; ik < nks; ++ik) - { - for (int ib = 0; ib < ekb.nc; ++ib) - { - if (std::abs(ekb(ik, ib)) > 1.0e10) - { - GlobalV::ofs_warning << " ik=" << ik + 1 << " ib=" << ib + 1 << " " << ekb(ik, ib) << " Ry" << std::endl; - wrong = true; - } - } - } -#ifdef __MPI - MPI_Allreduce(MPI_IN_PLACE, &wrong, 1, MPI_C_BOOL, MPI_LOR, MPI_COMM_WORLD); -#endif - if (wrong) - { - ModuleBase::WARNING_QUIT("print_eigenvalue", "Eigenvalues are too large!"); - } - - std::string filename = PARAM.globalv.global_out_dir + PARAM.globalv.log_file; - std::vector ngk_tot = klist->ngk; - -#ifdef __MPI - MPI_Allreduce(MPI_IN_PLACE, ngk_tot.data(), nks, MPI_INT, MPI_SUM, POOL_WORLD); -#endif - - ModuleBase::TITLE("ESolver_KS_PW", "print_eigenvalue"); - - ofs << "\n STATE ENERGY(eV) AND OCCUPATIONS "; - const int nk_fac = PARAM.inp.nspin == 2 ? 2 : 1; - const int nks_np = nks / nk_fac; - const int nkstot_np = nkstot / nk_fac; - ofs << " NSPIN == " << PARAM.inp.nspin << std::endl; - for (int is = 0; is < nk_fac; ++is) - { - if (is == 0 && nk_fac == 2) - { - ofs << "SPIN UP : " << std::endl; - } - else if (is == 1 && nk_fac == 2) - { - ofs << "SPIN DOWN : " << std::endl; - } - - for (int ip = 0; ip < GlobalV::KPAR; ++ip) - { -#ifdef __MPI - MPI_Barrier(MPI_COMM_WORLD); -#endif - bool ip_flag = PARAM.inp.out_alllog || (GlobalV::RANK_IN_POOL == 0 && GlobalV::MY_BNDGROUP == 0); - if (GlobalV::MY_POOL == ip && ip_flag) - { - const int start_ik = nks_np * is; - const int end_ik = nks_np * (is + 1); - for (int ik = start_ik; ik < end_ik; ++ik) - { - std::ofstream ofs_eig(filename.c_str(), std::ios::app); - ofs_eig << std::setprecision(5); - ofs_eig << std::setiosflags(std::ios::showpoint); - ofs_eig << " " << klist->ik2iktot[ik] + 1 - is * nkstot_np << "/" << nkstot_np - << " kpoint (Cartesian) = " << klist->kvec_c[ik].x << " " << klist->kvec_c[ik].y - << " " << klist->kvec_c[ik].z << " (" << ngk_tot[ik] << " pws)" << std::endl; - - ofs_eig << std::setprecision(6); - ofs_eig << std::setiosflags(std::ios::showpoint); - for (int ib = 0; ib < ekb.nc; ib++) - { - ofs_eig << std::setw(8) << ib + 1 << std::setw(15) << ekb(ik, ib) * ModuleBase::Ry_to_eV - << std::setw(15) << wg(ik, ib) << std::endl; - } - ofs_eig << std::endl; - ofs_eig.close(); - } - } - } -#ifdef __MPI - MPI_Barrier(MPI_COMM_WORLD); -#endif - ofs.seekp(0, std::ios::end); - } - return; -} /// @brief function for printing eigenvalues : ekb /// @param ik: index of kpoints diff --git a/source/module_elecstate/elecstate_print.h b/source/module_elecstate/elecstate_print.h index e1ad2fb284..fcf8ec91a2 100644 --- a/source/module_elecstate/elecstate_print.h +++ b/source/module_elecstate/elecstate_print.h @@ -16,11 +16,6 @@ namespace elecstate void print_format(const std::string& name, const double& value); - void print_eigenvalue(const ModuleBase::matrix& ekb, - const ModuleBase::matrix& wg, - const K_Vectors* klist, - std::ofstream& ofs); - void print_etot(const Magnetism& magnet, const ElecState& elec, const bool converged, diff --git a/source/module_elecstate/test/elecstate_print_test.cpp b/source/module_elecstate/test/elecstate_print_test.cpp index 3f5fdf994b..196594d1f8 100644 --- a/source/module_elecstate/test/elecstate_print_test.cpp +++ b/source/module_elecstate/test/elecstate_print_test.cpp @@ -48,7 +48,6 @@ bool XC_Functional::ked_flag = false; /** * - Tested functions: * - ElecState::print_format() - * - ElecState::print_eigenvalue() */ class ElecStatePrintTest : public ::testing::Test @@ -113,50 +112,6 @@ TEST_F(ElecStatePrintTest, PrintFormat) std::remove("test.dat"); } -TEST_F(ElecStatePrintTest, PrintEigenvalueS2) -{ - PARAM.input.nspin = 2; - GlobalV::ofs_running.open("test.dat", std::ios::out); - // print eigenvalue - elecstate::print_eigenvalue(elecstate.ekb,elecstate.wg,elecstate.klist,GlobalV::ofs_running); - GlobalV::ofs_running.close(); - ifs.open("test.dat", std::ios::in); - std::string str((std::istreambuf_iterator(ifs)), std::istreambuf_iterator()); - EXPECT_THAT(str, testing::HasSubstr("STATE ENERGY(eV) AND OCCUPATIONS")); - EXPECT_THAT(str, testing::HasSubstr("NSPIN == 2")); - EXPECT_THAT(str, testing::HasSubstr("SPIN UP :")); - EXPECT_THAT(str, testing::HasSubstr("1/1 kpoint (Cartesian) = 0.10000 0.11000 0.11100 (100 pws)")); - EXPECT_THAT(str, testing::HasSubstr("1 13.6057 0.100000")); - EXPECT_THAT(str, testing::HasSubstr("2 27.2114 0.200000")); - EXPECT_THAT(str, testing::HasSubstr("SPIN DOWN :")); - EXPECT_THAT(str, testing::HasSubstr("1/1 kpoint (Cartesian) = 0.20000 0.22000 0.22200 (101 pws)")); - EXPECT_THAT(str, testing::HasSubstr("1 40.8171 0.300000")); - EXPECT_THAT(str, testing::HasSubstr("2 54.4228 0.400000")); - ifs.close(); - std::remove("test.dat"); -} - -TEST_F(ElecStatePrintTest, PrintEigenvalueS4) -{ - PARAM.input.nspin = 4; - GlobalV::ofs_running.open("test.dat", std::ios::out); - // print eigenvalue - elecstate::print_eigenvalue(elecstate.ekb,elecstate.wg,elecstate.klist,GlobalV::ofs_running); - GlobalV::ofs_running.close(); - ifs.open("test.dat", std::ios::in); - std::string str((std::istreambuf_iterator(ifs)), std::istreambuf_iterator()); - EXPECT_THAT(str, testing::HasSubstr("STATE ENERGY(eV) AND OCCUPATIONS")); - EXPECT_THAT(str, testing::HasSubstr("NSPIN == 4")); - EXPECT_THAT(str, testing::HasSubstr("1/2 kpoint (Cartesian) = 0.10000 0.11000 0.11100 (100 pws)")); - EXPECT_THAT(str, testing::HasSubstr("1 13.6057 0.100000")); - EXPECT_THAT(str, testing::HasSubstr("2 27.2114 0.200000")); - EXPECT_THAT(str, testing::HasSubstr("2/2 kpoint (Cartesian) = 0.20000 0.22000 0.22200 (101 pws)")); - EXPECT_THAT(str, testing::HasSubstr("1 40.8171 0.300000")); - EXPECT_THAT(str, testing::HasSubstr("2 54.4228 0.400000")); - ifs.close(); - std::remove("test.dat"); -} - TEST_F(ElecStatePrintTest, PrintBand) { PARAM.input.nspin = 1; @@ -179,18 +134,6 @@ TEST_F(ElecStatePrintTest, PrintBand) std::remove("test.dat"); } -TEST_F(ElecStatePrintTest, PrintEigenvalueWarning) -{ - elecstate.ekb(0, 0) = 1.0e11; - PARAM.input.nspin = 4; - GlobalV::ofs_running.open("test.dat", std::ios::out); - testing::internal::CaptureStdout(); - EXPECT_EXIT(elecstate::print_eigenvalue(elecstate.ekb,elecstate.wg,elecstate.klist,GlobalV::ofs_running), ::testing::ExitedWithCode(1), ""); - output = testing::internal::GetCapturedStdout(); - EXPECT_THAT(output, testing::HasSubstr("Eigenvalues are too large!")); - GlobalV::ofs_running.close(); - std::remove("test.dat"); -} TEST_F(ElecStatePrintTest, PrintBandWarning) { diff --git a/source/module_esolver/esolver_ks.cpp b/source/module_esolver/esolver_ks.cpp index 748ca802e7..b14ba93249 100644 --- a/source/module_esolver/esolver_ks.cpp +++ b/source/module_esolver/esolver_ks.cpp @@ -554,7 +554,7 @@ void ESolver_KS::after_scf(UnitCell& ucell, const int istep, const bo // 3) write eigenvalues if (istep % PARAM.inp.out_interval == 0) { - elecstate::print_eigenvalue(this->pelec->ekb,this->pelec->wg,this->pelec->klist,GlobalV::ofs_running); +// elecstate::print_eigenvalue(this->pelec->ekb,this->pelec->wg,this->pelec->klist,GlobalV::ofs_running); } } @@ -597,11 +597,10 @@ void ESolver_KS::after_all_runners(UnitCell& ucell) GlobalV::ofs_running << "\n\n"; } - // 2) write information + // 2) write eigenvalue information ModuleIO::write_istate_info(this->pelec->ekb, this->pelec->wg, this->kv); - - // 3) print out band information + // 3) write band information if (PARAM.inp.out_band[0]) { const int nspin0 = (PARAM.inp.nspin == 2) ? 2 : 1; diff --git a/source/module_esolver/esolver_ks_lcao.cpp b/source/module_esolver/esolver_ks_lcao.cpp index 666f587a99..7dcd6e0b8c 100644 --- a/source/module_esolver/esolver_ks_lcao.cpp +++ b/source/module_esolver/esolver_ks_lcao.cpp @@ -27,7 +27,6 @@ #include "module_io/to_wannier90_lcao_in_pw.h" #include "module_io/write_HS.h" #include "module_io/write_elecstat_pot.h" -#include "module_io/write_istate_info.h" #include "module_io/write_proj_band_lcao.h" #include "module_parameter/parameter.h" diff --git a/source/module_esolver/esolver_ks_lcaopw.cpp b/source/module_esolver/esolver_ks_lcaopw.cpp index bcabe7d83c..23a8f6f7d4 100644 --- a/source/module_esolver/esolver_ks_lcaopw.cpp +++ b/source/module_esolver/esolver_ks_lcaopw.cpp @@ -4,7 +4,6 @@ #include "module_io/input_conv.h" #include "module_io/nscf_band.h" #include "module_io/output_log.h" -#include "module_io/write_istate_info.h" #include diff --git a/source/module_esolver/esolver_ks_pw.cpp b/source/module_esolver/esolver_ks_pw.cpp index 5e5177d1a9..62f0d4265e 100644 --- a/source/module_esolver/esolver_ks_pw.cpp +++ b/source/module_esolver/esolver_ks_pw.cpp @@ -30,7 +30,6 @@ #include "module_io/to_wannier90_pw.h" #include "module_io/winput.h" #include "module_io/write_dos_pw.h" -#include "module_io/write_istate_info.h" #include "module_io/write_wfc_pw.h" #include "module_io/write_wfc_r.h" #include "module_parameter/parameter.h" diff --git a/source/module_esolver/esolver_sdft_pw.cpp b/source/module_esolver/esolver_sdft_pw.cpp index 706a22bd65..bcda47328e 100644 --- a/source/module_esolver/esolver_sdft_pw.cpp +++ b/source/module_esolver/esolver_sdft_pw.cpp @@ -257,16 +257,22 @@ void ESolver_SDFT_PW::cal_stress(UnitCell& ucell, ModuleBase::matrix& template void ESolver_SDFT_PW::after_all_runners(UnitCell& ucell) { + // 1) write down total energy information GlobalV::ofs_running << "\n\n --------------------------------------------" << std::endl; GlobalV::ofs_running << std::setprecision(16); GlobalV::ofs_running << " !FINAL_ETOT_IS " << this->pelec->f_en.etot * ModuleBase::Ry_to_eV << " eV" << std::endl; GlobalV::ofs_running << " --------------------------------------------\n\n" << std::endl; + + // 2) write down eigenvalue information ModuleIO::write_istate_info(this->pelec->ekb, this->pelec->wg, this->kv); + // 3) release memory if (this->method_sto == 2) { stowf.clean_chiallorder(); // release lots of memories } + + // 4) write down DOS if (PARAM.inp.out_dos) { if(!std::is_same>::value || !std::is_same::value) @@ -292,7 +298,7 @@ void ESolver_SDFT_PW::after_all_runners(UnitCell& ucell) sto_dos.caldos(PARAM.inp.dos_sigma, PARAM.inp.dos_edelta_ev, PARAM.inp.npart_sto); } - // sKG cost memory, and it should be placed at the end of the program + // 5) sKG cost memory, and it should be placed at the end of the program if (PARAM.inp.cal_cond) { Sto_EleCond sto_elecond(&ucell, diff --git a/source/module_esolver/lcao_after_scf.cpp b/source/module_esolver/lcao_after_scf.cpp index 18cef20c6d..b7829d846c 100644 --- a/source/module_esolver/lcao_after_scf.cpp +++ b/source/module_esolver/lcao_after_scf.cpp @@ -23,7 +23,6 @@ #include "module_io/to_wannier90_lcao_in_pw.h" #include "module_io/write_dmr.h" #include "module_io/write_elecstat_pot.h" -#include "module_io/write_istate_info.h" #include "module_io/write_wfc_nao.h" #include "module_io/cal_pLpR.h" #include "module_parameter/parameter.h" diff --git a/source/module_esolver/pw_others.cpp b/source/module_esolver/pw_others.cpp index 6b6fba74a3..8e2fd78c71 100644 --- a/source/module_esolver/pw_others.cpp +++ b/source/module_esolver/pw_others.cpp @@ -5,7 +5,6 @@ #include "module_io/input_conv.h" #include "module_io/nscf_band.h" #include "module_io/output_log.h" -#include "module_io/write_istate_info.h" #include diff --git a/source/module_hsolver/hsolver_pw.cpp b/source/module_hsolver/hsolver_pw.cpp index 5411b98906..ccb1ec53ef 100644 --- a/source/module_hsolver/hsolver_pw.cpp +++ b/source/module_hsolver/hsolver_pw.cpp @@ -123,9 +123,9 @@ void HSolverPW::solve(hamilt::Hamilt* pHamilt, if (skip_charge) { - GlobalV::ofs_running << "Average iterative diagonalization steps for k-points " << ik - << " is: " << DiagoIterAssist::avg_iter - << " ; where current threshold is: " << this->diag_thr << " . " << std::endl; + GlobalV::ofs_running << " k(" << ik+1 << "/" << pes->klist->get_nkstot() + << ") Iter steps (avg)=" << DiagoIterAssist::avg_iter + << " threshold=" << this->diag_thr << std::endl; DiagoIterAssist::avg_iter = 0.0; } /// calculate the contribution of Psi for charge density rho @@ -134,10 +134,8 @@ void HSolverPW::solve(hamilt::Hamilt* pHamilt, // copy eigenvalues to ekb in ElecState base_device::memory::cast_memory_op()( - // pes->ekb.c, out_eigenvalues, eigenvalues.data(), - // pes->ekb.nr * pes->ekb.nc this->wfc_basis->nks * psi.get_nbands()); auto _pes_pw = reinterpret_cast*>(pes); @@ -148,6 +146,7 @@ void HSolverPW::solve(hamilt::Hamilt* pHamilt, _pes_pw->f_en, _pes_pw->nelec_spin, _pes_pw->skip_weights); + elecstate::calEBand(_pes_pw->ekb,_pes_pw->wg,_pes_pw->f_en); if (skip_charge) { @@ -155,16 +154,14 @@ void HSolverPW::solve(hamilt::Hamilt* pHamilt, { reinterpret_cast*>(pes)->cal_becsum(psi); } - ModuleBase::timer::tick("HSolverPW", "solve"); - return; } else { reinterpret_cast*>(pes)->psiToRho(psi); - - ModuleBase::timer::tick("HSolverPW", "solve"); - return; } + + ModuleBase::timer::tick("HSolverPW", "solve"); + return; } template diff --git a/source/module_io/write_istate_info.cpp b/source/module_io/write_istate_info.cpp index 7316fa468c..74456f9c30 100644 --- a/source/module_io/write_istate_info.cpp +++ b/source/module_io/write_istate_info.cpp @@ -4,6 +4,7 @@ #include "module_base/global_function.h" #include "module_base/global_variable.h" #include "module_base/timer.h" +#include "module_base/parallel_comm.h" // use POOL_WORLD #ifdef __MPI #include // use MPI_Barrier @@ -14,81 +15,98 @@ void ModuleIO::write_istate_info(const ModuleBase::matrix &ekb,const ModuleBase: ModuleBase::TITLE("ModuleIO","write_istate_info"); ModuleBase::timer::tick("ModuleIO", "write_istate_info"); - std::stringstream ss; - ss << PARAM.globalv.global_out_dir << "istate.info"; + const int nspin = PARAM.inp.nspin; + const int nks = kv.get_nks(); + const int nkstot = kv.get_nkstot(); + + bool wrong = false; + + for (int ik = 0; ik < nks; ++ik) + { + for (int ib = 0; ib < ekb.nc; ++ib) + { + if (std::abs(ekb(ik, ib)) > 1.0e10) + { + GlobalV::ofs_warning << " ik=" << ik + 1 << " ib=" << ib + 1 + << " " << ekb(ik, ib) << " Ry" << std::endl; + wrong = true; + } + } + } + +#ifdef __MPI + MPI_Allreduce(MPI_IN_PLACE, &wrong, 1, MPI_C_BOOL, MPI_LOR, MPI_COMM_WORLD); +#endif + if (wrong) + { + ModuleBase::WARNING_QUIT("ModuleIO::write_istate_info", "Eigenvalues are too large!"); + } + + + std::vector ngk_tot = kv.ngk; + +#ifdef __MPI + MPI_Allreduce(MPI_IN_PLACE, ngk_tot.data(), nks, MPI_INT, MPI_SUM, POOL_WORLD); +#endif + + // file name to store eigenvalues + std::string filename = PARAM.globalv.global_out_dir + "eig.txt"; + GlobalV::ofs_running << " The eigenvalues are in the file: " << filename << std::endl; + if (GlobalV::MY_RANK == 0) { - std::ofstream ofsi(ss.str().c_str()); // clear istate.info - ofsi.close(); + std::ofstream ofs_eig0(filename.c_str()); // clear eig.txt + ofs_eig0 << " Electronic state energy (eV) and occupations" << std::endl; + ofs_eig0 << " Spin number " << nspin << std::endl; + ofs_eig0.close(); } - for (int ip = 0; ip < GlobalV::KPAR; ip++) + const int nk_fac = nspin == 2 ? 2 : 1; + const int nks_np = nks / nk_fac; + const int nkstot_np = nkstot / nk_fac; + const int kpar = GlobalV::KPAR; + + for (int is = 0; is < nk_fac; ++is) { -#ifdef __MPI - MPI_Barrier(MPI_COMM_WORLD); - if (GlobalV::MY_POOL == ip) + for (int ip = 0; ip < kpar; ++ip) { - if (GlobalV::RANK_IN_POOL != 0 || GlobalV::MY_BNDGROUP != 0 ) - { - continue; - } -#endif - std::ofstream ofsi2(ss.str().c_str(), std::ios::app); - if (PARAM.inp.nspin == 1 || PARAM.inp.nspin == 4) - { - for (int ik = 0; ik < kv.get_nks(); ik++) - { #ifdef __MPI - int ik_global = kv.para_k.startk_pool[ip] + ik + 1; -#else - int ik_global = ik + 1; + MPI_Barrier(MPI_COMM_WORLD); #endif - ofsi2 << "BAND" << std::setw(25) << "Energy(ev)" << std::setw(25) << "Occupation" - << std::setw(25) << "Kpoint = " << ik_global - << std::setw(25) << "(" << kv.kvec_d[ik].x << " " << kv.kvec_d[ik].y - << " " << kv.kvec_d[ik].z << ")" << std::endl; - for (int ib = 0; ib < PARAM.globalv.nbands_l; ib++) - { - ofsi2.precision(16); - ofsi2 << std::setw(6) << ib + 1 << std::setw(25) - << ekb(ik, ib) * ModuleBase::Ry_to_eV << std::setw(25) << wg(ik, ib) - << std::endl; - } - ofsi2 << std::endl; - ofsi2 << std::endl; - } - } - else + bool ip_flag = PARAM.inp.out_alllog || (GlobalV::RANK_IN_POOL == 0 && GlobalV::MY_BNDGROUP == 0); + if (GlobalV::MY_POOL == ip && ip_flag) { - for (int ik = 0; ik < kv.get_nks() / 2; ik++) + std::ofstream ofs_eig(filename.c_str(), std::ios::app); + ofs_eig << std::setprecision(5); + ofs_eig << std::setiosflags(std::ios::showpoint); + + const int start_ik = nks_np * is; + const int end_ik = nks_np * (is + 1); + for (int ik = start_ik; ik < end_ik; ++ik) { -#ifdef __MPI - int ik_global = kv.para_k.startk_pool[ip] + ik + 1; -#else - int ik_global = ik + 1; -#endif - ofsi2 << "BAND" << std::setw(25) << "Spin up Energy(ev)" << std::setw(25) << "Occupation" - << std::setw(25) << "Spin down Energy(ev)" << std::setw(25) << "Occupation" - << std::setw(25) << "Kpoint = " << ik_global - << std::setw(25) << "(" << kv.kvec_d[ik].x << " " << kv.kvec_d[ik].y - << " " << kv.kvec_d[ik].z << ")" << std::endl; + ofs_eig << " spin=" << is+1 << " k-point=" + << kv.ik2iktot[ik] + 1 - is * nkstot_np << "/" << nkstot_np + << " Cartesian=" << kv.kvec_c[ik].x << " " << kv.kvec_c[ik].y + << " " << kv.kvec_c[ik].z << " (" << ngk_tot[ik] << " plane wave)" << std::endl; - for (int ib = 0; ib < PARAM.inp.nbands; ib++) + ofs_eig << std::setprecision(6); + ofs_eig << std::setiosflags(std::ios::showpoint); + for (int ib = 0; ib < ekb.nc; ib++) { - ofsi2 << std::setw(6) << ib + 1 << std::setw(25) - << ekb(ik, ib) * ModuleBase::Ry_to_eV << std::setw(25) << wg(ik, ib) - << std::setw(25) << ekb((ik + kv.get_nks() / 2), ib) * ModuleBase::Ry_to_eV - << std::setw(25) << wg(ik + kv.get_nks() / 2, ib) << std::endl; + ofs_eig << std::setw(8) << ib + 1 << std::setw(15) << ekb(ik, ib) * ModuleBase::Ry_to_eV + << std::setw(15) << wg(ik, ib) << std::endl; } - ofsi2 << std::endl; - ofsi2 << std::endl; + ofs_eig << std::endl; } + + ofs_eig.close(); } - ofsi2.close(); -#ifdef __MPI } +#ifdef __MPI + MPI_Barrier(MPI_COMM_WORLD); #endif } + ModuleBase::timer::tick("ModuleIO", "write_istate_info"); return; } From 5a7742f09239bd092fbde3de8549d0a0e5d4906e Mon Sep 17 00:00:00 2001 From: mohanchen Date: Sun, 1 Jun 2025 15:53:18 +0800 Subject: [PATCH 13/19] update information about writing eigenvalues, enable SDFT to write out eigenvalues if applicable --- docs/advanced/input_files/input-main.md | 5 ++- source/module_esolver/esolver_ks.cpp | 42 +++---------------- source/module_esolver/esolver_ks_lcao.cpp | 1 - source/module_esolver/esolver_sdft_pw.cpp | 25 +++-------- source/module_esolver/esolver_sdft_pw.h | 2 - source/module_io/nscf_band.cpp | 20 +++++++-- source/module_io/write_istate_info.cpp | 2 +- .../{refBANDS_1.dat => eigs1.txt.ref} | 0 tests/integrate/tools/catch_properties.sh | 4 +- 9 files changed, 34 insertions(+), 67 deletions(-) rename tests/01_PW/052_PW_OB/{refBANDS_1.dat => eigs1.txt.ref} (100%) diff --git a/docs/advanced/input_files/input-main.md b/docs/advanced/input_files/input-main.md index 6136ca4c1f..f645aa397a 100644 --- a/docs/advanced/input_files/input-main.md +++ b/docs/advanced/input_files/input-main.md @@ -1721,7 +1721,10 @@ These variables are used to control the output of properties. ### out_band - **Type**: Boolean \[Integer\](optional) -- **Description**: Whether to output the band structure (in eV), optionally output precision can be set by a second parameter, default is 8. For more information, refer to the [band.md](../elec_properties/band.md) +- **Description**: Whether to output the eigenvalues of Hamiltonian matrix (in eV), optionally output precision can be set by a second parameter, default is 8. The output file names are: + - nspin = 1 or 4: `eigs1.txt`; + - nspin = 2: `eigs1.txt` and `eigs2.txt`; + - For more information, refer to the [band.md](../elec_properties/band.md) - **Default**: False ### out_proj_band diff --git a/source/module_esolver/esolver_ks.cpp b/source/module_esolver/esolver_ks.cpp index b14ba93249..fbb38badfb 100644 --- a/source/module_esolver/esolver_ks.cpp +++ b/source/module_esolver/esolver_ks.cpp @@ -561,42 +561,9 @@ void ESolver_KS::after_scf(UnitCell& ucell, const int istep, const bo template void ESolver_KS::after_all_runners(UnitCell& ucell) { + // 1) write Etot information ESolver_FP::after_all_runners(ucell); - // 1) write information - if (PARAM.inp.out_dos != 0 || PARAM.inp.out_band[0] != 0 || PARAM.inp.out_proj_band != 0) - { - GlobalV::ofs_running << "\n\n"; - GlobalV::ofs_running << " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" - ">>>>>>>>>>>>>>>>>>>>>>>>>" - << std::endl; - GlobalV::ofs_running << " | " - " |" - << std::endl; - GlobalV::ofs_running << " | Post-processing of data: " - " |" - << std::endl; - GlobalV::ofs_running << " | DOS (density of states) and bands will be " - "output here. |" - << std::endl; - GlobalV::ofs_running << " | If atomic orbitals are used, Mulliken " - "charge analysis can be done. |" - << std::endl; - GlobalV::ofs_running << " | Also the .bxsf file containing fermi " - "surface information can be |" - << std::endl; - GlobalV::ofs_running << " | done here. " - " |" - << std::endl; - GlobalV::ofs_running << " | " - " |" - << std::endl; - GlobalV::ofs_running << " <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" - "<<<<<<<<<<<<<<<<<<<<<<<<<" - << std::endl; - GlobalV::ofs_running << "\n\n"; - } - // 2) write eigenvalue information ModuleIO::write_istate_info(this->pelec->ekb, this->pelec->wg, this->kv); @@ -607,12 +574,13 @@ void ESolver_KS::after_all_runners(UnitCell& ucell) for (int is = 0; is < nspin0; is++) { std::stringstream ss2; - ss2 << PARAM.globalv.global_out_dir << "BANDS_" << is + 1 << ".dat"; - GlobalV::ofs_running << "\n Output bands in file: " << ss2.str() << std::endl; + ss2 << PARAM.globalv.global_out_dir << "eigs" << is + 1 << ".txt"; + GlobalV::ofs_running << "\n Eigenvalues for plot are saved in file: " << ss2.str() << std::endl; + const double eshift = 0.0; ModuleIO::nscf_band(is, ss2.str(), PARAM.inp.nbands, - 0.0, + eshift, PARAM.inp.out_band[1], this->pelec->ekb, this->kv); diff --git a/source/module_esolver/esolver_ks_lcao.cpp b/source/module_esolver/esolver_ks_lcao.cpp index 8579e941e2..77d3d630ac 100644 --- a/source/module_esolver/esolver_ks_lcao.cpp +++ b/source/module_esolver/esolver_ks_lcao.cpp @@ -27,7 +27,6 @@ #include "module_io/to_wannier90_lcao_in_pw.h" #include "module_io/write_HS.h" #include "module_io/write_elecstat_pot.h" -#include "module_io/write_proj_band_lcao.h" #include "module_parameter/parameter.h" // be careful of hpp, there may be multiple definitions of functions, 20250302, mohan diff --git a/source/module_esolver/esolver_sdft_pw.cpp b/source/module_esolver/esolver_sdft_pw.cpp index bcda47328e..928d1bb052 100644 --- a/source/module_esolver/esolver_sdft_pw.cpp +++ b/source/module_esolver/esolver_sdft_pw.cpp @@ -257,22 +257,16 @@ void ESolver_SDFT_PW::cal_stress(UnitCell& ucell, ModuleBase::matrix& template void ESolver_SDFT_PW::after_all_runners(UnitCell& ucell) { - // 1) write down total energy information - GlobalV::ofs_running << "\n\n --------------------------------------------" << std::endl; - GlobalV::ofs_running << std::setprecision(16); - GlobalV::ofs_running << " !FINAL_ETOT_IS " << this->pelec->f_en.etot * ModuleBase::Ry_to_eV << " eV" << std::endl; - GlobalV::ofs_running << " --------------------------------------------\n\n" << std::endl; + // 1) write down etot and eigenvalues (for MDFT) information + ESolver_FP::after_all_runners(ucell); - // 2) write down eigenvalue information - ModuleIO::write_istate_info(this->pelec->ekb, this->pelec->wg, this->kv); - - // 3) release memory + // 2) release memory if (this->method_sto == 2) { stowf.clean_chiallorder(); // release lots of memories } - // 4) write down DOS + // 3) write down DOS if (PARAM.inp.out_dos) { if(!std::is_same>::value || !std::is_same::value) @@ -298,7 +292,7 @@ void ESolver_SDFT_PW::after_all_runners(UnitCell& ucell) sto_dos.caldos(PARAM.inp.dos_sigma, PARAM.inp.dos_edelta_ev, PARAM.inp.npart_sto); } - // 5) sKG cost memory, and it should be placed at the end of the program + // 4) sKG cost memory, and it should be placed at the end of the program if (PARAM.inp.cal_cond) { Sto_EleCond sto_elecond(&ucell, @@ -321,15 +315,6 @@ void ESolver_SDFT_PW::after_all_runners(UnitCell& ucell) } } -template -void ESolver_SDFT_PW::others(UnitCell& ucell, const int istep) -{ - ModuleBase::TITLE("ESolver_SDFT_PW", "others"); - - ModuleBase::WARNING_QUIT("ESolver_SDFT_PW::others", "CALCULATION type not supported"); - - return; -} // template class ESolver_SDFT_PW, base_device::DEVICE_CPU>; template class ESolver_SDFT_PW, base_device::DEVICE_CPU>; diff --git a/source/module_esolver/esolver_sdft_pw.h b/source/module_esolver/esolver_sdft_pw.h index dc284e7b21..eeb1580c96 100644 --- a/source/module_esolver/esolver_sdft_pw.h +++ b/source/module_esolver/esolver_sdft_pw.h @@ -37,8 +37,6 @@ class ESolver_SDFT_PW : public ESolver_KS_PW virtual void hamilt2rho_single(UnitCell& ucell, const int istep, const int iter, const double ethr) override; - virtual void others(UnitCell& ucell, const int istep) override; - virtual void iter_finish(UnitCell& ucell, const int istep, int& iter, bool& conv_esolver) override; virtual void after_scf(UnitCell& ucell, const int istep, const bool conv_esolver) override; diff --git a/source/module_io/nscf_band.cpp b/source/module_io/nscf_band.cpp index c59ffbe5df..e824b4ce84 100644 --- a/source/module_io/nscf_band.cpp +++ b/source/module_io/nscf_band.cpp @@ -21,6 +21,19 @@ void ModuleIO::nscf_band( ModuleBase::TITLE("ModuleIO","nscf_band"); ModuleBase::timer::tick("ModuleIO", "nscf_band"); + GlobalV::ofs_running << "\n"; + GlobalV::ofs_running << " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" + ">>>>>>>>>>>>>>>>>>>>>>>>>" << std::endl; + GlobalV::ofs_running << " | " + " |" << std::endl; + GlobalV::ofs_running << " | Print out the eigenvalues. " + " |" << std::endl; + GlobalV::ofs_running << " | " + " |" << std::endl; + GlobalV::ofs_running << " <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" + "<<<<<<<<<<<<<<<<<<<<<<<<<" << std::endl; + GlobalV::ofs_running << "\n"; + // number of k points without spin; // nspin = 1,2, nkstot = nkstot_np * nspin; // nspin = 4, nkstot = nkstot_np @@ -33,6 +46,7 @@ void ModuleIO::nscf_band( std::ofstream ofs(out_band_dir.c_str());//make the file clear!! ofs.close(); } + MPI_Barrier(MPI_COMM_WORLD); std::vector klength; klength.resize(nkstot_np); @@ -48,12 +62,12 @@ void ModuleIO::nscf_band( klength[ik] = klength[ik-1]; klength[ik] += (kv.kl_segids[ik] == kv.kl_segids[ik-1]) ? delta.norm() : 0.0; } - /* first find if present kpoint in present pool */ + //! first find if present kpoint in present pool if ( GlobalV::MY_POOL == kv.para_k.whichpool[ik] ) { - /* then get the local kpoint index, which starts definitly from 0 */ + //! then get the local kpoint index, which starts definitly from 0 const int ik_now = ik - kv.para_k.startk_pool[GlobalV::MY_POOL]; - /* if present kpoint corresponds the spin of the present one */ + //! if present kpoint corresponds the spin of the present one assert( kv.isk[ik_now+is*nks_np] == is ); if ( GlobalV::RANK_IN_POOL == 0) { diff --git a/source/module_io/write_istate_info.cpp b/source/module_io/write_istate_info.cpp index 74456f9c30..0bcd833af7 100644 --- a/source/module_io/write_istate_info.cpp +++ b/source/module_io/write_istate_info.cpp @@ -51,7 +51,7 @@ void ModuleIO::write_istate_info(const ModuleBase::matrix &ekb,const ModuleBase: // file name to store eigenvalues std::string filename = PARAM.globalv.global_out_dir + "eig.txt"; - GlobalV::ofs_running << " The eigenvalues are in the file: " << filename << std::endl; + GlobalV::ofs_running << " The eigenvalues and occupations are in file: " << filename << std::endl; if (GlobalV::MY_RANK == 0) { diff --git a/tests/01_PW/052_PW_OB/refBANDS_1.dat b/tests/01_PW/052_PW_OB/eigs1.txt.ref similarity index 100% rename from tests/01_PW/052_PW_OB/refBANDS_1.dat rename to tests/01_PW/052_PW_OB/eigs1.txt.ref diff --git a/tests/integrate/tools/catch_properties.sh b/tests/integrate/tools/catch_properties.sh index bc7f7a7bb9..b4e2913b58 100755 --- a/tests/integrate/tools/catch_properties.sh +++ b/tests/integrate/tools/catch_properties.sh @@ -247,8 +247,8 @@ fi # echo $has_band #------------------------------- if ! test -z "$has_band" && [ $has_band == 1 ]; then - bandref=refBANDS_1.dat - bandcal=OUT.autotest/BANDS_1.dat + bandref=eigs1.txt.ref + bandcal=OUT.autotest/eigs1.txt python3 $COMPARE_SCRIPT $bandref $bandcal 8 echo "CompareBand_pass $?" >>$1 fi From 585fc9b19c23120ee1107d6733404feeae9063b8 Mon Sep 17 00:00:00 2001 From: mohanchen Date: Sun, 1 Jun 2025 16:07:11 +0800 Subject: [PATCH 14/19] output input and output documents --- docs/advanced/elec_properties/band.md | 47 ++++++++++++------------- docs/advanced/input_files/input-main.md | 2 +- docs/quick_start/output.md | 16 ++------- 3 files changed, 27 insertions(+), 38 deletions(-) diff --git a/docs/advanced/elec_properties/band.md b/docs/advanced/elec_properties/band.md index aed66d0516..44fb88e1c5 100644 --- a/docs/advanced/elec_properties/band.md +++ b/docs/advanced/elec_properties/band.md @@ -1,41 +1,40 @@ # Extracting Band Structure -ABACUS can calculate the energy band structure, and the examples can be found in [examples/band](https://github.com/deepmodeling/abacus-develop/tree/develop/examples/band). -Similar to the [DOS case](https://abacus-rtd.readthedocs.io/en/latest/advanced/elec_properties/dos.html), we first, do a ground-state energy calculation ***with one additional keyword "[out_chg](https://abacus-rtd.readthedocs.io/en/latest/advanced/input_files/input-main.html#out-chg)" in the INPUT file***: +In ABACUS, in order to obtain the eigenvalues of Hamiltonian, or generally called band structure, examples can be found in [examples/band](https://github.com/deepmodeling/abacus-develop/tree/develop/examples/band). +Similar to the [DOS case](https://abacus-rtd.readthedocs.io/en/latest/advanced/elec_properties/dos.html), one first needs to perform a ground-state energy calculation ***with one additional keyword "[out_chg](https://abacus-rtd.readthedocs.io/en/latest/advanced/input_files/input-main.html#out-chg)" in the INPUT file***: ``` -out_chg 1 +out_chg 1 ``` -This will produce the converged charge density, which is contained in the file SPIN1_CHG.cube. -Then, use the same `STRU` file, pseudopotential file and atomic orbital file (and the local density matrix file onsite.dm if DFT+U is used) to do a non-self-consistent calculation. In this example, the potential is constructed from the ground-state charge density from the proceeding calculation. Now the INPUT file is like: +With this input parameter, the converged charge density will be output in the files such as `chgs1.cube`, `chgs2.cube`, etc. +Then, one can use the same `STRU` file, pseudopotential files and atomic orbital files (and the local density matrix file onsite.dm if DFT+U is used) to do a non-self-consistent (NSCF) calculation. In this example, the potential is constructed from the ground-state charge density from the proceeding calculation. Now the INPUT file is like: ``` INPUT_PARAMETERS #Parameters (General) -ntype 1 -nbands 8 -calculation nscf -basis_type lcao -read_file_dir ./ +nbands 8 +calculation nscf +basis_type lcao +read_file_dir ./ #Parameters (Accuracy) -ecutwfc 60 -scf_nmax 50 -scf_thr 1.0e-9 -pw_diag_thr 1.0e-7 +ecutwfc 60 +scf_nmax 50 +scf_thr 1.0e-9 +pw_diag_thr 1.0e-7 #Parameters (File) -init_chg file -out_band 1 +init_chg file +out_band 1 out_proj_band 1 #Parameters (Smearing) smearing_method gaussian -smearing_sigma 0.02 +smearing_sigma 0.02 ``` -Here the the relevant k-point file KPT looks like, +Here is a relevant k-point file KPT (in LINE mode): ``` K_POINTS # keyword for start @@ -49,16 +48,16 @@ Line # line-mode 0.0 0.0 0.0 1 # G ``` -This means we are using: +This means we are using the following k-points: -- 6 number of k points, here means 6 k points: +- 6 k points, here means 6 k points: (0.5, 0.0, 0.5) (0.0, 0.0, 0.0) (0.5, 0.5, 0.5) (0.5, 0.25, 0.75) (0.375, 0.375, 0.75) (0.0, 0.0, 0.0) - 20/1 number of k points along the segment line, which is constructed by two adjacent k points. -Run the program, and you will see a file named BANDS_1.dat in the output directory. Plot it -to get energy band structure. +Next, run ABACUS and you will see a file named `eigs1.txt` in the output directory. +Plot it and you will obtain the energy band structure! If "out_proj_band" set 1, it will also produce the projected band structure in a file called PBAND_1 in xml format. @@ -77,8 +76,8 @@ The rest of the files arranged in sections, each section with a header such as b ``` Date: Sun, 1 Jun 2025 16:30:17 +0800 Subject: [PATCH 15/19] update the reading wave functions according to eig.txt instead of the old istate.info --- source/module_io/read_wf2rho_pw.cpp | 42 +++++++++----------------- source/module_io/write_istate_info.cpp | 8 ++--- tests/01_PW/057_PW_SO_IW/eig.txt | 42 ++++++++++++++++++++++++++ tests/01_PW/057_PW_SO_IW/istate.info | 41 ------------------------- 4 files changed, 60 insertions(+), 73 deletions(-) create mode 100644 tests/01_PW/057_PW_SO_IW/eig.txt delete mode 100644 tests/01_PW/057_PW_SO_IW/istate.info diff --git a/source/module_io/read_wf2rho_pw.cpp b/source/module_io/read_wf2rho_pw.cpp index e6611fb271..c132d26fd6 100644 --- a/source/module_io/read_wf2rho_pw.cpp +++ b/source/module_io/read_wf2rho_pw.cpp @@ -65,7 +65,7 @@ void ModuleIO::read_wf2rho_pw( ModuleBase::matrix wg_tmp(nkstot, nbands); if (my_rank == 0) { - std::string filename = readin_dir + "istate.info"; + std::string filename = readin_dir + "eig.txt"; std::ifstream ifs(filename); if(!ifs) @@ -79,33 +79,19 @@ void ModuleIO::read_wf2rho_pw( ofs_running << " Find file containing weights of wave function: " << filename << std::endl; } - std::string useless; - if (nspin == 2) - { - const int nkstot_np = nkstot / 2; - for (int iktot_np = 0; iktot_np < nkstot_np; ++iktot_np) - { - ifs >> useless; - getline(ifs, useless); - for (int ib = 0; ib < nbands; ++ib) - { - ifs >> useless >> useless >> wg_tmp(iktot_np, ib) >> useless >> wg_tmp(iktot_np + nkstot_np, ib); - } - } - } - else - { - for (int ik_tot = 0; ik_tot < nkstot; ++ik_tot) - { - ifs >> useless; - getline(ifs, useless); - for (int ib = 0; ib < nbands; ++ib) - { - ifs >> useless >> useless >> wg_tmp(ik_tot, ib); - } - } - } - } + std::string useless; + getline(ifs, useless); + getline(ifs, useless); + for (int ik_tot = 0; ik_tot < nkstot; ++ik_tot) + { + ifs >> useless; + getline(ifs, useless); + for (int ib = 0; ib < nbands; ++ib) + { + ifs >> useless >> useless >> wg_tmp(ik_tot, ib); + } + } + } #ifdef __MPI MPI_Bcast(wg_tmp.c, nkstot * nbands, MPI_DOUBLE, 0, MPI_COMM_WORLD); diff --git a/source/module_io/write_istate_info.cpp b/source/module_io/write_istate_info.cpp index 0bcd833af7..bc278f9f7f 100644 --- a/source/module_io/write_istate_info.cpp +++ b/source/module_io/write_istate_info.cpp @@ -77,7 +77,7 @@ void ModuleIO::write_istate_info(const ModuleBase::matrix &ekb,const ModuleBase: if (GlobalV::MY_POOL == ip && ip_flag) { std::ofstream ofs_eig(filename.c_str(), std::ios::app); - ofs_eig << std::setprecision(5); + ofs_eig << std::setprecision(8); ofs_eig << std::setiosflags(std::ios::showpoint); const int start_ik = nks_np * is; @@ -89,12 +89,12 @@ void ModuleIO::write_istate_info(const ModuleBase::matrix &ekb,const ModuleBase: << " Cartesian=" << kv.kvec_c[ik].x << " " << kv.kvec_c[ik].y << " " << kv.kvec_c[ik].z << " (" << ngk_tot[ik] << " plane wave)" << std::endl; - ofs_eig << std::setprecision(6); + ofs_eig << std::setprecision(12); ofs_eig << std::setiosflags(std::ios::showpoint); for (int ib = 0; ib < ekb.nc; ib++) { - ofs_eig << std::setw(8) << ib + 1 << std::setw(15) << ekb(ik, ib) * ModuleBase::Ry_to_eV - << std::setw(15) << wg(ik, ib) << std::endl; + ofs_eig << " " << ib + 1 << " " << ekb(ik, ib) * ModuleBase::Ry_to_eV + << " " << wg(ik, ib) << std::endl; } ofs_eig << std::endl; } diff --git a/tests/01_PW/057_PW_SO_IW/eig.txt b/tests/01_PW/057_PW_SO_IW/eig.txt new file mode 100644 index 0000000000..697d882e61 --- /dev/null +++ b/tests/01_PW/057_PW_SO_IW/eig.txt @@ -0,0 +1,42 @@ + Electronic state energy (eV) and occupations + Spin number 4 + spin=1 k-point=1/1 Cartesian=0.0000000 0.0000000 0.0000000 (459 plane wave) + 1 -5.80225222622 1.00000000000 + 2 -4.86534434633 1.00000000000 + 3 -1.35559361415 1.00000000000 + 4 -1.28770881944 1.00000000000 + 5 -1.20706060019 1.00000000000 + 6 -0.832239230496 1.00000000000 + 7 -0.745307723916 1.00000000000 + 8 -0.697268567366 1.00000000000 + 9 -0.112301628562 1.00000000000 + 10 0.123623125781 1.00000000000 + 11 0.341813744923 1.00000000000 + 12 0.428354671894 1.00000000000 + 13 5.04091981334 1.00000000000 + 14 5.77892613770 1.00000000000 + 15 7.80569592791 1.00000000000 + 16 7.87725397013 1.00000000000 + 17 8.15442595699 1.00000000000 + 18 8.89322368722 1.00000000000 + 19 9.11964038392 0.00000000000 + 20 9.19552421755 0.00000000000 + 21 10.5213838032 0.00000000000 + 22 10.6320182260 0.00000000000 + 23 10.8531271179 0.00000000000 + 24 11.3477901066 0.00000000000 + 25 11.5256948470 0.00000000000 + 26 11.6581831328 0.00000000000 + 27 14.3648470428 0.00000000000 + 28 14.6499211384 0.00000000000 + 29 20.2108680938 0.00000000000 + 30 20.2320077701 0.00000000000 + 31 20.2362409803 0.00000000000 + 32 20.3432622143 0.00000000000 + 33 20.4942834293 0.00000000000 + 34 20.6081562024 0.00000000000 + 35 20.6542582936 0.00000000000 + 36 20.6743662012 0.00000000000 + 37 21.2186717697 0.00000000000 + 38 21.4338476449 0.00000000000 + diff --git a/tests/01_PW/057_PW_SO_IW/istate.info b/tests/01_PW/057_PW_SO_IW/istate.info deleted file mode 100644 index 19f81a7f10..0000000000 --- a/tests/01_PW/057_PW_SO_IW/istate.info +++ /dev/null @@ -1,41 +0,0 @@ -BAND Energy(ev) Occupation Kpoint = 1 (0 0 0) - 1 -5.803263354735877 1 - 2 -4.866061381925486 1 - 3 -1.359289336627868 1 - 4 -1.291335226565177 1 - 5 -1.210467148364243 1 - 6 -0.835724683428713 1 - 7 -0.7487598034766753 1 - 8 -0.7006064755786422 1 - 9 -0.1159407379615029 1 - 10 0.1202752942058206 1 - 11 0.3379864351497489 1 - 12 0.42475093966947 1 - 13 5.03913292971009 1 - 14 5.777091867159064 1 - 15 7.804249418022549 1 - 16 7.875810965994963 1 - 17 8.15305132930491 1 - 18 8.892183044618475 1 - 19 9.118640257671171 0 - 20 9.194376411776567 0 - 21 10.52053980690489 0 - 22 10.63124418435923 0 - 23 10.85237946040846 0 - 24 11.34745313536697 0 - 25 11.52540297156072 0 - 26 11.65802813524961 0 - 27 14.3643931732005 0 - 28 14.64648815353438 0 - 29 20.21048953868734 0 - 30 20.23168597745261 0 - 31 20.23594172430127 0 - 32 20.34318034125117 0 - 33 20.49433237237518 0 - 34 20.60686492006229 0 - 35 20.65290020434089 0 - 36 20.67304188342674 0 - 37 21.21963361965688 0 - 38 21.43507306548812 0 - - From 2048ad57fcfc43762919033c913c76cc3204a241 Mon Sep 17 00:00:00 2001 From: mohanchen Date: Sun, 1 Jun 2025 17:00:07 +0800 Subject: [PATCH 16/19] update write_istate_info.cpp --- source/module_io/write_istate_info.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/module_io/write_istate_info.cpp b/source/module_io/write_istate_info.cpp index bc278f9f7f..16f6bfebb0 100644 --- a/source/module_io/write_istate_info.cpp +++ b/source/module_io/write_istate_info.cpp @@ -89,7 +89,7 @@ void ModuleIO::write_istate_info(const ModuleBase::matrix &ekb,const ModuleBase: << " Cartesian=" << kv.kvec_c[ik].x << " " << kv.kvec_c[ik].y << " " << kv.kvec_c[ik].z << " (" << ngk_tot[ik] << " plane wave)" << std::endl; - ofs_eig << std::setprecision(12); + ofs_eig << std::setprecision(16); ofs_eig << std::setiosflags(std::ios::showpoint); for (int ib = 0; ib < ekb.nc; ib++) { From e78b052298d2f9ea23db51bcb6934e1f9e81f356 Mon Sep 17 00:00:00 2001 From: mohanchen Date: Mon, 2 Jun 2025 13:01:21 +0800 Subject: [PATCH 17/19] fix write_istate_info test --- source/module_cell/klist.cpp | 6 -- source/module_cell/parallel_kpoints.cpp | 43 +------- .../module_io/test/write_istate_info_test.cpp | 101 ++++++------------ source/module_io/write_istate_info.cpp | 3 +- 4 files changed, 40 insertions(+), 113 deletions(-) diff --git a/source/module_cell/klist.cpp b/source/module_cell/klist.cpp index fcc79bcfc3..51ecdc0008 100644 --- a/source/module_cell/klist.cpp +++ b/source/module_cell/klist.cpp @@ -178,12 +178,6 @@ void K_Vectors::renew(const int& kpoint_number) isk.resize(kpoint_number); ngk.resize(kpoint_number); - /*ModuleBase::Memory::record("KV::kvec_c",sizeof(double) * kpoint_number*3); - ModuleBase::Memory::record("KV::kvec_d",sizeof(double) * kpoint_number*3); - ModuleBase::Memory::record("KV::wk",sizeof(double) * kpoint_number*3); - ModuleBase::Memory::record("KV::isk",sizeof(int) * kpoint_number*3); - ModuleBase::Memory::record("KV::ngk",sizeof(int) * kpoint_number*3);*/ - return; } diff --git a/source/module_cell/parallel_kpoints.cpp b/source/module_cell/parallel_kpoints.cpp index 69dc13b898..a0351e6560 100644 --- a/source/module_cell/parallel_kpoints.cpp +++ b/source/module_cell/parallel_kpoints.cpp @@ -48,17 +48,12 @@ void Parallel_Kpoints::get_whichpool(const int& nkstot) { this->whichpool.resize(nkstot, 0); - // std::cout << " calculate : whichpool" << std::endl; - // std::cout << " nkstot is " << nkstot << std::endl; - - for (int i = 0; i < this->kpar; i++) { for (int ik = 0; ik < this->nks_pool[i]; ik++) { const int k_now = ik + startk_pool[i]; this->whichpool[k_now] = i; - // ofs_running << "\n whichpool[" << k_now <<"] = " << whichpool[k_now]; } } @@ -72,19 +67,13 @@ void Parallel_Kpoints::get_nks_pool(const int& nkstot) const int nks_ave = nkstot / this->kpar; const int remain = nkstot % this->kpar; - // ofs_running << "\n nkstot = " << nkstot; - // ofs_running << "\n this->kpar = " << this->kpar; - // ofs_running << "\n nks_ave = " << nks_ave; - for (int i = 0; i < this->kpar; i++) - { this->nks_pool[i] = nks_ave; if (i < remain) { nks_pool[i]++; } - // ofs_running << "\n nks_pool[i] = " << nks_pool[i]; } return; } @@ -93,14 +82,10 @@ void Parallel_Kpoints::get_startk_pool(const int& nkstot) { startk_pool.resize(this->kpar, 0); - // const int remain = nkstot%this->kpar; - startk_pool[0] = 0; for (int i = 1; i < this->kpar; i++) - { startk_pool[i] = startk_pool[i - 1] + nks_pool[i - 1]; - // ofs_running << "\n startk_pool[i] = " << startk_pool[i]; } return; } @@ -120,7 +105,6 @@ void Parallel_Kpoints::set_startpro_pool() { startpro_pool[i]++; } - // ofs_running << "\n startpro_pool[i] = " << startpro_pool[i]; } return; } @@ -138,8 +122,6 @@ void Parallel_Kpoints::gatherkvec(const std::vector> { vec_global[i + startk_pool[this->my_pool]] = vec_local[i]; } - // vec_global[i + startk_pool[MY_POOL]] = vec_local[i] / double(NPROC_IN_POOL); - } MPI_Allreduce(MPI_IN_PLACE, &vec_global[0], 3 * this->nkstot_np, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); @@ -152,7 +134,6 @@ void Parallel_Kpoints::pool_collection(double& value, const double* wk, const in #ifdef __MPI const int ik_now = ik - this->startk_pool[this->my_pool]; - // ofs_running << "\n\n ik=" << ik << " ik_now=" << ik_now; const int pool = this->whichpool[ik]; @@ -167,8 +148,6 @@ void Parallel_Kpoints::pool_collection(double& value, const double* wk, const in } else { - - // ofs_running << " receive data."; MPI_Status ierror; MPI_Recv(&value, 1, MPI_DOUBLE, this->startpro_pool[pool], ik, MPI_COMM_WORLD, &ierror); @@ -178,18 +157,12 @@ void Parallel_Kpoints::pool_collection(double& value, const double* wk, const in { if (this->my_pool == pool) { - - // ofs_running << " send data."; - MPI_Send(&wk[ik_now], 1, MPI_DOUBLE, 0, ik, MPI_COMM_WORLD); } } } else { - - // ofs_running << "\n do nothing."; - } MPI_Barrier(MPI_COMM_WORLD); @@ -238,13 +211,10 @@ void Parallel_Kpoints::pool_collection_aux(T* value, const V& w, const int& dim, T* p = &w.ptr[begin]; // temprary restrict kpar=1 for NSPIN=2 case for generating_orbitals int pool = 0; - if (this->nspin != 2) { - pool = this->whichpool[ik]; -} - - - // ofs_running << "\n ik=" << ik; - + if (this->nspin != 2) + { + pool = this->whichpool[ik]; + } if (this->rank_in_pool == 0) { @@ -261,7 +231,6 @@ void Parallel_Kpoints::pool_collection_aux(T* value, const V& w, const int& dim, } else { - // ofs_running << " receive data."; MPI_Status ierror; MPI_Recv(value, dim, MPI_DOUBLE, this->startpro_pool[pool], ik * 2 + 0, MPI_COMM_WORLD, &ierror); } @@ -270,14 +239,12 @@ void Parallel_Kpoints::pool_collection_aux(T* value, const V& w, const int& dim, { if (this->my_pool == pool) { - // ofs_running << " send data."; MPI_Send(p, dim, MPI_DOUBLE, 0, ik * 2 + 0, MPI_COMM_WORLD); } } } else { - // ofs_running << "\n do nothing."; } MPI_Barrier(MPI_COMM_WORLD); @@ -292,4 +259,4 @@ void Parallel_Kpoints::pool_collection_aux(T* value, const V& w, const int& dim, } // data transfer ends. #endif -} \ No newline at end of file +} diff --git a/source/module_io/test/write_istate_info_test.cpp b/source/module_io/test/write_istate_info_test.cpp index 9e95d17fa4..e17fb2c72e 100644 --- a/source/module_io/test/write_istate_info_test.cpp +++ b/source/module_io/test/write_istate_info_test.cpp @@ -43,13 +43,14 @@ class IstateInfoTest : public ::testing::Test TEST_F(IstateInfoTest, OutIstateInfoS1) { - // preconditions + // Global variables GlobalV::KPAR = 1; PARAM.input.nbands = 4; PARAM.sys.nbands_l = 4; PARAM.input.nspin = 1; PARAM.sys.global_out_dir = "./"; - // mpi setting + + // MPI setting Parallel_Global::init_pools(GlobalV::NPROC, GlobalV::MY_RANK, PARAM.input.bndpar, @@ -60,90 +61,54 @@ TEST_F(IstateInfoTest, OutIstateInfoS1) GlobalV::NPROC_IN_POOL, GlobalV::RANK_IN_POOL, GlobalV::MY_POOL); - kv->set_nkstot(100); + + const int nkstot_init = 10; + kv->set_nkstot(nkstot_init); int nkstot = kv->get_nkstot(); - kv->para_k.kinfo(nkstot, GlobalV::KPAR, GlobalV::MY_POOL, GlobalV::RANK_IN_POOL, GlobalV::NPROC_IN_POOL, PARAM.input.nspin); - // std::cout<<"my_rank "<para_k.kinfo(nkstot, GlobalV::KPAR, GlobalV::MY_POOL, GlobalV::RANK_IN_POOL, + GlobalV::NPROC_IN_POOL, PARAM.input.nspin); kv->set_nks(kv->para_k.nks_pool[GlobalV::MY_POOL]); - // std::cout<<"nks "<get_nks()<get_nks(), PARAM.input.nbands); - wg.create(kv->get_nks(), PARAM.input.nbands); - ekb.fill_out(0.15); - wg.fill_out(0.0); - kv->kvec_d.resize(kv->get_nkstot()); - int i = 0; - for (auto& kd: kv->kvec_d) + + // The number of plane waves for each k point + kv->ngk.resize(nkstot); + kv->ik2iktot.resize(nkstot); + for(int i=0; ingk[i]=299; + kv->ik2iktot[i]=i; } - ModuleIO::write_istate_info(ekb, wg, *kv); - std::ifstream ifs; - ifs.open("istate.info"); - std::string str((std::istreambuf_iterator(ifs)), std::istreambuf_iterator()); - EXPECT_THAT( - str, - testing::HasSubstr("BAND Energy(ev) Occupation Kpoint = 100")); - EXPECT_THAT(str, testing::HasSubstr("(0.99 0.99 0.99)")); - EXPECT_THAT(str, testing::HasSubstr("4 2.0408547 0")); - ifs.close(); - remove("istate.info"); -} -TEST_F(IstateInfoTest, OutIstateInfoS2) -{ - // preconditions - GlobalV::KPAR = 1; - PARAM.input.nbands = 4; - PARAM.sys.nbands_l = 4; - PARAM.input.nspin = 2; - PARAM.sys.global_out_dir = "./"; - // mpi setting - Parallel_Global::init_pools(GlobalV::NPROC, - GlobalV::MY_RANK, - PARAM.input.bndpar, - GlobalV::KPAR, - GlobalV::NPROC_IN_BNDGROUP, - GlobalV::RANK_IN_BPGROUP, - GlobalV::MY_BNDGROUP, - GlobalV::NPROC_IN_POOL, - GlobalV::RANK_IN_POOL, - GlobalV::MY_POOL); - kv->set_nkstot(100); - int nkstot = kv->get_nkstot(); - kv->para_k.kinfo(nkstot, GlobalV::KPAR, GlobalV::MY_POOL, GlobalV::RANK_IN_POOL, GlobalV::NPROC_IN_POOL, PARAM.input.nspin); - // std::cout<<"my_rank "<set_nks(kv->para_k.nks_pool[GlobalV::MY_POOL]); - // std::cout<<"nks "<get_nks()<get_nks(), PARAM.input.nbands); wg.create(kv->get_nks(), PARAM.input.nbands); + + // fill the eigenvalues ekb.fill_out(0.15); + + // fill the weights wg.fill_out(0.0); - kv->kvec_d.resize(kv->get_nkstot()); + + // setup coordinates of k-points + kv->kvec_c.resize(kv->get_nkstot()); int i = 0; - for (auto& kd: kv->kvec_d) + for (auto& kd: kv->kvec_c) { kd.set(0.01 * i, 0.01 * i, 0.01 * i); ++i; } + + // write eigenvalues and occupations ModuleIO::write_istate_info(ekb, wg, *kv); + + // check the output files std::ifstream ifs; - ifs.open("istate.info"); + ifs.open("eig.txt"); std::string str((std::istreambuf_iterator(ifs)), std::istreambuf_iterator()); - EXPECT_THAT(str, - testing::HasSubstr("BAND Spin up Energy(ev) Occupation Spin down Energy(ev) " - " Occupation Kpoint = 50")); - EXPECT_THAT( - str, - testing::HasSubstr( - "4 2.04085 0 2.04085 0")); - EXPECT_THAT(str, testing::HasSubstr("(0.49 0.49 0.49)")); + EXPECT_THAT(str, testing::HasSubstr("Electronic state energy (eV) and occupations")); + EXPECT_THAT(str, testing::HasSubstr("spin=1 k-point=1/10 Cartesian=0.0000000 0.0000000 0.0000000 (299 plane wave)")); + EXPECT_THAT(str, testing::HasSubstr("1 2.040854700000000 0.000000000000000")); ifs.close(); - remove("istate.info"); + remove("eig.txt"); } #ifdef __MPI diff --git a/source/module_io/write_istate_info.cpp b/source/module_io/write_istate_info.cpp index 16f6bfebb0..d6894066ee 100644 --- a/source/module_io/write_istate_info.cpp +++ b/source/module_io/write_istate_info.cpp @@ -42,7 +42,6 @@ void ModuleIO::write_istate_info(const ModuleBase::matrix &ekb,const ModuleBase: ModuleBase::WARNING_QUIT("ModuleIO::write_istate_info", "Eigenvalues are too large!"); } - std::vector ngk_tot = kv.ngk; #ifdef __MPI @@ -73,7 +72,9 @@ void ModuleIO::write_istate_info(const ModuleBase::matrix &ekb,const ModuleBase: #ifdef __MPI MPI_Barrier(MPI_COMM_WORLD); #endif + bool ip_flag = PARAM.inp.out_alllog || (GlobalV::RANK_IN_POOL == 0 && GlobalV::MY_BNDGROUP == 0); + if (GlobalV::MY_POOL == ip && ip_flag) { std::ofstream ofs_eig(filename.c_str(), std::ios::app); From 1501ed1b9ecd339f32d4baf839844779845e6fe9 Mon Sep 17 00:00:00 2001 From: mohanchen Date: Mon, 2 Jun 2025 13:16:44 +0800 Subject: [PATCH 18/19] update the test read_wf2rho_pw_test.cpp --- source/module_io/test/read_wf2rho_pw_test.cpp | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/source/module_io/test/read_wf2rho_pw_test.cpp b/source/module_io/test/read_wf2rho_pw_test.cpp index 0d3ec5dede..e8e0214236 100644 --- a/source/module_io/test/read_wf2rho_pw_test.cpp +++ b/source/module_io/test/read_wf2rho_pw_test.cpp @@ -186,14 +186,30 @@ TEST_F(ReadWfcRhoTest, ReadWfcRho) wg.fill_out(1.0); if (GlobalV::MY_RANK == 0) { - std::ofstream ofs("istate.info"); + // mohan update 2025-06-02 + std::ofstream ofs("eig.txt"); + ofs << " Electronic state energy (eV) and occupations" << std::endl; + ofs << " Spin number " << nspin << std::endl; + ofs << std::setprecision(8); + ofs << std::setiosflags(std::ios::showpoint); + + const int is = 0; // nspin is 1 for (int ik = 0; ik < nkstot; ++ik) - { - ofs << "BAND Energy(ev) Occupation Kpoint" << std::endl; - for (int ib = 0; ib < nbands; ++ib) - { - ofs << " " << ib + 1 << " 0.0000000 " << 1.0 << std::endl; - } + { + ofs << " spin=" << is+1 << " k-point=" + << ik + 1 << "/" << nkstot + << " Cartesian=" << kv->kvec_c[ik].x << " " << kv->kvec_c[ik].y + << " " << kv->kvec_c[ik].z << " (" << kv->ngk[ik] << " plane wave)" << std::endl; + + ofs << std::setprecision(16); + ofs << std::setiosflags(std::ios::showpoint); + + double ekb = -1.23456; // energy + for (int ib = 0; ib < nbands; ib++) + { + ofs << " " << ib + 1 << " " << ekb << " " << wg(ik,ib) << std::endl; + } + ofs << std::endl; } ofs.close(); @@ -313,7 +329,7 @@ TEST_F(ReadWfcRhoTest, ReadWfcRho) if (GlobalV::MY_RANK == 0) { remove("running_log0.txt"); - remove("istate.info"); + remove("eig.txt"); remove("wfs1k1_pw.dat"); remove("wfs1k2_pw.dat"); if (GlobalV::KPAR == 2) From 96d25d5fcbaef85dbc024d18235b8805500dce63 Mon Sep 17 00:00:00 2001 From: mohanchen Date: Mon, 2 Jun 2025 13:31:10 +0800 Subject: [PATCH 19/19] change the name of reference data eigs1.txt.ref --- .../01_PW/051_PW_OBOD_MemSaver/{refBANDS_1.dat => eigs1.txt.ref} | 0 tests/03_NAO_multik/15_NO_KP_OB/{refBANDS_1.dat => eigs1.txt.ref} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename tests/01_PW/051_PW_OBOD_MemSaver/{refBANDS_1.dat => eigs1.txt.ref} (100%) rename tests/03_NAO_multik/15_NO_KP_OB/{refBANDS_1.dat => eigs1.txt.ref} (100%) diff --git a/tests/01_PW/051_PW_OBOD_MemSaver/refBANDS_1.dat b/tests/01_PW/051_PW_OBOD_MemSaver/eigs1.txt.ref similarity index 100% rename from tests/01_PW/051_PW_OBOD_MemSaver/refBANDS_1.dat rename to tests/01_PW/051_PW_OBOD_MemSaver/eigs1.txt.ref diff --git a/tests/03_NAO_multik/15_NO_KP_OB/refBANDS_1.dat b/tests/03_NAO_multik/15_NO_KP_OB/eigs1.txt.ref similarity index 100% rename from tests/03_NAO_multik/15_NO_KP_OB/refBANDS_1.dat rename to tests/03_NAO_multik/15_NO_KP_OB/eigs1.txt.ref