Skip to content

Commit ca7978a

Browse files
authored
Update DOS output formats (pw basis). (#6113)
* update some timers * update timer * update output formats * update print_cell * add ofs in print_tau * update print_tau * update output formats * update md outputs * beging modifying the autotests * update integrate tests * update some timers * fix total force and total stress * update integrate tests * update print_band * fix print_band * update md print out information * update print_stress * update print_stress in dp, but still has problems in lj * fix dp_test.cpp * update esolver_lj * set mulliken charge accuracy from 4 to 3 * update print force and print stress * delete kv variable in hamilt_lcao * update some operators * update hamiltonian and operator * update updateHk funciton parameters * fix bug * fix bug in updateHk * update updateSk * update read atoms * update SCAN_BEGIN, now the function ignore lines starting with # * update * add SCAN_LINE_BEGIN * fix bug * fix issue * update dos output file name * update dos * update DOS, fix an output bug * update DOS calculations * output format updated * update warning message for reading charge density * fix tool_quit * fix write_dos_pw_test.cpp * update unittests * change Chinese note to English * update some formats * update some outputs * update DOS in integrated tests * update ref data * add prepare_dos in cal_dos.cpp * use prepare_dos in write_dos_lcao.cpp * update LCAO DOS codes * change DOS name * fix DOS name in SDFT * add dat after DOS and TDOS * add pdos * add cal_pdos * update ref for DOS * update cal_pdos_gamma * update timer and quit tests * fix two issues in unittests
1 parent aa52a32 commit ca7978a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1111
-782
lines changed

source/module_base/test/timer_test.cpp

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,22 @@ TEST_F(TimerTest, Tick)
5959
EXPECT_GT(ModuleBase::timer::timer_pool["wavefunc"]["evc"].cpu_second,0.0001);
6060
}
6161

62+
6263
TEST_F(TimerTest, Start)
6364
{
6465
ModuleBase::timer::start();
6566
// start() called tick() once
6667
EXPECT_FALSE(ModuleBase::timer::timer_pool[""]["total"].start_flag);
6768
}
6869

70+
6971
TEST_F(TimerTest, write_to_json)
7072
{
7173
ModuleBase::timer::tick("wavefunc","evc");
7274
std::this_thread::sleep_for(std::chrono::microseconds(T_Elapse)); // 0.1 ms
7375
ModuleBase::timer::tick("wavefunc","evc");
7476
ModuleBase::timer::write_to_json("tmp.json");
77+
7578
// check if tmp.json exists
7679
ifs.open("tmp.json");
7780
EXPECT_TRUE(ifs.good());
@@ -89,9 +92,6 @@ TEST_F(TimerTest, write_to_json)
8992
content += tmp;
9093
}
9194

92-
// check if the content is correct
93-
// shuold be like this:
94-
// {"total": 0, "sub":[{"class_name": "wavefunc","sub":[{"name":"evc","cpu_second": 0.000318,"calls":2,"cpu_second_per_call":0.000159,"cpu_second_per_total": null}]}]}
9595
EXPECT_THAT(content,testing::HasSubstr("\"total\":"));
9696
EXPECT_THAT(content,testing::HasSubstr("\"sub\":[{\"class_name\":\"wavefunc\",\"sub\":[{\"name\":\"evc\",\"cpu_second\":"));
9797
EXPECT_THAT(content,testing::HasSubstr("\"calls\":2,\"cpu_second_per_call\":"));
@@ -106,25 +106,29 @@ TEST_F(TimerTest, PrintAll)
106106
ModuleBase::timer::tick("wavefunc","evc");
107107
std::this_thread::sleep_for(std::chrono::microseconds(T_Elapse)); // 0.1 ms
108108
ModuleBase::timer::tick("wavefunc","evc");
109+
109110
// call print_all
110111
ofs.open("tmp");
111112
testing::internal::CaptureStdout();
112113
ModuleBase::timer::print_all(ofs);
113114
output = testing::internal::GetCapturedStdout();
114115
ofs.close();
116+
115117
// checout output on screen
116-
std::cout << "Get captured stdout: \n" << std::endl;
117-
std::cout << output << std::endl;
118+
// std::cout << "Get captured stdout: \n" << std::endl;
119+
// std::cout << output << std::endl;
118120
EXPECT_THAT(output,testing::HasSubstr("TIME STATISTICS"));
119121
EXPECT_THAT(output,testing::HasSubstr("CLASS_NAME"));
120122
EXPECT_THAT(output,testing::HasSubstr("NAME"));
121123
EXPECT_THAT(output,testing::HasSubstr("TIME/s"));
122124
EXPECT_THAT(output,testing::HasSubstr("CALLS"));
123125
EXPECT_THAT(output,testing::HasSubstr("AVG/s"));
124126
EXPECT_THAT(output,testing::HasSubstr("PER/%"));
127+
125128
// check output in file
126129
ifs.open("tmp");
127-
std::cout << "Capture contents line by line from output file: \n" << std::endl;
130+
// std::cout << "Capture contents line by line from output file: \n" << std::endl;
131+
getline(ifs,output);
128132
getline(ifs,output);
129133
EXPECT_THAT(output,testing::HasSubstr("TIME STATISTICS"));
130134
getline(ifs,output);
@@ -139,36 +143,41 @@ TEST_F(TimerTest, PrintAll)
139143
remove("time.json");
140144
}
141145

