Converting units of trained Allegro/NequIP model to match LAMMPS #298
-
I have trained a model using Allegro and am now using it to perform simulations on a system with Lammps. However, I have noticed a discrepancy in the units used by both programs. I chose to use Angstroms for positions, Hartrees for energies, and Hartrees/Angstroms for forces when training my model with Allegro, but Lammps uses Hartrees and Bohrs for electron-style units. My question is, should I retrain my model using the same units as Lammps to ensure consistent results across both the trained model and Lammps? If I continue to use my current model, I understand that the energies will be computed in Hartree correctly, but I may not be able to set the force threshold or other internal properties in the correct units. What are your thoughts and suggestions on this issue? How can I resolve this discrepancy and ensure the accuracy of my simulations? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Hi @ankur56 , The final step in our default NequIP/Allegro models is Given a deployed model import torch
from nequip.scripts.deploy import load_deployed_model
model, metadata = load_deployed_model("deployed.pth", device="cpu", set_global_options=False, freeze=False)
rescale_output = model.model # if nequip>=0.6.0
rescale_output = model # else (older versions)
assert rescale_output.original_name == "RescaleOutput"
with torch.no_grad():
rescale_output.scale_by *= conversion_factor_training_energy_units_to_desired_energy_units
torch.jit.save(model, "deployed-newunits.pth", _extra_files=metadata) Definitely check your predictions in LAMMPS after doing this to confirm their sanity. I would strongly recommend against using a model in LAMMPS whose units are inconsistent with the units LAMMPS is using; that seems like a way for a lot of things to go wrong. |
Beta Was this translation helpful? Give feedback.
Hi @ankur56 ,
The final step in our default NequIP/Allegro models is
RescaleEnergyEtc
, which scales the network's predictions into "physical" or "real" units, i.e. those in which it was trained. This rescaling can be easily modified in a deployed model to create a new deployed model that predicts in different energy units. You can use this to create a model that takes Angstroms and predicts eV (LAMMPSmetal
units) or Angstrom and kcal/mol (real
units). Please note that it is not straightforwardly possible to change the length units of a trained model, only the energy units.Given a deployed model
deployed.pth
, it should basically be this: