@@ -75,13 +75,6 @@ void ESolver_KS_LCAO<TK, TR>::before_all_runners(UnitCell& ucell, const Input_pa
7575
7676 LCAO_domain::set_psi_occ_dm_chg<TK >(this ->kv , this ->psi , this ->pv , this ->pelec ,
7777 this ->dmat , this ->chr , inp);
78-
79- if (inp.init_chg == " dm" )
80- {
81- // ! 4.1) init density matrix from file
82- std::string dmfile = PARAM .globalv .global_readin_dir + " /dmrs1_nao.csr" ;
83- LCAO_domain::init_dm_from_file<TK >(dmfile, this ->dmat , ucell, &(this ->pv ));
84- }
8578
8679 LCAO_domain::set_pot<TK >(ucell, this ->kv , this ->sf , *this ->pw_rho , *this ->pw_rhod ,
8780 this ->pelec , this ->orb_ , this ->pv , this ->locpp , this ->dftu ,
@@ -167,35 +160,42 @@ void ESolver_KS_LCAO<TK, TR>::before_scf(UnitCell& ucell, const int istep)
167160 // 11) set xc type before the first cal of xc in pelec->init_scf, Peize Lin add 2016-12-03
168161 this ->exx_nao .before_scf (ucell, this ->kv , orb_, this ->p_chgmix , istep, PARAM .inp );
169162
170- // 12.1) if init_chg = "dm", then calculate rho from readin DMR before init_scf
171- if (PARAM .inp .init_chg == " dm" )
172- {
173- LCAO_domain::dm2rho (this ->dmat .dm ->get_DMR_vector (), PARAM .inp .nspin , this ->pelec ->charge , true );
174- }
175- // 12.2) init_scf, should be before_scf? mohan add 2025-03-10
176- this ->pelec ->init_scf (ucell, this ->Pgrid , this ->sf .strucFac , this ->locpp .numeric , ucell.symm );
177-
178- // 13) initalize DM(R), which has the same size with Hamiltonian(R)
163+ // 12) initalize DM(R), which has the same size with Hamiltonian(R)
179164 auto * hamilt_lcao = dynamic_cast <hamilt::HamiltLCAO<TK , TR >*>(this ->p_hamilt );
165+
180166 if (!hamilt_lcao)
181167 {
182168 ModuleBase::WARNING_QUIT (" ESolver_KS_LCAO::before_scf" ," p_hamilt does not exist" );
183169 }
184- if (PARAM .inp .init_chg != " dm" ) this ->dmat .dm ->init_DMR (*hamilt_lcao->getHR ());
170+ this ->dmat .dm ->init_DMR (*hamilt_lcao->getHR ());
171+
172+ // 13.1) calculate or readin the density matrix DMR
173+ if (istep == 0 && PARAM .inp .init_chg == " dm" )// if the first scf step, readin DMR from file,
174+ {
175+ // ! 13.1.1) init density matrix from file
176+ std::string dmfile = PARAM .globalv .global_readin_dir + " /dmrs1_nao.csr" ;
177+ LCAO_domain::init_dm_from_file<TK >(dmfile, this ->dmat , ucell, &(this ->pv ));
178+ }
179+ else if (istep > 0 ) // if not, use the DMR calculated from last step
180+ {
181+ // 13.1.2) two cases are considered:
182+ // 1. DMK in DensityMatrix is not empty (istep > 0), then DMR is initialized by DMK
183+ // 2. DMK in DensityMatrix is empty (istep == 0), then DMR is initialized by zeros
184+ this ->dmat .dm ->cal_DMR ();
185+ }
186+ // 13.2 if init_chg = "dm", then calculate rho from readin DMR before init_scf
187+ if (PARAM .inp .init_chg == " dm" )
188+ {
189+ LCAO_domain::dm2rho (this ->dmat .dm ->get_DMR_vector (), PARAM .inp .nspin , this ->pelec ->charge , true );
190+ }
191+ // 13.2) init_scf, should be before_scf? mohan add 2025-03-10
192+ this ->pelec ->init_scf (ucell, this ->Pgrid , this ->sf .strucFac , this ->locpp .numeric , ucell.symm );
185193
186194#ifdef __MLALGO
187195 // 14) initialize DM2(R) of DeePKS, the DM2(R) is different from DM(R)
188196 this ->deepks .ld .init_DMR (ucell, orb_, this ->pv , this ->gd );
189197#endif
190198
191- // 15) two cases are considered:
192- // 1. DMK in DensityMatrix is not empty (istep > 0), then DMR is initialized by DMK
193- // 2. DMK in DensityMatrix is empty (istep == 0), then DMR is initialized by zeros
194- if (istep > 0 )
195- {
196- this ->dmat .dm ->cal_DMR ();
197- }
198-
199199 // 16) the electron charge density should be symmetrized,
200200 Symmetry_rho srho;
201201 for (int is = 0 ; is < PARAM .inp .nspin ; is++)
0 commit comments