Skip to content
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

Fix species test #55

Merged
merged 2 commits into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/NanoParticleTools/species_data/species.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,16 @@
with open(os.path.join(SPECIES_DATA_PATH, f'{symbol}.json'),
'r') as f:
species_data = json.load(f)
except FileNotFoundError:
except FileNotFoundError as e:
# File was not found, check if it is a legacy calc
if self.symbol in self.LEGACY_SURFACE_NAMES:
# This is a legacy calc. Load the corresponding calc
symbol = self.LEGACY_SURFACE_NAMES[self.symbol]
with open(os.path.join(SPECIES_DATA_PATH, f'{symbol}.json'),

Check warning on line 212 in src/NanoParticleTools/species_data/species.py

View check run for this annotation

Codecov / codecov/patch

src/NanoParticleTools/species_data/species.py#L211-L212

Added lines #L211 - L212 were not covered by tests
'r') as f:
species_data = json.load(f)

Check warning on line 214 in src/NanoParticleTools/species_data/species.py

View check run for this annotation

Codecov / codecov/patch

src/NanoParticleTools/species_data/species.py#L214

Added line #L214 was not covered by tests
else:
raise e

return species_data

Expand Down
28 changes: 14 additions & 14 deletions tests/machine_learning/models/gnn_model/test_graph_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ def test_graph_interaction_feature_processor(doc_one):
data = feature_processor.data_cls(**_data_dict)
assert data.radii.shape == (3, )
assert data.constraint_radii_idx.shape == (2, 2)
assert torch.allclose(data.constraint_indices, torch.tensor([0, 0, 1, 1]))
assert data.x.shape == (4, )
assert torch.allclose(data.x, torch.tensor([0.499, 0.25, 0.2, 0.1]))
assert torch.allclose(data.dopant_constraint_indices, torch.tensor([0, 0, 1, 1]))
assert data.dopant_concs.shape == (4, )
assert torch.allclose(data.dopant_concs, torch.tensor([0.499, 0.25, 0.2, 0.1]))
assert data.edge_index.shape == (2, 32)


Expand All @@ -180,10 +180,10 @@ def test_graph_interaction_feature_processor_zeros(doc_one):
data = feature_processor.data_cls(**_data_dict)
assert data.radii.shape == (3, )
assert data.constraint_radii_idx.shape == (2, 2)
assert torch.allclose(data.constraint_indices,
assert torch.allclose(data.dopant_constraint_indices,
torch.tensor([0, 0, 0, 1, 1, 1]))
assert data.x.shape == (6, )
assert torch.allclose(data.x, torch.tensor([0.499, 0.25, 0, 0.2, 0.1, 0]))
assert data.dopant_concs.shape == (6, )
assert torch.allclose(data.dopant_concs, torch.tensor([0.499, 0.25, 0, 0.2, 0.1, 0]))
assert data.edge_index.shape == (2, 72)


Expand All @@ -195,10 +195,10 @@ def test_invalid_doc(doc_one_invalid):
data = feature_processor.data_cls(**_data_dict)
assert data.radii.shape == (3, )
assert data.constraint_radii_idx.shape == (2, 2)
assert torch.allclose(data.constraint_indices,
assert torch.allclose(data.dopant_constraint_indices,
torch.tensor([0, 0, 0, 1, 1, 1]))
assert data.x.shape == (6, )
assert torch.allclose(data.x, torch.tensor([0.499, 0.25, 0, 0.2, 0.1, 0]))
assert data.dopant_concs.shape == (6, )
assert torch.allclose(data.dopant_concs, torch.tensor([0.499, 0.25, 0, 0.2, 0.1, 0]))
assert data.edge_index.shape == (2, 72)

feature_processor = GraphInteractionFeatureProcessor(
Expand All @@ -207,9 +207,9 @@ def test_invalid_doc(doc_one_invalid):
data = feature_processor.data_cls(**_data_dict)
assert data.radii.shape == (3, )
assert data.constraint_radii_idx.shape == (2, 2)
assert torch.allclose(data.constraint_indices, torch.tensor([0, 0, 1, 1]))
assert data.x.shape == (4, )
assert torch.allclose(data.x, torch.tensor([0.499, 0.25, 0.2, 0.1]))
assert torch.allclose(data.dopant_constraint_indices, torch.tensor([0, 0, 1, 1]))
assert data.dopant_concs.shape == (4, )
assert torch.allclose(data.dopant_concs, torch.tensor([0.499, 0.25, 0.2, 0.1]))
assert data.edge_index.shape == (2, 32)


Expand All @@ -220,12 +220,12 @@ def test_grad(doc_four):
_data_dict = feature_processor.process_doc(doc_four)
data = feature_processor.data_cls(**_data_dict)
assert data.radii.requires_grad
assert data.x.requires_grad
assert data.dopant_concs.requires_grad

feature_processor = GraphInteractionFeatureProcessor(
possible_elements=['Yb', 'Er', 'Mg'], input_grad=False)

_data_dict = feature_processor.process_doc(doc_four)
data = feature_processor.data_cls(**_data_dict)
assert not data.radii.requires_grad
assert not data.x.requires_grad
assert not data.dopant_concs.requires_grad
Loading