Skip to content

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.

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.

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

1 participant