Skip to content

Commit e71af25

Browse files
authored
Fix eig_occ.txt lifecycle (#7771)
* fix eig occ txt write mode * update test * update to make check pass
1 parent df5567a commit e71af25

3 files changed

Lines changed: 17 additions & 8 deletions

File tree

interfaces/ASE_interface/abacuslite/io/latestio.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -443,9 +443,6 @@ def read_abacus_out(fileobj,
443443

444444
# read the eigenvalues (nframe, nk, nbnd)
445445
elecstate = read_band_from_eig_occ(fileobj.parent / 'eig_occ.txt')
446-
# FIXME: remove thw following line till the eig_occ.txt is not written
447-
# in the append mode
448-
(fileobj.parent / 'eig_occ.txt').unlink()
449446

450447
# read the atomic forces (nframe, nat, 3)
451448
forces = read_forces_from_running_log(abacus_lines)
@@ -701,7 +698,7 @@ def test_read_pw_symm0_nspin4_gamma_md(self):
701698

702699
# remove the files
703700
(self.testfiles / 'running_md.log').unlink()
704-
# (self.testfiles / 'eig_occ.txt').unlink()
701+
(self.testfiles / 'eig_occ.txt').unlink()
705702
(self.testfiles / 'MD_dump').unlink()
706703

707704
def test_read_iter_header_from_running_log(self):

source/source_io/module_energy/write_eig_occ.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,11 @@ void ModuleIO::write_eig_file(const ModuleBase::matrix &ekb,
212212
if (GlobalV::MY_RANK == 0)
213213
{
214214
std::ofstream ofs_eig0;
215+
const auto& inp = PARAM.inp;
216+
const bool append = istep > 0
217+
|| (inp.calculation == "md" && inp.mdp.md_restart);
215218

216-
if(PARAM.inp.out_app_flag==true)
219+
if (append)
217220
{
218221
ofs_eig0.open(filename.c_str(), std::ios::app);
219222
}

source/source_io/test/write_eig_occ_test.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,14 @@ TEST_F(IstateInfoTest, OutIstateInfoS1)
9797
++i;
9898
}
9999

100-
// write eigenvalues and occupations
101-
const int istep_in = -1;
102-
ModuleIO::write_eig_file(ekb, wg, *kv, istep_in);
100+
{
101+
std::ofstream stale_file("eig_occ.txt");
102+
stale_file << "stale calculation" << std::endl;
103+
}
104+
105+
// A new calculation truncates stale output, then later ionic steps append.
106+
ModuleIO::write_eig_file(ekb, wg, *kv, 0);
107+
ModuleIO::write_eig_file(ekb, wg, *kv, 1);
103108

104109
// check the output files
105110
std::ifstream ifs;
@@ -108,7 +113,11 @@ TEST_F(IstateInfoTest, OutIstateInfoS1)
108113
EXPECT_THAT(str, testing::HasSubstr("Electronic state energy (eV) and occupations"));
109114
EXPECT_THAT(str, testing::HasSubstr("spin=1 k-point=1/10 Cartesian=0.0000000 0.0000000 0.0000000 (299 plane wave)"));
110115
EXPECT_THAT(str, testing::HasSubstr("1 2.040854700000000 0.000000000000000"));
116+
EXPECT_THAT(str, testing::Not(testing::HasSubstr("stale calculation")));
117+
EXPECT_THAT(str, testing::HasSubstr("1 # ionic step"));
118+
EXPECT_THAT(str, testing::HasSubstr("2 # ionic step"));
111119
ifs.close();
120+
112121
remove("eig_occ.txt");
113122
}
114123

0 commit comments

Comments
 (0)