首页 >> 仿真软件说明 >>ABACUS >>朱雪刚版 >> 4.1.3.2 dp训练质量测试 2024.04.15
详细内容

4.1.3.2 dp训练质量测试 2024.04.15

在训练出初步势函数后,首先应该对势函数的准确性进行验证,除了上述loss函数,力和能量差值以外,还可以通过利用势函数计算材料性质进行验证。对于平衡态附近的性质包括:EOS计算对比,杨氏模量对比,声子谱对比

首先利用DPGEN的自带的autotest功能计算一些性质,对于对比结果,关于ABACUS+DPGEN计算EOS的细节详见2.3.1,计算方法准确性验证。

  1. EOS计算对比 2024.05.30

EOS是equation of state状态方程,即能量和压缩拉伸之间的关系,当把模拟盒子压缩或拉伸一定程度,对应的能量变化曲线。

  1. DPGEN init_bulk +dptest

由于DPGEN的init_bulk可以对模拟盒子进行缩放,因此可以利用该功能进行能量和力的对比,并作图。由于DPGEN init_bulk和dptest已经在前边教程中有过讲解,因此这里不再给出具体做法。

基本步骤:

1:DPGEN init_bulk 对体系从0.60-2.0缩放并准备训练集,注意要把DFT中md的计算修改为scf计算(DPGEN收集数据出错,需要使用dpdata进行数据收集)

2:dptest 或dpdata测试训练集精确度

3:修改python脚本,把能量和力画成EOS图像

  1. DPGEN autotest 测DP势函数的EOS

ABACUS做DFT的autotest做EOS已经在前边给出详细操作教程。此处主要给出用DP势函数做autotest的计算。做计算首先需要对晶胞进行优化,获得稳定的基态构型和能量。之后对基态构型进行一定比例的缩放,并利用势函数计算材料能量和缩放比例之间的关系。


  1. 准备文件

运行DPGEN的autotest计算材料性质,做结构优化需要需要relaxation.json,做性质计算需要property.json,以及需要计算材料的结构文件。


对于EOS计算relaxation.json设置如下

{
   "structures":         ["confs/Be*"],
   "interaction": {
           "type":        "deepmd",
           "model":       "frozen_model.pb",
           "in_lammps":   "lammps_input/in.lammps",
           "type_map":   {"Be":0}
   },
   "relaxation": {
           "cal_setting":{"etol": 1e-12,
                          "ftol": 1e-6,
                          "maxiter": 5000,
                          "maximal": 500000,
                          "relax_shape":     true,
                          "relax_vol":       true}
   }
}

"structures":       ["confs/Be*"],#是做EOS计算结构文件所在文件夹,我在当前目录下建立了confs/Be54_hcp和confs/Be108_fcc两个文件夹,此处使用通配符“*”就会在两个文件夹下分别计算,并给出结果。下边的property.json设置需要跟这里一样才能在对应的文件夹下生成最终结构。


对于EOS计算property.json设置如下

{
   "structures":       ["confs/Be*"],
   "interaction": {
       "type":          "deepmd",
       "model":         "frozen_model.pb",
       "deepmd_version":"2.1.0",
       "type_map":     {"Be":0}
   },
   "properties": [
       {
        "type":         "eos",
        "vol_start":    0.55,
        "vol_end":      2.60,
        "vol_step":     0.05,
       "fix_shape":true
       }
   ]
}

"vol_start":    0.55,#EOS压缩最大比率 "vol_end":      2.60,#拉伸最大比率

"vol_step":     0.05,#压缩和拉伸之间取点间隔比率

由于我关注的研究问题涉及到了多晶模型,因此在做测试时考虑的原子距离范围比较大。


结构文件准备:经过测试,目前我使用的dpgen--Version: 0.11.1读取文件结构时需要在文件夹下有VASP的POSCAR文件才能正常计算DeePMD的EOS,我准备的ABACSU的STRU,LAMMPS的*.lmp等构型都不能正常读取。DPGEN会把

"structures":       ["confs/Be*"],中的"confs/Be*读入成文件夹路径,如果文件夹下有文件以Be开头命名也会导致读入出错。


势函数文件把frozen_model.pb放置到当前目录下,或在relax.json和property.json中正确指定势函数文件位置。


  1. 运行DPGEN autotest

跟ABACUS做EOS计算一样,分别需要对relax和property进行准备“make” 运行“run” 和后处理“post”


