Skip to content

Commit 4722169

Browse files
dyzhengdyzheng
andauthored
Fix: DFT+U nscf calculation of nspin=1 and output onsite.dm with out_chg>=0 (#6550)
* Fix: DFT+U nscf calculation of nspin=1 and output onsite.dm with out_chg>=0 * Fix: nscf force calculation with DFT+U --------- Co-authored-by: dyzheng <[email protected]>
1 parent 9438146 commit 4722169

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

source/module_esolver/esolver_ks_lcao.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,10 @@ void ESolver_KS_LCAO<TK, TR>::iter_init(UnitCell& ucell, const int istep, const
669669

670670
if (PARAM.inp.dft_plus_u)
671671
{
672-
if (istep != 0 || iter != 1)
672+
// set_dmr to calculate the onsite-matrix and the energy correction for DFT+U,
673+
// in SCF calculation, the DMR is updated from the second iteration
674+
// in NSCF calculation, the DMR is not updated, so always set_dmr here
675+
if (istep != 0 || iter != 1 || PARAM.inp.calculation == "nscf")
673676
{
674677
GlobalC::dftu.set_dmr(dynamic_cast<elecstate::ElecStateLCAO<TK>*>(this->pelec)->get_DM());
675678
}

source/module_hamilt_lcao/module_dftu/dftu_io.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void DFTU::output(const UnitCell &ucell)
5555

5656
//Write onsite.dm
5757
std::ofstream ofdftu;
58-
if(PARAM.inp.out_chg[0]){
58+
if(PARAM.inp.out_chg[0] != -1){
5959
if(GlobalV::MY_RANK == 0){
6060
ofdftu.open(PARAM.globalv.global_out_dir + "onsite.dm");
6161
}
@@ -309,7 +309,7 @@ void DFTU::read_occup_m(const UnitCell& ucell,
309309

310310
if (PARAM.inp.nspin == 1 || PARAM.inp.nspin == 2)
311311
{
312-
for (int is = 0; is < 2; is++)
312+
for (int is = 0; is < PARAM.inp.nspin; is++)
313313
{
314314
ifdftu >> word;
315315
if (strcmp("spin", word) == 0)

0 commit comments

Comments
 (0)