SchNet calculator
SchNet is one of the most popular message-passing neural-network-based MLIP.
Below are the instructions on how to initialize the SchNet calculator, to run dynamics simulations within NQCDynamics.jl using ASE interface.
The following instructions will include Julia-based code.
We start with importing NQCDynamics.jl packages and PyCall which allows importing Python-based packages.
using NQCDynamics
using PyCall
using NQCModels
# Importing Python modules with PyCall
io = pyimport("ase.io")
spk_utils = pyimport("schnetpack.utils")
spk_interfaces = pyimport("schnetpack.interfaces")
Now, we specify paths to the model and atoms objects. Then we read the ASE Atoms object and we convert it to NQCDynamics object.
pes_model_path = "path/to/schnet/model/best_model"
atoms_path = "path/to/atoms.xyz"
ase_atoms = io.read(atoms_path)
atoms, positions, cell = NQCDynamics.convert_from_ase_atoms(ase_atoms)
We then set up our SchNet calculator and create NQCModels AdiabaticASEModel object that includes the model.
spk_model = spk_utils.load_model(pes_model_path;map_location="cpu")
model_args = spk_utils.read_from_json("$(pes_model_path)/args.json")
environment_provider = spk_utils.script_utils.settings.get_environment_provider(model_args,device="cpu")
calculator = spk_interfaces.SpkCalculator(spk_model, energy="energy", forces="forces", environment_provider=environment_provider)
ase_atoms.set_calculator(calculator)
pes_model = AdiabaticASEModel(ase_atoms)
Finally, we can use the model to e.g. initialize Simulation object that is employed to run MD simulations.
sim = Simulation{Classical}(atoms, pes_model, cell=cell)