dpgen autotest make relax.json
dpgen autotest run relax.json machine.json
dpgen autotest post relax.json
dpgen autotest make property.json
dpgen autotest run property.json machine.json
dpgen autotest post property.json


其中在运行过程时间稍微多一些,如果要后台运行的话需要使用

nohup dpgen autotest run relax.json machine.json 1>log 2>err&

运行任何命令都会在对应的结构文件夹下生成新的文件或文件夹,这里不再解释。

  1. 计算结果画图

把ABACUS计算结果画图的python脚本路劲和注释进行修改即可用来画图

import numpy as np
import matplotlib.pyplot as plt

# 读取数据
data = np.loadtxt('/home/zxg/BeCu/dpgen/properties_compare/dp_dft_autotest/eos_dp/confs/Be54_hcp/eos_00/result.out', skiprows=2)
# 提取x和y数据
x = data[:, 0]
y = data[:, 1]

# 进行二次方的线性拟合
coefficients = np.polyfit(x, y, 3)
fit_func = np.poly1d(coefficients)
fit_y = fit_func(x)
# 绘制原始数据和拟合曲线
plt.plot(x, y, 'o', label='no fit data of dp potential', markersize=10, linewidth=2)
plt.plot(x, fit_y, label='fit with function order of tree', markersize=10, linewidth=2)
# 添加标题和标签
plt.title('Data Plot with Quadratic Fit')
plt.xlabel('VpA(A^3)')
plt.ylabel('EpA(eV)')

# 添加图例
plt.legend()

# 保存图像
plt.savefig('eos_Be54_hcp.png')


EOS计算获得之后需要把DFT和dp的进行对比,如果作图则需要修改python脚本,任何人都可通过借助智普清言等大语言模型完成。暂时不再给出。

  1. DPGEN autotest测杨氏模量 2024.05.30
  1. 准备DPGEN autotest求elastic的输入文件

对于elastic计算relaxation.json设置和EOS计算一样

{
   "structures":         ["confs/Be54*"],
   "interaction": {
           "type":        "deepmd",
           "model":       "frozen_model.pb",
           "in_lammps":   "lammps_input/in.lammps",
           "type_map":   {"Be":0}
   },
   "relaxation": {
           "cal_setting":{"etol": 1e-12,
                          "ftol": 1e-6,
                          "maxiter": 5000,
                          "maximal": 500000,
                          "relax_shape":     true,
                          "relax_vol":       true}
   }
}

property.json需要把计算的性质修改为elastic相关内容:如下

{
   "structures":       ["confs/Be54*"],
   "interaction": {
       "type":          "deepmd",
       "model":         "frozen_model.pb",
       "deepmd_version":"2.1.0",
       "type_map":     {"Be":0}
   },
   "properties": [
       {
           "type":         "elastic",
           "norm_deform":  2e-2,
           "shear_deform": 5e-2
       }
   ]
}

同样需要准备POSCAR来计算LAMMPS的后续结构对应的任务,

  1. 运行dpgen autotest

dpgen autotest make relax.json
dpgen autotest run relax.json machine.json
dpgen autotest post relax.json
dpgen autotest make property.json
dpgen autotest run property.json machine.json
dpgen autotest post property.json

同样需要结构优化的准备(make) 运行(run)和后处理(post),以及性质计算的准备(make) 运行(run)和后处理(post)


  1. 计算结果示例

DP势函数的计算结果如下,同时可以铜DFT计算的结果进行对比来验证势函数的准确性

/home/zxg/BeCu/dpgen/properties_compare/dp_dft_autotest/elastic_dp/confs/Be54_hcp/elastic_00
298.98   23.62   20.52    0.00    0.00    0.00
 26.66  293.53   20.29   -0.00   -0.00   -0.00
 24.67   24.67  356.44    0.00   -0.00    0.00
  0.00    0.00    0.00  156.17    0.00   -0.00
  0.00    0.00    0.00    0.00  159.47   -0.00
  0.00   -0.00    0.00    0.00   -0.00  129.52
# Bulk   Modulus BV = 121.04 GPa
# Shear  Modulus GV = 148.00 GPa
# Youngs Modulus EV = 315.44 GPa
# Poission Ratio uV = 0.07

  1. 缺陷原子vacancy能量计算DPGEN autotest 2024.05.30
  1. 准备DPGEN autotest求vacancy的输入文件

对于vacancy计算relaxation.json设置和EOS以及elastic的计算一样

