Skip to content

Update output filenames for PCHG #6299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jun 17, 2025
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 133 additions & 0 deletions source/module_io/ctrl_output_fp.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
#include "module_io/ctrl_output_fp.h" // use ctrl_output_fp()

namespace ModuleIO
{

template <typename TK, typename TR>
void ctrl_output_fp(UnitCell& ucell,
elecstate::ElecStateLCAO<TK>* pelec,
const int istep)
{
ModuleBase::TITLE("ModuleIO", "ctrl_output_fp");
ModuleBase::timer::tick("ModuleIO", "ctrl_output_fp");

const bool out_app_flag = PARAM.inp.out_app_flag;
const bool gamma_only = PARAM.globalv.gamma_only_local;
const int nspin = PARAM.inp.nspin;
const std::string global_out_dir = PARAM.globalv.global_out_dir;

// 1) write charge density
if (PARAM.inp.out_chg[0] > 0)
{
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 + "/chgs" + std::to_string(is + 1) + ".cube";
ModuleIO::write_vdata_palgrid(Pgrid,
this->chr.rho_save[is],
is,
PARAM.inp.nspin,
istep,
fn,
this->pelec->eferm.get_efval(is),
&(ucell),
PARAM.inp.out_chg[1],
1);

if (XC_Functional::get_ked_flag())
{
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,
PARAM.inp.nspin,
istep,
fn,
this->pelec->eferm.get_efval(is),
&(ucell));
}
}
}


// 2) write potential
if (PARAM.inp.out_pot == 1 || PARAM.inp.out_pot == 3)
{
for (int is = 0; is < PARAM.inp.nspin; is++)
{
std::string fn =PARAM.globalv.global_out_dir + "/pots" + std::to_string(is + 1) + ".cube";

ModuleIO::write_vdata_palgrid(Pgrid,
this->pelec->pot->get_effective_v(is),
is,
PARAM.inp.nspin,
istep,
fn,
0.0, // efermi
&(ucell),
3, // precision
0); // out_fermi
}
}
else if (PARAM.inp.out_pot == 2)
{
std::string fn =PARAM.globalv.global_out_dir + "/pot_es.cube";
ModuleIO::write_elecstat_pot(
#ifdef __MPI
this->pw_big->bz,
this->pw_big->nbz,
#endif
fn,
istep,
this->pw_rhod,
&this->chr,
&(ucell),
this->pelec->pot->get_fixed_v(),
this->solvent);
}


// 3) write ELF
if (PARAM.inp.out_elf[0] > 0)
{
this->chr.cal_elf = true;
Symmetry_rho srho;
for (int is = 0; is < PARAM.inp.nspin; is++)
{
srho.begin(is, this->chr, this->pw_rhod, ucell.symm);
}

std::string out_dir =PARAM.globalv.global_out_dir;
ModuleIO::write_elf(
#ifdef __MPI
this->pw_big->bz,
this->pw_big->nbz,
#endif
out_dir,
istep,
PARAM.inp.nspin,
this->chr.rho,
this->chr.kin_r,
this->pw_rhod,
this->Pgrid,
&(ucell),
PARAM.inp.out_elf[1]);
}

ModuleBase::timer::tick("ModuleIO", "ctrl_output_fp");
}

} // End ModuleIO


// For gamma only
template void ModuleIO::ctrl_output_lcao<double, double>(UnitCell& ucell,
const int istep);

// For multiple k-points
template void ModuleIO::ctrl_output_lcao<std::complex<double>, double>(UnitCell& ucell,
const int istep);

template void ModuleIO::ctrl_output_lcao<std::complex<double>, std::complex<double>>(UnitCell& ucell,
const int istep);

11 changes: 11 additions & 0 deletions source/module_io/ctrl_output_fp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef CTRL_OUTPUT_FP_H
#define CTRL_OUTPUT_FP_H

