Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 1 addition & 4 deletions interfaces/ASE_interface/abacuslite/io/latestio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down
5 changes: 4 additions & 1 deletion source/source_io/module_energy/write_eig_occ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
15 changes: 12 additions & 3 deletions source/source_io/test/write_eig_occ_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");
}

Expand Down
Loading