{
   "structures":         ["confs/Be54*"],
   "interaction": {
           "type":        "deepmd",
           "model":       "frozen_model.pb",
           "in_lammps":   "lammps_input/in.lammps",
           "type_map":   {"Be":0}
   },
   "relaxation": {
           "cal_setting":{"etol": 1e-12,
                          "ftol": 1e-6,
                          "maxiter": 5000,
                          "maximal": 500000,
                          "relax_shape":     true,
                          "relax_vol":       true}
   }
}

property.json需要把计算的性质修改为vacancy相关内容:如下

{
   "structures":       ["confs/Be54*"],
   "interaction": {
       "type":          "deepmd",
       "model":         "frozen_model.pb",
       "deepmd_version":"2.1.0",
       "type_map":     {"Be":0}
   },
   "properties": [
       {
           "type":             "vacancy",
           "supercell":        [1, 1, 1]
       }
   ]
}

同样需要准备POSCAR来计算LAMMPS的后续结构对应的任务

  1. 运行dpgen autotest

dpgen autotest make relax.json
dpgen autotest run relax.json machine.json
dpgen autotest post relax.json
dpgen autotest make property.json
dpgen autotest run property.json machine.json
dpgen autotest post property.json

同样需要结构优化的准备(make) 运行(run)和后处理(post),以及性质计算的准备(make) 运行(run)和后处理(post)。DPGEN会自动在LAMMPS计算文件夹下删除一个原子用以计算后续的间隙原子能量。


  1. 计算结果示例

在confs/Be54_hcp/vacancy_00/result.out中能看到最终的缺陷原子形成能信息,如下

/home/zxg/BeCu/dpgen/properties_compare/dp_dft_autotest/vacancy_dp/confs/Be54_hcp/vacancy_00
Structure:         Vac_E(eV)  E(eV) equi_E(eV)
[1, 1, 1]-task.000000:   0.926  -19183.887 -19184.813

  1. 间隙原子interstitial能量计算DPGEN autotest 2024.05.30
  1. 准备DPGEN autotest文件

对于vacancy计算relaxation.json设置和EOS以及elastic的计算一样,为了少复制几个DP势函数,我把DP势函数放置到特定文件夹下,用绝对路径来引用DP势函数

{
   "structures":         ["confs/Be54*"],
   "interaction": {
           "type":        "deepmd",
           "model":       "/home/zxg/BeCu/dpgennew/dp_potential/inter09/000/frozen_model.pb",
           "in_lammps":   "lammps_input/in.lammps",
           "type_map":   {"Be":0}
   },
   "relaxation": {
           "cal_setting":{"etol": 1e-12,
                          "ftol": 1e-6,
                          "maxiter": 5000,
                          "maximal": 500000,
                          "relax_shape":     true,
                          "relax_vol":       true}
   }
}

同样property.json也是用绝对路径

{
   "structures":       ["confs/Be54*"],
   "interaction": {
       "type":          "deepmd",
       "model":         "/home/zxg/BeCu/dpgennew/dp_potential/inter09/000/frozen_model.pb",
       "deepmd_version":"2.1.0",
       "type_map":     {"Be":0}
   },
   "properties": [
       {
           "type":         "interstitial",
           "supercell":   [1, 1, 1],
           "insert_ele":  ["Be"],
           "conf_filters":{"min_dist": 1.5},
           "cal_setting": {"input_prop": "lammps_input/lammps_high"}
       }
   ]
}

另外,需要准备结构文件的POSCAR文件,可用atomkit进行转换。

  1. 运行DPGEN 的autotest 计算

dpgen autotest make relax.json
dpgen autotest run relax.json machine.json
dpgen autotest post relax.json
dpgen autotest make property.json
dpgen autotest run property.json machine.json
dpgen autotest post property.json

需要结构优化的准备(make) 运行(run)和后处理(post),以及性质计算的准备(make) 运行(run)和后处理(post)。DPGEN会自动在LAMMPS计算文件夹下增加一个原子用以计算后续的间隙原子能量。

  1. 计算结果示例

Insert_ele-Struct: Inter_E(eV)  E(eV) equi_E(eV)
Be-[1, 1, 1]-task.000000:   4.859  -19903.910 -19908.769

  1. 表面形成能surface formation energy 计算DPGEN autotest 2024.05.30
  1. 准备DPGEN autotest文件

relaxation.json跟前边的一致

