Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: no STRU_ION_1 file output #4506

Merged
merged 4 commits into from
Jun 29, 2024
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
102 changes: 61 additions & 41 deletions source/module_relax/relax_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

#include "module_base/global_file.h"
#include "module_hamilt_pw/hamilt_pwdft/global.h" // use chr.
#include "module_io/json_output/output_info.h"
#include "module_io/print_info.h"
#include "module_io/write_wfc_r.h"

#include "module_io/json_output/output_info.h"


void Relax_Driver::relax_driver(ModuleESolver::ESolver *p_esolver)
void Relax_Driver::relax_driver(ModuleESolver::ESolver* p_esolver)
{
ModuleBase::TITLE("Ions", "opt_ions");
ModuleBase::timer::tick("Ions", "opt_ions");
Expand All @@ -32,7 +30,7 @@ void Relax_Driver::relax_driver(ModuleESolver::ESolver *p_esolver)

while (istep <= GlobalV::RELAX_NMAX && !stop)
{
time_t estart = time(NULL);
time_t estart = time(nullptr);

if (GlobalV::OUT_LEVEL == "ie"
&& (GlobalV::CALCULATION == "relax" || GlobalV::CALCULATION == "cell-relax" || GlobalV::CALCULATION == "scf"
Expand All @@ -43,13 +41,13 @@ void Relax_Driver::relax_driver(ModuleESolver::ESolver *p_esolver)

#ifdef __RAPIDJSON
Json::init_output_array_obj();
#endif //__RAPIDJSON
#endif //__RAPIDJSON

// mohan added eiter to count for the electron iteration number, 2021-01-28
p_esolver->runner(istep - 1, GlobalC::ucell);

time_t eend = time(NULL);
time_t fstart = time(NULL);
time_t eend = time(nullptr);
time_t fstart = time(nullptr);
ModuleBase::matrix force;
ModuleBase::matrix stress;
if (GlobalV::CALCULATION == "scf" || GlobalV::CALCULATION == "relax" || GlobalV::CALCULATION == "cell-relax")
Expand Down Expand Up @@ -93,62 +91,84 @@ void Relax_Driver::relax_driver(ModuleESolver::ESolver *p_esolver)
// changelog 20240509
// because I move out the dependence on GlobalV from UnitCell::print_stru_file
// so its parameter is calculated here
bool need_orb = GlobalV::BASIS_TYPE=="pw";
bool need_orb = GlobalV::BASIS_TYPE == "pw";
need_orb = need_orb && GlobalV::psi_initializer;
need_orb = need_orb && GlobalV::init_wfc.substr(0, 3)=="nao";
need_orb = need_orb || GlobalV::BASIS_TYPE=="lcao";
need_orb = need_orb || GlobalV::BASIS_TYPE=="lcao_in_pw";
need_orb = need_orb && GlobalV::init_wfc.substr(0, 3) == "nao";
need_orb = need_orb || GlobalV::BASIS_TYPE == "lcao";
need_orb = need_orb || GlobalV::BASIS_TYPE == "lcao_in_pw";
std::stringstream ss, ss1;
ss << GlobalV::global_out_dir << "STRU_ION_D";
GlobalC::ucell.print_stru_file(ss.str(), GlobalV::NSPIN, true, GlobalV::CALCULATION == "md",
GlobalV::out_mul, need_orb, GlobalV::deepks_setorb, GlobalV::MY_RANK);
GlobalC::ucell.print_stru_file(ss.str(),
GlobalV::NSPIN,
true,
GlobalV::CALCULATION == "md",
GlobalV::out_mul,
need_orb,
GlobalV::deepks_setorb,
GlobalV::MY_RANK);

if (Ions_Move_Basic::out_stru)
{
ss1 << GlobalV::global_out_dir << "STRU_ION";
ss1 << istep << "_D";
GlobalC::ucell.print_stru_file(ss.str(), GlobalV::NSPIN, true, GlobalV::CALCULATION == "md",
GlobalV::out_mul, need_orb, GlobalV::deepks_setorb, GlobalV::MY_RANK);
GlobalC::ucell.print_stru_file(ss1.str(),
GlobalV::NSPIN,
true,
GlobalV::CALCULATION == "md",
GlobalV::out_mul,
need_orb,
GlobalV::deepks_setorb,
GlobalV::MY_RANK);

GlobalC::ucell.print_cell_cif("STRU_NOW.cif");
}

if (p_esolver
&& stop
&& p_esolver->get_maxniter() == p_esolver->get_niter()
if (p_esolver && stop && p_esolver->get_maxniter() == p_esolver->get_niter()
&& !(p_esolver->get_conv_elec()))
{
std::cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << std::endl;
std::cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << std::endl;
std::cout << " Relaxation is converged, but the SCF is unconverged! The results are unreliable. " << std::endl;
std::cout << " It is suggested to increase the maximum SCF step and/or perform the relaxation again." << std::endl;
std::cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << std::endl;
std::cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << std::endl;
GlobalV::ofs_running << "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << std::endl;
GlobalV::ofs_running << "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << std::endl;
GlobalV::ofs_running << "\n Relaxation is converged, but the SCF is unconverged! The results are unreliable.. " << std::endl;
GlobalV::ofs_running << "\n It is suggested to increase the maximum SCF step and/or perform the relaxation again. " << std::endl;
GlobalV::ofs_running << "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << std::endl;
GlobalV::ofs_running << "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << std::endl;
std::cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
<< std::endl;
std::cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
<< std::endl;
std::cout << " Relaxation is converged, but the SCF is unconverged! The results are unreliable. "
<< std::endl;
std::cout
<< " It is suggested to increase the maximum SCF step and/or perform the relaxation again."
<< std::endl;
std::cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
<< std::endl;
std::cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
<< std::endl;
GlobalV::ofs_running
<< "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << std::endl;
GlobalV::ofs_running
<< "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << std::endl;
GlobalV::ofs_running
<< "\n Relaxation is converged, but the SCF is unconverged! The results are unreliable.. "
<< std::endl;
GlobalV::ofs_running
<< "\n It is suggested to increase the maximum SCF step and/or perform the relaxation again. "
<< std::endl;
GlobalV::ofs_running
<< "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << std::endl;
GlobalV::ofs_running
<< "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << std::endl;
}
}

#ifdef __RAPIDJSON
// add the energy to outout
Json::add_output_energy(p_esolver->cal_energy() * ModuleBase::Ry_to_eV);
#endif
Json::add_output_energy(p_esolver->cal_energy() * ModuleBase::Ry_to_eV);
#endif
}
#ifdef __RAPIDJSON
//add Json of cell coo stress force
// add Json of cell coo stress force
double unit_transform = ModuleBase::RYDBERG_SI / pow(ModuleBase::BOHR_RADIUS_SI, 3) * 1.0e-8;
double fac = ModuleBase::Ry_to_eV / 0.529177;
Json::add_output_cell_coo_stress_force(
&GlobalC::ucell,
force,fac,
stress,unit_transform);
#endif //__RAPIDJSON

time_t fend = time(NULL);
Json::add_output_cell_coo_stress_force(&GlobalC::ucell, force, fac, stress, unit_transform);
#endif //__RAPIDJSON

time_t fend = time(nullptr);

++istep;
}
Expand Down
1 change: 0 additions & 1 deletion tests/integrate/108_PW_RE_NEW/INPUT
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ mixing_beta 0.7
scf_thr 1e-08
cal_force 1
cal_stress 1
out_stru 1
chg_extrap second-order #atomic; first-order; second-order; dm:coefficients of SIA
pseudo_dir ../../../tests/PP_ORB

21 changes: 21 additions & 0 deletions tests/integrate/108_PW_RE_NEW/STRU_ION1_D.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
ATOMIC_SPECIES
Al 26.9820 Al.PD04.PBE.UPF upf201

LATTICE_CONSTANT
1.8897261255

LATTICE_VECTORS
4.8314802193 -0.3938948371 0.4195082125
-0.2269965014 2.9416829246 -0.2217641351
0.4439510395 -0.3954231677 4.8313338363

ATOMIC_POSITIONS
Direct

Al #label
0.0000 #magnetism
4 #number of atoms
0.0080517295 0.9967447610 0.0068914330 m 1 1 1
0.5068064301 0.5032799067 0.0031126280 m 1 1 1
0.5069481864 0.0032554942 0.5031087758 m 1 1 1
0.0081936541 0.4967198382 0.5068871632 m 1 1 1
5 changes: 3 additions & 2 deletions tests/integrate/108_PW_RE_NEW/result.ref
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
etotref -253.6810827494803391
etotref -253.6810827494790033
etotperatomref -63.4202706874
totalforceref 0.078384
totalstressref 2.163967
totaltimeref 4.32
STRU_ION1_D_pass 0
totaltimeref 4.77
Loading