在训练出初步势函数后,首先应该对势函数的准确性进行验证,除了上述loss函数,力和能量差值以外,还可以通过利用势函数计算材料性质进行验证。对于平衡态附近的性质包括:EOS计算对比,杨氏模量对比,声子谱对比
首先利用DPGEN的自带的autotest功能计算一些性质,对于对比结果,关于ABACUS+DPGEN计算EOS的细节详见2.3.1,计算方法准确性验证。
EOS计算对比 2024.05.30
EOS是equation of state状态方程,即能量和压缩拉伸之间的关系,当把模拟盒子压缩或拉伸一定程度,对应的能量变化曲线。
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图像
DPGEN autotest 测DP势函数的EOS
ABACUS做DFT的autotest做EOS已经在前边给出详细操作教程。此处主要给出用DP势函数做autotest的计算。做计算首先需要对晶胞进行优化,获得稳定的基态构型和能量。之后对基态构型进行一定比例的缩放,并利用势函数计算材料能量和缩放比例之间的关系。
准备文件
运行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中正确指定势函数文件位置。
运行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&
运行任何命令都会在对应的结构文件夹下生成新的文件或文件夹,这里不再解释。
计算结果画图
把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脚本,任何人都可通过借助智普清言等大语言模型完成。暂时不再给出。
DPGEN autotest测杨氏模量 2024.05.30
准备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的后续结构对应的任务,
运行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)
计算结果示例
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
缺陷原子vacancy能量计算DPGEN autotest 2024.05.30
准备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的后续结构对应的任务
运行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计算文件夹下删除一个原子用以计算后续的间隙原子能量。
计算结果示例
在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
间隙原子interstitial能量计算DPGEN autotest 2024.05.30
准备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进行转换。
运行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计算文件夹下增加一个原子用以计算后续的间隙原子能量。
计算结果示例
Insert_ele-Struct: Inter_E(eV) E(eV) equi_E(eV)
Be-[1, 1, 1]-task.000000: 4.859 -19903.910 -19908.769
表面形成能surface formation energy 计算DPGEN autotest 2024.05.30
准备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并做对应的表面的截取。
运行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
计算结果示例
(由于结构复制错误成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
作者:朱雪刚 邮箱:xuegangzhu@qq.com; 工作单位:石家庄学院 理学院/北京科学智能研究院(AISI)访问学者2023.07-2024.09,访问导师北京大学陈默涵; 徐张满仓 邮箱: xuzhangmancang@dp.tech