Skip to content

Fix: DeltaSpin energy fix - #7748

Open
dyzheng wants to merge 3 commits into
deepmodeling:developfrom
dyzheng:feat/issue-7728-deltaspin-energy-fix
Open

Fix: DeltaSpin energy fix#7748
dyzheng wants to merge 3 commits into
deepmodeling:developfrom
dyzheng:feat/issue-7728-deltaspin-energy-fix

Conversation

@dyzheng

@dyzheng dyzheng commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator

Reminder

  • I have read AGENTS.md and docs/developers_guide/agent_governance.md.
  • I have linked an issue or explained why this PR does not need one.
  • I have added adequate unit tests and/or case tests, or explained why not.
  • I have listed the exact verification commands run and their results.
  • I have described user-visible behavior changes, including INPUT parameter changes.
  • I have explained core-module impact for ESolver, HSolver, ElecState, Hamilt, Operator, Psi, or other source/ changes.
  • I have requested any needed governance exception below.

Linked Issue

Fix #

Unit Tests and/or Case Tests for my changes

  • Commands run:
  • Result summary:
  • Checks not run, with reason:

What's changed?

  • Example: brief summary of the user-visible or developer-facing change.

Governance Notes

  • INPUT/docs changes:
  • Core module impact:
  • Exceptions requested:

dyzheng added 3 commits August 1, 2026 23:57
… basis

- cal_escon(): replace is_Mi_converged gate with lambda_/Mi_ empty check
  to prevent segfault when uninitialized
- elecstate_pw: add get_spin_constrain_energy() override so PW basis
  computes DeltaSpin constraint energy (previously returned 0.0)
- elecstate_pw.h: declare get_spin_constrain_energy() override

Note: this fix enables escon computation for PW DeltaSpin but
lambda values from BFGS optimizer may differ from accel branch
due to energy functional convention differences. Full convergence
with accel requires lambda_loop.cpp migration.
… refs

Source changes:
- cal_escon(): replace is_Mi_converged guard with lambda_/Mi_ empty check
  to prevent segfault when uninitialized (matching accel convention)
- elecstate_pw: add get_spin_constrain_energy() override so PW basis
  includes DeltaSpin constraint energy in total energy (was always 0)

Test refs regenerated for 7 cases with significant energy changes:
- 14_PW_DS_S4_XYZ, 15_PW_DS_S4_Z, 16_PW_DS_S4_XY
- 18_PW_DFTU_DS_S2_Z, 19_PW_DFTU_DS_S4_XY, 21_PW_DFTU_DS_S4_Z
- 41_PW_DS_S4_Thr10_XY

nspin=2 tests and ReadLam/Thr1e10 tests unchanged.
…escon

Source fixes:
- spin_constrain.h: fix My = -Im(occ1-occ2) → Im(occ1-occ2)
  The magnetic moment y-component had the wrong sign in the Pauli matrix
  transformation, causing incorrect Mi computation for nspin=4 DeltaSpin.
- cal_escon(): replace is_Mi_converged guard with lambda_/Mi_ empty check
- elecstate_pw: add get_spin_constrain_energy() for PW basis DeltaSpin

Refs regenerated for nspin=4 DeltaSpin cases: 14, 15, 16, 19, 21, 41
Test 18 unchanged, nspin=2 tests unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant