diff --git a/interfaces/ASE_interface/abacuslite/io/latestio.py b/interfaces/ASE_interface/abacuslite/io/latestio.py index fbd6cc8bb3..2b5e4ac39a 100644 --- a/interfaces/ASE_interface/abacuslite/io/latestio.py +++ b/interfaces/ASE_interface/abacuslite/io/latestio.py @@ -443,9 +443,6 @@ def read_abacus_out(fileobj, # read the eigenvalues (nframe, nk, nbnd) elecstate = read_band_from_eig_occ(fileobj.parent / 'eig_occ.txt') - # FIXME: remove thw following line till the eig_occ.txt is not written - # in the append mode - (fileobj.parent / 'eig_occ.txt').unlink() # read the atomic forces (nframe, nat, 3) forces = read_forces_from_running_log(abacus_lines) @@ -701,7 +698,7 @@ def test_read_pw_symm0_nspin4_gamma_md(self): # remove the files (self.testfiles / 'running_md.log').unlink() - # (self.testfiles / 'eig_occ.txt').unlink() + (self.testfiles / 'eig_occ.txt').unlink() (self.testfiles / 'MD_dump').unlink() def test_read_iter_header_from_running_log(self): diff --git a/source/source_io/module_energy/write_eig_occ.cpp b/source/source_io/module_energy/write_eig_occ.cpp index e589a66524..ff5d9ea4cd 100644 --- a/source/source_io/module_energy/write_eig_occ.cpp +++ b/source/source_io/module_energy/write_eig_occ.cpp @@ -212,8 +212,11 @@ void ModuleIO::write_eig_file(const ModuleBase::matrix &ekb, if (GlobalV::MY_RANK == 0) { std::ofstream ofs_eig0; + const auto& inp = PARAM.inp; + const bool append = istep > 0 + || (inp.calculation == "md" && inp.mdp.md_restart); - if(PARAM.inp.out_app_flag==true) + if (append) { ofs_eig0.open(filename.c_str(), std::ios::app); } diff --git a/source/source_io/test/write_eig_occ_test.cpp b/source/source_io/test/write_eig_occ_test.cpp index b7139ba093..e758601a87 100644 --- a/source/source_io/test/write_eig_occ_test.cpp +++ b/source/source_io/test/write_eig_occ_test.cpp @@ -97,9 +97,14 @@ TEST_F(IstateInfoTest, OutIstateInfoS1) ++i; } - // write eigenvalues and occupations - const int istep_in = -1; - ModuleIO::write_eig_file(ekb, wg, *kv, istep_in); + { + std::ofstream stale_file("eig_occ.txt"); + stale_file << "stale calculation" << std::endl; + } + + // A new calculation truncates stale output, then later ionic steps append. + ModuleIO::write_eig_file(ekb, wg, *kv, 0); + ModuleIO::write_eig_file(ekb, wg, *kv, 1); // check the output files std::ifstream ifs; @@ -108,7 +113,11 @@ TEST_F(IstateInfoTest, OutIstateInfoS1) 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")); + EXPECT_THAT(str, testing::Not(testing::HasSubstr("stale calculation"))); + EXPECT_THAT(str, testing::HasSubstr("1 # ionic step")); + EXPECT_THAT(str, testing::HasSubstr("2 # ionic step")); ifs.close(); + remove("eig_occ.txt"); }