Skip to content

Fix: Fix UPF100 negative lmax handling#7221

Merged
mohanchen merged 7 commits intodeepmodeling:developfrom
sunliang98:fix_pp
Apr 9, 2026
Merged

Fix: Fix UPF100 negative lmax handling#7221
mohanchen merged 7 commits intodeepmodeling:developfrom
sunliang98:fix_pp

Conversation

@sunliang98
Copy link
Copy Markdown
Collaborator

Reminder

  • Have you linked an issue with this pull request?
  • Have you added adequate unit tests and/or case tests for your pull request?
  • Have you noticed possible changes of behavior below or in the linked issue?
  • Have you explained the changes of codes in core modules of ESolver, HSolver, ElecState, Hamilt, Operator or Psi? (ignore if not applicable)

Linked Issue

Fix #7208

Unit Tests and/or Case Tests for my changes

  • A unit test is added for each new feature or bug fix.

What's changed?

This PR fixes a stability issue when reading legacy UPF100 pseudopotentials where nbeta == 0 and lmax < 0 (for example, lmax = -1 in H.pz-vbc.UPF). The parser now normalizes this case to a safe value to prevent invalid dimension propagation and intermittent runtime failures.

To prevent regressions, this PR also adds an LCAO test case (02_NAO_Gamma/scf_upf100).

Any changes of core modules? (ignore if not applicable)

  • Example: I have added a new virtual function in the esolver base class in order to ...

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens the UPF100 pseudopotential reader against legacy files where nbeta == 0 and lmax < 0, preventing negative-dimension propagation and early-runtime failures, and adds a regression test case.

Changes:

  • Normalize legacy UPF100 header cases (nbeta == 0 && lmax < 0) to a safe lmax = 0.
  • Add additional validation while reading <PP_DIJ> indices to prevent out-of-range matrix writes.
  • Add a new LCAO regression test case (02_NAO_Gamma/scf_upf100) and register it in the CPU test list.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
source/source_cell/read_pp_upf100.cpp Normalizes legacy lmax and adds <PP_DIJ> bounds checking to avoid invalid allocations / writes.
tests/02_NAO_Gamma/scf_upf100/INPUT Adds a new LCAO SCF test input targeting UPF100 legacy pseudopotentials.
tests/02_NAO_Gamma/scf_upf100/STRU Defines the benzene structure and references legacy UPF100 pseudopotentials.
tests/02_NAO_Gamma/scf_upf100/KPT Gamma-only k-point setup for the new test.
tests/02_NAO_Gamma/scf_upf100/result.ref Reference outputs for autotest validation.
tests/02_NAO_Gamma/scf_upf100/README Brief description of the new test case.
tests/02_NAO_Gamma/CASES_CPU.txt Registers scf_upf100 in the NAO Gamma CPU test suite.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

sunliang98 and others added 3 commits April 8, 2026 19:52
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Collaborator

@mohanchen mohanchen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mohanchen mohanchen added Bugs Bugs that only solvable with sufficient knowledge of DFT Refactor Refactor ABACUS codes labels Apr 9, 2026
@mohanchen mohanchen merged commit 684d30a into deepmodeling:develop Apr 9, 2026
15 checks passed
@sunliang98 sunliang98 deleted the fix_pp branch April 9, 2026 08:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bugs Bugs that only solvable with sufficient knowledge of DFT Refactor Refactor ABACUS codes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: std::bad_alloc crash during charge initialization when using older LDA (pz-vbc) UPF pseudopotentials

3 participants