Fix Pauli-to-Spinor Conversion in LCAO Non-Collinear Calculations#7513
Open
dyzheng wants to merge 3 commits into
Open
Fix Pauli-to-Spinor Conversion in LCAO Non-Collinear Calculations#7513dyzheng wants to merge 3 commits into
dyzheng wants to merge 3 commits into
Conversation
Fix two bugs in LCAO non-collinear Hamiltonian construction:
1. Wrong sign in off-diagonal elements: H_{up,down} = B_x + i*B_y (wrong)
should be B_x - i*B_y (correct), and vice versa for H_{down,up}.
Fixed by correcting clx_j coefficients in merge_hr_part_to_hR().
2. Missing complex conjugate in lower triangle fill: H(-R) used transpose
instead of conjugate transpose, breaking Hermiticity for complex matrices.
Fixed by using std::conj() when filling lower triangle.
These errors caused the non-collinear Hamiltonian to be the complex conjugate
of the correct result, leading to incorrect spin textures in nspin=4 calculations.
The PW code path was not affected.
Add test case and verification script to validate:
- H(R=0) Hermiticity: max|H - H^dagger| < 1e-10
- Off-diagonal phase: Im(H_{up,down}) < 0 for m||+y direction
See tests/03_NAO_multik/verify_hamiltonian_convention/TEST_DESIGN.md for details.
…pin=4
Fix three critical bugs in non-collinear (nspin=4) LCAO calculations:
1. DFT+U transfer_vu (dftu_lcao.cpp): Fix sign error in Pauli-to-spinor
conversion. The off-diagonal elements had wrong imaginary part sign:
- Before: V_{up,down} = 0.5*(V_x + i*V_y) (wrong)
- After: V_{up,down} = 0.5*(V_x - i*V_y) (correct, from sigma_y)
2. DFT+U force/stress (dftu_force_stress.hpp): Convert VU from Pauli basis
to spinor basis before force calculation. The old code incorrectly mixed
Pauli-basis VU with spinor-basis DM.
3. DeltaSpin force/stress (dspin_force_stress.hpp): Convert lambda from
Pauli basis to spinor basis. The constraint force F = lambda·dM/dR
requires proper Pauli-to-spinor conversion:
- lambda_spinor = (lambda_z, lambda_x, lambda_x, -lambda_z)
for (uu, ud, du, dd) components.
These fixes ensure consistent Pauli-to-spinor conversion across all modules:
- H construction (gint_common.cpp): already fixed
- DFT+U Hamiltonian: fixed in this commit
- DFT+U force/stress: fixed in this commit
- DeltaSpin force/stress: fixed in this commit
Verified by scf_u_spin4 test (nspin=4 + DFT+U): SCF converges correctly.
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.
Summary
This PR fixes critical bugs in the Pauli-to-spinor basis conversion for LCAO non-collinear spin (nspin=4) calculations. The fixes ensure correct Hamiltonian construction, DFT+U potential handling, and force/stress calculations for systems with non-collinear magnetization and spin-orbit coupling (SOC).
Background
In ABACUS LCAO calculations with nspin=4 (non-collinear spin), the effective potential and other operators are initially computed in the Pauli basis (V₀, V_x, V_y, V_z) and must be converted to the spinor basis for the 2×2 spinor Hamiltonian matrix. The conversion follows:
where the Pauli matrices are:
This yields the spinor basis representation:
Issues Fixed
Issue 1: Incorrect Sign in Off-Diagonal Hamiltonian Elements
File:
source/source_lcao/module_gint/gint_common.cppProblem: The
merge_hr_part_to_hR()function used incorrect signs for the imaginary components when converting from Pauli to spinor basis.Original Code:
Fixed Code:
Additional Fix: Added complex conjugate transpose for lower triangle filling to ensure Hermiticity:
This ensures
H(-R) = H†(R), which is required for the Hamiltonian to be Hermitian in k-space.Issue 2: Incorrect Fourier Transform Sign in DM(R) Calculation
Files:
source/source_estate/module_dm/density_matrix.cppsource/source_lcao/module_lr/dm_trans/dmr_complex.cppProblem: The inverse Fourier transform from k-space to real-space used
e^{+ik·R}instead of the correcte^{-ik·R}.Mathematical Background:
The Fourier transform pair should be:
H(k) = Σ_R H(R) · e^{+ik·R}DM(R) = (1/N_k) Σ_k DM(k) · e^{-ik·R}Fix: Changed the sign in the phase factor:
Issue 3: Incorrect Pauli-to-Spinor Conversion in DFT+U
File:
source/source_lcao/module_operator_lcao/dftu_lcao.cppProblem: The
transfer_vu()function had the same sign error as Issue 1 when converting the DFT+U potential from Pauli to spinor basis.Fix:
Issue 4: Inconsistent Basis in DFT+U Force/Stress Calculation
File:
source/source_lcao/module_operator_lcao/dftu_force_stress.hppProblem: The force/stress calculation mixed Pauli-basis VU with spinor-basis DM, computing an incorrect trace.
Mathematical Background:
The force should be computed as:
In the spinor basis, this expands to:
Where:
For real DM (dDM_{ud} = dDM_{du}), this simplifies to:
Fix: Convert VU from Pauli to spinor basis before force calculation:
Issue 5: Inconsistent Basis in DeltaSpin Force/Stress Calculation
File:
source/source_lcao/module_operator_lcao/dspin_force_stress.hppProblem: Similar to Issue 4, the DeltaSpin constraint force calculation used lambda (Pauli basis) directly with DM (spinor basis).
Fix: Convert lambda from Pauli to spinor basis:
Verification
Code Review
Comprehensive code review was performed on all modules handling nspin=4:
gint_common.cppdensity_matrix.cpp,dmr_complex.cppdftu_lcao.cppdftu_force_stress.hppdspin_force_stress.hppsoc.cppnonlocal_force_stress.hppcal_dm_psi.cppMathematical Verification
Hermiticity Check: H(R=0) satisfies
H = H†to machine precision (max deviation: 1.00e-12)Phase Convention: For magnetization along +y direction:
Im(H_{↑,↓}) > 0❌Im(H_{↑,↓}) < 0✅This matches the correct physics:
H_{↑,↓} = V_x - i·V_yhas negative imaginary part whenV_y > 0.Test Results
Test Suite:
tests/03_NAO_multik/(nspin=4 LCAO tests)Note: Two tests (
scf_angle_spin4andscf_out_hsr_spin4) fail with MPI_Bcast errors. Investigation shows this is a pre-existing bug in the develop branch, unrelated to the Pauli matrix fixes. These tests also fail on the unmodified develop branch.Reference Value Updates
The
scf_u_spin4test reference values were updated to reflect the corrected physics:These changes are expected and correct, as the old reference values were computed with buggy code.
Impact Assessment
Affected Calculations
Unaffected Calculations
Backward Compatibility
Breaking Change: Results for nspin=4 LCAO calculations will change. This is intentional and correct - the old results were wrong due to the bugs fixed in this PR.
Users should:
Files Modified
Source Code
source/source_lcao/module_gint/gint_common.cpp- H construction fixsource/source_estate/module_dm/density_matrix.cpp- DM Fourier fixsource/source_lcao/module_lr/dm_trans/dmr_complex.cpp- DM Fourier fixsource/source_lcao/module_operator_lcao/dftu_lcao.cpp- DFT+U transfer_vu fixsource/source_lcao/module_operator_lcao/dftu_force_stress.hpp- DFT+U force fixsource/source_lcao/module_operator_lcao/dspin_force_stress.hpp- DeltaSpin force fixTests
tests/03_NAO_multik/scf_u_spin4/result.ref- Updated reference valuesTesting Instructions
To verify the fixes:
Expected output:
Related Issues
This PR addresses the Pauli-to-spinor conversion issues identified in the code review. The MPI errors in
scf_angle_spin4andscf_out_hsr_spin4are separate pre-existing issues that require dedicated investigation.Checklist