Skip to content

Commit 9f3e6e7

Browse files
authored
Change the file names of output charge densities and kinetic energy densities (#6254)
* add notes for the modified output file names, specify the names in the 3.10-LTS version * update the CHG file names in input-main.md and change the output file names of charge density * add explanations for taus1.cube, etc. * change the file names for 203_PW_OK example * update read in charge density codes and tests * fix example 050_PW_CHG_mismatch * update the file names of charge densities * update CHG files in support directories * fix file names in rho_io_test.cpp * update 203_PW_OK * update result.ref in 23_NO_KP_OK
1 parent aee5691 commit 9f3e6e7

File tree

31 files changed

+60
-47
lines changed

31 files changed

+60
-47
lines changed

docs/advanced/input_files/input-main.md

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ These variables are used to control general system parameters.
608608
- **Description**: This variable is used for both plane wave set and localized orbitals set. It indicates the type of starting density.
609609

610610
- atomic: the density is starting from the summation of the atomic density of single atoms.
611-
- 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.
611+
- 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.
612612
- 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`.
613613
- auto: Abacus first attempts to read the density from a file; if not found, it defaults to using atomic density.
614614
- **Default**: atomic
@@ -742,7 +742,7 @@ These variables are used to control parameters related to input files.
742742
### read_file_dir
743743

744744
- **Type**: String
745-
- **Description**: Indicates the location of files, such as electron density (`SPIN1_CHG.cube`), required as a starting point.
745+
- **Description**: Location of files, such as the electron density (`chgs1.cube`), required as a starting point.
746746
- Example: './' implies the files to be read are located in the working directory.
747747
- **Default**: OUT.$suffix
748748

@@ -1602,24 +1602,26 @@ These variables are used to control the output of properties.
16021602
- **Description**:
16031603
The first integer controls whether to output the charge density on real space grids:
16041604
- 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:
1605-
- nspin = 1: SPIN1_CHG.cube;
1606-
- nspin = 2: SPIN1_CHG.cube, and SPIN2_CHG.cube;
1607-
- nspin = 4: SPIN1_CHG.cube, SPIN2_CHG.cube, SPIN3_CHG.cube, and SPIN4_CHG.cube.
1608-
- 2: On top of 1, also output the initial charge density. The files are named as:
1609-
- nspin = 1: SPIN1_CHG_INI.cube
1610-
- nspin = 2: SPIN1_CHG_INI.cube, and SPIN2_CHG_INI.cube;
1611-
- nspin = 4: SPIN1_CHG_INI.cube, SPIN2_CHG_INI.cube, SPIN3_CHG_INI.cube, and SPIN4_CHG_INI.cube.
1605+
- nspin = 1: `chgs1.cube`;
1606+
- nspin = 2: `chgs1.cube`, and `chgs2.cube`;
1607+
- nspin = 4: `chgs1.cube`, `chgs2.cube`, `chgs3.cube`, and `chgs4.cube`;
1608+
Note that by using the Meta-GGA functional, additional files containing the kinetic energy density will be output with the following names:
1609+
- nspin = 1: `taus1.cube`;
1610+
- nspin = 2: `taus1.cube`, and `taus2.cube`;
1611+
- nspin = 4: `taus1.cube`, `taus2.cube`, `taus3.cube`, and `taus4.cube`;
1612+
- 2: On top of 1, also output the initial charge density files with a suffix name as '_ini', such as `taus1_ini.cube`, etc.
16121613
- -1: disable the charge density auto-back-up file `{suffix}-CHARGE-DENSITY.restart`, useful for large systems.
16131614

16141615
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`.
16151616

16161617
---
16171618
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).
16181619

1619-
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.
1620+
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.
16201621

