Skip to content

Fix: Robust handling of bandgap boundary conditions in ElecState and add unit tests#6917

Merged
mohanchen merged 7 commits intodeepmodeling:developfrom
A-006:estase
Jan 28, 2026
Merged

Fix: Robust handling of bandgap boundary conditions in ElecState and add unit tests#6917
mohanchen merged 7 commits intodeepmodeling:developfrom
A-006:estase

Conversation

@A-006
Copy link
Collaborator

@A-006 A-006 commented Jan 27, 2026

Linked Issue

Fix #6909

Description

This PR improves the robustness of bandgap calculations in ElecState::cal_bandgap and ElecState::cal_bandgap_updw by handling boundary conditions where only VBM or CBM is found. If either VBM or CBM is not found (remains ±infinity), it is now assigned the Fermi level, ensuring the bandgap is always a finite, physically meaningful value. This prevents the output of infinity or undefined values in metallic or pathological cases.

Additionally, new unit tests are added to elecstate_energy_test.cpp to verify the correct behavior for these boundary conditions, including cases where only VBM or only CBM is found for both spin-unpolarized and spin-polarized scenarios.

Changes

  • In cal_bandgap and cal_bandgap_updw, assign the Fermi level to VBM/CBM if not found.
  • Ensures bandgap is always finite and meaningful, even in edge cases.
  • Adds CalBandgapBoundaryConditions and CalBandgapUpDwBoundaryConditions unit tests to cover these scenarios.

Motivation

To make the bandgap calculation more robust and user-friendly, and to ensure that the code behaves correctly in all possible input cases, including metallic systems or when the number of bands is insufficient.

No changes to the physical calculation logic for normal cases; only edge case handling and test coverage are improved.

@mohanchen mohanchen added Refactor Refactor ABACUS codes Bugs Bugs that only solvable with sufficient knowledge of DFT Unit Tests/Integreate Tests Issues/PR related to unit tests and integrate tests labels Jan 28, 2026
@mohanchen mohanchen merged commit 95f6450 into deepmodeling:develop Jan 28, 2026
14 checks passed
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 Unit Tests/Integreate Tests Issues/PR related to unit tests and integrate tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Floating-point error due to CBM = inf in latest ABACUS version

2 participants