From 4372d333a9c9b9c0c4bcbb1b4667863ae90ef15a Mon Sep 17 00:00:00 2001 From: Mohan Chen Date: Fri, 26 Jul 2024 09:19:27 +0800 Subject: [PATCH] Refactor DeepKS (the fourth one) (#4784) * move save and load functions to LCAO_deepks_io.h * keep updating LCAO_deepks_io * update LCAO_deepks_io.cpp * update * update LCAO_deepks_io.cpp and add notations * update * update LCAO_deepks_io * update * fix all bugs * small updates of LCAO_deepks_io * move orbital_precalc and orbital_precalc_k from LCAO_deepks_torch.cpp * move cal_gdmx and cal_gdmx_k out of LCAO_deepks_pdm * update * seperate v_delta_precalc out * divide LCAO_deepks_torch.cpp into several files * seperate out fgamma and fk * delete stress_fill * update deepks refactor * fix Makefile.Objects * refactor deepks * update fk * update deepks force subroutines * update force in deepks * change the out_dir of descriptor * update check_descriptor * update outputs of deepks * update outputs of deepks * update deepks outputs * update output format of multi-k case * [pre-commit.ci lite] apply automatic fixes * update s_base and s_tot * update tests/deepks * update tests of examples * update 602 example * update reference data for deepks * fix a typo * fix bugs in catch_properties.sh * update deepks tests * update Autotest1.sh --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> --- examples/deepks/lcao_H2O/INPUT | 19 +-- .../hamilt_lcaodft/FORCE_STRESS.cpp | 36 ++--- .../hamilt_lcaodft/FORCE_gamma.cpp | 18 ++- .../hamilt_lcaodft/FORCE_k.cpp | 18 ++- .../module_deepks/LCAO_deepks.h | 100 ++++++++----- .../module_deepks/LCAO_deepks_fgamma.cpp | 120 +++++++++------- .../module_deepks/LCAO_deepks_fk.cpp | 66 +++++---- .../module_deepks/LCAO_deepks_interface.cpp | 133 +++++++++++------- .../module_deepks/LCAO_deepks_io.cpp | 26 +++- .../module_deepks/LCAO_deepks_io.h | 4 + .../module_deepks/LCAO_deepks_pdm.cpp | 11 +- .../module_deepks/cal_descriptor.cpp | 38 +++-- .../602_NO_deepks_d_H2O_md_lda2pbe/INPUT | 8 +- .../get_dm_eig.py | 4 +- .../get_grad_vepsl.py | 6 +- .../get_grad_vx.py | 6 +- .../get_dm_eig.py | 4 +- .../get_grad_vepsl.py | 6 +- .../get_grad_vx.py | 6 +- tests/deepks/603_NO_deepks_CH4/INPUT | 6 +- tests/deepks/603_NO_deepks_CH4/STRU | 2 +- tests/deepks/603_NO_deepks_CH4/result.ref | 8 +- .../603_NO_deepks_H2O_bandgap/get_dm_eig.py | 4 +- .../603_NO_deepks_H2O_bandgap/get_odelta.py | 4 +- .../603_NO_deepks_H2O_bandgap/get_oprec.py | 2 +- .../603_NO_deepks_H2O_v_delta_1/get_dm_eig.py | 4 +- .../get_v_delta.py | 4 +- .../603_NO_deepks_H2O_v_delta_2/get_dm_eig.py | 4 +- .../get_v_delta.py | 4 +- .../get_dm_eig.py | 4 +- .../get_grad_vepsl.py | 6 +- .../get_grad_vx.py | 6 +- .../get_odelta.py | 4 +- .../get_oprec.py | 2 +- tests/deepks/Autotest1.sh | 0 tests/deepks/clean.sh | 23 +-- tests/integrate/clean.sh | 12 -- tests/integrate/tools/catch_properties.sh | 6 +- 38 files changed, 426 insertions(+), 308 deletions(-) mode change 100644 => 100755 tests/deepks/Autotest1.sh diff --git a/examples/deepks/lcao_H2O/INPUT b/examples/deepks/lcao_H2O/INPUT index cce57df555..99ebfa114e 100644 --- a/examples/deepks/lcao_H2O/INPUT +++ b/examples/deepks/lcao_H2O/INPUT @@ -2,23 +2,23 @@ INPUT_PARAMETERS #Parameters (1.General) suffix abacus pseudo_dir ../../../tests/PP_ORB -orbital_dir ../../../tests/PP_ORB +orbital_dir ../../../tests/PP_ORB calculation scf nbands 16 symmetry 0 #Parameters (2.Iteration) ecutwfc 50 -scf_thr 1e-8 -scf_nmax 50 +scf_thr 1e-8 +scf_nmax 5 #Parameters (3.Basis) basis_type lcao -gamma_only 1 +gamma_only 0 #Parameters (4.Smearing) -smearing_method gaussian -smearing_sigma 0.02 +smearing_method gaussian +smearing_sigma 0.02 #Parameters (5.Mixing) mixing_type broyden @@ -27,6 +27,7 @@ mixing_beta 0.4 #Parameters (6.Deepks) cal_force 1 test_force 1 -deepks_out_labels 1 -deepks_scf 1 -deepks_model model.ptg +deepks_out_labels 1 +deepks_scf 1 +deepks_model model.ptg +deepks_bandgap 1 diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/FORCE_STRESS.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/FORCE_STRESS.cpp index f6c14302b4..338a315ad6 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/FORCE_STRESS.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/FORCE_STRESS.cpp @@ -394,18 +394,20 @@ void Force_Stress_LCAO::getForceStress(const bool isforce, } #ifdef __DEEPKS - // DeePKS force, caoyu add 2021-06-03 + // DeePKS force if (GlobalV::deepks_out_labels) // not parallelized yet { + const std::string file_ftot = GlobalV::global_out_dir + "deepks_ftot.npy"; LCAO_deepks_io::save_npy_f(fcs, - "f_tot.npy", + file_ftot, GlobalC::ucell.nat, GlobalV::MY_RANK); // Ty/Bohr, F_tot if (GlobalV::deepks_scf) { + const std::string file_fbase = GlobalV::global_out_dir + "deepks_fbase.npy"; LCAO_deepks_io::save_npy_f(fcs - GlobalC::ld.F_delta, - "f_base.npy", + file_fbase, GlobalC::ucell.nat, GlobalV::MY_RANK); // Ry/Bohr, F_base @@ -446,13 +448,15 @@ void Force_Stress_LCAO::getForceStress(const bool isforce, LCAO_deepks_io::save_npy_gvx(GlobalC::ucell.nat, GlobalC::ld.des_per_atom, GlobalC::ld.gvx_tensor, + GlobalV::global_out_dir, GlobalV::MY_RANK); } } else { + const std::string file_fbase = GlobalV::global_out_dir + "deepks_fbase.npy"; LCAO_deepks_io::save_npy_f(fcs, - "f_base.npy", + file_fbase, GlobalC::ucell.nat, GlobalV::MY_RANK); // no scf, F_base=F_tot } @@ -613,8 +617,9 @@ void Force_Stress_LCAO::getForceStress(const bool isforce, #ifdef __DEEPKS if (GlobalV::deepks_out_labels) // not parallelized yet { + const std::string file_s = GlobalV::global_out_dir + "deepks_sbase.npy"; LCAO_deepks_io::save_npy_s(scs, - "s_base.npy", + file_s, GlobalC::ucell.omega, GlobalV::MY_RANK); // change to energy unit Ry when printing, S_base; } @@ -634,14 +639,16 @@ void Force_Stress_LCAO::getForceStress(const bool isforce, } if (GlobalV::deepks_out_labels) // not parallelized yet { + const std::string file_s = GlobalV::global_out_dir + "deepks_stot.npy"; + LCAO_deepks_io::save_npy_s( + scs, + file_s, + GlobalC::ucell.omega, + GlobalV::MY_RANK); // change to energy unit Ry when printing, S_tot, w/ model + // wenfei add 2021/11/2 if (GlobalV::deepks_scf) { - LCAO_deepks_io::save_npy_s( - scs, - "s_tot.npy", - GlobalC::ucell.omega, - GlobalV::MY_RANK); // change to energy unit Ry when printing, S_tot, w/ model if (!GlobalV::deepks_equiv) // training with stress label not supported by equivariant version now { @@ -651,17 +658,10 @@ void Force_Stress_LCAO::getForceStress(const bool isforce, GlobalC::ucell.nat, GlobalC::ld.des_per_atom, GlobalC::ld.gvepsl_tensor, + GlobalV::global_out_dir, GlobalV::MY_RANK); // unitless, grad_vepsl } } - else - { - LCAO_deepks_io::save_npy_s( - scs, - "s_tot.npy", - GlobalC::ucell.omega, - GlobalV::MY_RANK); // change to energy unit Ry when printing, S_tot, w/o model; - } } #endif diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/FORCE_gamma.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/FORCE_gamma.cpp index 6af0974da4..241a2d071c 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/FORCE_gamma.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/FORCE_gamma.cpp @@ -241,7 +241,19 @@ void Force_LCAO::ftable(const bool isforce, GlobalC::ld.cal_gedm(ucell.nat); - GlobalC::ld.cal_f_delta_gamma(dm_gamma, ucell, GlobalC::ORB, GlobalC::GridD, isstress, svnl_dalpha); + DeePKS_domain::cal_f_delta_gamma( + dm_gamma, + ucell, + GlobalC::ORB, + GlobalC::GridD, + *this->ParaV, + GlobalC::ld.lmaxd, + GlobalC::ld.nlm_save, + GlobalC::ld.gedm, + GlobalC::ld.inl_index, + GlobalC::ld.F_delta, + isstress, + svnl_dalpha); #ifdef __MPI Parallel_Reduce::reduce_all(GlobalC::ld.F_delta.c, GlobalC::ld.F_delta.nr * GlobalC::ld.F_delta.nc); @@ -258,7 +270,7 @@ void Force_LCAO::ftable(const bool isforce, GlobalC::ld.check_projected_dm(); - GlobalC::ld.check_descriptor(ucell); + GlobalC::ld.check_descriptor(ucell, GlobalV::global_out_dir); GlobalC::ld.check_gedm(); @@ -270,7 +282,7 @@ void Force_LCAO::ftable(const bool isforce, std::ofstream ofs1("E_delta.dat"); ofs1 << std::setprecision(10) << GlobalC::ld.E_delta; - GlobalC::ld.check_f_delta(ucell.nat, svnl_dalpha); + DeePKS_domain::check_f_delta(ucell.nat, GlobalC::ld.F_delta, svnl_dalpha); } } #endif diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/FORCE_k.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/FORCE_k.cpp index dd2d2743dc..4a15f7de24 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/FORCE_k.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/FORCE_k.cpp @@ -335,8 +335,22 @@ void Force_LCAO>::ftable(const bool isforce, GlobalC::ld.cal_gedm(ucell.nat); - GlobalC::ld - .cal_f_delta_k(dm_k, ucell, GlobalC::ORB, GlobalC::GridD, kv->get_nks(), kv->kvec_d, isstress, svnl_dalpha); + DeePKS_domain::cal_f_delta_k( + dm_k, + ucell, + GlobalC::ORB, + GlobalC::GridD, + pv, + GlobalC::ld.lmaxd, + kv->get_nks(), + kv->kvec_d, + GlobalC::ld.nlm_save_k, + GlobalC::ld.gedm, + GlobalC::ld.inl_index, + GlobalC::ld.F_delta, + isstress, + svnl_dalpha); + #ifdef __MPI Parallel_Reduce::reduce_all(GlobalC::ld.F_delta.c, GlobalC::ld.F_delta.nr * GlobalC::ld.F_delta.nc); if (isstress) diff --git a/source/module_hamilt_lcao/module_deepks/LCAO_deepks.h b/source/module_hamilt_lcao/module_deepks/LCAO_deepks.h index 7fc07b1984..87146ba554 100644 --- a/source/module_hamilt_lcao/module_deepks/LCAO_deepks.h +++ b/source/module_hamilt_lcao/module_deepks/LCAO_deepks.h @@ -62,6 +62,7 @@ class LCAO_Deepks /// In k space: std::vector>> H_V_delta_k; + // F_delta will be deleted soon, mohan 2024-07-25 ///(Unit: Ry/Bohr) Total Force due to the DeePKS correction term \f$E_{\delta}\f$ ModuleBase::matrix F_delta; @@ -373,41 +374,6 @@ class LCAO_Deepks void cal_e_delta_band_k(const std::vector>>& dm /**<[in] density matrix*/, const int nks); - //------------------- - // LCAO_deepks_fdelta.cpp - //------------------- - - // This file contains subroutines for calculating F_delta, - // which is defind as sum_mu,nu rho_mu,nu d/dX (V(D)) - - // There are 3 subroutines in this file: - // 1. cal_f_delta_gamma, which is used for gamma point calculation - // 2. cal_f_delta_k, which is used for multi-k calculation - // 3. check_f_delta, which prints F_delta into F_delta.dat for checking - - public: - // for gamma only, pulay and HF terms of force are calculated together - void cal_f_delta_gamma( // const std::vector& dm/**< [in] density matrix*/, - const std::vector>& dm, - const UnitCell& ucell, - const LCAO_Orbitals& orb, - Grid_Driver& GridD, - const bool isstress, - ModuleBase::matrix& svnl_dalpha); - - // for multi-k, pulay and HF terms of force are calculated together - void cal_f_delta_k( // const std::vector& dm/**<[in] density matrix*/, - const std::vector>>& dm, - const UnitCell& ucell, - const LCAO_Orbitals& orb, - Grid_Driver& GridD, - const int nks, - const std::vector>& kvec_d, - const bool isstress, - ModuleBase::matrix& svnl_dalpha); - - void check_f_delta(const int nat, ModuleBase::matrix& svnl_dalpha); - //------------------- // LCAO_deepks_odelta.cpp //------------------- @@ -471,7 +437,7 @@ class LCAO_Deepks /// which are eigenvalues of pdm in blocks of I_n_l void cal_descriptor(const int nat); /// print descriptors based on LCAO basis - void check_descriptor(const UnitCell& ucell); + void check_descriptor(const UnitCell& ucell, const std::string &out_dir); void cal_descriptor_equiv(const int nat); @@ -561,10 +527,70 @@ class LCAO_Deepks }; + +namespace DeePKS_domain +{ + //------------------------ + // LCAO_deepks_fgamma.cpp + // LCAO_deepks_fk.cpp + //------------------------ + + // This file contains subroutines for calculating F_delta, + // which is defind as sum_mu,nu rho_mu,nu d/dX (V(D)) + + // There are 3 subroutines in this file: + // 1. cal_f_delta_gamma, which is used for gamma point calculation + // 2. cal_f_delta_k, which is used for multi-k calculation + // 3. check_f_delta, which prints F_delta into F_delta.dat for checking + + // for gamma only, pulay and HF terms of force are calculated together + void cal_f_delta_gamma( + const std::vector>& dm, + const UnitCell &ucell, + const LCAO_Orbitals &orb, + Grid_Driver& gd, + const Parallel_Orbitals &pv, + const int lmaxd, + std::vector>>>>& nlm_save, + double** gedm, + ModuleBase::IntArray* inl_index, + ModuleBase::matrix& f_delta, + const bool isstress, + ModuleBase::matrix& svnl_dalpha); + + // for multi-k, pulay and HF terms of force are calculated together + + typedef std::tuple key_tuple; + + void cal_f_delta_k( + const std::vector>>& dm,/**<[in] density matrix*/ + const UnitCell &ucell, + const LCAO_Orbitals &orb, + Grid_Driver& GridD, + const Parallel_Orbitals& pv, + const int lmaxd, + const int nks, + const std::vector> &kvec_d, + std::vector>>>> &nlm_save_k, + double** gedm, + ModuleBase::IntArray* inl_index, + ModuleBase::matrix& f_delta, + const bool isstress, + ModuleBase::matrix& svnl_dalpha); + + void check_f_delta( + const int nat, + ModuleBase::matrix& f_delta, + ModuleBase::matrix& svnl_dalpha); +} + + + namespace GlobalC { -extern LCAO_Deepks ld; + extern LCAO_Deepks ld; } + #endif #endif diff --git a/source/module_hamilt_lcao/module_deepks/LCAO_deepks_fgamma.cpp b/source/module_hamilt_lcao/module_deepks/LCAO_deepks_fgamma.cpp index 4d71eb9933..94e07a5c43 100644 --- a/source/module_hamilt_lcao/module_deepks/LCAO_deepks_fgamma.cpp +++ b/source/module_hamilt_lcao/module_deepks/LCAO_deepks_fgamma.cpp @@ -18,42 +18,52 @@ //force for gamma only calculations //Pulay and HF terms are calculated together -void LCAO_Deepks::cal_f_delta_gamma(const std::vector>& dm, +void DeePKS_domain::cal_f_delta_gamma( + const std::vector>& dm, const UnitCell &ucell, const LCAO_Orbitals &orb, - Grid_Driver& GridD, - const bool isstress, ModuleBase::matrix& svnl_dalpha) + Grid_Driver& gd, + const Parallel_Orbitals &pv, + const int lmaxd, + std::vector>>>>& nlm_save, + double** gedm, + ModuleBase::IntArray* inl_index, + ModuleBase::matrix& f_delta, + const bool isstress, + ModuleBase::matrix& svnl_dalpha) { - ModuleBase::TITLE("LCAO_Deepks", "cal_f_delta_gamma"); - this->F_delta.zero_out(); + ModuleBase::TITLE("DeePKS_domain", "cal_f_delta_gamma"); + f_delta.zero_out(); const double Rcut_Alpha = orb.Alpha[0].getRcut(); - int nrow = this->pv->nrow; + + const int nrow = pv.nrow; + for (int T0 = 0; T0 < ucell.ntype; T0++) { Atom* atom0 = &ucell.atoms[T0]; for (int I0 =0; I0< atom0->na; I0++) { - int iat = ucell.itia2iat(T0,I0); + const int iat = ucell.itia2iat(T0,I0); const ModuleBase::Vector3 tau0 = atom0->tau[I0]; - GridD.Find_atom(ucell, atom0->tau[I0] ,T0, I0); + gd.Find_atom(ucell, atom0->tau[I0] ,T0, I0); - for (int ad1=0; ad1 tau1 = GridD.getAdjacentTau(ad1); + const ModuleBase::Vector3 tau1 = gd.getAdjacentTau(ad1); const Atom* atom1 = &ucell.atoms[T1]; const int nw1_tot = atom1->nw*GlobalV::NPOL; const double Rcut_AO1 = orb.Phi[T1].getRcut(); - for (int ad2=0; ad2 < GridD.getAdjacentNum()+1 ; ad2++) + for (int ad2=0; ad2 < gd.getAdjacentNum()+1 ; ad2++) { - const int T2 = GridD.getType(ad2); - const int I2 = GridD.getNatom(ad2); + const int T2 = gd.getType(ad2); + const int I2 = gd.getNatom(ad2); const int ibt2 = ucell.itia2iat(T2,I2); - const ModuleBase::Vector3 tau2 = GridD.getAdjacentTau(ad2); + const ModuleBase::Vector3 tau2 = gd.getAdjacentTau(ad2); const Atom* atom2 = &ucell.atoms[T2]; const int nw2_tot = atom2->nw*GlobalV::NPOL; @@ -79,23 +89,30 @@ void LCAO_Deepks::cal_f_delta_gamma(const std::vector>& dm, r0[2] = ( tau2.z - tau0.z) ; } - auto row_indexes = pv->get_indexes_row(ibt1); - auto col_indexes = pv->get_indexes_col(ibt2); - if(row_indexes.size() * col_indexes.size() == 0) continue; + auto row_indexes = pv.get_indexes_row(ibt1); + auto col_indexes = pv.get_indexes_col(ibt2); + + if(row_indexes.size() * col_indexes.size() == 0) + { + continue; + } + + hamilt::AtomPair dm_pair(ibt1, ibt2, 0, 0, 0, &pv); - hamilt::AtomPair dm_pair(ibt1, ibt2, 0, 0, 0, pv); dm_pair.allocate(nullptr, 1); + for(int is=0;isget_row_size(), 1.0, 1); + dm_pair.add_from_matrix(dm[is].data(), pv.get_row_size(), 1.0, 1); } else { - dm_pair.add_from_matrix(dm[is].data(), pv->get_col_size(), 1.0, 0); + dm_pair.add_from_matrix(dm[is].data(), pv.get_col_size(), 1.0, 0); } } + const double* dm_current = dm_pair.get_pointer(); for (int iw1=0; iw1>& dm, { double nlm[3]={0,0,0}; double nlm_t[3] = {0,0,0}; //for stress - std::vector nlm1 = this->nlm_save[iat][ad1][row_indexes[iw1]][0]; + std::vector nlm1 = nlm_save[iat][ad1][row_indexes[iw1]][0]; std::vector> nlm2; nlm2.resize(3); - for(int dim=0;dim<3;dim++) + for(int dim=0;dim<3;++dim) { - nlm2[dim] = this->nlm_save[iat][ad2][col_indexes[iw2]][dim+1]; + nlm2[dim] = nlm_save[iat][ad2][col_indexes[iw2]][dim+1]; } assert(nlm1.size()==nlm2[0].size()); @@ -122,7 +139,7 @@ void LCAO_Deepks::cal_f_delta_gamma(const std::vector>& dm, { for (int N0 = 0;N0 < orb.Alpha[0].getNchi(L0);++N0) { - const int inl = this->inl_index[T0](I0, L0, N0); + const int inl = inl_index[T0](I0, L0, N0); const int nm = 2*L0+1; for (int m1 = 0;m1 < nm; ++m1) { @@ -130,7 +147,7 @@ void LCAO_Deepks::cal_f_delta_gamma(const std::vector>& dm, { for(int dim=0;dim<3;dim++) { - nlm[dim] += this->gedm[inl][m1*nm+m2]*nlm1[ib+m1]*nlm2[dim][ib+m2]; + nlm[dim] += gedm[inl][m1*nm+m2]*nlm1[ib+m1]*nlm2[dim][ib+m2]; } } } @@ -142,7 +159,7 @@ void LCAO_Deepks::cal_f_delta_gamma(const std::vector>& dm, else { int nproj = 0; - for(int il = 0; il < this->lmaxd + 1; il++) + for(int il = 0; il < lmaxd + 1; il++) { nproj += (2 * il + 1) * orb.Alpha[0].getNchi(il); } @@ -152,28 +169,28 @@ void LCAO_Deepks::cal_f_delta_gamma(const std::vector>& dm, { for(int dim=0;dim<3;dim++) { - nlm[dim] += this->gedm[iat][iproj*nproj+jproj] * nlm1[iproj] * nlm2[dim][jproj]; + nlm[dim] += gedm[iat][iproj*nproj+jproj] * nlm1[iproj] * nlm2[dim][jproj]; } } } } // HF term is minus, only one projector for each atom force. - this->F_delta(iat, 0) -= 2 * *dm_current * nlm[0]; - this->F_delta(iat, 1) -= 2 * *dm_current * nlm[1]; - this->F_delta(iat, 2) -= 2 * *dm_current * nlm[2]; + f_delta(iat, 0) -= 2 * *dm_current * nlm[0]; + f_delta(iat, 1) -= 2 * *dm_current * nlm[1]; + f_delta(iat, 2) -= 2 * *dm_current * nlm[2]; // Pulay term is plus, only one projector for each atom force. - this->F_delta(ibt2, 0) += 2 * *dm_current * nlm[0]; - this->F_delta(ibt2, 1) += 2 * *dm_current * nlm[1]; - this->F_delta(ibt2, 2) += 2 * *dm_current * nlm[2]; + f_delta(ibt2, 0) += 2 * *dm_current * nlm[0]; + f_delta(ibt2, 1) += 2 * *dm_current * nlm[1]; + f_delta(ibt2, 2) += 2 * *dm_current * nlm[2]; if(isstress) { - nlm1 = this->nlm_save[iat][ad2][col_indexes[iw2]][0]; + nlm1 = nlm_save[iat][ad2][col_indexes[iw2]][0]; for(int i=0;i<3;i++) { - nlm2[i] = this->nlm_save[iat][ad1][row_indexes[iw1]][i+1]; + nlm2[i] = nlm_save[iat][ad1][row_indexes[iw1]][i+1]; } assert(nlm1.size()==nlm2[0].size()); @@ -185,15 +202,16 @@ void LCAO_Deepks::cal_f_delta_gamma(const std::vector>& dm, { for (int N0 = 0;N0 < orb.Alpha[0].getNchi(L0);++N0) { - const int inl = this->inl_index[T0](I0, L0, N0); + const int inl = inl_index[T0](I0, L0, N0); const int nm = 2*L0+1; + for (int m1 = 0;m1 < nm; ++m1) { for (int m2 = 0; m2 < nm; ++m2) { - for(int dim=0;dim<3;dim++) + for(int dim=0;dim<3;++dim) { - nlm_t[dim] += this->gedm[inl][m1*nm+m2]*nlm1[ib+m1]*nlm2[dim][ib+m2]; + nlm_t[dim] += gedm[inl][m1*nm+m2]*nlm1[ib+m1]*nlm2[dim][ib+m2]; } } } @@ -205,7 +223,7 @@ void LCAO_Deepks::cal_f_delta_gamma(const std::vector>& dm, else { int nproj = 0; - for(int il = 0; il < this->lmaxd + 1; il++) + for(int il = 0; il < lmaxd + 1; il++) { nproj += (2 * il + 1) * orb.Alpha[0].getNchi(il); } @@ -215,7 +233,7 @@ void LCAO_Deepks::cal_f_delta_gamma(const std::vector>& dm, { for(int dim=0;dim<3;dim++) { - nlm_t[dim] += this->gedm[iat][iproj*nproj+jproj] * nlm1[iproj] * nlm2[dim][jproj]; + nlm_t[dim] += gedm[iat][iproj*nproj+jproj] * nlm1[iproj] * nlm2[dim][jproj]; } } } @@ -225,8 +243,8 @@ void LCAO_Deepks::cal_f_delta_gamma(const std::vector>& dm, { for(int jpol=ipol;jpol<3;jpol++) { - //svnl_dalpha(ipol, jpol) += dm[is](iw1_local, iw2_local) * (nlm[jpol] * r0[ipol] + nlm_t[jpol] * r1[ipol]); - svnl_dalpha(ipol, jpol) += *dm_current * (nlm[jpol] * r0[ipol] + nlm_t[jpol] * r1[ipol]); + svnl_dalpha(ipol, jpol) += *dm_current * + (nlm[jpol] * r0[ipol] + nlm_t[jpol] * r1[ipol]); } } } @@ -246,8 +264,9 @@ void LCAO_Deepks::cal_f_delta_gamma(const std::vector>& dm, { for(int j=0;j<3;++j) { - if(j>i) svnl_dalpha(j,i) = svnl_dalpha(i,j); - svnl_dalpha(i,j) *= weight ; + if(j>i) { svnl_dalpha(j,i) = svnl_dalpha(i,j); +} + svnl_dalpha(i,j) *= weight; } } } @@ -256,8 +275,11 @@ void LCAO_Deepks::cal_f_delta_gamma(const std::vector>& dm, } -//prints F_delta into F_delta.dat -void LCAO_Deepks::check_f_delta(const int nat, ModuleBase::matrix& svnl_dalpha) +//prints forces and stress from DeePKS (LCAO) +void DeePKS_domain::check_f_delta( + const int nat, + ModuleBase::matrix& f_delta, + ModuleBase::matrix& svnl_dalpha) { ModuleBase::TITLE("LCAO_Deepks", "check_F_delta"); @@ -266,7 +288,7 @@ void LCAO_Deepks::check_f_delta(const int nat, ModuleBase::matrix& svnl_dalpha) for (int iat=0; iat>>& dm,/**<[in] density matrix*/ +typedef std::tuple key_tuple; // used in nlm_save_k + +void DeePKS_domain::cal_f_delta_k( + const std::vector>>& dm,/**<[in] density matrix*/ const UnitCell &ucell, const LCAO_Orbitals &orb, Grid_Driver& GridD, + const Parallel_Orbitals& pv, + const int lmaxd, const int nks, const std::vector> &kvec_d, - const bool isstress, ModuleBase::matrix& svnl_dalpha) + std::vector>>>> &nlm_save_k, + double** gedm, + ModuleBase::IntArray* inl_index, + ModuleBase::matrix& f_delta, + const bool isstress, + ModuleBase::matrix& svnl_dalpha) { ModuleBase::TITLE("LCAO_Deepks", "cal_f_delta_hf_k_new"); ModuleBase::timer::tick("LCAO_Deepks","cal_f_delta_hf_k_new"); - this->F_delta.zero_out(); + f_delta.zero_out(); const double Rcut_Alpha = orb.Alpha[0].getRcut(); - int nrow = this->pv->nrow; + const int nrow = pv.nrow; + for (int T0 = 0; T0 < ucell.ntype; T0++) { Atom* atom0 = &ucell.atoms[T0]; @@ -82,11 +93,11 @@ void LCAO_Deepks::cal_f_delta_k(const std::vectorget_indexes_row(ibt1); - auto col_indexes = pv->get_indexes_col(ibt2); + auto row_indexes = pv.get_indexes_row(ibt1); + auto col_indexes = pv.get_indexes_col(ibt2); if(row_indexes.size() * col_indexes.size() == 0) continue; - hamilt::AtomPair dm_pair(ibt1, ibt2, (dR2-dR1).x, (dR2-dR1).y, (dR2-dR1).z, pv); + hamilt::AtomPair dm_pair(ibt1, ibt2, (dR2-dR1).x, (dR2-dR1).y, (dR2-dR1).z, &pv); dm_pair.allocate(nullptr, 1); for(int ik=0;ik kphase = std::complex(cosp, sinp); if(ModuleBase::GlobalFunc::IS_COLUMN_MAJOR_KS_SOLVER()) { - dm_pair.add_from_matrix(dm[ik].data(), pv->get_row_size(), kphase, 1); + dm_pair.add_from_matrix(dm[ik].data(), pv.get_row_size(), kphase, 1); } else { - dm_pair.add_from_matrix(dm[ik].data(), pv->get_col_size(), kphase, 0); + dm_pair.add_from_matrix(dm[ik].data(), pv.get_col_size(), kphase, 0); } } + const double* dm_current = dm_pair.get_pointer(); for (int iw1=0; iw1 nlm1 = this->nlm_save_k[iat][key_1][row_indexes[iw1]][0]; + std::vector nlm1 = nlm_save_k[iat][key_1][row_indexes[iw1]][0]; std::vector> nlm2; nlm2.resize(3); for(int dim=0;dim<3;dim++) { - nlm2[dim] = this->nlm_save_k[iat][key_2][col_indexes[iw2]][dim+1]; + nlm2[dim] = nlm_save_k[iat][key_2][col_indexes[iw2]][dim+1]; } assert(nlm1.size()==nlm2[0].size()); @@ -130,7 +142,7 @@ void LCAO_Deepks::cal_f_delta_k(const std::vectorinl_index[T0](I0, L0, N0); + const int inl = inl_index[T0](I0, L0, N0); const int nm = 2*L0+1; for (int m1 = 0;m1 < nm; ++m1) { @@ -138,7 +150,7 @@ void LCAO_Deepks::cal_f_delta_k(const std::vectorgedm[inl][m1*nm+m2]*nlm1[ib+m1]*nlm2[dim][ib+m2]; + nlm[dim] += gedm[inl][m1*nm+m2]*nlm1[ib+m1]*nlm2[dim][ib+m2]; } } } @@ -150,7 +162,7 @@ void LCAO_Deepks::cal_f_delta_k(const std::vectorlmaxd + 1; il++) + for(int il = 0; il < lmaxd + 1; il++) { nproj += (2 * il + 1) * orb.Alpha[0].getNchi(il); } @@ -160,28 +172,28 @@ void LCAO_Deepks::cal_f_delta_k(const std::vectorgedm[iat][iproj*nproj+jproj] * nlm1[iproj] * nlm2[dim][jproj]; + nlm[dim] += gedm[iat][iproj*nproj+jproj] * nlm1[iproj] * nlm2[dim][jproj]; } } } } // Pulay term is plus - this->F_delta(ibt2, 0) += 2.0 * *dm_current * nlm[0]; - this->F_delta(ibt2, 1) += 2.0 * *dm_current * nlm[1]; - this->F_delta(ibt2, 2) += 2.0 * *dm_current * nlm[2]; + f_delta(ibt2, 0) += 2.0 * *dm_current * nlm[0]; + f_delta(ibt2, 1) += 2.0 * *dm_current * nlm[1]; + f_delta(ibt2, 2) += 2.0 * *dm_current * nlm[2]; // HF term is minus, only one projector for each atom force. - this->F_delta(iat, 0) -= 2.0 * *dm_current * nlm[0]; - this->F_delta(iat, 1) -= 2.0 * *dm_current * nlm[1]; - this->F_delta(iat, 2) -= 2.0 * *dm_current * nlm[2]; + f_delta(iat, 0) -= 2.0 * *dm_current * nlm[0]; + f_delta(iat, 1) -= 2.0 * *dm_current * nlm[1]; + f_delta(iat, 2) -= 2.0 * *dm_current * nlm[2]; if(isstress) { - nlm1 = this->nlm_save_k[iat][key_2][col_indexes[iw2]][0]; + nlm1 = nlm_save_k[iat][key_2][col_indexes[iw2]][0]; for(int i=0;i<3;i++) { - nlm2[i] = this->nlm_save_k[iat][key_1][row_indexes[iw1]][i+1]; + nlm2[i] = nlm_save_k[iat][key_1][row_indexes[iw1]][i+1]; } assert(nlm1.size()==nlm2[0].size()); @@ -193,7 +205,7 @@ void LCAO_Deepks::cal_f_delta_k(const std::vectorinl_index[T0](I0, L0, N0); + const int inl = inl_index[T0](I0, L0, N0); const int nm = 2*L0+1; for (int m1 = 0;m1 < nm; ++m1) { @@ -201,7 +213,7 @@ void LCAO_Deepks::cal_f_delta_k(const std::vectorgedm[inl][m1*nm+m2]*nlm1[ib+m1]*nlm2[dim][ib+m2]; + nlm_t[dim] += gedm[inl][m1*nm+m2]*nlm1[ib+m1]*nlm2[dim][ib+m2]; } } } @@ -213,7 +225,7 @@ void LCAO_Deepks::cal_f_delta_k(const std::vectorlmaxd + 1; il++) + for(int il = 0; il < lmaxd + 1; il++) { nproj += (2 * il + 1) * orb.Alpha[0].getNchi(il); } @@ -223,7 +235,7 @@ void LCAO_Deepks::cal_f_delta_k(const std::vectorgedm[iat][iproj*nproj+jproj] * nlm1[iproj] * nlm2[dim][jproj]; + nlm_t[dim] += gedm[iat][iproj*nproj+jproj] * nlm1[iproj] * nlm2[dim][jproj]; } } } diff --git a/source/module_hamilt_lcao/module_deepks/LCAO_deepks_interface.cpp b/source/module_hamilt_lcao/module_deepks/LCAO_deepks_interface.cpp index a7c1d81b9e..a8784c9685 100644 --- a/source/module_hamilt_lcao/module_deepks/LCAO_deepks_interface.cpp +++ b/source/module_hamilt_lcao/module_deepks/LCAO_deepks_interface.cpp @@ -25,50 +25,65 @@ void LCAO_Deepks_Interface::out_deepks_labels(const double& etot, const int& deepks_v_delta) { ModuleBase::TITLE("LCAO_Deepks_Interface", "out_deepks_labels"); + + const int my_rank = GlobalV::MY_RANK; + const int nspin = GlobalV::NSPIN; + // calculating deepks correction to bandgap // and save the results - if (GlobalV::deepks_out_labels) // caoyu add 2021-06-04 + if (GlobalV::deepks_out_labels) { - LCAO_deepks_io::save_npy_e(etot, "e_tot.npy", GlobalV::MY_RANK); + // mohan updated 2024-07-25 + const std::string file_etot = GlobalV::global_out_dir + "deepks_etot.npy"; + const std::string file_ebase = GlobalV::global_out_dir + "deepks_ebase.npy"; + + LCAO_deepks_io::save_npy_e(etot, file_etot, my_rank); + if (GlobalV::deepks_scf) { + /// ebase :no deepks E_delta including LCAO_deepks_io::save_npy_e(etot - ld->E_delta, - "e_base.npy", GlobalV::MY_RANK); // ebase :no deepks E_delta including + file_ebase, my_rank); } else // deepks_scf = 0; base calculation { - LCAO_deepks_io::save_npy_e(etot, "e_base.npy", GlobalV::MY_RANK); // no scf, e_tot=e_base + /// no scf, e_tot=e_base + LCAO_deepks_io::save_npy_e(etot, file_ebase, my_rank); } if (GlobalV::deepks_bandgap) { - int nocc = GlobalV::nelec / 2; + const int nocc = GlobalV::nelec / 2; ModuleBase::matrix deepks_bands; deepks_bands.create(nks, 1); - for (int iks = 0; iks < nks; iks++) + for (int iks = 0; iks < nks; ++iks) { - for (int hl = 0; hl < 1; hl++) + // record band gap for each k point (including spin) + for (int hl = 0; hl < 1; ++hl) { deepks_bands(iks, hl) = ekb(iks, nocc + hl) - ekb(iks, nocc - 1 + hl); } } - LCAO_deepks_io::save_npy_o(deepks_bands, "o_tot.npy", nks, GlobalV::MY_RANK); + + const std::string file_otot = GlobalV::global_out_dir + "deepks_otot.npy"; + LCAO_deepks_io::save_npy_o(deepks_bands, file_otot, nks, my_rank); if (GlobalV::deepks_scf) { - int nocc = GlobalV::nelec / 2; ModuleBase::matrix wg_hl; - wg_hl.create(GlobalV::NSPIN, GlobalV::NBANDS); + wg_hl.create(nspin, GlobalV::NBANDS); + std::vector> dm_bandgap_gamma; - dm_bandgap_gamma.resize(GlobalV::NSPIN); - for (int is = 0; is < GlobalV::NSPIN; is++) + + dm_bandgap_gamma.resize(nspin); + for (int is = 0; is < nspin; ++is) { - for (int ib = 0; ib < 1; ib++) + for (int ib = 0; ib < 1; ++ib) { wg_hl.zero_out(); wg_hl(is, ib + nocc - 1) = -1.0; wg_hl(is, ib + nocc) = 1.0; - dm_bandgap_gamma[ib].resize(GlobalV::NSPIN); + dm_bandgap_gamma[ib].resize(nspin); elecstate::cal_dm(ParaV, wg_hl, psid, dm_bandgap_gamma[ib]); } } @@ -79,24 +94,30 @@ void LCAO_Deepks_Interface::out_deepks_labels(const double& etot, nks, ld->des_per_atom, ld->orbital_precalc_tensor, - GlobalV::MY_RANK); + GlobalV::global_out_dir, + my_rank); ld->cal_o_delta(dm_bandgap_gamma); - LCAO_deepks_io::save_npy_o(deepks_bands - ld->o_delta, "o_base.npy", nks, GlobalV::MY_RANK); + const std::string file_obase = GlobalV::global_out_dir + "deepks_obase.npy"; + LCAO_deepks_io::save_npy_o(deepks_bands - ld->o_delta, file_obase, nks, my_rank); } // end deepks_scf == 1 else // deepks_scf == 0 { - LCAO_deepks_io::save_npy_o(deepks_bands, "o_base.npy", nks, GlobalV::MY_RANK); // no scf, o_tot=o_base + const std::string file_obase = GlobalV::global_out_dir + "deepks_obase.npy"; + LCAO_deepks_io::save_npy_o(deepks_bands, file_obase, nks, my_rank); // no scf, o_tot=o_base } // end deepks_scf == 0 - } // end bandgap label + } // end bandgap label + if(deepks_v_delta)//gamma only now { ModuleBase::matrix h_tot; h_tot.create(nlocal,nlocal); ld->collect_h_mat(ld->h_mat,h_tot,nlocal); - LCAO_deepks_io::save_npy_h(h_tot, "h_tot.npy",nlocal,GlobalV::MY_RANK); + + const std::string file_htot = GlobalV::global_out_dir + "deepks_htot.npy"; + LCAO_deepks_io::save_npy_h(h_tot, file_htot, nlocal, my_rank); if(GlobalV::deepks_scf) { @@ -104,8 +125,11 @@ void LCAO_Deepks_Interface::out_deepks_labels(const double& etot, v_delta.create(nlocal,nlocal); ld->collect_h_mat(ld->H_V_delta,v_delta,nlocal); - LCAO_deepks_io::save_npy_h(h_tot-v_delta, "h_base.npy",nlocal,GlobalV::MY_RANK); - LCAO_deepks_io::save_npy_h(v_delta, "v_delta.npy",nlocal,GlobalV::MY_RANK); + const std::string file_hbase = GlobalV::global_out_dir + "deepks_hbase.npy"; + LCAO_deepks_io::save_npy_h(h_tot-v_delta, file_hbase, nlocal, my_rank); + + const std::string file_vdelta = GlobalV::global_out_dir + "deepks_vdelta.npy"; + LCAO_deepks_io::save_npy_h(v_delta, file_vdelta, nlocal, my_rank); if(deepks_v_delta==1)//v_delta_precalc storage method 1 { @@ -122,7 +146,7 @@ void LCAO_Deepks_Interface::out_deepks_labels(const double& etot, nlocal, ld->des_per_atom, ld->v_delta_precalc_tensor, - GlobalV::MY_RANK); + my_rank); } else if(deepks_v_delta==2)//v_delta_precalc storage method 2 { @@ -139,7 +163,7 @@ void LCAO_Deepks_Interface::out_deepks_labels(const double& etot, ld->inlmax, ld->lmaxd, ld->psialpha_tensor, - GlobalV::MY_RANK); + my_rank); ld->prepare_gevdm( nat, @@ -149,16 +173,18 @@ void LCAO_Deepks_Interface::out_deepks_labels(const double& etot, ld->inlmax, ld->lmaxd, ld->gevdm_tensor, - GlobalV::MY_RANK); + my_rank); } } else //deepks_scf == 0 { - LCAO_deepks_io::save_npy_h(h_tot, "h_base.npy",nlocal,GlobalV::MY_RANK); + const std::string file_hbase = GlobalV::global_out_dir + "deepks_hbase.npy"; + LCAO_deepks_io::save_npy_h(h_tot, file_hbase, nlocal, my_rank); } }//end v_delta label - } // end deepks_out_labels + } // end deepks_out_labels + // DeePKS PDM and descriptor if (GlobalV::deepks_out_labels || GlobalV::deepks_scf) @@ -174,7 +200,7 @@ void LCAO_Deepks_Interface::out_deepks_labels(const double& etot, ld->cal_descriptor(nat); // final descriptor - ld->check_descriptor(ucell); + ld->check_descriptor(ucell, GlobalV::global_out_dir); if (GlobalV::deepks_out_labels) { @@ -185,13 +211,13 @@ void LCAO_Deepks_Interface::out_deepks_labels(const double& etot, ld->inl_l, GlobalV::deepks_equiv, ld->d_tensor, - GlobalV::MY_RANK); // libnpy needed + my_rank); // libnpy needed } } - // + + /// print out deepks information to the screen if (GlobalV::deepks_scf) { - ld->cal_e_delta_band(dm->get_DMK_vector()); std::cout << "E_delta_band = " << std::setprecision(8) << ld->e_delta_band << " Ry" << " = " << std::setprecision(8) << ld->e_delta_band * ModuleBase::Ry_to_eV << " eV" @@ -218,24 +244,28 @@ void LCAO_Deepks_Interface::out_deepks_labels(const double& etot, { ModuleBase::TITLE("LCAO_Deepks_Interface", "out_deepks_labels"); ModuleBase::timer::tick("LCAO_Deepks_Interface", "out_deepks_labels"); - // calculating deepks correction to bandgap - // and save the results - if (GlobalV::deepks_out_labels) // caoyu add 2021-06-04 + + const int my_rank = GlobalV::MY_RANK; + const int nspin = GlobalV::NSPIN; + + /// calculating deepks correction to bandgap and save the results + if (GlobalV::deepks_out_labels) { - LCAO_deepks_io::save_npy_e(etot, - "e_tot.npy", - GlobalV::MY_RANK); + // mohan updated 2024-07-25 + const std::string file_etot = GlobalV::global_out_dir + "deepks_etot.npy"; + const std::string file_ebase = GlobalV::global_out_dir + "deepks_ebase.npy"; + + LCAO_deepks_io::save_npy_e(etot, file_etot, my_rank); if (GlobalV::deepks_scf) { - LCAO_deepks_io::save_npy_e( - etot - ld->E_delta, - "e_base.npy", - GlobalV::MY_RANK); // ebase :no deepks E_delta including + /// ebase :no deepks E_delta including + LCAO_deepks_io::save_npy_e(etot - ld->E_delta, + file_ebase, my_rank); } else // deepks_scf = 0; base calculation { - LCAO_deepks_io::save_npy_e(etot, "e_base.npy", GlobalV::MY_RANK); // no scf, e_tot=e_base + LCAO_deepks_io::save_npy_e(etot, file_ebase, my_rank); } if (GlobalV::deepks_bandgap) @@ -251,7 +281,8 @@ void LCAO_Deepks_Interface::out_deepks_labels(const double& etot, } } - LCAO_deepks_io::save_npy_o(deepks_bands, "o_tot.npy", nks, GlobalV::MY_RANK); + const std::string file_otot = GlobalV::global_out_dir + "deepks_otot.npy"; + LCAO_deepks_io::save_npy_o(deepks_bands, file_otot, nks, my_rank); if (GlobalV::deepks_scf) { @@ -281,24 +312,18 @@ void LCAO_Deepks_Interface::out_deepks_labels(const double& etot, nks, ld->des_per_atom, ld->orbital_precalc_tensor, + GlobalV::global_out_dir, GlobalV::MY_RANK); ld->cal_o_delta_k(dm_bandgap_k, nks); - LCAO_deepks_io::save_npy_o( - deepks_bands - ld->o_delta, - "o_base.npy", - nks, - GlobalV::MY_RANK); - + const std::string file_obase = GlobalV::global_out_dir + "deepks_obase.npy"; + LCAO_deepks_io::save_npy_o(deepks_bands - ld->o_delta, file_obase, nks, my_rank); } // end deepks_scf == 1 else // deepks_scf == 0 { - LCAO_deepks_io::save_npy_o( - deepks_bands, - "o_base.npy", - nks, - GlobalV::MY_RANK); // no scf, o_tot=o_base + const std::string file_obase = GlobalV::global_out_dir + "deepks_obase.npy"; + LCAO_deepks_io::save_npy_o(deepks_bands, file_obase, nks, my_rank); // no scf, o_tot=o_base } // end deepks_scf == 0 } // end bandgap label if(deepks_v_delta) @@ -323,7 +348,7 @@ void LCAO_Deepks_Interface::out_deepks_labels(const double& etot, ld->cal_descriptor(nat); // final descriptor - ld->check_descriptor(ucell); + ld->check_descriptor(ucell, GlobalV::global_out_dir); if (GlobalV::deepks_out_labels) { diff --git a/source/module_hamilt_lcao/module_deepks/LCAO_deepks_io.cpp b/source/module_hamilt_lcao/module_deepks/LCAO_deepks_io.cpp index 84fb2df0ca..722ffb73be 100644 --- a/source/module_hamilt_lcao/module_deepks/LCAO_deepks_io.cpp +++ b/source/module_hamilt_lcao/module_deepks/LCAO_deepks_io.cpp @@ -148,7 +148,9 @@ void LCAO_deepks_io::save_npy_d(const int nat, const long unsigned dshape[] = {static_cast(nat), static_cast(des_per_atom)}; if (rank == 0) { - npy::SaveArrayAsNumpy("dm_eig.npy", false, 2, dshape, npy_des); + //std::string file_dm_eig = GlobalV::global_out_dir + "dm_eig.npy"; + std::string file_dm_eig = "dm_eig.npy"; + npy::SaveArrayAsNumpy(file_dm_eig, false, 2, dshape, npy_des); } } else @@ -165,7 +167,9 @@ void LCAO_deepks_io::save_npy_d(const int nat, const long unsigned dshape[] = {static_cast(nat), static_cast(des_per_atom)}; if (rank == 0) { - npy::SaveArrayAsNumpy("dm_eig.npy", false, 2, dshape, npy_des); + //std::string file_dm_eig = GlobalV::global_out_dir + "dm_eig.npy"; + std::string file_dm_eig = "dm_eig.npy"; + npy::SaveArrayAsNumpy(file_dm_eig, false, 2, dshape, npy_des); } } return; @@ -176,6 +180,7 @@ void LCAO_deepks_io::save_npy_d(const int nat, void LCAO_deepks_io::save_npy_gvx(const int nat, const int des_per_atom, const torch::Tensor &gvx_tensor, + const std::string &out_dir, const int rank) { ModuleBase::TITLE("LCAO_deepks_io", "save_npy_gvx"); @@ -209,7 +214,9 @@ void LCAO_deepks_io::save_npy_gvx(const int nat, } } } - npy::SaveArrayAsNumpy("grad_vx.npy", false, 4, gshape, npy_gvx); + + std::string file_gradvx = out_dir + "deepks_gradvx.npy"; + npy::SaveArrayAsNumpy(file_gradvx, false, 4, gshape, npy_gvx); return; } @@ -217,6 +224,7 @@ void LCAO_deepks_io::save_npy_gvx(const int nat, void LCAO_deepks_io::save_npy_gvepsl(const int nat, const int des_per_atom, const torch::Tensor &gvepsl_tensor, + const std::string& out_dir, const int rank) { ModuleBase::TITLE("LCAO_deepks_io", "save_npy_gvepsl"); @@ -246,7 +254,10 @@ void LCAO_deepks_io::save_npy_gvepsl(const int nat, } } - npy::SaveArrayAsNumpy("grad_vepsl.npy", false, 3, gshape, npy_gvepsl); + + // change the name from grad_vepsl.npy to deepks_gvepsl.npy + const std::string file = out_dir + "deepks_gvepsl.npy"; + npy::SaveArrayAsNumpy(file, false, 3, gshape, npy_gvepsl); return; } @@ -346,7 +357,7 @@ void LCAO_deepks_io::save_npy_o(const ModuleBase::matrix &bandgap, std::vector npy_o; for (int iks = 0; iks < nks; ++iks) { - for (int hl = 0;hl < 1;hl++) + for (int hl = 0;hl < 1; ++hl) { npy_o.push_back(bandgap(iks,hl)); } @@ -361,6 +372,7 @@ void LCAO_deepks_io::save_npy_orbital_precalc(const int nat, const int nks, const int des_per_atom, const torch::Tensor& orbital_precalc_tensor, + const std::string& out_dir, const int rank) { ModuleBase::TITLE("LCAO_deepks_io", "save_npy_orbital_precalc"); @@ -390,7 +402,9 @@ void LCAO_deepks_io::save_npy_orbital_precalc(const int nat, } } } - npy::SaveArrayAsNumpy("orbital_precalc.npy", false, 4, gshape, npy_orbital_precalc); + + const std::string file_orbpre = out_dir + "deepks_orbpre.npy"; + npy::SaveArrayAsNumpy(file_orbpre, false, 4, gshape, npy_orbital_precalc); return; } diff --git a/source/module_hamilt_lcao/module_deepks/LCAO_deepks_io.h b/source/module_hamilt_lcao/module_deepks/LCAO_deepks_io.h index 0becab1122..96f615ce44 100644 --- a/source/module_hamilt_lcao/module_deepks/LCAO_deepks_io.h +++ b/source/module_hamilt_lcao/module_deepks/LCAO_deepks_io.h @@ -24,6 +24,7 @@ namespace LCAO_deepks_io /// 2. print_dm_k : for multi-k /// others print quantities in .npy format + /// 3. save_npy_d : descriptor ->dm_eig.npy /// 4. save_npy_gvx : gvx ->grad_vx.npy /// 5. save_npy_e : energy @@ -75,11 +76,13 @@ void save_npy_d(const int nat, void save_npy_gvx(const int nat, const int des_per_atom, const torch::Tensor &gvx_tensor, + const std::string& out_dir, const int rank); void save_npy_gvepsl(const int nat, const int des_per_atom, const torch::Tensor &gvepsl_tensor, + const std::string& out_dir, const int rank); void save_npy_e(const double &e, /**<[in] \f$E_{base}\f$ or \f$E_{tot}\f$, in Ry*/ @@ -106,6 +109,7 @@ void save_npy_orbital_precalc(const int nat, const int nks, const int des_per_atom, const torch::Tensor& orbital_precalc_tensor, + const std::string& out_dir, const int rank); /// xinyuan added on 2023-2-20 diff --git a/source/module_hamilt_lcao/module_deepks/LCAO_deepks_pdm.cpp b/source/module_hamilt_lcao/module_deepks/LCAO_deepks_pdm.cpp index abf37f80c1..80e40c5a4b 100644 --- a/source/module_hamilt_lcao/module_deepks/LCAO_deepks_pdm.cpp +++ b/source/module_hamilt_lcao/module_deepks/LCAO_deepks_pdm.cpp @@ -43,10 +43,13 @@ void LCAO_Deepks::read_projected_DM(bool read_pdm_file, bool is_equiv, const Num } pdm_size = nproj * nproj; } - std::ifstream ifs("pdm.dat"); + + const std::string file_projdm = GlobalV::global_out_dir + "deepks_projdm.dat"; + std::ifstream ifs(file_projdm.c_str()); + if (!ifs) { - ModuleBase::WARNING_QUIT("LCAO_Deepks::cal_projected_DM", "Can not find the file pdm.dat . Please do DeePKS SCF calculation first."); + ModuleBase::WARNING_QUIT("LCAO_Deepks::cal_projected_DM", "Cannot find the file deepks_projdm.dat"); } for(int inl=0;inlinlmax;inl++) { @@ -560,7 +563,9 @@ void LCAO_Deepks::cal_projected_DM_k(const elecstate::DensityMatrixlmaxd * 2 + 1) * (this->lmaxd * 2 + 1); ofs<cal_descriptor_equiv(nat); return; } @@ -47,32 +49,42 @@ void LCAO_Deepks::cal_descriptor(const int nat) { torch::Tensor tmp; // if pdm_tensor and d_tensor is not empty, clear it !! - if (!this->d_tensor.empty()) { + if (!this->d_tensor.empty()) + { this->d_tensor.erase(this->d_tensor.begin(), this->d_tensor.end()); } - if (!this->pdm_tensor.empty()) { + + if (!this->pdm_tensor.empty()) + { this->pdm_tensor.erase(this->pdm_tensor.begin(), this->pdm_tensor.end()); } - for (int inl = 0; inl < this->inlmax; ++inl) { - int nm = 2 * inl_l[inl] + 1; + for (int inl = 0; inl < this->inlmax; ++inl) + { + const int nm = 2 * inl_l[inl] + 1; tmp = torch::ones({nm, nm}, torch::TensorOptions().dtype(torch::kFloat64)); - for (int m1 = 0; m1 < nm; ++m1) { - for (int m2 = 0; m2 < nm; ++m2) { + + for (int m1 = 0; m1 < nm; ++m1) + { + for (int m2 = 0; m2 < nm; ++m2) + { tmp.index_put_({m1, m2}, this->pdm[inl][m1 * nm + m2]); } } + // torch::Tensor tmp = torch::from_blob(this->pdm[inl], { nm, nm }, // torch::requires_grad()); + tmp.requires_grad_(true); this->pdm_tensor.push_back(tmp); this->d_tensor.push_back(torch::ones({nm}, torch::requires_grad(true))); } // cal d_tensor - for (int inl = 0; inl < inlmax; ++inl) { + for (int inl = 0; inl < inlmax; ++inl) + { torch::Tensor vd; std::tuple d_v(this->d_tensor[inl], vd); // d_v = torch::symeig(pdm_tensor[inl], /*eigenvalues=*/true, @@ -84,15 +96,19 @@ void LCAO_Deepks::cal_descriptor(const int nat) { return; } -void LCAO_Deepks::check_descriptor(const UnitCell& ucell) { + +void LCAO_Deepks::check_descriptor(const UnitCell& ucell, const std::string& out_dir) { ModuleBase::TITLE("LCAO_Deepks", "check_descriptor"); if (GlobalV::MY_RANK != 0) { return; } + + // mohan updated 2024-07-25 + std::string file = out_dir + "deepks_desc.dat"; - std::ofstream ofs("descriptor.dat"); + std::ofstream ofs(file.c_str()); ofs << std::setprecision(10); if (!GlobalV::deepks_equiv) { diff --git a/tests/deepks/602_NO_deepks_d_H2O_md_lda2pbe/INPUT b/tests/deepks/602_NO_deepks_d_H2O_md_lda2pbe/INPUT index 267a4867b9..34b2a93c3f 100644 --- a/tests/deepks/602_NO_deepks_d_H2O_md_lda2pbe/INPUT +++ b/tests/deepks/602_NO_deepks_d_H2O_md_lda2pbe/INPUT @@ -29,10 +29,10 @@ mixing_beta 0.4 #Parameters (6.File) deepks_out_labels 1 -deepks_scf 1 -deepks_model ../Model_ProjOrb/model_lda_pbe_18.ptg -cal_force 1 -cal_stress 1 +deepks_scf 1 +deepks_model ../Model_ProjOrb/model_lda_pbe_18.ptg +cal_force 1 +cal_stress 1 md_type nvt md_nstep 3 diff --git a/tests/deepks/602_NO_deepks_d_H2O_md_lda2pbe/get_dm_eig.py b/tests/deepks/602_NO_deepks_d_H2O_md_lda2pbe/get_dm_eig.py index 418c658dee..8bdf34720f 100644 --- a/tests/deepks/602_NO_deepks_d_H2O_md_lda2pbe/get_dm_eig.py +++ b/tests/deepks/602_NO_deepks_d_H2O_md_lda2pbe/get_dm_eig.py @@ -1,5 +1,5 @@ import numpy a=numpy.load('dm_eig.npy') -b=numpy.load('e_tot.npy') -c=numpy.load('e_base.npy') +b=numpy.load('OUT.autotest/deepks_etot.npy') +c=numpy.load('OUT.autotest/deepks_ebase.npy') print(numpy.sum(numpy.absolute(a))+numpy.sum(b)+numpy.sum(c)) diff --git a/tests/deepks/602_NO_deepks_d_H2O_md_lda2pbe/get_grad_vepsl.py b/tests/deepks/602_NO_deepks_d_H2O_md_lda2pbe/get_grad_vepsl.py index e6d1fccc40..b641f72929 100644 --- a/tests/deepks/602_NO_deepks_d_H2O_md_lda2pbe/get_grad_vepsl.py +++ b/tests/deepks/602_NO_deepks_d_H2O_md_lda2pbe/get_grad_vepsl.py @@ -1,5 +1,5 @@ import numpy -a=numpy.load('grad_vepsl.npy') -b=numpy.load('s_tot.npy') -c=numpy.load('s_base.npy') +a=numpy.load('OUT.autotest/deepks_gvepsl.npy') +b=numpy.load('OUT.autotest/deepks_stot.npy') +c=numpy.load('OUT.autotest/deepks_sbase.npy') print(numpy.sum(numpy.absolute(a))+numpy.sum(numpy.absolute(b))+numpy.sum(numpy.absolute(c))) diff --git a/tests/deepks/602_NO_deepks_d_H2O_md_lda2pbe/get_grad_vx.py b/tests/deepks/602_NO_deepks_d_H2O_md_lda2pbe/get_grad_vx.py index 1cbc2f36a0..de48ae9fcd 100644 --- a/tests/deepks/602_NO_deepks_d_H2O_md_lda2pbe/get_grad_vx.py +++ b/tests/deepks/602_NO_deepks_d_H2O_md_lda2pbe/get_grad_vx.py @@ -1,5 +1,5 @@ import numpy -a=numpy.load('grad_vx.npy') -b=numpy.load('f_tot.npy') -c=numpy.load('f_base.npy') +a=numpy.load('OUT.autotest/deepks_gradvx.npy') +b=numpy.load('OUT.autotest/deepks_ftot.npy') +c=numpy.load('OUT.autotest/deepks_fbase.npy') print(numpy.sum(numpy.absolute(a))+numpy.sum(numpy.absolute(b))+numpy.sum(numpy.absolute(c))) diff --git a/tests/deepks/602_NO_deepks_d_H2O_scf_lda2pbe/get_dm_eig.py b/tests/deepks/602_NO_deepks_d_H2O_scf_lda2pbe/get_dm_eig.py index 418c658dee..8bdf34720f 100644 --- a/tests/deepks/602_NO_deepks_d_H2O_scf_lda2pbe/get_dm_eig.py +++ b/tests/deepks/602_NO_deepks_d_H2O_scf_lda2pbe/get_dm_eig.py @@ -1,5 +1,5 @@ import numpy a=numpy.load('dm_eig.npy') -b=numpy.load('e_tot.npy') -c=numpy.load('e_base.npy') +b=numpy.load('OUT.autotest/deepks_etot.npy') +c=numpy.load('OUT.autotest/deepks_ebase.npy') print(numpy.sum(numpy.absolute(a))+numpy.sum(b)+numpy.sum(c)) diff --git a/tests/deepks/602_NO_deepks_d_H2O_scf_lda2pbe/get_grad_vepsl.py b/tests/deepks/602_NO_deepks_d_H2O_scf_lda2pbe/get_grad_vepsl.py index e6d1fccc40..b641f72929 100644 --- a/tests/deepks/602_NO_deepks_d_H2O_scf_lda2pbe/get_grad_vepsl.py +++ b/tests/deepks/602_NO_deepks_d_H2O_scf_lda2pbe/get_grad_vepsl.py @@ -1,5 +1,5 @@ import numpy -a=numpy.load('grad_vepsl.npy') -b=numpy.load('s_tot.npy') -c=numpy.load('s_base.npy') +a=numpy.load('OUT.autotest/deepks_gvepsl.npy') +b=numpy.load('OUT.autotest/deepks_stot.npy') +c=numpy.load('OUT.autotest/deepks_sbase.npy') print(numpy.sum(numpy.absolute(a))+numpy.sum(numpy.absolute(b))+numpy.sum(numpy.absolute(c))) diff --git a/tests/deepks/602_NO_deepks_d_H2O_scf_lda2pbe/get_grad_vx.py b/tests/deepks/602_NO_deepks_d_H2O_scf_lda2pbe/get_grad_vx.py index 1cbc2f36a0..de48ae9fcd 100644 --- a/tests/deepks/602_NO_deepks_d_H2O_scf_lda2pbe/get_grad_vx.py +++ b/tests/deepks/602_NO_deepks_d_H2O_scf_lda2pbe/get_grad_vx.py @@ -1,5 +1,5 @@ import numpy -a=numpy.load('grad_vx.npy') -b=numpy.load('f_tot.npy') -c=numpy.load('f_base.npy') +a=numpy.load('OUT.autotest/deepks_gradvx.npy') +b=numpy.load('OUT.autotest/deepks_ftot.npy') +c=numpy.load('OUT.autotest/deepks_fbase.npy') print(numpy.sum(numpy.absolute(a))+numpy.sum(numpy.absolute(b))+numpy.sum(numpy.absolute(c))) diff --git a/tests/deepks/603_NO_deepks_CH4/INPUT b/tests/deepks/603_NO_deepks_CH4/INPUT index 88c140b038..a6aea75fb6 100644 --- a/tests/deepks/603_NO_deepks_CH4/INPUT +++ b/tests/deepks/603_NO_deepks_CH4/INPUT @@ -10,9 +10,9 @@ pseudo_dir ../../PP_ORB orbital_dir ../../PP_ORB #Parameters (2.Iteration) -ecutwfc 50 -scf_thr 1e-8 -scf_nmax 50 +ecutwfc 20 +scf_thr 1e-7 +scf_nmax 50 #Parameters (3.Basis) basis_type lcao diff --git a/tests/deepks/603_NO_deepks_CH4/STRU b/tests/deepks/603_NO_deepks_CH4/STRU index 86e5331ebd..25696cb70c 100644 --- a/tests/deepks/603_NO_deepks_CH4/STRU +++ b/tests/deepks/603_NO_deepks_CH4/STRU @@ -10,7 +10,7 @@ NUMERICAL_DESCRIPTOR ../Model_ProjOrb/6au_50Ry_jle.orb LATTICE_CONSTANT -47.24314972 #Lattice constant +20 #Lattice constant LATTICE_VECTORS 1 0 0 diff --git a/tests/deepks/603_NO_deepks_CH4/result.ref b/tests/deepks/603_NO_deepks_CH4/result.ref index c677595f2b..6d918bafdb 100644 --- a/tests/deepks/603_NO_deepks_CH4/result.ref +++ b/tests/deepks/603_NO_deepks_CH4/result.ref @@ -1,4 +1,4 @@ -etotref -218.6306615759586 -etotperatomref -43.7261323152 -totalforceref 31.955731 -totaltimeref 11.539 +etotref -69.48662943248219 +etotperatomref -13.8973258865 +totalforceref 1495.193380 +totaltimeref 4.31 diff --git a/tests/deepks/603_NO_deepks_H2O_bandgap/get_dm_eig.py b/tests/deepks/603_NO_deepks_H2O_bandgap/get_dm_eig.py index 418c658dee..8bdf34720f 100644 --- a/tests/deepks/603_NO_deepks_H2O_bandgap/get_dm_eig.py +++ b/tests/deepks/603_NO_deepks_H2O_bandgap/get_dm_eig.py @@ -1,5 +1,5 @@ import numpy a=numpy.load('dm_eig.npy') -b=numpy.load('e_tot.npy') -c=numpy.load('e_base.npy') +b=numpy.load('OUT.autotest/deepks_etot.npy') +c=numpy.load('OUT.autotest/deepks_ebase.npy') print(numpy.sum(numpy.absolute(a))+numpy.sum(b)+numpy.sum(c)) diff --git a/tests/deepks/603_NO_deepks_H2O_bandgap/get_odelta.py b/tests/deepks/603_NO_deepks_H2O_bandgap/get_odelta.py index 10a2b6f633..c37f9aee2a 100644 --- a/tests/deepks/603_NO_deepks_H2O_bandgap/get_odelta.py +++ b/tests/deepks/603_NO_deepks_H2O_bandgap/get_odelta.py @@ -1,4 +1,4 @@ import numpy -a=numpy.load('o_tot.npy') -b=numpy.load('o_base.npy') +a=numpy.load('OUT.autotest/deepks_otot.npy') +b=numpy.load('OUT.autotest/deepks_obase.npy') print((a-b)[0][0]) diff --git a/tests/deepks/603_NO_deepks_H2O_bandgap/get_oprec.py b/tests/deepks/603_NO_deepks_H2O_bandgap/get_oprec.py index 1eac41dcdf..3b59699e0d 100644 --- a/tests/deepks/603_NO_deepks_H2O_bandgap/get_oprec.py +++ b/tests/deepks/603_NO_deepks_H2O_bandgap/get_oprec.py @@ -1,3 +1,3 @@ import numpy -a=numpy.load('orbital_precalc.npy') +a=numpy.load('OUT.autotest/deepks_orbpre.npy') print(numpy.sum(a)) diff --git a/tests/deepks/603_NO_deepks_H2O_v_delta_1/get_dm_eig.py b/tests/deepks/603_NO_deepks_H2O_v_delta_1/get_dm_eig.py index 418c658dee..8bdf34720f 100644 --- a/tests/deepks/603_NO_deepks_H2O_v_delta_1/get_dm_eig.py +++ b/tests/deepks/603_NO_deepks_H2O_v_delta_1/get_dm_eig.py @@ -1,5 +1,5 @@ import numpy a=numpy.load('dm_eig.npy') -b=numpy.load('e_tot.npy') -c=numpy.load('e_base.npy') +b=numpy.load('OUT.autotest/deepks_etot.npy') +c=numpy.load('OUT.autotest/deepks_ebase.npy') print(numpy.sum(numpy.absolute(a))+numpy.sum(b)+numpy.sum(c)) diff --git a/tests/deepks/603_NO_deepks_H2O_v_delta_1/get_v_delta.py b/tests/deepks/603_NO_deepks_H2O_v_delta_1/get_v_delta.py index c25f7d2ec9..a55cc53f1a 100644 --- a/tests/deepks/603_NO_deepks_H2O_v_delta_1/get_v_delta.py +++ b/tests/deepks/603_NO_deepks_H2O_v_delta_1/get_v_delta.py @@ -1,4 +1,4 @@ import numpy -a=numpy.load('h_tot.npy') -b=numpy.load('h_base.npy') +a=numpy.load('OUT.autotest/deepks_htot.npy') +b=numpy.load('OUT.autotest/deepks_hbase.npy') print(numpy.sum(a-b)) diff --git a/tests/deepks/603_NO_deepks_H2O_v_delta_2/get_dm_eig.py b/tests/deepks/603_NO_deepks_H2O_v_delta_2/get_dm_eig.py index 418c658dee..8bdf34720f 100644 --- a/tests/deepks/603_NO_deepks_H2O_v_delta_2/get_dm_eig.py +++ b/tests/deepks/603_NO_deepks_H2O_v_delta_2/get_dm_eig.py @@ -1,5 +1,5 @@ import numpy a=numpy.load('dm_eig.npy') -b=numpy.load('e_tot.npy') -c=numpy.load('e_base.npy') +b=numpy.load('OUT.autotest/deepks_etot.npy') +c=numpy.load('OUT.autotest/deepks_ebase.npy') print(numpy.sum(numpy.absolute(a))+numpy.sum(b)+numpy.sum(c)) diff --git a/tests/deepks/603_NO_deepks_H2O_v_delta_2/get_v_delta.py b/tests/deepks/603_NO_deepks_H2O_v_delta_2/get_v_delta.py index c25f7d2ec9..a55cc53f1a 100644 --- a/tests/deepks/603_NO_deepks_H2O_v_delta_2/get_v_delta.py +++ b/tests/deepks/603_NO_deepks_H2O_v_delta_2/get_v_delta.py @@ -1,4 +1,4 @@ import numpy -a=numpy.load('h_tot.npy') -b=numpy.load('h_base.npy') +a=numpy.load('OUT.autotest/deepks_htot.npy') +b=numpy.load('OUT.autotest/deepks_hbase.npy') print(numpy.sum(a-b)) diff --git a/tests/deepks/603_NO_deepks_SiO2_bandgap_multik/get_dm_eig.py b/tests/deepks/603_NO_deepks_SiO2_bandgap_multik/get_dm_eig.py index 418c658dee..8bdf34720f 100644 --- a/tests/deepks/603_NO_deepks_SiO2_bandgap_multik/get_dm_eig.py +++ b/tests/deepks/603_NO_deepks_SiO2_bandgap_multik/get_dm_eig.py @@ -1,5 +1,5 @@ import numpy a=numpy.load('dm_eig.npy') -b=numpy.load('e_tot.npy') -c=numpy.load('e_base.npy') +b=numpy.load('OUT.autotest/deepks_etot.npy') +c=numpy.load('OUT.autotest/deepks_ebase.npy') print(numpy.sum(numpy.absolute(a))+numpy.sum(b)+numpy.sum(c)) diff --git a/tests/deepks/603_NO_deepks_SiO2_bandgap_multik/get_grad_vepsl.py b/tests/deepks/603_NO_deepks_SiO2_bandgap_multik/get_grad_vepsl.py index e6d1fccc40..b641f72929 100644 --- a/tests/deepks/603_NO_deepks_SiO2_bandgap_multik/get_grad_vepsl.py +++ b/tests/deepks/603_NO_deepks_SiO2_bandgap_multik/get_grad_vepsl.py @@ -1,5 +1,5 @@ import numpy -a=numpy.load('grad_vepsl.npy') -b=numpy.load('s_tot.npy') -c=numpy.load('s_base.npy') +a=numpy.load('OUT.autotest/deepks_gvepsl.npy') +b=numpy.load('OUT.autotest/deepks_stot.npy') +c=numpy.load('OUT.autotest/deepks_sbase.npy') print(numpy.sum(numpy.absolute(a))+numpy.sum(numpy.absolute(b))+numpy.sum(numpy.absolute(c))) diff --git a/tests/deepks/603_NO_deepks_SiO2_bandgap_multik/get_grad_vx.py b/tests/deepks/603_NO_deepks_SiO2_bandgap_multik/get_grad_vx.py index 1cbc2f36a0..de48ae9fcd 100644 --- a/tests/deepks/603_NO_deepks_SiO2_bandgap_multik/get_grad_vx.py +++ b/tests/deepks/603_NO_deepks_SiO2_bandgap_multik/get_grad_vx.py @@ -1,5 +1,5 @@ import numpy -a=numpy.load('grad_vx.npy') -b=numpy.load('f_tot.npy') -c=numpy.load('f_base.npy') +a=numpy.load('OUT.autotest/deepks_gradvx.npy') +b=numpy.load('OUT.autotest/deepks_ftot.npy') +c=numpy.load('OUT.autotest/deepks_fbase.npy') print(numpy.sum(numpy.absolute(a))+numpy.sum(numpy.absolute(b))+numpy.sum(numpy.absolute(c))) diff --git a/tests/deepks/603_NO_deepks_SiO2_bandgap_multik/get_odelta.py b/tests/deepks/603_NO_deepks_SiO2_bandgap_multik/get_odelta.py index 10a2b6f633..c37f9aee2a 100644 --- a/tests/deepks/603_NO_deepks_SiO2_bandgap_multik/get_odelta.py +++ b/tests/deepks/603_NO_deepks_SiO2_bandgap_multik/get_odelta.py @@ -1,4 +1,4 @@ import numpy -a=numpy.load('o_tot.npy') -b=numpy.load('o_base.npy') +a=numpy.load('OUT.autotest/deepks_otot.npy') +b=numpy.load('OUT.autotest/deepks_obase.npy') print((a-b)[0][0]) diff --git a/tests/deepks/603_NO_deepks_SiO2_bandgap_multik/get_oprec.py b/tests/deepks/603_NO_deepks_SiO2_bandgap_multik/get_oprec.py index 1eac41dcdf..3b59699e0d 100644 --- a/tests/deepks/603_NO_deepks_SiO2_bandgap_multik/get_oprec.py +++ b/tests/deepks/603_NO_deepks_SiO2_bandgap_multik/get_oprec.py @@ -1,3 +1,3 @@ import numpy -a=numpy.load('orbital_precalc.npy') +a=numpy.load('OUT.autotest/deepks_orbpre.npy') print(numpy.sum(a)) diff --git a/tests/deepks/Autotest1.sh b/tests/deepks/Autotest1.sh old mode 100644 new mode 100755 diff --git a/tests/deepks/clean.sh b/tests/deepks/clean.sh index ff4f8510b7..0524c2e600 100755 --- a/tests/deepks/clean.sh +++ b/tests/deepks/clean.sh @@ -24,37 +24,16 @@ for directory in `ls | grep $module`; do # delete OUT.autotest (if it exists) #-------------------------------------------- OUT_directory="$directory/OUT.autotest" - #test -e "$OUT_directory" && echo $OUT_directory test -e "$OUT_directory" && rm -rf $OUT_directory - #-------------------------------------------- - # delete descriptor.dat (if it exists) - #-------------------------------------------- - descriptor="$directory/descriptor.dat" - test -e "$descriptor" && rm -rf $descriptor - - #-------------------------------------------- - # delete H_V_delta.dat (if it exists) - #-------------------------------------------- - H_V_delta="$directory/H_V_delta.dat" - test -e "$H_V_delta" && rm -rf $H_V_delta - #-------------------------------------------- # delete projected_DM.dat (if it exists) #-------------------------------------------- projected_DM="$directory/projected_DM.dat" test -e "$projected_DM" && rm -rf $projected_DM - #-------------------------------------------- - # delete *.npy (if it exists) - #-------------------------------------------- - num=$(find -name '*.npy' | wc -l) - if [ $num != "0" ]; then - rm -rf $directory/*.npy - fi - done done -test -e "check_file" && rm -rf check_file \ No newline at end of file +test -e "check_file" && rm -rf check_file diff --git a/tests/integrate/clean.sh b/tests/integrate/clean.sh index baf568eed1..05e2953de3 100755 --- a/tests/integrate/clean.sh +++ b/tests/integrate/clean.sh @@ -40,18 +40,6 @@ for directory in `ls | grep $module`; do #test -e "$time_json" && echo $time_json test -e "$time_json" && rm $time_json - #-------------------------------------------- - # delete descriptor.dat (if it exists) - #-------------------------------------------- - descriptor="$directory/descriptor.dat" - test -e "$descriptor" && rm -rf $descriptor - - #-------------------------------------------- - # delete H_V_delta.dat (if it exists) - #-------------------------------------------- - H_V_delta="$directory/H_V_delta.dat" - test -e "$H_V_delta" && rm -rf $H_V_delta - #-------------------------------------------- # delete projected_DM.dat (if it exists) #-------------------------------------------- diff --git a/tests/integrate/tools/catch_properties.sh b/tests/integrate/tools/catch_properties.sh index cb9ca4695a..1951cba05c 100755 --- a/tests/integrate/tools/catch_properties.sh +++ b/tests/integrate/tools/catch_properties.sh @@ -445,7 +445,7 @@ if ! test -z "$run_rpa" && [ $run_rpa == 1 ]; then fi if ! test -z "$deepks_out_labels" && [ $deepks_out_labels == 1 ]; then - sed '/n_des/d' descriptor.dat > des_tmp.txt + sed '/n_des/d' OUT.autotest/deepks_desc.dat > des_tmp.txt total_des=`sum_file des_tmp.txt 5` rm des_tmp.txt echo "totaldes $total_des" >>$1 @@ -471,7 +471,7 @@ if ! test -z "$deepks_bandgap" && [ $deepks_bandgap == 1 ]; then fi if ! test -z "$deepks_v_delta" && [ $deepks_v_delta == 1 ]; then - totalh=`python3 get_sum_numpy.py h_tot.npy ` + totalh=`python3 get_sum_numpy.py OUT.autotest/deepks_htot.npy ` echo "totalh $totalh" >>$1 totalvdelta=`python3 get_v_delta.py` echo "totalvdelta $totalvdelta" >>$1 @@ -480,7 +480,7 @@ if ! test -z "$deepks_v_delta" && [ $deepks_v_delta == 1 ]; then fi if ! test -z "$deepks_v_delta" && [ $deepks_v_delta == 2 ]; then - totalh=`python3 get_sum_numpy.py h_tot.npy ` + totalh=`python3 get_sum_numpy.py OUT.autotest/deepks_htot.npy ` echo "totalh $totalh" >>$1 totalvdelta=`python3 get_v_delta.py` echo "totalvdelta $totalvdelta" >>$1