146+
142147
TEST_F(TimerTest, PrintUntilNow)
143148
{
144149
long double time = ModuleBase::timer::print_until_now();
145150
EXPECT_TRUE(time>0.0);
146151
}
147152

153+
148154
TEST_F(TimerTest, Finish)
149155
{
150156
ModuleBase::timer::tick("wavefunc","evc");
151157
std::this_thread::sleep_for(std::chrono::microseconds(T_Elapse)); // 0.1 ms
152158
ModuleBase::timer::tick("wavefunc","evc");
159+
153160
// call print_all
154161
ofs.open("tmp");
155162
testing::internal::CaptureStdout();
156163
ModuleBase::timer::finish(ofs);
157164
output = testing::internal::GetCapturedStdout();
158165
ofs.close();
159166
// checout output on screen
160-
std::cout << "Get captured stdout: \n" << std::endl;
161-
std::cout << output << std::endl;
167+
//std::cout << "Get captured stdout: \n" << std::endl;
168+
//std::cout << output << std::endl;
162169
EXPECT_THAT(output,testing::HasSubstr("TIME STATISTICS"));
163170
EXPECT_THAT(output,testing::HasSubstr("CLASS_NAME"));
164171
EXPECT_THAT(output,testing::HasSubstr("NAME"));
165172
EXPECT_THAT(output,testing::HasSubstr("TIME/s"));
166173
EXPECT_THAT(output,testing::HasSubstr("CALLS"));
167174
EXPECT_THAT(output,testing::HasSubstr("AVG/s"));
168175
EXPECT_THAT(output,testing::HasSubstr("PER/%"));
176+
169177
// check output in file
170178
ifs.open("tmp");
171-
std::cout << "Capture contents line by line from output file: \n" << std::endl;
179+
//std::cout << "Capture contents line by line from output file: \n" << std::endl;
180+
getline(ifs,output);
172181
getline(ifs,output);
173182
EXPECT_THAT(output,testing::HasSubstr("TIME STATISTICS"));
174183
getline(ifs,output);
@@ -182,7 +191,6 @@ TEST_F(TimerTest, Finish)
182191
ifs.close();
183192
}
184193

185-
// use __MPI to activate parallel environment
186194
#ifdef __MPI
187195
int main(int argc, char **argv)
188196
{

source/module_base/test/tool_quit_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ TEST_F(ToolQuitTest,warningquit)
9393
ifs.open("running.log");
9494
getline(ifs,output);
9595
// test output in running.log file
96-
EXPECT_THAT(output,testing::HasSubstr("!!!!!!!"));
96+
EXPECT_THAT(output,testing::HasSubstr("-------"));
9797
ifs.close();
9898
}
9999

@@ -116,7 +116,7 @@ TEST_F(ToolQuitTest,warningquit_with_ret)
116116
ifs.open("running.log");
117117
getline(ifs,output);
118118
// test output in running.log file
119-
EXPECT_THAT(output,testing::HasSubstr("!!!!!!!"));
119+
EXPECT_THAT(output,testing::HasSubstr("-------"));
120120
ifs.close();
121121
}
122122
// use __MPI to activate parallel environment

