Repository navigation
fix(dftu): apply 1/2 Pauli-basis trace factor to LCAO nspin=4 DFT+U stress - #8496
Open
songfeitong wants to merge 1 commit into
Open
songfeitong wants to merge 1 commit into
songfeitong wants to merge 1 commit into
Conversation
For nspin=4 in real-space LCAO DFT+U (dft_plus_u=1), dmR and pot_onsite are stored in 4-component Pauli form without the 1/2 spinor trace factor. While cal_for_IJR_nao_r differentiates only one projector overlap (so the product-rule factor of 2 cancels the 1/2 factor for nspin=4), cal_str_IJR_nao_r sums both projector derivative terms explicitly and therefore needs an explicit 0.5 factor in reduce_stress_impl when nspin==4. - Pass nspin into DFTU_LCAO::reduce_stress_impl and scale by 0.5 for nspin=4 - Add nspin=1/2/4 stress scaling unit tests in test_dftu_nao_fs_reduce.cpp - Update tests/03_NAO_multik/scf_u_spin4/result.ref totalstressref
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reminder
AGENTS.mdanddocs/developers_guide/agent_governance.md.source/changes.Linked Issue
No existing issue; this is a self-contained bug fix discovered while validating LCAO
nspin=4DFT+U stress against finite differences of total energy.What's changed?
Fixes a factor-of-2 overestimation in the real-space LCAO DFT+U stress (
dft_plus_u = 1) for non-collinear / SOC (nspin = 4) calculations.Root Cause
In the real-space LCAO DFT+U implementation ($(\alpha = 0, 1, 2, 3)$ :$E_U$ is the Dudarev Hubbard energy functional (note that
source/source_lcao/module_dftu/), fornspin = 4both the real-space density matrixdmRand the onsite occupation/potential arrays are stored in the 4-component Pauli basis$$\mathbf{n} = \frac{1}{2}\sum_{\alpha=0}^{3} n^{(\alpha)} \sigma_\alpha, \qquad E_U = \frac{U}{2}\mathrm{Tr}[\mathbf{n}(1-\mathbf{n})] = \frac{U}{2}\mathrm{Tr}{\mathrm{orb}}[n^{(0)}] - \frac{U}{4}\sum{\alpha=0}^{3}\mathrm{Tr}_{\mathrm{orb}}!\left[(n^{(\alpha)})^2\right],$$
where
cal_pot_onsite()accumulateseuas the double-counting energy correction subtracted from the band energy).cal_pot_onsite()computes the unhalved Pauli-channel potentials (already transposed in orbital indices):$$V^{(0)}{m_1 m_2} = U\bigl(\delta{m_1 m_2} - n^{(0)}{m_2 m_1}\bigr), \qquad V^{(k)}{m_1 m_2} = -U n^{(k)}{m_2 m_1} \quad (k = 1, 2, 3).$$
Accordingly, the variation of the Hubbard functional carries a $\tfrac{1}{2}$ spinor trace factor:
$$dE_U = \frac{1}{2} \sum{\alpha=0}^{3} \sum_{m_1, m_2} V^{(\alpha)}{m_1 m_2}, dn^{(\alpha)}{m_1 m_2}.$$
transfer_pot_onsite<std::complex<double>>()(dftu_nao_pots.h) explicitly applies the factor0.5.cal_for_IJR_nao_r()differentiates only one of the two projector overlaps (missing the product-rule factor of2). Fornspin = 4, the missing product-rule factor2and the missing Pauli trace factor1/2cancel (2 * 0.5 = 1), soreduce_force_impl()only multiplies by2.0whennspin != 4.cal_str_IJR_nao_r()already sums both projector derivative terms explicitly (contractingpot_onsite[m1, m2]with the strain derivative ofocc[m1, m2]), butreduce_stress_impl()did not acceptnspinand did not apply the0.5factor fornspin == 4. Consequently,DFTU STRESSwas overestimated by an exact factor of2fornspin = 4, whilenspin = 1, 2were unaffected.Code Changes
int nspinparameter toDFTU_LCAO::reduce_stress_impl()(dftu_nao_fs_r.h,dftu_nao_fs_reduce.cpp) and applyspin_scale = (nspin == 4) ? 0.5 : 1.0before scaling bylat0 / omega.nspinat the single production call site incal_fs_nao_r_impl()(dftu_nao_fs_r.cpp) and clarify the docstrings forreduce_force_impl()andreduce_stress_impl().source/source_lcao/module_dftu/unittests/test_dftu_nao_fs_reduce.cppto covernspin = 1, 2, 4stress scaling, and update the call signature intest_dftu_nao_fs_r.cpp.totalstressrefintests/03_NAO_multik/scf_u_spin4/result.ref(4697.840104->4891.796432, exact shift+193.956328matching half the previousDFTU STRESSL1 norm;etotrefandtotalforcerefare unchanged).Unit Tests and/or Case Tests for my changes
ctest --test-dir build-fixed --output-on-failure -R "MODULE_DFTU"cd tests/03_NAO_multik && ../integrate/Autotest.sh -a <abacus> -n 4 -o 1 -f CASES_CPU.txt -r '^scf_u_spin(1|2|4)$'cd tests/02_NAO_Gamma && ../integrate/Autotest.sh -a <abacus> -n 4 -o 1 -f CASES_CPU.txt -r '^scf_u_spin2$'python3 tools/03_code_analysis/agent_governance_check.py --base develop --head HEAD --event-path <pr-event.json> --format textpython3 tools/03_code_analysis/code_quality_score.py <modified C++ files>Unit tests: 15/15
MODULE_DFTUCTest targets passed (100%), includingMODULE_DFTU_fs_reduce,MODULE_DFTU_fs_r, andMODULE_DFTU_op_conjugate_k_mpi4.Integration tests:
03_NAO_multikpassed 12/12 checks (scf_u_spin1,scf_u_spin2unchanged;scf_u_spin4matches updatedtotalstressref = 4891.796432, with all 9DFTU STRESScomponents halved and total stress tensor shifted component-by-component to< 5e-11 kbar);02_NAO_Gammapassed 4/4 checks (scf_u_spin2unchanged).Governance & quality:
agent_governance_check.pyreported 0 findings;code_quality_score.pypassed 5/5 modified C++ files (average score 91.2).Physical finite-difference validation (converged 2-atom rocksalt FeO using$\delta = 5 \times 10^{-4}$ ; all runs converged in 24–28 SCF iterations;
tests/PP_ORB,ecutwfc = 160 Ry,scf_thr = 1e-10, fixed48x48x48FFT grid,dft_plus_u = 1,U = 5.0 eV, central finite differencenspin = 4, lspinorb = 0uses tilted moment(1.0, 0.8, 1.5)activating all four Pauli channels, physically equivalent tonspin = 2with total energy agreement8.8e-11 eV):DFTU STRESS xx(kbar)TOTAL STRESS xx(kbar)FD xx(kbar)TOTAL - FD(kbar)nspin = 2(control, before / after)52.004025/52.004025-297.943235/-297.943235-298.148530+0.205295nspin = 4, lspinorb = 0(before)104.008050(2.000×)-245.939211-298.148530+52.209319nspin = 4, lspinorb = 0(after)52.004025(1.000×)-297.943235-298.148530+0.205294After the fix,
nspin = 4(lspinorb = 0) agrees withnspin = 2to< 4e-7 kbarin bothDFTU STRESSandTOTAL STRESS, and matches the finite-difference baseline residual to6.1e-7 kbar.nspin == 4branch) and will be covered by PR CI.Governance Notes
nspin = 4LCAO DFT+U stress without adding or changing anyINPUTparameters or user-facing interfaces.DFTU_LCAO::reduce_stress_impl()insource/source_lcao/module_dftu/(nspin == 4stress path only;nspin = 1, 2and all force/energy/Hamiltonian paths are unchanged).