Table of contents
Use DeePMD-kit
In this tutorial, we will call the deep neural network that is used to represent the interatomic interactions (Deep Potential) the model. The typical procedure of using DeePMD-kit is
- Prepare data
- Train a model
- Freeze the model
- MD runs with the model (LAMMPS or ASE)
In this tutorial, we will take water as an example to practice the deepmd-kit, the folders in
/root/workshop/deepmd-kit
are:
1 | . |
ase
folder contains the script for invoking deep potential fromASE
,data
folder contains the raw data for training, test and practice,interfaces
folder contains a simple example for python script,lmp
folder contains the input file for LAMMPS MD run andtrain
folder contains the input file for trainning the model. In every folder, the sub-folderref
means the reference data and thecalc
can be used for your practice.
Prepare data
One needs to extract the following information from DFT calculation to train a model: the atom type, the simulation box, the atom coordinate, the atom force, system energy and virial. A snapshot of a system that contains these information is called a frame. We use the following convention of units:
Properties | Unit |
---|---|
Time | ps |
Length | Å |
Energy | eV |
Force | eV/Å |
Pressure | Bar |
Once you finished runing the DFT calculation, you may run the following command:
1 | from dpdata import LabeledSystem |
then you can convert DFT data into DeepMD-kit format. The directory tree is similar to this:
1 | deepmd/ |
we will skip the above step, since we have already prepared the data set in the folder:
/root/workshop/deepmd-kit/data/deepmd
You may change directory to this folder:
1 | cd /root/workshop/deepmd-kit/data/deepmd |
it contains related files:
1 | box.raw coord.raw energy.raw force.raw set.000 set.001 type_map.raw type.raw |
Or you may change directory to this folder:
1 | $ cd /root/workshop/deepmd-kit/data/others/Li |
then run the following command:
1 | $ python script.py |
The standard output will shows:
1 | Data Summary |
By running this script, you can convert VASP output file to deepmd raw and npy data format.
Train a model
Write the input script
Here we provide a small training dataset taken from 400 frames generated by NVT ab-initio water MD trajectory with 300 frames for training and 100 for validation. One can configure the input file by
1 | $ cd /root/workshop/deepmd-kit/train/calc |
where water.json
is the json
format parameter file that controls the training.
Training
The training can be invoked by
1 | $ cd /root/workshop/deepmd-kit/train/calc |
During the training, the error of the model is tested every disp_freq
batches with numb_test
frames from the last set in the systems
directory on the fly, and the results are output to lcurve.out
. A typical lcurve.out
looks like
1 | # batch l2_tst l2_trn l2_e_tst l2_e_trn l2_f_tst l2_f_trn lr |
Freeze a model
After finishing training, the trained neural network can be extracted from a checkpoint and dumped into a database. This process is called “freezing” a model. To freeze a model, typically one does
1 | $ cd /root/workshop/deepmd-kit/train/calc |
in the folder where the model is trained. The output database is called graph.pb
.
Test a model
The frozen model can be used in many ways.The most straightforward test can be performed using dp test
. Assuming that you have prepared the test set in folder: /root/workshop/deepmd-kit/data/test
. To test the performace of model, you should run the following command:
1 | $ cd /root/workshop/deepmd-kit/train/calc |
The standard ouput is:
1 | # number of test data : 30 |
at the same time, the output files result.e.out
, result.f.out
and result.v.out
will record the predicted energy, force and viral information.
Model inference
To use the python interface of DeePMD-kit for model inference, an example is given as follows
1 | import deepmd.DeepPot as DP |
where e
, f
and v
are predicted energy, force and virial of the system, respectively.
To run this example, just type:
1 | $ cd /root/workshop/deepmd-kit/interfaces/calc |
Run MD with LAMMPS
Include deepmd in the pair style
Here we will use the previous water potential to run MD with LAMMPS. In the LAMMPS input file, one needs to specify the pair style as follows
1 | # bulk water |
where graph.pb
is the file name of the frozen model. The pair_coeff
should be left blank. It should be noted that LAMMPS counts atom types starting from 1, therefore, all LAMMPS atom type will be firstly subtracted by 1, and then passed into the DeePMD-kit engine to compute the interactions.
To run this example, just type:
1 | $ cd /root/workshop/deepmd-kit/lmp/calc |
Use deep potential with ASE
Deep potential can be set up as a calculator with ASE to obtain potential energies and forces.
1 | from ase import Atoms |
To run this example, just type:
1 | $ cd /root/workshop/deepmd-kit/ase/calc |
Optimization is also available:
1 | from ase import Atoms |
To run this example, just type:
1 | $ cd /root/workshop/deepmd-kit/ase/calc |