{
   "structures":         ["confs/Be108*"],
   "interaction": {
           "type":        "deepmd",
           "model":       "/home/zxg/BeCu/dpgennew/dp_potential/inter09/000/frozen_model.pb",
           "in_lammps":   "lammps_input/in.lammps",
           "type_map":   {"Be":0}
   },
   "relaxation": {
           "cal_setting":{"etol": 1e-12,
                          "ftol": 1e-6,
                          "maxiter": 5000,
                          "maximal": 500000,
                          "relax_shape":     true,
                          "relax_vol":       true}
   }
}


property.json需要把计算"properties":内部内容进行修改

{
   "structures":       ["confs/Be108*"],
   "interaction": {
       "type":          "deepmd",
       "model":         "/home/zxg/BeCu/dpgennew/dp_potential/inter09/000/frozen_model.pb",
       "deepmd_version":"2.1.0",
       "type_map":     {"Be":0}
   },
   "properties": [
       {
           "type":           "surface",
           "min_slab_size":  10,
           "min_vacuum_size":11,
           "max_miller":     1,
           "cal_type":       "static",
           "static-opt": true,
          "pert_xz":0.01,
          "relax_box":false
       }
   ]
}


同样需要准备VASP的POSCAR结构文件,DPGEN会将其转换成LAMMPS的结构文件conf.lmp并做对应的表面的截取。


  1. 运行dpgen autotest

需要结构优化的准备(make) 运行(run)和后处理(post),以及性质计算的准备(make) 运行(run)和后处理(post)。DPGEN会自动在LAMMPS计算文件夹下增加一个原子用以计算后续的间隙原子能量。

dpgen autotest make relax.json
dpgen autotest run relax.json machine.json
dpgen autotest post relax.json
dpgen autotest make property.json
dpgen autotest run property.json machine.json
dpgen autotest post property.json

  1. 计算结果示例

(由于结构复制错误成hcp构型,因此计算结果是错误的,但出了计算结果)

/home/zxg/BeCu/dpgen/properties_compare/dp_dft_autotest/surface_dp/confs/Be108_fcc/surface_00
Miller_Indices:         Surf_E(J/m^2) EpA(eV) equi_EpA(eV)
[1, 1, 1]-task.000000:          0.352    -361.951 -361.978
[1, 1, 0]-task.000001:          0.566    -361.923 -361.978
[1, 0, 1]-task.000002:          0.374    -361.942 -361.978
[1, 0, 1]-task.000003:          0.161    -361.962 -361.978
[1, 0, 0]-task.000004:          0.728    -361.917 -361.978
[1, 0, 0]-task.000005:          0.174    -361.963 -361.978
[0, 0, 1]-task.000006:         -0.093    -361.986 -361.978


  1. EOS 杨氏模量缺陷原子间隙原子表面形成能一起计算

以上5小节的relaxation.json是一致的,在计算性质时可把以上五个性质合并到一个property.json中进行计算,需要把计算"properties":内部内容进行修改,即[{property_1.seting},{property_2.seting},{property_3.seting},.......,{}]。

同样按照结构优化的准备(make) 运行(run)和后处理(post),以及性质计算的准备(make) 运行(run)和后处理(post)来获取相关性质。

  1. 声子谱对比 phonopy 后补

DFT计算声子谱可参考notebook:ABACUS+Phonopy 计算声子谱

LAMMPS计算声子谱后补

  1. 其他性质查阅相关文献后补充


作者:朱雪刚 邮箱:xuegangzhu@qq.com; 工作单位:石家庄学院 理学院/北京科学智能研究院(AISI)访问学者2023.07-2024.09,访问导师北京大学陈默涵; 徐张满仓 邮箱: xuzhangmancang@dp.tech

截止2024.07.21录制视频教程已上传至Bohrium的课程《DeePMD应用案例讲解:铜原子掺杂铍晶体的机器学习势函数拟合过程演示》网址: https://bohrium.dp.tech/courses/1075495070?tab=courses 后续会在Bohrium平台更新

注意:后续的更新,大部分会在Bohrium课程平台进行,请看教程入门的同学加入课程进行学习;且录制的视频课程会把一些个人观点给加入,从个人观点来看比文字教程的内容更多

写教程内容讨论QQ群:143276924 DPGEN+ABACUS教程准备;

ABACUS软件的QQ群:759914681,群内有专职开发人员,目前ABACUS提问问题以github的issue为主,群内可作为辅助提问。

欢迎大家推广本教程,让更多的dp入门学习者有个参考,目前2024.09.16我联系的微信公众号推广是 lammps加油站的小马老师(我也报名了小马老师的一对一辅导)。当然也看到lammps爱好者在转发推广。感谢大家公众号的推广。


技术支持: CLOUD | 管理登录
seo seo