Skip to content

Commit 757bb58

Browse files
authored
Update DeePKS and do some reconstructions (#6576)
* update DFT-1/2 INPUT file * update deepks using Setup_DeePKS class * add write_stress in setup_deepks.h * reduce one more #ifdefine MLALGO in ctrl_iter_lcao * add build_overlap in setup_deepks.h * update build_overlap in Setup_DeePKS class * update arrays of force and stress * remove some MLALGO * update pulay_fs files
1 parent 57ea55d commit 757bb58

23 files changed

+417
-587
lines changed

source/Makefile.Objects

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ OBJS_LCAO=evolve_elec.o\
655655
FORCE_k.o\
656656
stress_tools.o\
657657
edm.o\
658-
pulay_force_stress_center2.o\
658+
pulay_fs_center2.o\
659659
grid_init.o\
660660
spar_dh.o\
661661
spar_exx.o\

source/source_basis/module_nao/two_center_bundle.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef W_ABACUS_DEVELOP_ABACUS_DEVELOP_SOURCE_MODULE_BASIS_MODULE_NAO_TWO_CENTER_BUNDLE_H
2-
#define W_ABACUS_DEVELOP_ABACUS_DEVELOP_SOURCE_MODULE_BASIS_MODULE_NAO_TWO_CENTER_BUNDLE_H
1+
#ifndef TWO_CENTER_BUNDLE_H
2+
#define TWO_CENTER_BUNDLE_H
33

44
#include "source_basis/module_ao/ORB_read.h"
55
#include "source_basis/module_nao/two_center_integrator.h"

source/source_esolver/esolver_double_xc.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include "source_lcao/module_deepks/LCAO_deepks.h"
77
#include "source_lcao/module_deepks/LCAO_deepks_interface.h"
88
#endif
9-
//-----force& stress-------------------
109
#include "source_lcao/FORCE_STRESS.h"
1110

1211
//-----HSolver ElecState Hamilt--------
@@ -16,6 +15,7 @@
1615
#include "source_hsolver/hsolver_lcao.h"
1716
#include "source_io/module_parameter/parameter.h"
1817
#include "source_io/write_HS.h" // use ModuleIO::write_hsk()
18+
#include "source_lcao/setup_deepks.h" // use deepks, mohan add 2025-10-10
1919

2020
namespace ModuleESolver
2121
{
@@ -388,6 +388,8 @@ void ESolver_DoubleXC<TK, TR>::cal_force(UnitCell& ucell, ModuleBase::matrix& fo
388388
// set as base functional Temporarily
389389
XC_Functional::set_xc_type(PARAM.inp.deepks_out_base);
390390

391+
this->deepks.dpks_out_type = "base"; // for deepks method
392+
391393
fsl.getForceStress(ucell,
392394
PARAM.inp.cal_force,
393395
PARAM.inp.cal_stress,
@@ -408,12 +410,10 @@ void ESolver_DoubleXC<TK, TR>::cal_force(UnitCell& ucell, ModuleBase::matrix& fo
408410
this->kv,
409411
this->pw_rho,
410412
this->solvent,
411-
#ifdef __MLALGO
412-
this->deepks.ld,
413-
"base",
414-
#endif
413+
this->deepks,
415414
this->exx_nao,
416415
&ucell.symm);
416+
417417
// restore to original xc
418418
XC_Functional::set_xc_type(ucell.atoms[0].ncpp.xc_func);
419419

source/source_esolver/esolver_ks_lcao.cpp

Lines changed: 5 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77
#include "source_estate/module_charge/symmetry_rho.h"
88
#include "source_lcao/LCAO_domain.h" // need DeePKS_init
99
#include "source_lcao/module_dftu/dftu.h"
10-
#ifdef __MLALGO
11-
#include "source_lcao/module_deepks/LCAO_deepks.h"
12-
#include "source_lcao/module_deepks/LCAO_deepks_interface.h"
13-
#endif
1410
#include "source_lcao/FORCE_STRESS.h"
1511
#include "source_estate/elecstate_lcao.h"
1612
#include "source_lcao/hamilt_lcao.h"
@@ -203,6 +199,8 @@ void ESolver_KS_LCAO<TK, TR>::cal_force(UnitCell& ucell, ModuleBase::matrix& for
203199

204200
Force_Stress_LCAO<TK> fsl(this->RA, ucell.nat);
205201

202+
deepks.dpks_out_type = "tot"; // for deepks method
203+
206204
fsl.getForceStress(ucell,
207205
PARAM.inp.cal_force,
208206
PARAM.inp.cal_stress,
@@ -223,10 +221,7 @@ void ESolver_KS_LCAO<TK, TR>::cal_force(UnitCell& ucell, ModuleBase::matrix& for
223221
this->kv,
224222
this->pw_rho,
225223
this->solvent,
226-
#ifdef __MLALGO
227-
this->deepks.ld,
228-
"tot",
229-
#endif
224+
this->deepks,
230225
this->exx_nao,
231226
&ucell.symm);
232227

@@ -337,43 +332,6 @@ void ESolver_KS_LCAO<TK, TR>::iter_init(UnitCell& ucell, const int istep, const
337332
}
338333
#endif
339334
elecstate::setup_dm<TK>(ucell, estate, this->psi, this->chr, iter, exx_two_level_step);
340-
341-
/*
342-
if (iter == 1 && exx_two_level_step == 0)
343-
{
344-
std::cout << " WAVEFUN -> CHARGE " << std::endl;
345-
346-
// calculate the density matrix using read in wave functions
347-
// and then calculate the charge density on grid.
348-
349-
estate->skip_weights = true;
350-
elecstate::calculate_weights(estate->ekb,
351-
estate->wg,
352-
estate->klist,
353-
estate->eferm,
354-
estate->f_en,
355-
estate->nelec_spin,
356-
estate->skip_weights);
357-
358-
elecstate::calEBand(estate->ekb, estate->wg, estate->f_en);
359-
elecstate::cal_dm_psi(estate->DM->get_paraV_pointer(), estate->wg, *this->psi, *(estate->DM));
360-
estate->DM->cal_DMR();
361-
362-
estate->psiToRho(*this->psi);
363-
estate->skip_weights = false;
364-
365-
elecstate::cal_ux(ucell);
366-
367-
//! update the potentials by using new electron charge density
368-
estate->pot->update_from_charge(&this->chr, &ucell);
369-
370-
//! compute the correction energy for metals
371-
estate->f_en.descf = estate->cal_delta_escf();
372-
}
373-
374-
*/
375-
376-
377335
}
378336

379337
#ifdef __EXX
@@ -410,11 +368,6 @@ void ESolver_KS_LCAO<TK, TR>::iter_init(UnitCell& ucell, const int istep, const
410368
{
411369
this->p_hamilt->refresh();
412370
}
413-
// if (iter == 1 && istep == 0)
414-
// {
415-
// // initialize DMR
416-
// this->deepks.ld.init_DMR(ucell, orb_, this->pv, this->gd);
417-
// }
418371
#endif
419372

420373
if (PARAM.inp.vl_in_h)
@@ -591,11 +544,8 @@ void ESolver_KS_LCAO<TK, TR>::iter_finish(UnitCell& ucell, const int istep, int&
591544
// control the output related to the finished iteration
592545
ModuleIO::ctrl_iter_lcao<TK, TR>(ucell, PARAM.inp, this->kv, estate,
593546
this->pv, this->gd, this->psi, this->chr, this->p_chgmix,
594-
hamilt_lcao, this->orb_,
595-
#ifdef __MLALGO
596-
this->deepks.ld,
597-
#endif
598-
exx_nao, iter, istep, conv_esolver, this->scf_ene_thr);
547+
hamilt_lcao, this->orb_, this->deepks,
548+
this->exx_nao, iter, istep, conv_esolver, this->scf_ene_thr);
599549

600550
}
601551

source/source_esolver/lcao_before_scf.cpp

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
#include "source_cell/module_neighbor/sltk_grid_driver.h"
77
#include "source_io/module_parameter/parameter.h"
88
#include "source_estate/elecstate_tools.h"
9-
#ifdef __MLALGO
10-
#include "source_lcao/module_deepks/LCAO_deepks.h"
11-
#endif
129
#include "source_estate/elecstate_lcao.h"
1310
#include "source_lcao/LCAO_domain.h"
1411
#include "source_lcao/module_operator_lcao/op_exx_lcao.h"
@@ -140,25 +137,10 @@ void ESolver_KS_LCAO<TK, TR>::before_scf(UnitCell& ucell, const int istep)
140137
);
141138
}
142139

143-
#ifdef __MLALGO
140+
144141
// 9) for each ionic step, the overlap <phi|alpha> must be rebuilt
145142
// since it depends on ionic positions
146-
if (PARAM.globalv.deepks_setorb)
147-
{
148-
const Parallel_Orbitals* pv = &this->pv;
149-
// allocate <phi(0)|alpha(R)>, phialpha is different every ion step, so it is allocated here
150-
DeePKS_domain::allocate_phialpha(PARAM.inp.cal_force, ucell, orb_, this->gd, pv, this->deepks.ld.phialpha);
151-
// build and save <phi(0)|alpha(R)> at beginning
152-
DeePKS_domain::build_phialpha(PARAM.inp.cal_force, ucell, orb_, this->gd,
153-
pv, *(two_center_bundle_.overlap_orb_alpha), this->deepks.ld.phialpha);
154-
155-
if (PARAM.inp.deepks_out_unittest)
156-
{
157-
DeePKS_domain::check_phialpha(PARAM.inp.cal_force, ucell, orb_,
158-
this->gd, pv, this->deepks.ld.phialpha, GlobalV::MY_RANK);
159-
}
160-
}
161-
#endif
143+
this->deepks.build_overlap(ucell, orb_, pv, gd, *(two_center_bundle_.overlap_orb_alpha), PARAM.inp);
162144

163145
// 10) prepare sc calculation
164146
if (PARAM.inp.sc_mag_switch)

source/source_esolver/lcao_others.cpp

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
#include "source_base/timer.h"
1616
#include "source_cell/module_neighbor/sltk_atom_arrange.h"
1717
#include "source_cell/module_neighbor/sltk_grid_driver.h"
18-
#ifdef __MLALGO
19-
#include "source_lcao/module_deepks/LCAO_deepks.h"
20-
#endif
2118
#include "source_lcao/LCAO_domain.h"
2219
#include "source_lcao/module_operator_lcao/op_exx_lcao.h"
2320
#include "source_lcao/module_operator_lcao/operator_lcao.h"
@@ -242,35 +239,11 @@ void ESolver_KS_LCAO<TK, TR>::others(UnitCell& ucell, const int istep)
242239
);
243240
}
244241

245-
#ifdef __MLALGO
242+
246243
// for each ionic step, the overlap <phi|alpha> must be rebuilt
247244
// since it depends on ionic positions
248-
if (PARAM.globalv.deepks_setorb)
249-
{
250-
const Parallel_Orbitals* pv = &this->pv;
251-
// allocate <phi(0)|alpha(R)>, phialpha is different every ion step, so it is allocated here
252-
DeePKS_domain::allocate_phialpha(PARAM.inp.cal_force, ucell, orb_, this->gd, pv, this->deepks.ld.phialpha);
253-
// build and save <phi(0)|alpha(R)> at beginning
254-
DeePKS_domain::build_phialpha(PARAM.inp.cal_force,
255-
ucell,
256-
orb_,
257-
this->gd,
258-
pv,
259-
*(two_center_bundle_.overlap_orb_alpha),
260-
this->deepks.ld.phialpha);
245+
this->deepks.build_overlap(ucell, orb_, pv, gd, *(two_center_bundle_.overlap_orb_alpha), PARAM.inp);
261246

262-
if (PARAM.inp.deepks_out_unittest)
263-
{
264-
DeePKS_domain::check_phialpha(PARAM.inp.cal_force,
265-
ucell,
266-
orb_,
267-
this->gd,
268-
pv,
269-
this->deepks.ld.phialpha,
270-
GlobalV::MY_RANK);
271-
}
272-
}
273-
#endif
274247
if (PARAM.inp.sc_mag_switch)
275248
{
276249
spinconstrain::SpinConstrain<TK>& sc = spinconstrain::SpinConstrain<TK>::getScInstance();

source/source_io/berryphase.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#ifdef __LCAO
55
#include "unk_overlap_lcao.h"
66
#endif
7-
//#include "source_basis/module_pw/pw_basis.h"
87
#include "source_basis/module_pw/pw_basis_k.h"
98
#include "source_cell/klist.h"
109
#include "source_psi/psi.h"

source/source_io/ctrl_iter_lcao.cpp

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ void ctrl_iter_lcao(UnitCell& ucell, // unit cell *
2121
Charge_Mixing* p_chgmix, // charge mixing *
2222
hamilt::HamiltLCAO<TK, TR>* p_hamilt, // hamiltonian *
2323
LCAO_Orbitals &orb, // orbital info *
24-
#ifdef __MLALGO
25-
LCAO_Deepks<TK>& ld,
26-
#endif
24+
Setup_DeePKS<TK> &deepks,
2725
Exx_NAO<TK> &exx_nao,
2826
int &iter,
2927
const int istep,
@@ -65,7 +63,7 @@ void ctrl_iter_lcao(UnitCell& ucell, // unit cell *
6563
{
6664
if (iter % inp.deepks_out_freq_elec == 0 )
6765
{
68-
std::shared_ptr<LCAO_Deepks<TK>> ld_shared_ptr(&ld, [](LCAO_Deepks<TK>*) {});
66+
std::shared_ptr<LCAO_Deepks<TK>> ld_shared_ptr(&deepks.ld, [](LCAO_Deepks<TK>*) {});
6967
LCAO_Deepks_Interface<TK, TR> deepks_interface(ld_shared_ptr);
7068

7169
deepks_interface.out_deepks_labels(pelec->f_en.etot, kv.get_nks(),
@@ -91,9 +89,7 @@ template void ctrl_iter_lcao<double, double>(UnitCell& ucell, // unit cell *
9189
Charge_Mixing* p_chgmix, // charge mixing *
9290
hamilt::HamiltLCAO<double, double>* p_hamilt, // hamiltonian *
9391
LCAO_Orbitals &orb, // orbital info *
94-
#ifdef __MLALGO
95-
LCAO_Deepks<double>& ld,
96-
#endif
92+
Setup_DeePKS<double> &deepks,
9793
Exx_NAO<double> &exx_nao,
9894
int &iter,
9995
const int istep,
@@ -112,9 +108,7 @@ template void ctrl_iter_lcao<std::complex<double>, double>(UnitCell& ucell, // u
112108
Charge_Mixing* p_chgmix, // charge mixing *
113109
hamilt::HamiltLCAO<std::complex<double>, double>* p_hamilt, // hamiltonian *
114110
LCAO_Orbitals &orb, // orbital info *
115-
#ifdef __MLALGO
116-
LCAO_Deepks<std::complex<double>>& ld,
117-
#endif
111+
Setup_DeePKS<std::complex<double>> &deepks,
118112
Exx_NAO<std::complex<double>> &exx_nao,
119113
int &iter,
120114
const int istep,
@@ -133,9 +127,7 @@ template void ctrl_iter_lcao<std::complex<double>, std::complex<double>>(UnitCel
133127
Charge_Mixing* p_chgmix, // charge mixing *
134128
hamilt::HamiltLCAO<std::complex<double>, std::complex<double>>* p_hamilt, // hamiltonian *
135129
LCAO_Orbitals &orb, // orbital info *
136-
#ifdef __MLALGO
137-
LCAO_Deepks<std::complex<double>>& ld,
138-
#endif
130+
Setup_DeePKS<std::complex<double>> &deepks,
139131
Exx_NAO<std::complex<double>> &exx_nao,
140132
int &iter,
141133
const int istep,

source/source_io/ctrl_iter_lcao.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "source_estate/module_charge/charge_mixing.h" // use charge mixing
1010
#include "source_lcao/hamilt_lcao.h" // use hamilt::HamiltLCAO<TK, TR>
1111
#include "source_lcao/setup_exx.h" // mohan add 20251008
12+
#include "source_lcao/setup_deepks.h" // mohan add 20251010
1213

1314
namespace ModuleIO
1415
{
@@ -25,9 +26,7 @@ void ctrl_iter_lcao(UnitCell& ucell, // unit cell *
2526
Charge_Mixing* p_chgmix, // charge mixing *
2627
hamilt::HamiltLCAO<TK, TR>* p_hamilt, // hamiltonian *
2728
LCAO_Orbitals &orb, // orbital info *
28-
#ifdef __MLALGO
29-
LCAO_Deepks<TK>& ld,
30-
#endif
29+
Setup_DeePKS<TK> &deepks,
3130
Exx_NAO<TK> &exx_nao,
3231
int &iter,
3332
const int istep,

source/source_lcao/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ if(ENABLE_LCAO)
2222
module_operator_lcao/td_pot_hybrid.cpp
2323
module_operator_lcao/dspin_lcao.cpp
2424
module_operator_lcao/dftu_lcao.cpp
25-
pulay_force_stress_center2.cpp
25+
pulay_fs_center2.cpp
2626
FORCE_STRESS.cpp
2727
FORCE_gamma.cpp
2828
FORCE_k.cpp

0 commit comments

Comments
 (0)