Eastsheng's Wiki

DP-GEN生成深度学习模型:methane

2024-10-21 12:18:28

[toc]

DP-GEN (Deep Generator)是一个用Python编写的软件,精心设计用于生成基于原子间势能和力场的深度学习模型,依赖于DeepMD-kit。

下载并安装

Python >= 3.9

  • pip install

    1
    2
    conda activate base
    pip install dpgen
  • conda install

    1
    conda install -c conda-forge dpgen
  • git clone

    1
    git clone https://github.com/deepmodeling/dpgen && pip install ./dpgen

快速上手:以甲烷力场构建为例

在本地WSL-Ubuntu 20.04运行

1
dpgen -h

DP-GEN功能多样,包括init_bulk、init_surf、run和test

  • DP-GEN的run工作流是由以下三步组成的循环:

    • 训练:DeePMD-kit同时训练 多条(一般是4条)参数初始化不同的势函数;

    • 采样和筛选:基于训练得到的势函数和指定的初始结构利用LAMMPS进行classical MD,扩展构型空间。然后对MD中得到的构型依照特定指标(对某个构型用不同的势函数预测所得的原子力的标准差)进行筛选;

    • 标记:将筛选所得的构型进行DFT-MD单点能计算(VASP/CP2K),得到力和能量,加入训练集进行新一轮的训练。

  • DP-GEN所需输入文件:

    • 参数设置文件param.json

      三步计算中所用的参数,具体指神经网络训练的参数,lammps中MD的参数和DFT-MD计算单点能的参数。

    • 机器配置文件machine.json

      制定上述三个步骤分别采用什么软件、CPU/GPU、运行核数、服务器等配置。

    • 初始训练集数据(init)

      放在提交dpgen所在的服务器上,用于训练势函数,可以自己准备也可以参照DeePMD-kit中方法生成。

    • MD采样的初始结构

输入文件例子

param.json

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
{
"type_map": ["H","C"],
"mass_map": [1,12],
"init_data_prefix": "../",
"init_data_sys": ["init/CH4.POSCAR.01x01x01/02.md/sys-0004-0001/deepmd"],
"sys_configs_prefix": "../",
"sys_configs": [
["init/CH4.POSCAR.01x01x01/01.scale_pert/sys-0004-0001/scale-1.000/00000*/POSCAR"],
["init/CH4.POSCAR.01x01x01/01.scale_pert/sys-0004-0001/scale-1.000/00001*/POSCAR"]
],
"_comment": " that's all ",
"numb_models": 4,
"default_training_param": {
"model": {
"type_map": ["H","C"],
"descriptor": {
"type": "se_a",
"sel": [16,4],
"rcut_smth": 0.5,
"rcut": 5.0,
"neuron": [120,120,120],
"resnet_dt": true,
"axis_neuron": 12,
"seed": 1
},
"fitting_net": {
"neuron": [25,50,100],
"resnet_dt": false,
"seed": 1
}
},
"learning_rate": {
"type": "exp",
"start_lr": 0.001,
"decay_steps": 5000
},
"loss": {
"start_pref_e": 0.02,
"limit_pref_e": 2,
"start_pref_f": 1000,
"limit_pref_f": 1,
"start_pref_v": 0.0,
"limit_pref_v": 0.0
},
"training": {
"stop_batch": 2000,
"disp_file": "lcurve.out",
"disp_freq": 1000,
"numb_test": 4,
"save_freq": 1000,
"save_ckpt": "model.ckpt",
"disp_training": true,
"time_training": true,
"profiling": false,
"profiling_file": "timeline.json",
"_comment": "that's all"
}
},
"model_devi_dt": 0.002,
"model_devi_skip": 0,
"model_devi_f_trust_lo": 0.05,
"model_devi_f_trust_hi": 0.15,
"model_devi_e_trust_lo": 10000000000.0,
"model_devi_e_trust_hi": 10000000000.0,
"model_devi_clean_traj": true,
"model_devi_jobs": [
{"sys_idx": [0],"temps": [100],"press": [1.0],"trj_freq": 10,"nsteps": 300,"ensemble": "nvt","_idx": "00"},
{"sys_idx": [1],"temps": [100],"press": [1.0],"trj_freq": 10,"nsteps": 3000,"ensemble": "nvt","_idx": "01"}
],
"fp_style": "vasp",
"shuffle_poscar": false,
"fp_task_max": 20,
"fp_task_min": 5,
"fp_pp_path": "./",
"fp_pp_files": ["POTCAR_H","POTCAR_C"],
"fp_incar": "./INCAR_methane"
}

