Molecular dynamics
MLatom can run molecular dynamics simulation. Here we use the trained model of KREG for H2.
Note
You need to have a KREG model trained in the previous section before running MD.
Now prepare the input file for MD simulation: h2_md_kreg.inp
.
# h2_md_kreg.inp
MD # molecular dynamics
initXYZ=h2_md_kreg_init.xyz # initial geometry; Unit: Angstrom
initVXYZ=h2_md_kreg_init.vxyz # initial velocity; Unit: Angstrom/fs
dt=0.3 # time step; Unit: fs
trun=30 # total time; Unit: fs
ensemble=NVE # NVE ensemble
MLprog=KREG_API # for KREG model implemented in KREG Python API
MLmodelIn=energies.npz # file that saves the model
#MLprog=MLatomF # for KREG model implemented in the Fortran part of MLatom
#MLmodelIn=energies.unf # file that saves the model
#MLmodelType=ANI # or use an ANI model
#MLmodelIn=energies_ani.pt # the ANI model file
And provide the initial XYZ coordinates (h2_md_kreg_init.xyz
) and initial XYZ
velocities (h2_md_kreg_init.vxyz
) of this model.
# h2_md_kreg_init.xyz
2
H 0.0 0.0 1.0
H 0.0 0.0 0.0
Run the MD simulation.
mlatom h2_md_kreg.inp
The result will be saved in traj.xyz
. We can view it by:
cat traj.xyz
In Python, same as above, we should provide the initial XYZ coordinates .xyz
and initial XYZ velocities .vxyz
.
The result will be saved in traj.xyz
.
import mlatom as ml
# Get initial condition
mol = ml.data.molecule.from_xyz_file('h2_md_kreg_init.xyz')
init_cond_db = ml.generate_initial_conditions(molecule = mol,
generation_method = 'user-defined',
file_with_initial_xyz_coordinates = 'h2_md_kreg_init.xyz',
file_with_initial_xyz_velocities = 'h2_md_kreg_init.vxyz')
init_mol = init_cond_db[0]
# Initialize model
model = ml.models.kreg(model_file='energies.npz', ml_program='KREG_API')
# model = ml.models.kreg(model_file='energies.unf', ml_program='MLatomF') # use KREG model from MLatomF
# model = ml.models.ani(model_file='energies_ani.pt') # or use an ANI model
# Run molecular dynamics
dyn = ml.md(model=model,
molecule_with_initial_conditions = init_mol,
ensemble='NVE',
time_step=0.3,
maximum_propagation_time = 30.0)
# Dump trajectory
traj = dyn.molecular_trajectory
traj.dump(filename='traj', format='plain_text')
traj.dump(filename='traj.h5', format='h5md')