1621-
In molecular dynamics calculations, the output frequency is controlled by [out_interval](#out_interval).
1622+
In molecular dynamics simulations, the output frequency is controlled by [out_interval](#out_interval).
16221623
- **Default**: 0 3
1624+
- **NOTE**: In the 3.10-LTS version, the file names are SPIN1_CHG.cube and SPIN1_CHG_INI.cube, etc.
16231625

16241626
### out_pot
16251627

@@ -1638,6 +1640,7 @@ These variables are used to control the output of properties.
16381640

16391641
In molecular dynamics calculations, the output frequency is controlled by [out_interval](#out_interval).
16401642
- **Default**: 0
1643+
- **NOTE**: In the 3.10-LTS version, the file names are SPIN1_POT.cube and SPIN1_POT_INI.cube, etc.
16411644

16421645
### out_dm
16431646

@@ -1651,6 +1654,7 @@ These variables are used to control the output of properties.
16511654
- nspin = 1: `dms1k1_nao.csr`, `dms1k2_nao.csr`, ...;
16521655
- nspin = 2: `dms1k1_nao.csr`... and `dms2k1_nao.csr`... for the two spin channels.
16531656
- **Default**: False
1657+
- **NOTE**: In the 3.10-LTS version, the file names are SPIN1_DM and SPIN2_DM, etc.
16541658

16551659
### out_dm1
16561660

@@ -1660,6 +1664,7 @@ These variables are used to control the output of properties.
16601664
- nspin = 1: `dmrs1_nao.csr`;
16611665
- nspin = 2: `dmrs1_nao.csr` and `dmrs2_nao.csr` for the two spin channels.
16621666
- **Default**: False
1667+
- **NOTE**: In the 3.10-LTS version, the file names are data-DMR-sparse_SPIN0.csr and data-DMR-sparse_SPIN1.csr, etc.
16631668

16641669
### out_wfc_pw
16651670

@@ -1672,6 +1677,7 @@ These variables are used to control the output of properties.
16721677
- 2: (binary format)
16731678
- non-gamma-only: `wfs1k1_pw.dat` or `wfs1k2_pw.dat`, ....
16741679
- **Default**: 0
1680+
- **NOTE**: In the 3.10-LTS version, the file names are OUT.${suffix}/WAVEFUNC${K}.dat, etc.
16751681

16761682
### out_wfc_lcao
16771683

@@ -1689,7 +1695,8 @@ These variables are used to control the output of properties.
16891695
The corresponding sequence of the orbitals can be seen in [Basis Set](../pp_orb.md#basis-set).
16901696

16911697
Also controled by [out_interval](#out_interval) and [out_app_flag](#out_app_flag).
1692-
- **Default**: Flase
1698+
- **Default**: False
1699+
- **NOTE**: In the 3.10-LTS version, the file names are WFC_NAO_GAMMA1_ION1.txt and WFC_NAO_K1_ION1.txt, etc.
16931700

16941701
### out_dos
16951702

source/module_elecstate/module_charge/charge_init.cpp

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,12 @@ void Charge::init_rho(elecstate::efermi& eferm_iout,
2828
{
2929
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "init_chg", PARAM.inp.init_chg);
3030

31+
const int nspin = PARAM.inp.nspin;
32+
assert(nspin>0);
33+
3134
std::cout << " START CHARGE : " << PARAM.inp.init_chg << std::endl;
32-
//here we need to set the omega for the charge density
35+
36+
// we need to set the omega for the charge density
3337
set_omega(&ucell.omega);
3438
this->pgrid = &pgrid;
3539

@@ -46,17 +50,17 @@ void Charge::init_rho(elecstate::efermi& eferm_iout,
4650
if (ModuleIO::read_rhog(binary.str(), rhopw, rhog))
4751
{
4852
GlobalV::ofs_running << " Read electron density from file: " << binary.str() << std::endl;
49-
for (int is = 0; is < PARAM.inp.nspin; ++is)
53+
for (int is = 0; is < nspin; ++is)
5054
{
5155
rhopw->recip2real(rhog[is], rho[is]);
5256
}
5357
}
5458
else
5559
{
56-
for (int is = 0; is < PARAM.inp.nspin; ++is)
60+
for (int is = 0; is < nspin; ++is)
5761
{
5862
std::stringstream ssc;
59-
ssc << PARAM.globalv.global_readin_dir << "SPIN" << is + 1 << "_CHG.cube";
63+
ssc << PARAM.globalv.global_readin_dir << "chgs" << is + 1 << ".cube";
6064
if (ModuleIO::read_vdata_palgrid(pgrid,
6165
(PARAM.inp.esolver_type == "sdft" ? GlobalV::RANK_IN_BPGROUP : GlobalV::MY_RANK),
6266
GlobalV::ofs_running,
@@ -103,7 +107,7 @@ void Charge::init_rho(elecstate::efermi& eferm_iout,
103107
{
104108
const std::string warn_msg
105109
= " WARNING: \"init_chg\" is enabled but ABACUS failed to read\n charge density from file.\n"
106-
" Please check if there is SPINX_CHG.cube (X=1,...) or\n {suffix}-CHARGE-DENSITY.restart in the "
110+
" Please check if there is chgsx.cube (x=1,2,etc.) or\n {suffix}-CHARGE-DENSITY.restart in the "
107111
"directory.\n";
108112
std::cout << warn_msg;
109113
if (PARAM.inp.init_chg == "file")
@@ -121,9 +125,9 @@ void Charge::init_rho(elecstate::efermi& eferm_iout,
121125
{
122126
GlobalV::ofs_running << " try to read kinetic energy density from file" << std::endl;
123127
// try to read charge from binary file first, which is the same as QE
124-
std::vector<std::complex<double>> kin_g_space(PARAM.inp.nspin * this->ngmc, {0.0, 0.0});
128+
std::vector<std::complex<double>> kin_g_space(nspin * this->ngmc, {0.0, 0.0});
125129
std::vector<std::complex<double>*> kin_g;
126-
for (int is = 0; is < PARAM.inp.nspin; is++)
130+
for (int is = 0; is < nspin; is++)
127131
{
128132
kin_g.push_back(kin_g_space.data() + is * this->ngmc);
129133
}
@@ -133,14 +137,14 @@ void Charge::init_rho(elecstate::efermi& eferm_iout,
133137
if (ModuleIO::read_rhog(binary.str(), rhopw, kin_g.data()))
134138
{
135139
GlobalV::ofs_running << " Read in the kinetic energy density: " << binary.str() << std::endl;
136-
for (int is = 0; is < PARAM.inp.nspin; ++is)
140+
for (int is = 0; is < nspin; ++is)
137141
{
138142
rhopw->recip2real(kin_g[is], this->kin_r[is]);
139143
}
140144
}
141145
else
142146
{
143-
for (int is = 0; is < PARAM.inp.nspin; is++)
147+
for (int is = 0; is < nspin; is++)
144148
{
145149
std::stringstream ssc;
146150
ssc << PARAM.globalv.global_readin_dir << "SPIN" << is + 1 << "_TAU.cube";
@@ -175,16 +179,16 @@ void Charge::init_rho(elecstate::efermi& eferm_iout,
175179
}
176180
}
177181

178-
if (PARAM.inp.init_chg == "atomic" || read_error) // mohan add 2007-10-17
182+
if (PARAM.inp.init_chg == "atomic" || read_error)
179183
{
180184
if (read_error)
181185
{
182186
std::cout << " Charge::init_rho: use atomic initialization instead." << std::endl;
183187
}
184-
this->atomic_rho(PARAM.inp.nspin, ucell.omega, rho, strucFac, ucell);
188+
this->atomic_rho(nspin, ucell.omega, rho, strucFac, ucell);
185189
}
186190

187-
// wenfei 2021-7-29 : initial tau = 3/5 rho^2/3, Thomas-Fermi
191+
// initial tau = 3/5 rho^2/3, Thomas-Fermi
188192
if (XC_Functional::get_ked_flag())
189193
{
190194
if (PARAM.inp.init_chg == "atomic" || read_kin_error)
@@ -194,11 +198,11 @@ void Charge::init_rho(elecstate::efermi& eferm_iout,
194198
std::cout << " Charge::init_rho: init kinetic energy density from rho." << std::endl;
195199
}
196200
const double fact = (3.0 / 5.0) * pow(3.0 * ModuleBase::PI * ModuleBase::PI, 2.0 / 3.0);
197-
for (int is = 0; is < PARAM.inp.nspin; ++is)
201+
for (int is = 0; is < nspin; ++is)
198202
{
199203
for (int ir = 0; ir < this->rhopw->nrxx; ++ir)
200204
{
201-
kin_r[is][ir] = fact * pow(std::abs(rho[is][ir]) * PARAM.inp.nspin, 5.0 / 3.0) / PARAM.inp.nspin;
205+
kin_r[is][ir] = fact * pow(std::abs(rho[is][ir]) * nspin, 5.0 / 3.0) / nspin;
202206
}
203207
}
204208
}
@@ -207,7 +211,7 @@ void Charge::init_rho(elecstate::efermi& eferm_iout,
207211
// Peize Lin add 2020.04.04
208212
if (GlobalC::restart.info_load.load_charge && !GlobalC::restart.info_load.load_charge_finish)
209213
{
210-
for (int is = 0; is < PARAM.inp.nspin; ++is)
214+
for (int is = 0; is < nspin; ++is)
211215
{
212216
try
213217
{
@@ -217,20 +221,21 @@ void Charge::init_rho(elecstate::efermi& eferm_iout,
217221
{
218222
// try to load from the output of `out_chg`
219223
std::stringstream ssc;
220-
ssc << PARAM.globalv.global_readin_dir << "SPIN" << is + 1 << "_CHG.cube";
224+
ssc << PARAM.globalv.global_readin_dir << "chgs" << is + 1 << ".cube";
221225
if (ModuleIO::read_vdata_palgrid(pgrid,
222226
(PARAM.inp.esolver_type == "sdft" ? GlobalV::RANK_IN_BPGROUP : GlobalV::MY_RANK),
223227
GlobalV::ofs_running,
224228
ssc.str(),
225229
this->rho[is],
226230
ucell.nat))
227231
{
228-
GlobalV::ofs_running << " Read in the electron density: " << ssc.str() << std::endl;
232+
GlobalV::ofs_running << " Read in electron density: " << ssc.str() << std::endl;
229233
}
230234
}
231235
}
232236
GlobalC::restart.info_load.load_charge_finish = true;
233237
}
238+
234239
#ifdef __MPI
235240
this->init_chgmpi();
236241
#endif
@@ -248,7 +253,7 @@ void Charge::init_rho(elecstate::efermi& eferm_iout,
248253
PARAM.globalv.global_readin_dir,
249254
GlobalV::KPAR, GlobalV::MY_POOL, GlobalV::MY_RANK,
250255
GlobalV::NPROC_IN_POOL, GlobalV::RANK_IN_POOL,
251-
PARAM.inp.nbands, PARAM.inp.nspin, PARAM.globalv.npol,
256+
PARAM.inp.nbands, nspin, PARAM.globalv.npol,
252257
kv->get_nkstot(),kv->ik2iktot,kv->isk,GlobalV::ofs_running);
253258
}
254259
}

source/module_esolver/esolver_fp.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ void ESolver_FP::after_scf(UnitCell& ucell, const int istep, const bool conv_eso
165165
for (int is = 0; is < PARAM.inp.nspin; is++)
166166
{
167167
this->pw_rhod->real2recip(this->chr.rho_save[is], this->chr.rhog_save[is]);
168-
std::string fn =PARAM.globalv.global_out_dir + "/SPIN" + std::to_string(is + 1) + "_CHG.cube";
168+
std::string fn =PARAM.globalv.global_out_dir + "/chgs" + std::to_string(is + 1) + ".cube";
169169
ModuleIO::write_vdata_palgrid(Pgrid,
170170
this->chr.rho_save[is],
171171
is,
@@ -176,9 +176,10 @@ void ESolver_FP::after_scf(UnitCell& ucell, const int istep, const bool conv_eso
176176
&(ucell),
177177
PARAM.inp.out_chg[1],
178178
1);
179+
179180
if (XC_Functional::get_ked_flag())
180181
{
181-
fn =PARAM.globalv.global_out_dir + "/SPIN" + std::to_string(is + 1) + "_TAU.cube";
182+
fn =PARAM.globalv.global_out_dir + "/taus" + std::to_string(is + 1) + ".cube";
182183
ModuleIO::write_vdata_palgrid(Pgrid,
183184
this->chr.kin_r_save[is],
184185
is,
@@ -339,7 +340,7 @@ void ESolver_FP::before_scf(UnitCell& ucell, const int istep)
339340
for (int is = 0; is < PARAM.inp.nspin; is++)
340341
{
341342
std::stringstream ss;
342-
ss << PARAM.globalv.global_out_dir << "SPIN" << is + 1 << "_CHG_INI.cube";
343+
ss << PARAM.globalv.global_out_dir << "/chgs" << is + 1 << "_ini.cube";
343344
ModuleIO::write_vdata_palgrid(this->Pgrid,
344345
this->chr.rho[is],
345346
is,

source/module_io/test_serial/rho_io_test.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class RhoIOTest : public ::testing::Test
9191
TEST_F(RhoIOTest, Read)
9292
{
9393
int is = 0;
94-
std::string fn = "./support/SPIN1_CHG.cube";
94+
std::string fn = "./support/chgs1.cube";
9595
int nx = 36;
9696
int ny = 36;
9797
int nz = 36;
@@ -117,9 +117,9 @@ TEST_F(RhoIOTest, Write)
117117
ucell->atoms[0].tau[1] = ModuleBase::Vector3<double>(-0.75, 0.75, 0.75);
118118
ucell->atoms[0].ncpp.zv = 4;
119119
Parallel_Grid pgrid(nx, ny, nz, nz, nrxx, nz, 1);
120-
ModuleIO::read_vdata_palgrid(pgrid, my_rank, ofs_running, "support/SPIN1_CHG.cube", rho[0], ucell->nat);
120+
ModuleIO::read_vdata_palgrid(pgrid, my_rank, ofs_running, "support/chgs1.cube", rho[0], ucell->nat);
121121
ModuleIO::write_vdata_palgrid(pgrid, rho[0], 0, nspin, 0, "test_write_vdata_palgrid.cube", 0.461002, ucell, 11, 1);
122-
EXPECT_EQ(system("diff -q test_write_vdata_palgrid.cube support/SPIN1_CHG.cube"), 0);
122+
EXPECT_EQ(system("diff -q test_write_vdata_palgrid.cube support/chgs1.cube"), 0);
123123
}
124124

125125
TEST_F(RhoIOTest, TrilinearInterpolate)
@@ -130,7 +130,7 @@ TEST_F(RhoIOTest, TrilinearInterpolate)
130130
int nx_read = 36;
131131
int ny_read = 36;
132132
int nz_read = 36;
133-
std::ifstream ifs("./support/SPIN1_CHG.cube");
133+
std::ifstream ifs("./support/chgs1.cube");
134134
for (int i = 0; i < 8; ++i)
135135
{
136136
ifs.ignore(300, '\n');
@@ -190,7 +190,7 @@ struct CubeIOTest : public ::testing::Test
190190
std::vector<double> atom_charge;
191191
std::vector<std::vector<double>> atom_pos;
192192
std::vector<double> data_read;
193-
const std::string fn = "./support/SPIN1_CHG.cube";
193+
const std::string fn = "./support/chgs1.cube";
194194
};
195195

196196

@@ -236,5 +236,5 @@ TEST_F(CubeIOTest, WriteCube)
236236
dx, dy, dz, atom_type,
237237
atom_charge, atom_pos, data_read, 11);
238238

239-
EXPECT_EQ(system("diff -q test_write.cube ./support/SPIN1_CHG.cube"), 0);
239+
EXPECT_EQ(system("diff -q test_write.cube ./support/chgs1.cube"), 0);
240240
}

0 commit comments

Comments
 (0)