Skip to content

fix(perception): Gracefully Handle Isolated Metals with Unknown Valence#18

Merged
TKanX merged 3 commits intomainfrom
bugfix/17-harden-electron-perception-for-missing-valence-metals
Dec 9, 2025
Merged

fix(perception): Gracefully Handle Isolated Metals with Unknown Valence#18
TKanX merged 3 commits intomainfrom
bugfix/17-harden-electron-perception-for-missing-valence-metals

Conversation

@TKanX
Copy link
Copy Markdown
Member

@TKanX TKanX commented Dec 9, 2025

Summary:

Updated the electron perception logic to prevent crashes when encountering isolated metal atoms (e.g., ions like Na+, Ca2+, or noble metals like Au) that have no predefined valence electron count. Previously, assign_general would return an error for any element without a valence definition, regardless of its bonding state. Now, the system safely defaults to zero valence electrons for isolated atoms (degree 0), allowing them to be processed correctly. Bonded atoms with unknown valence will still trigger an error to ensure chemical correctness.

Changes:

  • Modified assign_general in electrons.rs to check the atom's degree.
  • If valence_electrons() returns None but the atom is isolated (degree == 0), the valence is now defaulted to 0 instead of returning an error.
  • Added unit tests:
    • isolated_unknown_valence_metal_defaults_to_zero: Verifies that an isolated Gold (Au) atom is processed without error.
    • bonded_unknown_valence_metal_errors: Confirms that a bonded Gold atom still raises a PerceptionError, maintaining safety for bonded systems.

@TKanX TKanX self-assigned this Dec 9, 2025
Copilot AI review requested due to automatic review settings December 9, 2025 12:55
@TKanX TKanX added bug 🐛 Something isn't working enhancement ✨ New feature or request labels Dec 9, 2025
@TKanX TKanX linked an issue Dec 9, 2025 that may be closed by this pull request
8 tasks
Copy link
Copy Markdown
Contributor

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 pull request fixes a crash in the electron perception logic when processing isolated metal atoms (e.g., Au, transition metals) that lack predefined valence electron counts. The fix introduces a graceful fallback that defaults to zero valence electrons for isolated atoms (degree 0) while maintaining the existing error behavior for bonded atoms with unknown valence.

Key Changes

  • Modified assign_general to check atom degree before erroring on unknown valence
  • Isolated atoms with unknown valence now default to 0 valence electrons instead of crashing
  • Added comprehensive test coverage for both isolated and bonded unknown-valence cases

Reviewed changes

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

File Description
src/perception/electrons.rs Updated valence assignment logic to handle isolated atoms gracefully; added unit tests for isolated Au and bonded Au-H cases
docs/02_perception.md Updated electron assignment documentation to describe the new degree-0 fallback behavior

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

@TKanX TKanX merged commit 2a8856f into main Dec 9, 2025
8 checks passed
@TKanX TKanX deleted the bugfix/17-harden-electron-perception-for-missing-valence-metals branch December 9, 2025 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug 🐛 Something isn't working enhancement ✨ New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Harden Electron Perception for Missing Valence Metals

2 participants