作者:梁文硕liangws@dp.tech, 张琳爽zhanglinshuang@dp.tech
推荐镜像: bohrium-notebook:2023-04-07
推荐资源:CPU
内容:📖 本文档为「能源学人——DeePMD用于电极材料前沿探索案例」课程教学文档。 本教程主要以电池正极材料LiCoO2体系为例,具体展示DP模型在热力学和动力学性质计算中的应用。 如您遇到任何问题,请联系 bohrium@dp.tech 。
注意:由于许可限制,部分内容以视频展示。你可以通过有效的许可在 Bohrium 上运行相关程序。
使用方式: 您可以在 Bohrium Notebook 上直接运行。你可以点击界面上方按钮 开始连接,选择 bohrium-notebook:2023-04-07 镜像及任意节点配置,稍等片刻即可运行。
共享协议:本作品采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议进行许可。
🎯 欢迎阅读《哥伦布训练营 | DeePMD——正极材料实战之性质计算篇》
本文档旨在结合J. Phys. Chem. Lett. 2023, 14, 3677−3684 这篇于2023年发表的使用深度势能进行电池正极材料研究工作,介绍机器学习与分子动力学的结合如何发挥作用的。 接下来,本文档手把手带你复现文章中的电压数据、评估势函数对空位低能构型的搜索能力。
📖 本文将直接使用已经构建好的适用于LiCoO2体系的深度神经网络势函数进行计算,而不再展示势函数构建的过程。
这是因为我们的重点在于展示DPMD方法在实际应用中的性能,而构建神经网络势函数的过程可以在其他相关文献中找到详细介绍。
实践
1 课前准备
数据下载和解压
--2023-07-14 12:53:18-- https://dp-public.oss-cn-beijing.aliyuncs.com/community/demo_LiCoO2.tar.gz Resolving ga.dp.tech (ga.dp.tech)... 10.255.254.37, 10.255.254.7, 10.255.254.18 Connecting to ga.dp.tech (ga.dp.tech)|10.255.254.37|:8118... connected. Proxy request sent, awaiting response... 200 OK Length: 392891040 (375M) [application/gzip] Saving to: ‘demo_LiCoO2.tar.gz’ demo_LiCoO2.tar.gz 100%[===================>] 374.69M 11.8MB/s in 31s 2023-07-14 12:53:51 (12.1 MB/s) - ‘demo_LiCoO2.tar.gz’ saved [392891040/392891040]
lbg 的安装和登录
Lbg是一款用于资源管理、任务管理、项目监控的工具。
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple Requirement already satisfied: lbg in /opt/conda/lib/python3.8/site-packages (1.2.17) Requirement already satisfied: packaging in /opt/conda/lib/python3.8/site-packages (from lbg) (23.0) Requirement already satisfied: tqdm in /opt/conda/lib/python3.8/site-packages (from lbg) (4.64.1) Requirement already satisfied: requests in /opt/conda/lib/python3.8/site-packages (from lbg) (2.28.2) Requirement already satisfied: aliyun-python-sdk-core in /opt/conda/lib/python3.8/site-packages (from lbg) (2.13.36) Requirement already satisfied: validators in /opt/conda/lib/python3.8/site-packages (from lbg) (0.20.0) Requirement already satisfied: pytimeparse in /opt/conda/lib/python3.8/site-packages (from lbg) (1.1.8) Requirement already satisfied: pandas in /opt/conda/lib/python3.8/site-packages (from lbg) (1.5.3) Requirement already satisfied: pyhumps in /opt/conda/lib/python3.8/site-packages (from lbg) (3.8.0) Requirement already satisfied: requests-toolbelt in /opt/conda/lib/python3.8/site-packages (from lbg) (0.10.1) Requirement already satisfied: colorama in /opt/conda/lib/python3.8/site-packages (from lbg) (0.4.6) Requirement already satisfied: aliyun-python-sdk-sts in /opt/conda/lib/python3.8/site-packages (from lbg) (3.1.0) Requirement already satisfied: oss2 in /opt/conda/lib/python3.8/site-packages (from lbg) (2.16.0) Requirement already satisfied: pyreadline3 in /opt/conda/lib/python3.8/site-packages (from lbg) (3.4.1) Requirement already satisfied: argcomplete in /opt/conda/lib/python3.8/site-packages (from lbg) (2.0.0) Requirement already satisfied: pyyaml in /opt/conda/lib/python3.8/site-packages (from lbg) (6.0) Requirement already satisfied: pyreadline in /opt/conda/lib/python3.8/site-packages (from lbg) (2.1) Requirement already satisfied: readchar in /opt/conda/lib/python3.8/site-packages (from lbg) (4.0.3) Requirement already satisfied: aliyun-python-sdk-kms in /opt/conda/lib/python3.8/site-packages (from lbg) (2.16.0) Requirement already satisfied: cryptography>=2.6.0 in /opt/conda/lib/python3.8/site-packages (from aliyun-python-sdk-core->lbg) (39.0.1) Requirement already satisfied: jmespath<1.0.0,>=0.9.3 in /opt/conda/lib/python3.8/site-packages (from aliyun-python-sdk-core->lbg) (0.10.0) Requirement already satisfied: six in /opt/conda/lib/python3.8/site-packages (from oss2->lbg) (1.16.0) Requirement already satisfied: crcmod>=1.7 in /opt/conda/lib/python3.8/site-packages (from oss2->lbg) (1.7) Requirement already satisfied: pycryptodome>=3.4.7 in /opt/conda/lib/python3.8/site-packages (from oss2->lbg) (3.17) Requirement already satisfied: charset-normalizer<4,>=2 in /opt/conda/lib/python3.8/site-packages (from requests->lbg) (3.0.1) Requirement already satisfied: urllib3<1.27,>=1.21.1 in /opt/conda/lib/python3.8/site-packages (from requests->lbg) (1.26.14) Requirement already satisfied: certifi>=2017.4.17 in /opt/conda/lib/python3.8/site-packages (from requests->lbg) (2022.12.7) Requirement already satisfied: idna<4,>=2.5 in /opt/conda/lib/python3.8/site-packages (from requests->lbg) (3.4) Requirement already satisfied: python-dateutil>=2.8.1 in /opt/conda/lib/python3.8/site-packages (from pandas->lbg) (2.8.2) Requirement already satisfied: pytz>=2020.1 in /opt/conda/lib/python3.8/site-packages (from pandas->lbg) (2022.7) Requirement already satisfied: numpy>=1.20.3 in /opt/conda/lib/python3.8/site-packages (from pandas->lbg) (1.22.4) Requirement already satisfied: setuptools>=41.0 in /opt/conda/lib/python3.8/site-packages (from readchar->lbg) (65.6.3) Requirement already satisfied: decorator>=3.4.0 in /opt/conda/lib/python3.8/site-packages (from validators->lbg) (5.1.1) Requirement already satisfied: cffi>=1.12 in /opt/conda/lib/python3.8/site-packages (from cryptography>=2.6.0->aliyun-python-sdk-core->lbg) (1.15.1) Requirement already satisfied: pycparser in /opt/conda/lib/python3.8/site-packages (from cffi>=1.12->cryptography>=2.6.0->aliyun-python-sdk-core->lbg) (2.21) WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
LiCoO2.pb POSCAR POSCAR_optimized energy opt.py
我们可以使用DP模型作为计算器,使用ASE程序,对上述构型进行结构优化。
from ase.io import read, write from ase.io import Trajectory from ase.constraints import StrainFilter from ase.optimize import BFGS from deepmd.calculator import DP import time start_time = time.time() calculator = DP(model="/data/demo_LiCoO2/LiCoO2-opt/DP/LiCoO2.pb") stru = read('/data/demo_LiCoO2/LiCoO2-opt/DP/POSCAR', format='vasp') stru.set_calculator(calculator) sf = StrainFilter(stru) dyn = BFGS(sf) dyn.run(1e-5) write('/data/demo_LiCoO2/LiCoO2-opt/DP/POSCAR_optimized', stru, format='vasp') energy = stru.get_total_energy() with open('/data/demo_LiCoO2/LiCoO2-opt/DP/energy', 'w') as fp: fp.write(str(energy)) print("Execution time: %s seconds" % (time.time() - start_time))
2023-07-14 12:55:03.945950: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2 AVX512F FMA To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags. 2023-07-14 12:55:06.841700: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer.so.7'; dlerror: libnvinfer.so.7: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /usr/mpi/gcc/openmpi-4.1.0rc5/lib:/usr/local/nccl-rdma-sharp-plugins/lib:/usr/local/nvidia/lib64:/usr/local/cuda/lib64:/usr/local/nvidia/lib:/usr/local/nvidia/lib64 2023-07-14 12:55:06.842787: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer_plugin.so.7'; dlerror: libnvinfer_plugin.so.7: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /usr/mpi/gcc/openmpi-4.1.0rc5/lib:/usr/local/nccl-rdma-sharp-plugins/lib:/usr/local/nvidia/lib64:/usr/local/cuda/lib64:/usr/local/nvidia/lib:/usr/local/nvidia/lib64 2023-07-14 12:55:06.842824: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Cannot dlopen some TensorRT libraries. If you would like to use Nvidia GPU with TensorRT, please make sure the missing libraries mentioned above are installed properly. WARNING:tensorflow:From /opt/conda/lib/python3.8/site-packages/tensorflow/python/compat/v2_compat.py:107: disable_resource_variables (from tensorflow.python.ops.variable_scope) is deprecated and will be removed in a future version. Instructions for updating: non-resource variables are not supported in the long term WARNING:root:To get the best performance, it is recommended to adjust the number of threads by setting the environment variables OMP_NUM_THREADS, TF_INTRA_OP_PARALLELISM_THREADS, and TF_INTER_OP_PARALLELISM_THREADS. 2023-07-14 12:55:10.665666: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcuda.so.1'; dlerror: /usr/lib/x86_64-linux-gnu/libcuda.so.1: file too short; LD_LIBRARY_PATH: /usr/mpi/gcc/openmpi-4.1.0rc5/lib:/usr/local/nccl-rdma-sharp-plugins/lib:/usr/local/nvidia/lib64:/usr/local/cuda/lib64:/usr/local/nvidia/lib:/usr/local/nvidia/lib64 2023-07-14 12:55:10.665736: W tensorflow/compiler/xla/stream_executor/cuda/cuda_driver.cc:265] failed call to cuInit: UNKNOWN ERROR (303) WARNING:tensorflow:From /opt/conda/lib/python3.8/site-packages/deepmd/utils/batch_size.py:61: is_gpu_available (from tensorflow.python.framework.test_util) is deprecated and will be removed in a future version. Instructions for updating: Use `tf.config.list_physical_devices('GPU')` instead. WARNING:tensorflow:From /opt/conda/lib/python3.8/site-packages/deepmd/utils/batch_size.py:61: is_gpu_available (from tensorflow.python.framework.test_util) is deprecated and will be removed in a future version. Instructions for updating: Use `tf.config.list_physical_devices('GPU')` instead. WARNING:deepmd.utils.batch_size:You can use the environment variable DP_INFER_BATCH_SIZE tocontrol the inference batch size (nframes * natoms). The default value is 1024. Step Time Energy fmax BFGS: 0 12:55:11 -276.076977 13.9439 BFGS: 1 12:55:11 -243.941126 232.3193 BFGS: 2 12:55:12 -275.882182 26.7527 BFGS: 3 12:55:12 -268.527002 98.5378 BFGS: 4 12:55:12 -276.099741 14.2600 BFGS: 5 12:55:12 -263.858882 127.5108 BFGS: 6 12:55:12 -276.082801 10.1510 BFGS: 7 12:55:12 -274.918630 25.0773 BFGS: 8 12:55:12 -276.200384 1.8851 BFGS: 9 12:55:12 -276.137437 8.3510 BFGS: 10 12:55:12 -276.206263 1.0258 BFGS: 11 12:55:12 -276.205628 0.7183 BFGS: 12 12:55:13 -276.206874 0.1333 BFGS: 13 12:55:13 -276.206885 0.1421 BFGS: 14 12:55:13 -276.206893 0.0012 BFGS: 15 12:55:13 -276.206893 0.0003 BFGS: 16 12:55:13 -276.206893 0.0000 BFGS: 17 12:55:13 -276.206893 0.0000 Execution time: 3.2218334674835205 seconds
我们将DFT和DP数据汇总到/data/demo_LiCoO2/LiCoO2-opt/plot/plot_data
,作图对比DFT和DP的计算精度和计算时长:
name energy time DFT -279.9 1121 DPMD -276.2 3
可以看出,DP模型在能量精度方面与DFT方法表现一致,但计算成本更低。这意味着DP模型,为研究和优化LiCoO等材料的性能提供了更高效的途径。
3 DP 对LiCoO体系电压平台描述
LiCoO作为一种主要的正极材料,在其脱嵌过程中电压变化的计算尤为重要,以指导其在锂离子电池中的实际应用。
通过构建不同脱锂量下的多个构型,并通过DFT和DP对上述构型进行计算,绘制得到的凸包图如下图所示:
通过分析凸包图(Convexhull),我们提取得到了不同脱嵌量时稳定的LixCoO结构,并提取相关数据绘制DFT和DP的电压平台。
文献[1]构建的LiCoODP势函数和DFT在计算LiCoO脱嵌过程电压变化方面的结果具有很高的一致性。
3 基于DP模型的大尺度、长时间MD模拟
在锂离子电池材料中,锂离子在充放电过程中的迁移能力是非常关键的。为了准确模拟这一过程,需要在长时间尺度和较大晶胞的条件下进行计算。然而,传统的AIMD方法往往无法胜任这样的任务。相较之下,DPMD模型可以有效地实现这一目标,为锂离子电池材料的研究提供了有力的支持。
输入文件 in.lammps
LiCoO2.pb
Li0.5CoO2.lmp
param.json
echo both variable pid world 0 # --------------------- VARIABLES------------------------- variable THERMO_FREQ equal 10 variable DUMP_FREQ equal 100 variable TEMP equal 1000.000000 variable TEMP2 equal 1000.000000 variable PRES equal 1.000000 variable TAU_T equal 0.100000 variable TAU_P equal 1.000000 variable Seed equal 32564 variable msdxli equal c_1[1] variable msdyli equal c_1[2] variable msdzli equal c_1[3] variable msdli equal c_1[4] variable msdxCo equal c_2[1] variable msdyCo equal c_2[2] variable msdzCo equal c_2[3] variable msdCo equal c_2[4] variable msdxO equal c_3[1] variable msdyO equal c_3[2] variable msdzO equal c_3[3] variable msdO equal c_3[4] variable istep equal step # ---------------------- INITIALIZAITION ------------------ units metal boundary p p p atom_style atomic # --------------------- ATOM DEFINITION ------------------ box tilt large read_data Li0.5CoO2.input mass 1 6.941 mass 2 58.933 mass 3 16 # --------------------- FORCE FIELDS --------------------- pair_style deepmd LiCoO2.pb pair_coeff * * # --------------------- MD SETTINGS ---------------------- neighbor 1.0 bin timestep 0.001 thermo ${THERMO_FREQ} thermo_style custom step ke pe etotal enthalpy temp press vol lx ly lz xy xz yz pxx pyy pzz pxy pxz pyz restart ${DUMP_FREQ} restart.lmp.${pid} restart2.lmp.${pid} dump 0 all custom ${DUMP_FREQ} dump_${DUMP_FREQ}fs.equi id element x y z dump_modify 0 sort id element Li Co O velocity all create ${TEMP} ${Seed} velocity all zero linear group liatoms type 1 compute 1 liatoms msd com yes fix 4 liatoms print 1 "${istep} ${msdxli} ${msdyli} ${msdzli} ${msdli}" screen no file msd-li.dat group coatoms type 2 compute 2 coatoms msd com yes fix 5 coatoms print 1 "${istep} ${msdxCo} ${msdyCo} ${msdzCo} ${msdCo}" screen no file msd-co.dat group oatoms type 3 compute 3 oatoms msd com yes fix 6 oatoms print 1 "${istep} ${msdxO} ${msdyO} ${msdzO} ${msdO}" screen no file msd-o.dat # --------------------- RUN ------------------------------ fix 7 all npt temp ${TEMP} ${TEMP2} ${TAU_T} aniso ${PRES} ${PRES} ${TAU_P} fix mzero all momentum 10 linear 1 1 1 run 500000 #500 ps unfix 7 write_data data.final
执行提交任务命令:
cd /data/demo_LiCoO2/Diffusion/1000k
lbg job submit -i job.json -p ./
{ "job_name":"1000k-msd", "command": "lmp -in in.start.lmp", "log_file": "log", "backward_file": [], "program_id": 15359, "job_group_id": "", "platform": "ali", "job_type": "container", "machine_type": "c8_m32_1 * NVIDIA V100", "image_name": "registry.dp.tech/dptech/deepmd-kit:2.2.1-cuda11.6", "result": "./" }
输出文件包括dump_100fs.equi
log.lammps
msd-li.dat
等
我们以msd-li.dat为例展示均方位移的输出格式:
# Fix print output for fix 4 0 8.85642451463404e-31 1.05181454029468e-30 2.62953635073671e-31 2.20041062683176e-30 1 0.000116344458795415 0.000116963042388933 9.55739035090524e-05 0.0003288814046934 2 0.000464318945173845 0.000466784343643858 0.000380367050750345 0.00131147033956805 3 0.00104035139671962 0.00104544222445041 0.000848039051181463 0.00293383267235149 4 0.00183760483456243 0.00184481784544355 0.00148702984492018 0.00516945252492616 5 0.00284584814044392 0.00285247390772897 0.00228042533296386 0.00797874738113675 6 0.00405175279157205 0.00405186796364002 0.00320635038403628 0.0113099711392484 7 0.00543913690958795 0.00542271615451357 0.00423864221934627 0.0151004952834478 8 0.00698948386776909 0.00694145158105126 0.00534777243828375 0.0192787078871041 9 0.00868237651918469 0.00858184113920391 0.00650151301706877 0.0237657306754574 10 0.0104958904149312 0.0103154271342036 0.00766602313231568 0.0284773406814505 11 0.0124067912991325 0.0121125214659588 0.00880682480625211 0.0333261375713435 12 0.0143907465753516 0.0139428168584287 0.0098897270138642 0.0382232904476445 13 0.0164227275652906 0.0157758293597513 0.0108815819228767 0.0430801388479186 14 0.0184776396142197 0.0175815279550812 0.0117518061971564 0.0478109737664572 15 0.020530808394137 0.0193305624704187 0.0124739595168928 0.0523353303814485 16 0.0225583793817308 0.0209953367826327 0.0130268758515714 0.0565805920159348 17 0.0245376120970886 0.0225508865994023 0.0133952781816941 0.0604837768781849 18 0.0264476612937954 0.0239753580618043 0.0135704323753613 0.0639934517309609 cat: write error: Broken pipe
MSD计算公式:
其中,表示粒子的总数,表示粒子在时刻的位置,表示粒子在初始时刻的位置。
扩散系数(D)计算公式:
这里,表示时间,单位为秒。在实际计算中,我们通常使用MSD随时间的线性拟合斜率除以6得到扩散系数。
# Temperature (K) Diffusion Coefficient (m^2/s) 8.000000000000000000e+02 1.512969348071375718e-10 1.000000000000000000e+03 7.521645281666237925e-10 1.200000000000000000e+03 2.103456264103633486e-09
根据计算结果,我们得到了不同温度下锂离子的传导率。拟合Arrhenius公式,计算离子的激活能。
其中:
- :锂离子扩散系数
- :温度为绝对零度时的扩散系数
- :激活能,表示达到反应所需的能量阈值
- :气体常数,数值约为 8.314 J/(mol·K)
- :绝对温度(单位:开尔文,K)
4 低能空位构型的搜索
我们将DP模型应用于LiCoO中不同脱嵌量下的空位结构的搜索。
我们基于LiCoO的初始构型,生成了和的结构,并对其进行DFT计算和DP计算。
输出结果总结在下述文档中:
45 0 -.24508752E+03 -255.47650945156326 45 1 -.24622006E+03 -255.94926231529158 45 2 -.24595753E+03 -255.9107038163852 45 3 -.24595679E+03 -255.91419784563394 45 4 -.24655206E+03 -256.53936125243933 45 5 -.24664783E+03 -256.59951533233277 45 6 -.24621900E+03 -255.94893680322923 45 7 -.24664790E+03 -256.5985602153588 45 8 -.24681387E+03 -256.70201657520926 39 0 -0.196256107445E+03 -202.03445795499707 39 1 -.21093893E+03 -216.60215580718597 39 2 -.21071719E+03 -216.00456367651793 39 3 -.21105025E+03 -216.59512932266978 39 4 -.21088330E+03 -216.5721124205345 39 5 -.21062566E+03 -216.53997244707477 39 6 -.21094058E+03 -216.36702942136822 39 7 -.21035044E+03 -216.03239314524544 39 8 -.21150228E+03 -216.56808433936908 39 9 -.21090383E+03 -216.54783461302847
为了直观得对比DP的预测效果,我们统计了DP和DFT各自预测的最低空位结构的构型编号如下:
由图可知,DP对空位结构的绝对能量预测结果与DFT数据存在一定偏差,但是能量变化趋势完全一致。
总结
DP模型具有较高的计算精度和较小的计算成本,基于DP模型可以实现大尺度、长时间的MD模拟,是电池等材料体系研究的有力工具,将极大地拓宽研究领域的边界,推动电池等领域相关科学问题的解决,促进新发现的产生。
参考
[1] Hu T, Dai F, Zhou G, et al. Unraveling the Dynamic Correlations between Transition Metal Migrations and the Oxygen Dimer Formation in the Layered LiCoO2 Cathode[J]. 2023.