machine.json

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
{
"api_version": "1.0",
"train" :[
{
"command": "dp",
"machine": {
"batch_type": "Shell",
"context_type": "local",
"local_root" : "./",
"remote_root": "/home/cup/workspace/deepmd/methane/dpgen_example/run/temp"
},
"resources": {
"number_node": 1,
"cpu_per_node": 8,
"gpu_per_node": 0,
"group_size": 4,
"source_list": ["/home/cup/softwares/deepmd-kit/bin/activate"]
}
}
],
"model_devi":[
{
"command": "mpirun -np 8 lmp_mpi -i input.lammps",
"machine": {
"batch_type": "Shell",
"context_type": "local",
"local_root" : "./",
"remote_root": "/home/cup/workspace/deepmd/methane/dpgen_example/run/temp"
},
"resources": {
"number_node": 1,
"cpu_per_node": 8,
"gpu_per_node": 0,
"group_size": 5
}
}
],
"fp":[
{
"command": "ulimit -s unlimited && mpirun -np 8 vasp_std",
"machine": {
"batch_type": "Shell",
"context_type": "local",
"local_root" : "./",
"remote_root": "/home/cup/workspace/deepmd/methane/dpgen_example/run/temp"
},
"resources": {
"number_node": 1,
"cpu_per_node": 8,
"gpu_per_node": 0,
"group_size": 4,
"source_list": ["/home/cup/softwares/vasp/env.sh"]
}
}
]
}

初始训练集数据

运行

1
dpgen run param.json machine.json

结果分析

  • tree ./ -L 2

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    ├── dpdispatcher.log
    ├── dpgen.log
    ├── INCAR_methane
    ├── iter.000000
    │   ├── 00.train
    │   ├── 01.model_devi
    │   └── 02.fp
    ├── iter.000001
    │   ├── 00.train
    │   ├── 01.model_devi
    │   └── 02.fp
    ├── iter.000002
    │   └── 00.train
    ├── machine.json
    ├── machine_new.json
    ├── param.json
    ├── POTCAR_C
    ├── POTCAR_H
    ├── record.dpgen
    └── temp

    11 directories, 9 files
  • head record.dpgen:记录运行进程的当前阶段。

    0 0
    0 1
    0 2
    0 3
    0 4
    0 5
    0 6
    0 7
    0 8
    1 0

  • tail dpgen.log:包括时间和迭代信息。

    2024-10-21 23:37:08,570 - INFO : ————————-iter.000001 task 07————————–
    2024-10-22 00:09:21,283 - INFO : ————————-iter.000001 task 08————————–
    2024-10-22 00:09:21,312 - INFO : failed frame: 0 in 20 0.00 %
    2024-10-22 00:09:21,313 - INFO : failed tasks: 0 in 20 0.00 %
    2024-10-22 00:09:21,357 - INFO : =============================iter.000002==============================
    2024-10-22 00:09:21,357 - INFO : ————————-iter.000002 task 00————————–
    2024-10-22 00:09:21,364 - INFO : ————————-iter.000002 task 01————————–
    2024-10-22 00:17:52,940 - INFO : ————————-iter.000002 task 02————————–
    2024-10-22 00:17:52,941 - INFO : ————————-iter.000002 task 03————————–
    2024-10-22 00:17:52,941 - INFO : finished

执行LAMMPS

  • 生成的四个模型文件到底用哪个?全部都用?
  • 与DeepMD一致

参考

[1] https://tutorials.deepmodeling.com/en/latest/Tutorials/DP-GEN/learnDoc/DP-GEN_handson.html

[2] https://zhuanlan.zhihu.com/p/348076838

[3] https://zhuanlan.zhihu.com/p/349760551

[4] https://wiki.cheng-group.net/wiki/software_usage/DP-GEN/

[5] https://www.bilibili.com/video/BV1ZZ4y1k7d2/?spm_id_from=333.999.0.0&vd_source=2185efff299da2ddae224af51ba53bcd

[6] https://www.bilibili.com/video/BV1h94y1o72C/?spm_id_from=333.999.0.0&vd_source=2185efff299da2ddae224af51ba53bcd

[7] https://www.bilibili.com/video/BV1JZ4y1E7hp/?spm_id_from=333.999.0.0&vd_source=2185efff299da2ddae224af51ba53bcd

[8] https://www.bilibili.com/video/BV1Tv4y1M72Y?spm_id_from=333.788.videopod.episodes&vd_source=2185efff299da2ddae224af51ba53bcd&p=5

[9] https://www.bilibili.com/video/BV1Ba4y1j7He?spm_id_from=333.788.recommend_more_video.10&vd_source=2185efff299da2ddae224af51ba53bcd

[10] 基于深度势模型的LiCl熔体分子动力学研究

Tags: DeepMD