| import os |
|
|
| |
| _REPO_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
| _JD_PATH = os.path.join(_REPO_ROOT, "weight", "Jd.pt") |
| if os.path.isfile(_JD_PATH): |
| os.environ.setdefault("ONESCIENCE_UMA_JD_PATH", _JD_PATH) |
|
|
| from ase.build import bulk |
|
|
| from onescience.datapipes.materials.custom_stack.core.atomic_data import ( |
| AtomicData, |
| atomicdata_list_to_batch, |
| ) |
| from onescience.utils.uma.units.mlip_unit import load_predict_unit |
|
|
| |
| atoms_list = [ |
| bulk("Pt"), |
| bulk("Cu"), |
| bulk("NaCl", crystalstructure="rocksalt", a=2.0), |
| ] |
|
|
| |
| atomic_data_list = [ |
| AtomicData.from_ase(atoms, task_name="omat") for atoms in atoms_list |
| ] |
|
|
| |
| batch = atomicdata_list_to_batch(atomic_data_list) |
|
|
| |
| checkpoint_path = os.environ.get( |
| "UMA_CHECKPOINT_PATH", |
| os.path.join(_REPO_ROOT, "weight", "uma-s-1p1_converted.pt"), |
| ) |
| predictor = load_predict_unit(checkpoint_path, device="cuda") |
|
|
| |
| preds = predictor.predict(batch) |
|
|
| |
| for i, atoms in enumerate(atoms_list): |
| energy = preds["energy"][i].item() |
| forces = preds["forces"][batch.batch == i].cpu().numpy() |
|
|
| print(f"\nStructure #{i + 1}: {atoms.get_chemical_formula()}") |
| print("Predicted energy:", energy) |
| print("Predicted forces:\n", forces) |
|
|