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: DeePKS MD calculation restart by DMK and fixed the lack of DeePKS tests #4605

Merged
merged 10 commits into from
Jul 19, 2024
10 changes: 4 additions & 6 deletions source/module_esolver/esolver_ks_lcao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ void ESolver_KS_LCAO<TK, TR>::before_all_runners(const Input_para& inp, UnitCell
//------------------init Basis_lcao----------------------

// 5) initialize density matrix
// DensityMatrix is allocated here, DMK is also initialized here
// DMR is not initialized here, it will be constructed in each before_scf
dynamic_cast<elecstate::ElecStateLCAO<TK>*>(this->pelec)
->init_DM(&this->kv, &(this->ParaV), GlobalV::NSPIN);

Expand Down Expand Up @@ -1315,13 +1317,9 @@ bool ESolver_KS_LCAO<TK, TR>::do_after_converge(int& iter)
// use the converged occupation matrix for next MD/Relax SCF calculation
GlobalC::dftu.initialed_locale = true;
}
// FIXME: for developer who want to test restarting DeePKS with same Descriptor/PDM in last MD step
// RUN: " GlobalC::ld.set_init_pdm(true); " can skip the calculation of PDM in the next iter_init

#ifdef __DEEPKS
if (GlobalV::deepks_scf)
{
GlobalC::ld.set_init_pdm(true);
}
#endif
#ifdef __EXX
if (GlobalC::exx_info.info_global.cal_exx)
{
Expand Down
9 changes: 9 additions & 0 deletions source/module_esolver/esolver_ks_lcao_elec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,15 @@ void ESolver_KS_LCAO<TK, TR>::before_scf(const int istep)
dynamic_cast<elecstate::ElecStateLCAO<TK>*>(this->pelec)
->get_DM()
->init_DMR(*(dynamic_cast<hamilt::HamiltLCAO<TK, TR>*>(this->p_hamilt)->getHR()));
// two cases are considered:
// 1. DMK in DensityMatrix is not empty (istep > 0), then DMR is initialized by DMK
// 2. DMK in DensityMatrix is empty (istep == 0), then DMR is initialized by zeros
if(istep > 0)
{
dynamic_cast<elecstate::ElecStateLCAO<TK>*>(this->pelec)
->get_DM()
->cal_DMR();
}

if (PARAM.inp.dm_to_rho)
{
Expand Down
42 changes: 42 additions & 0 deletions tests/deepks/602_NO_deepks_d_H2O_md_lda2pbe/INPUT
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
INPUT_PARAMETERS
#Parameters (1.General)
suffix autotest
calculation md

nbands 6
symmetry 0
pseudo_dir ../../PP_ORB
orbital_dir ../../PP_ORB

#Parameters (2.Iteration)
ecutwfc 50
scf_thr 1e-6
scf_nmax 50

#Parameters (3.Basis)
basis_type lcao
gamma_only 1
mixing_restart 1e-3
mixing_dmr 1

#Parameters (4.Smearing)
smearing_method gaussian
smearing_sigma 0.02

#Parameters (5.Mixing)
mixing_type broyden
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

md_type nvt
md_nstep 3
md_dt 1
md_tfirst 300
md_tfreq 0.025
md_tchain 1
4 changes: 4 additions & 0 deletions tests/deepks/602_NO_deepks_d_H2O_md_lda2pbe/KPT
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
K_POINTS
0
Gamma
1 1 1 0 0 0
31 changes: 31 additions & 0 deletions tests/deepks/602_NO_deepks_d_H2O_md_lda2pbe/STRU
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
ATOMIC_SPECIES
H 1.008 H_ONCV_PBE2PZ-1.0.upf
O 15.9994 O_ONCV_PBE2PZ-1.0.upf

NUMERICAL_ORBITAL
H_gga_6au_60Ry_2s1p.orb
O_gga_6au_60Ry_2s2p1d.orb

NUMERICAL_DESCRIPTOR
jle.orb

LATTICE_CONSTANT
1

LATTICE_VECTORS
28 0 0
0 28 0
0 0 28

ATOMIC_POSITIONS
Cartesian

H
0
2
-12.081531451316582 16.463368531712373 10.304287878967891 1 1 1
-12.056180479123837 19.25408045699522 10.010554611214044 1 1 1
O
0
1
-13.1930046246741 17.91132430713516 10.440289103003526 1 1 1
5 changes: 5 additions & 0 deletions tests/deepks/602_NO_deepks_d_H2O_md_lda2pbe/get_dm_eig.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import numpy
a=numpy.load('dm_eig.npy')
b=numpy.load('e_tot.npy')
c=numpy.load('e_base.npy')
print(numpy.sum(numpy.absolute(a))+numpy.sum(b)+numpy.sum(c))
5 changes: 5 additions & 0 deletions tests/deepks/602_NO_deepks_d_H2O_md_lda2pbe/get_grad_vepsl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import numpy
a=numpy.load('grad_vepsl.npy')
b=numpy.load('s_tot.npy')
c=numpy.load('s_base.npy')
print(numpy.sum(numpy.absolute(a))+numpy.sum(numpy.absolute(b))+numpy.sum(numpy.absolute(c)))
5 changes: 5 additions & 0 deletions tests/deepks/602_NO_deepks_d_H2O_md_lda2pbe/get_grad_vx.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import numpy
a=numpy.load('grad_vx.npy')
b=numpy.load('f_tot.npy')
c=numpy.load('f_base.npy')
print(numpy.sum(numpy.absolute(a))+numpy.sum(numpy.absolute(b))+numpy.sum(numpy.absolute(c)))
1 change: 1 addition & 0 deletions tests/deepks/602_NO_deepks_d_H2O_md_lda2pbe/jd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test MD calculation with deepks_scf = ture , for gamma_only H2O molecule
336 changes: 336 additions & 0 deletions tests/deepks/602_NO_deepks_d_H2O_md_lda2pbe/jle.orb

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions tests/deepks/602_NO_deepks_d_H2O_md_lda2pbe/result.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
etotref -465.998623450138
etotperatomref -155.3328744834
totalforceref 5.535421
totalstressref 1.520071
totaldes 2.163703
deepks_e_dm -57.88571808911911
deepks_f_label 19.095622987658235
deepks_s_label 19.250436793943024
totaltimeref 19.73
8 changes: 5 additions & 3 deletions tests/deepks/602_NO_deepks_d_H2O_scf_lda2pbe/result.ref
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
etotref -466.0342709734276241
etotref -466.0342709734272262
etotperatomref -155.3447569911
totalforceref 3.194893
totalstressref 1.190505
totaldes 2.319513
deepks_e_dm -57.521935318566165
totaltimeref 5.79
deepks_e_dm -57.521935314706305
deepks_f_label 19.875352737513325
deepks_s_label 19.58791026543513
totaltimeref 5.81
5 changes: 4 additions & 1 deletion tests/deepks/603_NO_deepks_H2O_bandgap/INPUT
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ INPUT_PARAMETERS
suffix autotest
calculation scf

ecutwfc 100.000000
ecutwfc 50.000000
scf_thr 5.000000e-07
scf_nmax 35
pseudo_dir ../../PP_ORB
Expand All @@ -20,3 +20,6 @@ deepks_scf 1
deepks_model model.ptg
deepks_out_labels 1
deepks_bandgap 1

mixing_restart 1e-3
mixing_dmr 1
5 changes: 5 additions & 0 deletions tests/deepks/603_NO_deepks_H2O_bandgap/get_dm_eig.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import numpy
a=numpy.load('dm_eig.npy')
b=numpy.load('e_tot.npy')
c=numpy.load('e_base.npy')
print(numpy.sum(numpy.absolute(a))+numpy.sum(b)+numpy.sum(c))
13 changes: 7 additions & 6 deletions tests/deepks/603_NO_deepks_H2O_bandgap/result.ref
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
etotref -466.8186510233240
etotperatomref -155.6062170078
totaldes 4.393002
odelta 0.051970104930806116
oprec 0.37294027391042905
totaltimeref 12.539
etotref -466.8189388994859
etotperatomref -155.6063129665
totaldes 4.392987
deepks_e_dm -49.145154045309184
odelta 0.05196672366779986
oprec 0.3729036159496012
totaltimeref 11.14
8 changes: 4 additions & 4 deletions tests/deepks/603_NO_deepks_H2O_multik/result.ref
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
etotref -466.8864070000542
etotperatomref -155.6288023334
totalforceref 9.640519
totaltimeref 10.324
etotref -466.8863937897737
etotperatomref -155.6287979299
totalforceref 9.640495
totaltimeref 5.86
5 changes: 5 additions & 0 deletions tests/deepks/603_NO_deepks_H2O_v_delta_1/get_dm_eig.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import numpy
a=numpy.load('dm_eig.npy')
b=numpy.load('e_tot.npy')
c=numpy.load('e_base.npy')
print(numpy.sum(numpy.absolute(a))+numpy.sum(b)+numpy.sum(c))
9 changes: 5 additions & 4 deletions tests/deepks/603_NO_deepks_H2O_v_delta_1/result.ref
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
etotref -466.0342709734289
etotref -466.0342709734271
etotperatomref -155.3447569911
totaldes 2.319513
totalh 27.746059584700017
totalvdelta -0.09650548509283462
deepks_e_dm -57.5219353147063
totalh 27.746059584703197
totalvdelta -0.09650548509283459
totalvdp 20.2336158456532
totaltimeref 6.40
totaltimeref 5.41
5 changes: 5 additions & 0 deletions tests/deepks/603_NO_deepks_H2O_v_delta_2/get_dm_eig.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import numpy
a=numpy.load('dm_eig.npy')
b=numpy.load('e_tot.npy')
c=numpy.load('e_base.npy')
print(numpy.sum(numpy.absolute(a))+numpy.sum(b)+numpy.sum(c))
9 changes: 5 additions & 4 deletions tests/deepks/603_NO_deepks_H2O_v_delta_2/result.ref
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
etotref -466.0342709734280
etotref -466.0342709734271
etotperatomref -155.3447569911
totaldes 2.319513
totalh 27.746059584699335
totalvdelta -0.09650548509283462
deepks_e_dm -57.5219353147063
totalh 27.746059584703197
totalvdelta -0.09650548509283459
total_psialpha 17.716143578864877
total_gevdm 54.0
totaltimeref 6.26
totaltimeref 5.42
108 changes: 0 additions & 108 deletions tests/deepks/603_NO_deepks_SiO2_bandgap_multik/log.scf

This file was deleted.

14 changes: 8 additions & 6 deletions tests/deepks/603_NO_deepks_SiO2_bandgap_multik/result.ref
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
etotref -1958.3608711386159484
etotref -1958.3608711386157211
etotperatomref -326.3934785231
totalforceref 33.057695
totalstressref 279.260109
totaldes 13.256025
deepks_e_dm -224.21161147759534
totalstressref 279.260111
totaldes 13.256027
deepks_e_dm -224.21161067867445
deepks_f_label 71.31484483346455
deepks_s_label 164.31396229224615
odelta 0.026994440153412902
oprec 26.182031170349624
totaltimeref 23.36
oprec 26.18203117034944
totaltimeref 22.75
8 changes: 4 additions & 4 deletions tests/deepks/603_NO_deepks_watertrimer/result.ref
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
etotref -1397.837494742079
etotperatomref -155.3152771936
totalforceref 50.518227
totaltimeref 4.3342
etotref -1397.837494858906
etotperatomref -155.3152772065
totalforceref 50.518134
totaltimeref 3.62
1 change: 1 addition & 0 deletions tests/deepks/CASES → tests/deepks/CASES_CPU.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#601_PW_deepks_p_H2O
#601_PW_deepks_d_H2O
602_NO_deepks_d_H2O_scf_lda2pbe
602_NO_deepks_d_H2O_md_lda2pbe
603_NO_deepks_H2O_multik
603_NO_deepks_CH4
603_NO_deepks_ethanol
Expand Down
Loading
Loading