Skip to content
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
e79c1d0
update some timers
mohanchen Mar 25, 2025
3a8b520
update timer
mohanchen Mar 25, 2025
aabb29a
update output formats
mohanchen Mar 25, 2025
931f4ac
update print_cell
mohanchen Mar 26, 2025
71e5556
add ofs in print_tau
mohanchen Mar 26, 2025
4353a55
update print_tau
mohanchen Mar 26, 2025
959fe8b
update output formats
mohanchen Mar 26, 2025
9a8552d
update md outputs
mohanchen Mar 26, 2025
cc35adf
Merge branch 'deepmodeling:develop' into develop
mohanchen Mar 26, 2025
357d43e
Merge branch 'develop' of https://github.com/mohanchen/abacus-mc into…
mohanchen Mar 26, 2025
eb0a302
beging modifying the autotests
mohanchen Mar 27, 2025
258245d
update previous commits
mohanchen Mar 27, 2025
2fc86bb
update integrate tests
mohanchen Mar 27, 2025
5840f50
update some timers
mohanchen Mar 27, 2025
0189b6c
fix total force and total stress
mohanchen Mar 27, 2025
34bcd1a
update integrate tests
mohanchen Mar 27, 2025
9deffae
update print_band
mohanchen Mar 27, 2025
8718960
fix print_band
mohanchen Mar 27, 2025
05e9cc7
update md print out information
mohanchen Mar 27, 2025
abc61a0
update print_stress
mohanchen Mar 27, 2025
bda0769
update print_stress in dp, but still has problems in lj
mohanchen Mar 27, 2025
c4b4b19
fix dp_test.cpp
mohanchen Mar 27, 2025
1060d4a
update esolver_lj
mohanchen Mar 28, 2025
3f77545
Merge branch 'develop' of https://github.com/mohanchen/abacus-mc into…
mohanchen Mar 28, 2025
34c8748
merge new codes
mohanchen Mar 28, 2025
b0d2d0a
set mulliken charge accuracy from 4 to 3
mohanchen Mar 29, 2025
3956c6f
update print force and print stress
mohanchen Mar 30, 2025
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
34 changes: 17 additions & 17 deletions source/driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,27 @@ Driver::~Driver()

void Driver::init()
{
ModuleBase::TITLE("Driver", "init");
// 1) Let's start by printing a title.
ModuleBase::TITLE("Driver", "ABACUS_begins");

// 2) Print the current time, since it may run a long time.
time_t time_start = std::time(nullptr);
ModuleBase::timer::start();

// (1) read the input parameters.
// INPUT should be initalized here and then pass to atomic world, mohan
// 2024-05-12 INPUT should not be GlobalC, mohan 2024-05-12
Driver::reading();

// (2) welcome to the atomic world!
// 3) Welcome to the atomic world! Let's do some fancy stuff here.
this->atomic_world();

// (3) output information
// 4) All timers recorders are printed.
ModuleBase::timer::finish(GlobalV::ofs_running);

// 5) All memory recorders are printed.
ModuleBase::Memory::print_all(GlobalV::ofs_running);

// 6) Print the final time, hopefully it will not cost too long.
time_t time_finish = std::time(nullptr);
ModuleIO::print_time(time_start, time_finish);

// (4) close all of the running logs
// 7) Clean up: close all of the running logs
ModuleBase::Global_File::close_all_log(GlobalV::MY_RANK, PARAM.inp.out_alllog,PARAM.inp.calculation);

}
Expand Down Expand Up @@ -169,16 +172,13 @@ void Driver::reading()
void Driver::atomic_world()
{
ModuleBase::TITLE("Driver", "atomic_world");
//--------------------------------------------------
// choose basis sets:
// pw: plane wave basis set
// lcao_in_pw: LCAO expaned by plane wave basis set
// lcao: linear combination of atomic orbitals
//--------------------------------------------------
ModuleBase::timer::tick("Driver", "atomic_world");

// reading information
this->reading();

// where the actual stuff is done
this->driver_run();

ModuleBase::timer::finish(GlobalV::ofs_running);
ModuleBase::Memory::print_all(GlobalV::ofs_running);
ModuleBase::timer::tick("Driver", "atomic_world");
}
4 changes: 3 additions & 1 deletion source/driver_run.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@
*/
void Driver::driver_run()
{
ModuleBase::TITLE("Driver", "driver_line");
ModuleBase::TITLE("Driver", "driver_run");

//! 1: setup cell and atom information
// this warning should not be here, mohan 2024-05-22
#ifndef __LCAO
if (PARAM.inp.basis_type == "lcao_in_pw" || PARAM.inp.basis_type == "lcao") {
ModuleBase::timer::tick("Driver","driver_run");
ModuleBase::WARNING_QUIT("driver",
"to use LCAO basis, compile with __LCAO");
}
Expand Down Expand Up @@ -92,5 +93,6 @@ void Driver::driver_run()

//! 6: output the json file
Json::create_Json(&ucell, PARAM);

return;
}
7 changes: 4 additions & 3 deletions source/module_base/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,9 @@ void Memory::print_all(std::ofstream &ofs)
Parallel_Reduce::reduce_all(Memory::total_gpu);
#endif
#endif
ofs <<"\n NAME-------------------------|MEMORY(MB)--------" << std::endl;
ofs <<std::setw(30)<< "total" << std::setw(15) <<std::setprecision(4)<< Memory::total << std::endl;
ofs <<"\n NAME-------------------------|MEMORY(MB)------------------" << std::endl;
ofs << std::right;
ofs << std::setw(30)<< "total" << std::setw(15) <<std::setprecision(4)<< Memory::total << std::endl;