source/module_base/timer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ void timer::print_all(std::ofstream &ofs)
306306
/*indent=*/0,
307307
/*align=*/{/*value*/FmtTable::Align::LEFT, /*title*/FmtTable::Align::CENTER});
308308
time_statistics << class_names << names << times << calls << avgs << pers;
309-
const std::string table = "TIME STATISTICS\n" + time_statistics.str();
309+
const std::string table = "\nTIME STATISTICS\n" + time_statistics.str();
310310
std::cout<<table<<std::endl;
311311
ofs<<table<<std::endl;
312312
write_to_json("time.json");

source/module_base/tool_quit.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -68,34 +68,34 @@ void WARNING_QUIT(const std::string &file,const std::string &description,int ret
6868
{
6969
#ifdef __NORMAL
7070

71-
std::cout << " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
72-
std::cout << " NOTICE " << std::endl;
73-
std::cout << " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
71+
std::cout << " ---------------------------------------------------------" << std::endl;
72+
std::cout << " !NOTICE! " << std::endl;
73+
std::cout << " ---------------------------------------------------------" << std::endl;
7474

7575
#else
7676
std::cout << " " << std::endl;
77-
std::cout << " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
78-
std::cout << " NOTICE " << std::endl;
79-
std::cout << " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
77+
std::cout << " ---------------------------------------------------------" << std::endl;
78+
std::cout << " !NOTICE! " << std::endl;
79+
std::cout << " ---------------------------------------------------------" << std::endl;
8080
std::cout << " " << std::endl;
8181
std::cout << " " << description << std::endl;
8282
std::cout << " CHECK IN FILE : " << PARAM.globalv.global_out_dir << "warning.log" << std::endl;
8383
std::cout << " " << std::endl;
84-
std::cout << " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
85-
std::cout << " NOTICE " << std::endl;
86-
std::cout << " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
84+
std::cout << " ---------------------------------------------------------" << std::endl;
85+
std::cout << " !NOTICE! " << std::endl;
86+
std::cout << " ---------------------------------------------------------" << std::endl;
8787

8888

89-
GlobalV::ofs_running << " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
90-
GlobalV::ofs_running << " NOTICE " << std::endl;
91-
GlobalV::ofs_running << " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
89+
GlobalV::ofs_running << " ---------------------------------------------------------" << std::endl;
90+
GlobalV::ofs_running << " !NOTICE! " << std::endl;
91+
GlobalV::ofs_running << " ---------------------------------------------------------" << std::endl;
9292
GlobalV::ofs_running << std::endl;
9393
GlobalV::ofs_running << " " << description << std::endl;
9494
GlobalV::ofs_running << " CHECK IN FILE : " << PARAM.globalv.global_out_dir << "warning.log" << std::endl;
9595
GlobalV::ofs_running << std::endl;
96-
GlobalV::ofs_running << " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
96+
GlobalV::ofs_running << " ---------------------------------------------------------" << std::endl;
9797
GlobalV::ofs_running << " NOTICE " << std::endl;
98-
GlobalV::ofs_running << " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
98+
GlobalV::ofs_running << " ---------------------------------------------------------" << std::endl;
9999

100100
WARNING(file,description);
101101
GlobalV::ofs_running<<" Check in file : "<<PARAM.globalv.global_out_dir<<"warning.log"<<std::endl;
@@ -128,10 +128,10 @@ void CHECK_WARNING_QUIT(const bool error_in, const std::string &file,const std::
128128
}
129129

130130
//print error information
131-
std::cout << " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
131+
std::cout << " ---------------------------------------------------------" << std::endl;
132132
std::cout << " ERROR! " << description << std::endl;
133133
std::cout << " CHECK IN FILE : " << PARAM.globalv.global_out_dir << "warning.log" << std::endl;
134-
std::cout << " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
134+
std::cout << " ---------------------------------------------------------" << std::endl;
135135
GlobalV::ofs_running << " ERROR! CHECK IN FILE : " << PARAM.globalv.global_out_dir << "warning.log" << std::endl;
136136
GlobalV::ofs_warning << std::endl;
137137
GlobalV::ofs_warning << " ERROR! " << file << ", core " << GlobalV::MY_RANK+1 << ": " << description << std::endl;

source/module_cell/unitcell.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,6 @@ void UnitCell::setup_cell(const std::string& fn, std::ofstream& log)
301301
assert(lat0 > 0.0);
302302
this->omega = latvec.Det() * this->lat0 * this->lat0 * this->lat0;
303303

304-
std::cout << "latvec.det=" << latvec.Det() << std::endl;
305-
std::cout << "lat0=" << lat0 << std::endl;
306-
307304

308305
if (this->omega < 0)
309306
{

source/module_elecstate/fp_energy.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
#ifndef FP_ENERGY_H
2+
#define FP_ENERGY_H
3+
14
#include <vector>
25

36
/**
47
* @file fp_energy.h
58
* @brief This file contains all energies about first-principle calculations
69
*/
7-
#ifndef FP_ENERGY_H
8-
#define FP_ENERGY_H
910
namespace elecstate
1011
{
1112
/**
@@ -63,11 +64,11 @@ struct efermi
6364
double ef = 0.0; ///< Fermi energy
6465
double ef_up = 0.0; ///< spin up Fermi energy
6566
double ef_dw = 0.0; ///< spin down Fermi energy
66-
bool two_efermi = false; ///<
67+
bool two_efermi = false;
6768
void set_efval(const int& is, const double& ef_in);
6869
double get_efval(const int& is) const;
6970
std::vector<double> get_all_ef() const;
7071
};
7172

7273
} // namespace elecstate
73-
#endif
74+
#endif

source/module_elecstate/module_charge/charge_init.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ void Charge::init_rho(elecstate::efermi& eferm_iout,
7373
{
7474
if (is == 1) // failed at the second spin
7575
{
76-
std::cout << "Incomplete electron density file!" << std::endl;
76+
std::cout << " Incomplete electron density file." << std::endl;
7777
read_error = true;
7878
break;
7979
}
@@ -105,15 +105,15 @@ void Charge::init_rho(elecstate::efermi& eferm_iout,
105105
if (read_error)
106106
{
107107
const std::string warn_msg
108-
= " WARNING: \"init_chg\" is enabled but ABACUS failed to read charge density from file.\n"
109-
" Please check if there is SPINX_CHG.cube (X=1,...) or {suffix}-CHARGE-DENSITY.restart in the "
108+
= " WARNING: \"init_chg\" is enabled but ABACUS failed to read\n charge density from file.\n"
109+
" Please check if there is SPINX_CHG.cube (X=1,...) or\n {suffix}-CHARGE-DENSITY.restart in the "
110110
"directory.\n";
111-
std::cout << std::endl << warn_msg;
111+
std::cout << warn_msg;
112112
if (PARAM.inp.init_chg == "file")
113113
{
114114
ModuleBase::WARNING_QUIT("Charge::init_rho",
115-
"Failed to read in charge density from file.\nIf you want to use atomic "
116-
"charge initialization, \nplease set init_chg to atomic in INPUT.");
115+
"Failed to read in charge density from file.\n For initializing atomic "
116+
"charge in calculations,\n please set init_chg to atomic in INPUT.");
117117
}
118118
}
119119

source/module_esolver/esolver_ks.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ void ESolver_KS<T, Device>::after_all_runners(UnitCell& ucell)
733733
// 1) write information
734734
if (PARAM.inp.out_dos != 0 || PARAM.inp.out_band[0] != 0 || PARAM.inp.out_proj_band != 0)
735735
{
736-
GlobalV::ofs_running << "\n\n\n\n";
736+
GlobalV::ofs_running << "\n\n";
737737
GlobalV::ofs_running << " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
738738
">>>>>>>>>>>>>>>>>>>>>>>>>"
739739
<< std::endl;
@@ -761,17 +761,17 @@ void ESolver_KS<T, Device>::after_all_runners(UnitCell& ucell)
761761
GlobalV::ofs_running << " <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
762762
"<<<<<<<<<<<<<<<<<<<<<<<<<"
763763
<< std::endl;
764-
GlobalV::ofs_running << "\n\n\n\n";
764+
GlobalV::ofs_running << "\n\n";
765765
}
766766

767767
// 2) write information
768768
ModuleIO::write_istate_info(this->pelec->ekb, this->pelec->wg, this->kv);
769769

770-
const int nspin0 = (PARAM.inp.nspin == 2) ? 2 : 1;
771770

772771
// 3) print out band information
773772
if (PARAM.inp.out_band[0])
774773
{
774+
const int nspin0 = (PARAM.inp.nspin == 2) ? 2 : 1;
775775
for (int is = 0; is < nspin0; is++)
776776
{
777777
std::stringstream ss2;

source/module_esolver/esolver_ks_pw.cpp

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -827,29 +827,18 @@ void ESolver_KS_PW<T, Device>::after_all_runners(UnitCell& ucell)
827827
{
828828
ESolver_KS<T, Device>::after_all_runners(ucell);
829829

830-
const int nspin0 = (PARAM.inp.nspin == 2) ? 2 : 1;
831-
832-
//! 3) Compute density of states (DOS)
830+
//! 1) Compute density of states (DOS)
833831
if (PARAM.inp.out_dos)
834832
{
835833
ModuleIO::write_dos_pw(this->pelec->ekb,
836834
this->pelec->wg,
837835
this->kv,
836+
PARAM.inp.nbands,
837+
this->pelec->eferm,
838838
PARAM.inp.dos_edelta_ev,
839839
PARAM.inp.dos_scale,
840-
PARAM.inp.dos_sigma);
841-
842-
if (nspin0 == 1)
843-
{
844-
GlobalV::ofs_running << " Fermi energy is " << this->pelec->eferm.ef << " Rydberg" << std::endl;
845-
}
846-
else if (nspin0 == 2)
847-
{
848-
GlobalV::ofs_running << " Fermi energy (spin = 1) is " << this->pelec->eferm.ef_up << " Rydberg"
849-
<< std::endl;
850-
GlobalV::ofs_running << " Fermi energy (spin = 2) is " << this->pelec->eferm.ef_dw << " Rydberg"
851-
<< std::endl;
852-
}
840+
PARAM.inp.dos_sigma,
841+
GlobalV::ofs_running);
853842
}
854843

855844
// out ldos
@@ -862,7 +851,7 @@ void ESolver_KS_PW<T, Device>::after_all_runners(UnitCell& ucell)
862851
ucell);
863852
}
864853

865-
//! 5) Calculate the spillage value, used to generate numerical atomic orbitals
854+
//! 3) Calculate the spillage value, used to generate numerical atomic orbitals
866855
if (PARAM.inp.basis_type == "pw" && winput::out_spillage)
867856
{
868857
// ! Print out overlap matrices
@@ -882,13 +871,13 @@ void ESolver_KS_PW<T, Device>::after_all_runners(UnitCell& ucell)
882871
}
883872
}
884873

885-
//! 6) Print out electronic wave functions in real space
874+
//! 4) Print out electronic wave functions in real space
886875
if (PARAM.inp.out_wfc_r == 1) // Peize Lin add 2021.11.21
887876
{
888877
ModuleIO::write_psi_r_1(ucell, this->psi[0], this->pw_wfc, "wfc_realspace", true, this->kv);
889878
}
890879

891-
//! 7) Use Kubo-Greenwood method to compute conductivities
880+
//! 5) Use Kubo-Greenwood method to compute conductivities
892881
if (PARAM.inp.cal_cond)
893882
{
894883
EleCond<Real, Device> elec_cond(&ucell, &this->kv, this->pelec, this->pw_wfc, this->kspw_psi, &this->ppcell);
@@ -902,7 +891,7 @@ void ESolver_KS_PW<T, Device>::after_all_runners(UnitCell& ucell)
902891
}
903892

904893
#ifdef __MLKEDF
905-
// generate training data for ML-KEDF
894+
//! 6) generate training data for ML-KEDF
906895
if (PARAM.inp.of_ml_gene_data == 1)
907896
{
908897
this->pelec->pot->update_from_charge(&this->chr, &ucell);

0 commit comments

Comments
 (0)