Conversation
…in general assignment
…ectron perception
… electron perception
8 tasks
Contributor
There was a problem hiding this comment.
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_generalto 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_generalwould 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:
assign_generalinelectrons.rsto check the atom's degree.valence_electrons()returnsNonebut the atom is isolated (degree == 0), the valence is now defaulted to 0 instead of returning an error.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 aPerceptionError, maintaining safety for bonded systems.