assert(n_memory>0);

Expand Down Expand Up @@ -440,7 +441,7 @@ void Memory::print_all(std::ofstream &ofs)
return;
}

ofs <<"\n NAME-------------------------|GPU MEMORY(MB)----" << std::endl;
ofs <<"\n NAME-------------------------|GPU MEMORY(MB)--------------" << std::endl;
ofs <<std::setw(30)<< "total" << std::setw(15) <<std::setprecision(4)<< Memory::total_gpu << std::endl;

assert(n_memory>0);
Expand Down
5 changes: 3 additions & 2 deletions source/module_cell/module_neighbor/sltk_atom_arrange.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ void atom_arrange::search(const bool pbc_flag,
ModuleBase::WARNING_QUIT("atom_arrange::search", " search_radius_bohr < 0,forbidden");
}

ModuleBase::GlobalFunc::OUT(ofs_in, "searching radius is (Bohr))", search_radius_bohr);
ModuleBase::GlobalFunc::OUT(ofs_in, "searching radius unit is (Bohr))", ucell.lat0);
ofs_in << " SEARCH ADJACENT ATOMS" << std::endl;
ModuleBase::GlobalFunc::OUT(ofs_in, "searching radius is (Bohr)", search_radius_bohr);
ModuleBase::GlobalFunc::OUT(ofs_in, "searching radius unit is (Bohr)", ucell.lat0);

assert(ucell.nat > 0);

Expand Down
9 changes: 5 additions & 4 deletions source/module_cell/module_neighbor/sltk_grid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,10 @@ void Grid::setMemberVariables(std::ofstream& ofs_in, // output data to ofs
}
}
}
ModuleBase::GlobalFunc::OUT(ofs_in, "Find the coordinate range of the input atom(unit:lat0).");
ModuleBase::GlobalFunc::OUT(ofs_in, "min_tau", x_min, y_min, z_min);
ModuleBase::GlobalFunc::OUT(ofs_in, "max_tau", x_max, y_max, z_max);

ofs_in << " RANGE OF ATOMIC COORDINATES (unit: lat0)" << std::endl;
ModuleBase::GlobalFunc::OUT(ofs_in, "smallest coordinates of atoms", x_min, y_min, z_min);
ModuleBase::GlobalFunc::OUT(ofs_in, "largest coordinates of atoms", x_max, y_max, z_max);

this->box_edge_length = sradius + 0.1; // To avoid edge cases, the size of the box is slightly increased.

