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

sevennet-l3i5 unit test #141

Merged
merged 1 commit into from
Dec 12, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file.
## [0.10.3]
### Added
- SevenNet-l3i5, checkpoint, preset. (keywords: 7net-l3i5, sevennet-l3i5)
- SevenNet-l3i5 test
### Changed
- Now --help do not load unnecessary imports (fast!)
- README
Expand Down
47 changes: 46 additions & 1 deletion tests/unit_tests/test_pretrained.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import pytest
import torch
from ase.build import bulk, molecule
from torch_geometric.data.batch import Batch

from sevenn.atom_graph_data import AtomGraphData
from sevenn.train.dataload import unlabeled_atoms_to_graph
Expand Down Expand Up @@ -116,3 +115,49 @@ def test_7net0_11July2024(atoms_pbc, atoms_mol):

assert acl(g2.inferred_total_energy, g2_ref_e)
assert acl(g2.inferred_force, g2_ref_f)


def test_7net_l3i5(atoms_pbc, atoms_mol):
"""
Reference from v0.9.3.post1 with sevennet_calculator
"""
cp_path = pretrained_name_to_path('7net-l3i5')
model, config = model_from_checkpoint(cp_path)
cutoff = config['cutoff']

g1 = AtomGraphData.from_numpy_dict(unlabeled_atoms_to_graph(atoms_pbc, cutoff))
g2 = AtomGraphData.from_numpy_dict(unlabeled_atoms_to_graph(atoms_mol, cutoff))

model.set_is_batch_data(False)
g1 = model(g1)
g2 = model(g2)

model.set_is_batch_data(True)

g1_ref_e = torch.tensor([-3.611131191253662])
g1_ref_f = torch.tensor(
[
[13.430887, 0.08655541, 0.08754013],
[-13.430886, -0.08655544, -0.08754011],
]
)
g1_ref_s = -1 * torch.tensor(
# xx, yy, zz, xy, yz, zx
[-0.6818918, -0.04104544, -0.04107663, 0.04794561, 0.00565416, 0.04793138]
)

g2_ref_e = torch.tensor([-12.700481414794922])
g2_ref_f = torch.tensor(
[
[0.0, -1.4547814e01, 8.1347866],
[0.0, 1.0308369e01, -1.0880318e01],
[0.0, 4.2394452, 2.7455316],
]
)

assert acl(g1.inferred_total_energy, g1_ref_e)
assert acl(g1.inferred_force, g1_ref_f)
assert acl(g1.inferred_stress, g1_ref_s)

assert acl(g2.inferred_total_energy, g2_ref_e)
assert acl(g2.inferred_force, g2_ref_f)
Loading