| import warnings |
| from types import MethodType |
|
|
| import torch |
| from ase.units import GPa |
| from mattersim.datasets.utils.build import build_dataloader |
| from mattersim.forcefield.potential import Potential |
|
|
| warnings.filterwarnings("ignore") |
|
|
| |
|
|
|
|
| def load_pretrained_mattersim(device="cpu"): |
| mattersim_model = Potential.from_checkpoint( |
| load_path="mattersim-v1.0.0-1m", device=device |
| ) |
|
|
| mattersim_model.original_forward = mattersim_model.forward |
|
|
| def forward(self, atoms): |
| dataloader = build_dataloader([atoms], only_inference=True) |
| mattersim_model.forward = mattersim_model.original_forward |
| predictions = mattersim_model.mattersim_forward( |
| dataloader, include_forces=True, include_stresses=True |
| ) |
| mattersim_model.forward = MethodType(forward, mattersim_model) |
| s = predictions[2][0] * GPa |
| stress = torch.tensor([s[0, 0], s[1, 1], s[2, 2], s[1, 2], s[0, 2], s[0, 1]], device=device) |
| results = { |
| "energy": torch.tensor(predictions[0][0], device=device), |
| "forces": torch.tensor(predictions[1][0], device=device), |
| "stress": stress, |
| } |
| return results |
|
|
| mattersim_model.mattersim_forward = mattersim_model.predict_properties |
| mattersim_model.forward = MethodType(forward, mattersim_model) |
| return mattersim_model |
|
|
|
|
|
|
|
|
|
|
| """ |
| from ase.io import read |
| |
| atoms = read("/store/nosnap/mlip-eval/uip-data/amcsd_processed_final/all/Abellaite/0_Abellaite_298.00_1.01_.cif") |
| |
| structures = [atoms] |
| device = "cpu" |
| potential = Potential.from_checkpoint(device=device) |
| dataloader = build_dataloader(structures, only_inference=True) |
| for _ in range(5): |
| predictions = potential.predict_properties(dataloader, include_forces=True, include_stresses=True) |
| """ |
|
|
|
|
| |
| |
|
|
| |
| |
|
|
| |
| |
| |
| |
|
|
| |
| |
|
|
| |
| |
|
|
| |
| |
| |
| |
| |
|
|