Expand All @@ -220,7 +221,7 @@ void Grid::setMemberVariables(std::ofstream& ofs_in, // output data to ofs
this->box_nx = glayerX + glayerX_minus;
this->box_ny = glayerY + glayerY_minus;
this->box_nz = glayerZ + glayerZ_minus;
ModuleBase::GlobalFunc::OUT(ofs_in, "BoxNumber", box_nx, box_ny, box_nz);
ModuleBase::GlobalFunc::OUT(ofs_in, "number of needed cells", box_nx, box_ny, box_nz);

atoms_in_box.resize(this->box_nx);
for (int i = 0; i < this->box_nx; i++)
Expand Down
7 changes: 4 additions & 3 deletions source/module_cell/print_cell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ namespace unitcell
void print_tau(Atom* atoms,
const std::string& Coordinate,
const int ntype,
const double lat0)
const double lat0,
std::ofstream &ofs)
{
ModuleBase::TITLE("UnitCell", "print_tau");
// assert (direct || Coordinate == "Cartesian" || Coordinate == "Cartesian_angstrom"); // this line causes abort in unittest ReadAtomPositionsCACXY.
Expand All @@ -22,7 +23,7 @@ namespace unitcell
assert(std::regex_search(Coordinate, pattern));
bool direct = (Coordinate == "Direct");
std::string table;
table += direct? "DIRECT COORDINATES\n": FmtCore::format("CARTESIAN COORDINATES ( UNIT = %20.12f Bohr ).\n", lat0);
table += direct? "DIRECT COORDINATES\n": FmtCore::format(" CARTESIAN COORDINATES ( UNIT = %15.8f Bohr ).\n", lat0);
table += FmtCore::format("%8s%10s%10s%10s%8s%8s%8s%8s\n", "atom", "x", "y", "z", "mag", "vx", "vy", "vz");
for(int it = 0; it < ntype; it++)
{
Expand All @@ -43,7 +44,7 @@ namespace unitcell
}
}
table += "\n";
GlobalV::ofs_running << table << std::endl;
ofs << table << std::endl;
return;
}

Expand Down
5 changes: 3 additions & 2 deletions source/module_cell/print_cell.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ namespace unitcell
void print_tau(Atom* atoms,
const std::string& Coordinate,
const int ntype,
const double lat0);
const double lat0,
std::ofstream &ofs);

