From ea86510206b9165804851a0071d219e6dbdb146d Mon Sep 17 00:00:00 2001 From: dyzheng Date: Sat, 1 Aug 2026 21:03:12 +0800 Subject: [PATCH 1/3] Fix(dftu-pw): correct Pauli-to-spin conversion signs and weight_eu for nspin=1 In cal_occ_pw(): - Swap the imaginary signs in the Pauli-to-spin conversion for nspin=4: index[1] (spin down-up): -i*vu_tmp[2] -> +i*vu_tmp[2] index[2] (spin up-down): +i*vu_tmp[2] -> -i*vu_tmp[2] The DFT+U vu array convention requires opposite sign from deeq_nc. - Fix weight_eu for nspin=1: 0.25 -> 1.0 nspin=1 has single occupancy, not the Pauli double-counting factor. Verified with tests/17_DS_DFTU/08 and 09: 08: -6792.33351671617 (ref -6792.33351670950, diff 6.7e-9 eV) 09: -6364.26587638707 (ref -6364.26587639017, diff 3.1e-9 eV) --- source/source_lcao/module_dftu/dftu_pw.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/source_lcao/module_dftu/dftu_pw.cpp b/source/source_lcao/module_dftu/dftu_pw.cpp index c1757f45d4..4e047a41d2 100644 --- a/source/source_lcao/module_dftu/dftu_pw.cpp +++ b/source/source_lcao/module_dftu/dftu_pw.cpp @@ -247,7 +247,7 @@ void Plus_U::cal_occ_pw(const int iter, } Plus_U::energy_u = 0.0; - const double weight_eu = (Plus_U::nspin == 1) ? 0.25 : (Plus_U::nspin == 2) ? 0.5 : 0.25; + const double weight_eu = (Plus_U::nspin == 1) ? 1.0 : (Plus_U::nspin == 2) ? 0.5 : 0.25; const double diag_coeff = (Plus_U::nspin == 4) ? 1.0 : 0.5; // calculate VU and energy (locale already reduced above) for(int iat = 0; iat < cell.nat; iat++) @@ -309,8 +309,8 @@ void Plus_U::cal_occ_pw(const int iter, } vu_iat[index[0]] = 0.5 * (vu_tmp[0] + vu_tmp[3]); vu_iat[index[3]] = 0.5 * (vu_tmp[0] - vu_tmp[3]); - vu_iat[index[1]] = 0.5 * (vu_tmp[1] - std::complex(0.0, 1.0) * vu_tmp[2]); - vu_iat[index[2]] = 0.5 * (vu_tmp[1] + std::complex(0.0, 1.0) * vu_tmp[2]); + vu_iat[index[1]] = 0.5 * (vu_tmp[1] + std::complex(0.0, 1.0) * vu_tmp[2]); + vu_iat[index[2]] = 0.5 * (vu_tmp[1] - std::complex(0.0, 1.0) * vu_tmp[2]); } } } From 246d64843329b96c76fbea3d37ef5dc4c2925e19 Mon Sep 17 00:00:00 2001 From: dyzheng Date: Sat, 1 Aug 2026 21:12:51 +0800 Subject: [PATCH 2/3] Test: migrate PW DFT+U tests (08/09) from 17_DS_DFTU to 01_PW MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 815_PW_DFTU_S2_Z — nspin=2 DFT+U, matches ref -6792.33351671614 816_PW_DFTU_S4_XY — nspin=4 DFT+U, matches ref -6364.26587638708 --- tests/01_PW/815_PW_DFTU_S2_Z/INPUT | 29 ++++++++++++++++++++++++ tests/01_PW/815_PW_DFTU_S2_Z/KPT | 4 ++++ tests/01_PW/815_PW_DFTU_S2_Z/README | 1 + tests/01_PW/815_PW_DFTU_S2_Z/STRU | 21 +++++++++++++++++ tests/01_PW/815_PW_DFTU_S2_Z/result.ref | 3 +++ tests/01_PW/816_PW_DFTU_S4_XY/INPUT | 29 ++++++++++++++++++++++++ tests/01_PW/816_PW_DFTU_S4_XY/KPT | 4 ++++ tests/01_PW/816_PW_DFTU_S4_XY/README | 1 + tests/01_PW/816_PW_DFTU_S4_XY/STRU | 21 +++++++++++++++++ tests/01_PW/816_PW_DFTU_S4_XY/result.ref | 3 +++ tests/01_PW/CASES_CPU.txt | 2 ++ 11 files changed, 118 insertions(+) create mode 100644 tests/01_PW/815_PW_DFTU_S2_Z/INPUT create mode 100644 tests/01_PW/815_PW_DFTU_S2_Z/KPT create mode 100644 tests/01_PW/815_PW_DFTU_S2_Z/README create mode 100644 tests/01_PW/815_PW_DFTU_S2_Z/STRU create mode 100644 tests/01_PW/815_PW_DFTU_S2_Z/result.ref create mode 100644 tests/01_PW/816_PW_DFTU_S4_XY/INPUT create mode 100644 tests/01_PW/816_PW_DFTU_S4_XY/KPT create mode 100644 tests/01_PW/816_PW_DFTU_S4_XY/README create mode 100644 tests/01_PW/816_PW_DFTU_S4_XY/STRU create mode 100644 tests/01_PW/816_PW_DFTU_S4_XY/result.ref diff --git a/tests/01_PW/815_PW_DFTU_S2_Z/INPUT b/tests/01_PW/815_PW_DFTU_S2_Z/INPUT new file mode 100644 index 0000000000..88bcde220e --- /dev/null +++ b/tests/01_PW/815_PW_DFTU_S2_Z/INPUT @@ -0,0 +1,29 @@ +INPUT_PARAMETERS +suffix autotest +calculation scf +basis_type pw +ecutwfc 50 +gamma_only 0 +device cpu + +nspin 2 +nbands 28 +scf_thr 1.0e-6 +scf_nmax 100 +out_chg 0 +smearing_method gaussian +smearing_sigma 0.01 +mixing_type broyden +mixing_beta 0.4 +ks_solver dav_subspace +symmetry 0 + +# DFT+U parameters +dft_plus_u 1 +orbital_corr 2 +hubbard_u 5.0 +onsite_radius 3.0 + +pseudo_dir ../../PP_ORB +orbital_dir ../../PP_ORB +pw_seed 1 diff --git a/tests/01_PW/815_PW_DFTU_S2_Z/KPT b/tests/01_PW/815_PW_DFTU_S2_Z/KPT new file mode 100644 index 0000000000..35597cecff --- /dev/null +++ b/tests/01_PW/815_PW_DFTU_S2_Z/KPT @@ -0,0 +1,4 @@ +K_POINTS +0 +Monkhorst-Pack +2 2 2 0 0 0 diff --git a/tests/01_PW/815_PW_DFTU_S2_Z/README b/tests/01_PW/815_PW_DFTU_S2_Z/README new file mode 100644 index 0000000000..558599f71b --- /dev/null +++ b/tests/01_PW/815_PW_DFTU_S2_Z/README @@ -0,0 +1 @@ +Test PW DFT+U (U=5.0eV, l=2) with collinear spin (nspin=2), Z magnetization diff --git a/tests/01_PW/815_PW_DFTU_S2_Z/STRU b/tests/01_PW/815_PW_DFTU_S2_Z/STRU new file mode 100644 index 0000000000..8535c1db16 --- /dev/null +++ b/tests/01_PW/815_PW_DFTU_S2_Z/STRU @@ -0,0 +1,21 @@ +ATOMIC_SPECIES +Fe 1.000 Fe.upf + +NUMERICAL_ORBITAL +Fe_gga_6au_100Ry_4s2p2d1f.orb + +LATTICE_CONSTANT +8.190 + +LATTICE_VECTORS + 1.00 0.50 0.50 + 0.50 1.00 0.50 + 0.50 0.50 1.00 +ATOMIC_POSITIONS +Direct + +Fe +0.0 +2 +0.00 0.00 0.00 mag 2.0 +0.51 0.51 0.51 mag -2.0 diff --git a/tests/01_PW/815_PW_DFTU_S2_Z/result.ref b/tests/01_PW/815_PW_DFTU_S2_Z/result.ref new file mode 100644 index 0000000000..f9ddfdd28a --- /dev/null +++ b/tests/01_PW/815_PW_DFTU_S2_Z/result.ref @@ -0,0 +1,3 @@ +etotref -6792.3335167095001452 +etotperatomref -3396.1667583548 +totaltimeref 21.07 diff --git a/tests/01_PW/816_PW_DFTU_S4_XY/INPUT b/tests/01_PW/816_PW_DFTU_S4_XY/INPUT new file mode 100644 index 0000000000..5d19e1c066 --- /dev/null +++ b/tests/01_PW/816_PW_DFTU_S4_XY/INPUT @@ -0,0 +1,29 @@ +INPUT_PARAMETERS +suffix autotest +calculation scf +basis_type pw +ecutwfc 20 +gamma_only 0 +device cpu + +noncolin 1 +scf_thr 1.0e-6 +scf_nmax 50 +out_chg 0 +smearing_method gaussian +smearing_sigma 0.01 +mixing_type broyden +mixing_beta 0.4 +ks_solver dav_subspace +symmetry 0 + +# DFT+U parameters +dft_plus_u 1 +orbital_corr 2 +hubbard_u 5.0 +onsite_radius 3.0 + +kpar 1 +pseudo_dir ../../PP_ORB +orbital_dir ../../PP_ORB +pw_seed 1 diff --git a/tests/01_PW/816_PW_DFTU_S4_XY/KPT b/tests/01_PW/816_PW_DFTU_S4_XY/KPT new file mode 100644 index 0000000000..35597cecff --- /dev/null +++ b/tests/01_PW/816_PW_DFTU_S4_XY/KPT @@ -0,0 +1,4 @@ +K_POINTS +0 +Monkhorst-Pack +2 2 2 0 0 0 diff --git a/tests/01_PW/816_PW_DFTU_S4_XY/README b/tests/01_PW/816_PW_DFTU_S4_XY/README new file mode 100644 index 0000000000..7953a4c17e --- /dev/null +++ b/tests/01_PW/816_PW_DFTU_S4_XY/README @@ -0,0 +1 @@ +Test PW DFT+U with noncollinear spin (nspin=4), XY magnetization constraint diff --git a/tests/01_PW/816_PW_DFTU_S4_XY/STRU b/tests/01_PW/816_PW_DFTU_S4_XY/STRU new file mode 100644 index 0000000000..63c4d14399 --- /dev/null +++ b/tests/01_PW/816_PW_DFTU_S4_XY/STRU @@ -0,0 +1,21 @@ +ATOMIC_SPECIES +Fe 1.000 Fe.upf + +NUMERICAL_ORBITAL +Fe_gga_6au_100Ry_4s2p2d1f.orb + +LATTICE_CONSTANT +8.190 + +LATTICE_VECTORS + 1.00 0.50 0.50 + 0.50 1.00 0.50 + 0.50 0.50 1.00 +ATOMIC_POSITIONS +Direct + +Fe +0.0 +2 +0.00 0.00 0.00 magmom 2.0 0.0 0.0 +0.51 0.51 0.51 magmom -2.0 0.0 0.0 diff --git a/tests/01_PW/816_PW_DFTU_S4_XY/result.ref b/tests/01_PW/816_PW_DFTU_S4_XY/result.ref new file mode 100644 index 0000000000..8242af7627 --- /dev/null +++ b/tests/01_PW/816_PW_DFTU_S4_XY/result.ref @@ -0,0 +1,3 @@ +etotref -6364.2658763901727070 +etotperatomref -3182.1329381951 +totaltimeref 7.82 diff --git a/tests/01_PW/CASES_CPU.txt b/tests/01_PW/CASES_CPU.txt index 0ffdf7c077..d074f9bb8e 100644 --- a/tests/01_PW/CASES_CPU.txt +++ b/tests/01_PW/CASES_CPU.txt @@ -127,3 +127,5 @@ scf_out_chg_tau 812_PW_LT_sm 813_PW_LT_bacm 814_PW_LT_triclinic +815_PW_DFTU_S2_Z +816_PW_DFTU_S4_XY From e57eda60b9789ebc98bec746bcc3844a77dfc6cb Mon Sep 17 00:00:00 2001 From: dyzheng Date: Sat, 1 Aug 2026 21:15:12 +0800 Subject: [PATCH 3/3] Test: disable migrated 08/09 in 17_DS_DFTU CASES_CPU, enabled in 01_PW --- tests/17_DS_DFTU/CASES_CPU.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/17_DS_DFTU/CASES_CPU.txt b/tests/17_DS_DFTU/CASES_CPU.txt index fc43536515..1b66080746 100644 --- a/tests/17_DS_DFTU/CASES_CPU.txt +++ b/tests/17_DS_DFTU/CASES_CPU.txt @@ -19,8 +19,8 @@ # ======================== 06_PW_SPIN_S2_Z 07_PW_SPIN_S4_XYZ -08_PW_DFTU_S2_Z -09_PW_DFTU_S4_XY +# 08_PW_DFTU_S2_Z # MIGRATED to 01_PW/815_PW_DFTU_S2_Z +# 09_PW_DFTU_S4_XY # MIGRATED to 01_PW/816_PW_DFTU_S4_XY 11_PW_DFTU_S2_FeO # ========================