namespace ModuleIO
{
template <typename TK, typename TR>
void ctrl_output_fp(UnitCell& ucell,
elecstate::ElecStateLCAO<TK>* pelec,
const int istep);
}
#endif
21 changes: 11 additions & 10 deletions source/module_io/get_pchg_lcao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void IState_Charge::begin(Gint_Gamma& gg,
{
ModuleBase::TITLE("IState_Charge", "begin");

std::cout << " Calculate |psi(i)|^2 for selected bands (band-decomposed charge densities, gamma only)."
std::cout << " Calculate |psi(i)|^2 for selected electronic states (gamma only)."
<< std::endl;

// Determine the mode based on the input parameters
Expand All @@ -77,8 +77,8 @@ void IState_Charge::begin(Gint_Gamma& gg,
// if ucell is even, it's also correct.
// +1.0e-8 in case like (2.999999999+1)/2
const int fermi_band = static_cast<int>((nelec + 1) / 2 + 1.0e-8);
std::cout << " number of electrons = " << nelec << std::endl;
std::cout << " number of occupied bands = " << fermi_band << std::endl;
GlobalV::ofs_running << " number of electrons = " << nelec << std::endl;
GlobalV::ofs_running << " number of occupied bands = " << fermi_band << std::endl;

// Set this->bands_picked_ according to the mode
select_bands(nbands_istate, out_pchg, nbands, nelec, mode, fermi_band);
Expand All @@ -101,7 +101,7 @@ void IState_Charge::begin(Gint_Gamma& gg,
ModuleBase::GlobalFunc::ZEROS(rho[is], rhopw_nrxx);
}

std::cout << " Performing grid integral over real space grid for band " << ib + 1 << "..." << std::endl;
//std::cout << " Performing grid integral over real space grid for band " << ib + 1 << "..." << std::endl;

DM.init_DMR(GridD_in, ucell_in);
DM.cal_DMR();
Expand All @@ -120,21 +120,22 @@ void IState_Charge::begin(Gint_Gamma& gg,
ModuleBase::GlobalFunc::DCOPY(rho[is], rho_save[is].data(), rhopw_nrxx); // Copy data
}

std::cout << " Writing cube files...";

for (int is = 0; is < nspin; ++is)
{
// ssc should be inside the inner loop to reset the string stream each time
std::stringstream ssc;
ssc << global_out_dir << "BAND" << ib + 1 << "_GAMMA" << "_SPIN" << is + 1 << "_CHG.cube";
ssc << global_out_dir << "pchgs" << is + 1 << "i" << ib + 1 << ".cube";

GlobalV::ofs_running << " Writing cube file " << ssc.str() << std::endl;

// Use a const vector to store efermi for all spins, replace the original implementation:
// const double ef_tmp = pelec->eferm.get_efval(is);
double ef_spin = ef_all_spin[is];
ModuleIO::write_vdata_palgrid(pgrid, rho_save[is].data(), is, nspin, 0, ssc.str(), ef_spin, ucell_in);
}

std::cout << " Complete!" << std::endl;
//std::cout << " Complete!" << std::endl;
}
}

Expand Down Expand Up @@ -251,7 +252,7 @@ void IState_Charge::begin(Gint_k& gk,
{
// ssc should be inside the inner loop to reset the string stream each time
std::stringstream ssc;
ssc << global_out_dir << "BAND" << ib + 1 << "_K" << ik + 1 << "_SPIN" << is + 1 << "_CHG.cube";
ssc << global_out_dir << "pchgs" << is + 1 << "k" << ik+1 << "i" << ib + 1 << ".cube";

double ef_spin = ef_all_spin[is];
ModuleIO::write_vdata_palgrid(pgrid,
Expand Down Expand Up @@ -292,7 +293,7 @@ void IState_Charge::begin(Gint_k& gk,
}

// Symmetrize the charge density, otherwise the results are incorrect if the symmetry is on
std::cout << " Symmetrizing band-decomposed charge density..." << std::endl;
// std::cout << " Symmetrizing band-decomposed charge density..." << std::endl;
Symmetry_rho srho;
for (int is = 0; is < nspin; ++is)
{
Expand All @@ -310,7 +311,7 @@ void IState_Charge::begin(Gint_k& gk,
{
// ssc should be inside the inner loop to reset the string stream each time
std::stringstream ssc;
ssc << global_out_dir << "BAND" << ib + 1 << "_SPIN" << is + 1 << "_CHG.cube";
ssc << global_out_dir << "pchgs" << is + 1 << "i" << ib + 1 << ".cube";

double ef_spin = ef_all_spin[is];
ModuleIO::write_vdata_palgrid(pgrid,
Expand Down
8 changes: 4 additions & 4 deletions source/module_io/get_pchg_pw.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ void get_pchg_pw(const std::vector<int>& out_pchg,
}

std::stringstream ssc;
ssc << global_out_dir << "BAND" << ib + 1 << "_K" << k_number << "_SPIN" << spin_index + 1
<< "_CHG.cube";
ssc << global_out_dir << "pchgs" << spin_index + 1 << "k" << k_number << "i" << ib + 1
<< ".cube";

ModuleIO::write_vdata_palgrid(pgrid,
rho_band[spin_index].data(),
Expand Down Expand Up @@ -182,7 +182,7 @@ void get_pchg_pw(const std::vector<int>& out_pchg,
#endif

// Symmetrize the charge density, otherwise the results are incorrect if the symmetry is on
std::cout << " Symmetrizing band-decomposed charge density..." << std::endl;
// std::cout << " Symmetrizing band-decomposed charge density..." << std::endl;
Symmetry_rho srho;
for (int is = 0; is < nspin; ++is)
{
Expand All @@ -208,7 +208,7 @@ void get_pchg_pw(const std::vector<int>& out_pchg,
for (int is = 0; is < nspin; ++is)
{
std::stringstream ssc;
ssc << global_out_dir << "BAND" << ib + 1 << "_SPIN" << is + 1 << "_CHG.cube";
ssc << global_out_dir << "pchgs" << is + 1 << "i" << ib + 1 << ".cube";

ModuleIO::write_vdata_palgrid(pgrid, rho_band[is].data(), is, nspin, 0, ssc.str(), 0.0, ucell);
}
Expand Down
10 changes: 0 additions & 10 deletions tests/01_PW/074_PW_SY_6K/INPUT

This file was deleted.

4 changes: 0 additions & 4 deletions tests/01_PW/074_PW_SY_6K/KPT

This file was deleted.

8 changes: 0 additions & 8 deletions tests/01_PW/074_PW_SY_6K/README

This file was deleted.

18 changes: 0 additions & 18 deletions tests/01_PW/074_PW_SY_6K/STRU

This file was deleted.

3 changes: 0 additions & 3 deletions tests/01_PW/074_PW_SY_6K/result.ref

This file was deleted.

1 change: 0 additions & 1 deletion tests/01_PW/074_PW_SY_6K/threshold

This file was deleted.

4 changes: 2 additions & 2 deletions tests/01_PW/087_PW_OP/result.ref
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
etotref -3526.201516177710
etotperatomref -3526.2015161777
etotref -3526.201517581517
etotperatomref -3526.2015175815
ComparePot1_pass 0
pointgroupref O_h
spacegroupref O_h
Expand Down
12 changes: 6 additions & 6 deletions tests/01_PW/111_PW_get_pchg/result.ref
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
etotref -197.1405644417787
etotref -197.1405644417785
etotperatomref -98.5702822209
BAND1_SPIN1_CHG.cube 2
BAND2_SPIN1_CHG.cube 2
BAND3_SPIN1_CHG.cube 2
BAND4_SPIN1_CHG.cube 2
pchgs1i1.cube 2
pchgs1i2.cube 2
pchgs1i3.cube 2
pchgs1i4.cube 2
pointgroupref T_d
spacegroupref O_h
nksibzref 1
totaltimeref 0.35
totaltimeref 0.36
12 changes: 6 additions & 6 deletions tests/01_PW/113_PW_get_pchg_kpar/result.ref
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
etotref -211.8032873347874
etotref -211.8032873347996
etotperatomref -105.9016436674
BAND1_SPIN1_CHG.cube 2
BAND2_SPIN1_CHG.cube 2
BAND3_SPIN1_CHG.cube 2
BAND4_SPIN1_CHG.cube 2
pchgs1i1.cube 2
pchgs1i2.cube 2
pchgs1i3.cube 2
pchgs1i4.cube 2
pointgroupref T_d
spacegroupref O_h
nksibzref 3
totaltimeref 1.35
totaltimeref 0.46
28 changes: 14 additions & 14 deletions tests/01_PW/114_PW_get_pchg_sepk/result.ref
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
etotref -211.8032873348292
etotref -211.8032873347996
etotperatomref -105.9016436674
BAND1_K1_SPIN1_CHG.cube 2
BAND1_K2_SPIN1_CHG.cube 2
BAND1_K3_SPIN1_CHG.cube 2
BAND2_K1_SPIN1_CHG.cube 2
BAND2_K2_SPIN1_CHG.cube 2
BAND2_K3_SPIN1_CHG.cube 2
BAND3_K1_SPIN1_CHG.cube 2
BAND3_K2_SPIN1_CHG.cube 2
BAND3_K3_SPIN1_CHG.cube 2
BAND4_K1_SPIN1_CHG.cube 2
BAND4_K2_SPIN1_CHG.cube 2
BAND4_K3_SPIN1_CHG.cube 2
pchgs1k1i1.cube 2
pchgs1k1i2.cube 2
pchgs1k1i3.cube 2
pchgs1k1i4.cube 2
pchgs1k2i1.cube 2
pchgs1k2i2.cube 2
pchgs1k2i3.cube 2
pchgs1k2i4.cube 2
pchgs1k3i1.cube 2
pchgs1k3i2.cube 2
pchgs1k3i3.cube 2
pchgs1k3i4.cube 2
pointgroupref T_d
spacegroupref O_h
nksibzref 3
totaltimeref 1.23
totaltimeref 0.48
1 change: 0 additions & 1 deletion tests/01_PW/CASES_CPU.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
070_PW_CR_fix_c
071_PW_CR_move
073_PW_SY
074_PW_SY_6K
075_PW_SY_LiRh
076_PW_elec_add
077_PW_elec_minus
Expand Down
Loading
Loading