/**
* @brief UnitCell class is too heavy, this function would be moved
Expand Down Expand Up @@ -40,4 +41,4 @@ namespace unitcell
const int& iproc = 0);
}

#endif
#endif
9 changes: 6 additions & 3 deletions source/module_cell/read_atoms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,9 @@ bool read_atom_positions(UnitCell& ucell,
ucell.atoms[it].m_loc_[ia].x = 1.0;
ucell.atoms[it].m_loc_[ia].y = 1.0;
ucell.atoms[it].m_loc_[ia].z = 1.0;
ucell.atoms[it].mag[ia] = sqrt(pow(ucell.atoms[it].m_loc_[ia].x,2)+pow(ucell.atoms[it].m_loc_[ia].y,2)+pow(ucell.atoms[it].m_loc_[ia].z,2));
ucell.atoms[it].mag[ia] = sqrt(pow(ucell.atoms[it].m_loc_[ia].x,2)
+pow(ucell.atoms[it].m_loc_[ia].y,2)
+pow(ucell.atoms[it].m_loc_[ia].z,2));
ModuleBase::GlobalFunc::OUT(ofs_running,"Autoset magnetism for this atom", 1.0, 1.0, 1.0);
}
}
Expand All @@ -535,13 +537,14 @@ bool read_atom_positions(UnitCell& ucell,
// End Autoset magnetization
} // end scan_begin

//check if any atom can move in MD
//check if any atom can move in MD
if(!ucell.if_atoms_can_move() && PARAM.inp.calculation=="md" && PARAM.inp.esolver_type!="tddft")
{
ModuleBase::WARNING("read_atoms", "no atom can move in MD!");
return false;
}


ofs_running << std::endl;
ModuleBase::GlobalFunc::OUT(ofs_running,"TOTAL ATOM NUMBER",ucell.nat);

Expand All @@ -556,7 +559,7 @@ bool read_atom_positions(UnitCell& ucell,

if (unitcell::check_tau(ucell.atoms, ucell.ntype, ucell.lat0))
{
unitcell::print_tau(ucell.atoms,ucell.Coordinate,ucell.ntype,ucell.lat0);
unitcell::print_tau(ucell.atoms,ucell.Coordinate,ucell.ntype,ucell.lat0,ofs_running);
return true;
}
return false;
Expand Down
24 changes: 18 additions & 6 deletions source/module_cell/test/unitcell_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1010,17 +1010,23 @@ TEST_F(UcellTest, PrintTauDirect)
UcellTestPrepare utp = UcellTestLib["C1H2-Index"];
PARAM.input.relax_new = utp.relax_new;
ucell = utp.SetUcellInfo();
GlobalV::ofs_running.open("print_tau_direct");
EXPECT_EQ(ucell->Coordinate, "Direct");
unitcell::print_tau(ucell->atoms,ucell->Coordinate,ucell->ntype,ucell->lat0);
GlobalV::ofs_running.close();

// open a file
std::ofstream ofs("print_tau_direct");
unitcell::print_tau(ucell->atoms,ucell->Coordinate,ucell->ntype,ucell->lat0,ofs);
ofs.close();

// readin the data
std::ifstream ifs;
ifs.open("print_tau_direct");
std::string str((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
EXPECT_THAT(str, testing::HasSubstr("DIRECT COORDINATES"));
EXPECT_THAT(str, testing::HasSubstr(" C 0.100 0.100 0.100 0.000 0.100 0.100 0.100"));
EXPECT_THAT(str, testing::HasSubstr(" H 0.150 0.150 0.150 0.000 0.100 0.100 0.100"));
ifs.close();

// remove the file
remove("print_tau_direct");
}

Expand All @@ -1029,17 +1035,23 @@ TEST_F(UcellTest, PrintTauCartesian)
UcellTestPrepare utp = UcellTestLib["C1H2-Cartesian"];
PARAM.input.relax_new = utp.relax_new;
ucell = utp.SetUcellInfo();
GlobalV::ofs_running.open("print_tau_Cartesian");
EXPECT_EQ(ucell->Coordinate, "Cartesian");
unitcell::print_tau(ucell->atoms,ucell->Coordinate,ucell->ntype,ucell->lat0);
GlobalV::ofs_running.close();

// open a file
std::ofstream ofs("print_tau_Cartesian");
unitcell::print_tau(ucell->atoms,ucell->Coordinate,ucell->ntype,ucell->lat0,ofs);
ofs.close();

// readin the data
std::ifstream ifs;
ifs.open("print_tau_Cartesian");
std::string str((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
EXPECT_THAT(str, testing::HasSubstr("CARTESIAN COORDINATES"));
EXPECT_THAT(str, testing::HasSubstr(" C 1.000 1.000 1.000 0.000 0.000 0.000 0.000"));
EXPECT_THAT(str, testing::HasSubstr(" H 1.500 1.500 1.500 0.000 0.000 0.000 0.000"));
ifs.close();

// remove the file
remove("print_tau_Cartesian");
}

Expand Down
38 changes: 26 additions & 12 deletions source/module_elecstate/elecstate_print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,13 +250,16 @@ void print_band(const ModuleBase::matrix& ekb,
const K_Vectors* klist,
const int& ik,
const int& printe,
const int& iter)
const int& iter,
std::ofstream &ofs)
{
const double largest_eig = 1.0e10;

// check the band energy.
bool wrong = false;
for (int ib = 0; ib < PARAM.globalv.nbands_l; ++ib)
{
if (std::abs(ekb(ik, ib)) > 1.0e10)
if (std::abs(ekb(ik, ib)) > largest_eig)
{
GlobalV::ofs_warning << " ik=" << ik + 1 << " ib=" << ib + 1 << " " << ekb(ik, ib) << " Ry" << std::endl;
wrong = true;
Expand All @@ -271,18 +274,18 @@ void print_band(const ModuleBase::matrix& ekb,
{
if (printe > 0 && ((iter + 1) % printe == 0))
{
GlobalV::ofs_running << std::setprecision(6);
GlobalV::ofs_running << " Energy (eV) & Occupations for spin=" << klist->isk[ik] + 1
<< " K-point=" << ik + 1 << std::endl;
GlobalV::ofs_running << std::setiosflags(std::ios::showpoint);
ofs << std::setprecision(6);
ofs << " Energy (eV) & Occupations for spin=" << klist->isk[ik] + 1
<< " k-point=" << ik + 1 << std::endl;
ofs << std::setiosflags(std::ios::showpoint);
for (int ib = 0; ib < PARAM.globalv.nbands_l; ib++)
{
GlobalV::ofs_running << " " << std::setw(6) << ib + 1 << std::setw(15)
ofs << " " << std::setw(6) << ib + 1 << std::setw(15)
<< ekb(ik, ib) * ModuleBase::Ry_to_eV;
// for the first electron iteration, we don't have the energy
// spectrum, so we can't get the occupations.
GlobalV::ofs_running << std::setw(15) << wg(ik, ib);
GlobalV::ofs_running << std::endl;
ofs << std::setw(15) << wg(ik, ib);
ofs << std::endl;
}
}
}
Expand Down Expand Up @@ -317,7 +320,7 @@ void print_etot(const Magnetism& magnet,

GlobalV::ofs_running << std::setprecision(12);
GlobalV::ofs_running << std::setiosflags(std::ios::right);
GlobalV::ofs_running << "\n Density error is " << scf_thr << std::endl;
GlobalV::ofs_running << " Electron density error is " << scf_thr << std::endl;

if (PARAM.inp.basis_type == "pw")
{
Expand All @@ -327,6 +330,7 @@ void print_etot(const Magnetism& magnet,
std::vector<std::string> titles;
std::vector<double> energies_Ry;
std::vector<double> energies_eV;

if (printe > 0 && ((iter + 1) % printe == 0 || converged || iter == PARAM.inp.scf_nmax))
{
int n_order = std::max(0, Occupy::gaussian_type);
Expand Down Expand Up @@ -384,7 +388,7 @@ void print_etot(const Magnetism& magnet,
}

#ifdef __DEEPKS
if (PARAM.inp.deepks_scf) // caoyu add 2021-08-10
if (PARAM.inp.deepks_scf)
{
titles.push_back("E_DeePKS");
energies_Ry.push_back(elec.f_en.edeepks_delta);
Expand All @@ -399,6 +403,7 @@ void print_etot(const Magnetism& magnet,
energies_Ry.push_back(elec.f_en.etot_harris);
}

// print out the Fermi energy if needed
if (PARAM.globalv.two_fermi)
{
titles.push_back("E_Fermi_up");
Expand All @@ -411,6 +416,8 @@ void print_etot(const Magnetism& magnet,
titles.push_back("E_Fermi");
energies_Ry.push_back(elec.eferm.ef);
}

// print out the band gap if needed
if (PARAM.inp.out_bandgap)
{
if (!PARAM.globalv.two_fermi)
Expand All @@ -430,14 +437,21 @@ void print_etot(const Magnetism& magnet,
std::transform(energies_Ry.begin(), energies_Ry.end(), energies_eV.begin(), [](double ener) {
return ener * ModuleBase::Ry_to_eV;
});

// for each SCF step, we print out energy
FmtTable table(/*titles=*/{"Energy", "Rydberg", "eV"},
/*nrows=*/titles.size(),
/*formats=*/{"%-14s", "%20.10f", "%20.10f"},
/*indents=*/0,
/*align=*/{/*value*/FmtTable::Align::LEFT, /*title*/FmtTable::Align::CENTER});
// print out the titles
table << titles << energies_Ry << energies_eV;

GlobalV::ofs_running << table.str() << std::endl;
if (PARAM.inp.out_level == "ie" || PARAM.inp.out_level == "m") // xiaohui add 'm' option, 2015-09-16



if (PARAM.inp.out_level == "ie" || PARAM.inp.out_level == "m")
{
std::vector<double> mag;
switch (PARAM.inp.nspin)
Expand Down
Loading
Loading