-
Notifications
You must be signed in to change notification settings - Fork 4
fix(rf3): add_missing_atoms also, along with giving elements that wer… #171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
37425c4
fix(rf3): add_missing_atoms also, along with giving elements that wer…
k-chrispens 040715f
fix(tests): remove zero occupancy test, we can allow that
k-chrispens e813218
Apply suggestions from code review--handle case where all coordinates…
marcuscollins 37d182e
Update RewardInputs documentation to note that it accepts all non-neg…
marcuscollins File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| """Tests for RewardInputs validation. | ||
|
|
||
| Verifies that RewardInputs.from_atom_array rejects atom arrays with NaN | ||
| B-factors, NaN coordinates, and invalid occupancies. | ||
| """ | ||
|
|
||
| import numpy as np | ||
| import pytest | ||
| from sampleworks.core.rewards.protocol import RewardInputs | ||
|
|
||
|
|
||
| class TestRewardInputsFromAtomArray: | ||
| """Validate that RewardInputs.from_atom_array rejects invalid atom arrays.""" | ||
|
|
||
| def test_nan_b_factors_from_missing_atoms_rejected(self, atom_array_1vme_with_missing_atoms): | ||
| """ | ||
| RewardInputs rejects the raw atom array from add_missing_atoms. | ||
| """ | ||
| with pytest.raises(ValueError, match="NaN B-factors"): | ||
| RewardInputs.from_atom_array(atom_array_1vme_with_missing_atoms, ensemble_size=1) | ||
|
|
||
| def test_cleaned_missing_atoms_accepted(self, atom_array_1vme_with_missing_atoms): | ||
| """After applying the same fixes as the RF3 wrapper, the atom array passes.""" | ||
|
k-chrispens marked this conversation as resolved.
|
||
| aa = atom_array_1vme_with_missing_atoms.copy() | ||
|
|
||
| # Fix NaN coordinates | ||
| nan_coord_mask = np.any(np.isnan(aa.coord), axis=-1) | ||
| if nan_coord_mask.any(): | ||
| resolved_coords = aa.coord[~nan_coord_mask] | ||
| if len(resolved_coords) > 0: | ||
| centroid = resolved_coords.mean(axis=0) | ||
| else: | ||
| centroid = np.zeros(3) | ||
| n_nan = int(nan_coord_mask.sum()) | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| noise = np.random.normal(loc=0.0, scale=1.0, size=(n_nan, 3)).astype(np.float32) | ||
|
marcuscollins marked this conversation as resolved.
|
||
| new_coords = aa.coord.copy() | ||
| new_coords[nan_coord_mask] = centroid + noise | ||
| aa.coord = new_coords | ||
|
|
||
| # Fix occupancy | ||
| aa.set_annotation("occupancy", np.ones(len(aa), dtype=np.float32)) | ||
|
|
||
| # Fix NaN b_factors | ||
| nan_b_mask = np.isnan(aa.b_factor) | ||
| if nan_b_mask.any(): | ||
| b_factors = aa.b_factor.copy() | ||
| b_factors[nan_b_mask] = 20.0 | ||
| aa.set_annotation("b_factor", b_factors) | ||
|
|
||
| reward_inputs = RewardInputs.from_atom_array(aa, ensemble_size=1) | ||
| assert reward_inputs.b_factors.shape[-1] == len(aa) | ||
|
|
||
| def test_nan_coordinates_rejected(self, structure_1vme): | ||
| """NaN coordinates must be caught before constructing reward tensors.""" | ||
| atom_array = structure_1vme["asym_unit"].copy() | ||
| # Fix any pre-existing NaN b_factors so the coordinate check passes | ||
| b_factors = np.nan_to_num(atom_array.b_factor, nan=20.0) | ||
| atom_array.set_annotation("b_factor", b_factors) | ||
| coords = atom_array.coord.copy() | ||
| coords[..., 3, :] = np.nan | ||
| atom_array.coord = coords | ||
|
k-chrispens marked this conversation as resolved.
|
||
|
|
||
| with pytest.raises(ValueError, match="NaN coordinates"): | ||
| RewardInputs.from_atom_array(atom_array, ensemble_size=1) | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.