DP-GEN Auto-test
本文基于bohrium,以DP-Library中Al-Mg-Cu的势函数为例(从DPLibrary下载后用DeePMD-kit升级)进行性质计算。
「Bohrium 帮助文档|DP-GEN Auto-test」是 Notebook 版帮助文档,可直接运行,请点击查看。
注:本教程使用的软件版本:DP-GEN 0.10.6 DP-Dispatcher 0.4.16 dpdata 0.2.8
步骤1:准备文件与文件夹
首先新建一个工作目录,这里以名为autotest的文件夹为例,并把你要计算的模型文件(比如叫做graph.pb)放在里面。
在本例中,模型文件要升级到dp对应的版本,可以在DeePMD-kit镜像下使用dp convert-from 1.1 -i graph.pb -o new_graph.pb
命令升级模型。dp convert-from -h
可以查看该命令的使用方式。
您可以将旧的模型命名为old_graph.pb,使用这个脚本在bohrium提交任务并回收文件,不需要开新的节点,非常便捷。
submit.json
{
"job_name": "dp-update-model",
"job_type": "container",
"image_address": "registry.dp.tech/dptech/deepmd-kit:2.1.5-cuda11.6" ,
"command": "dp convert-from 1.1 -i old_graph.pb -o graph.pb",
"log_file": "tmp_log",
"backward_files": ["graph.pb"],
"program_id": 0000,
"platform": "ali",
"disk_size": 200,
"machine_type": "c16_m32_cpu"
}
注意: "project_id":
后的 0000
需替换为您自己的项目ID,可在“项目管理”页查看。
由于要使用 Bohrium CLI 提交任务,因此首先需要安装Bohrium CLI
分别执行:
mkdir autotest
cd autotest
mv <the-path-where-you-download-graph.pb>/graph.pb old_graph.pb
bohr job submit -i submit.json -p ./
(如果文件graph.pb没有自动回传,需要从任务管理页面下载并放在当前所在的autotest文件夹下)
注:如果您的模型不用升级,只需下列命令即可
mkdir autotest
cd autotest
mv <the-path-where-graph.pb-is>/graph.pb graph.pb
接下来准备构象文件夹和参数文件:
mkdir confs
cd confs
mkdir mp-3034
cd ..
touch relaxation.json
touch machine.json
touch property.json
在confs文件夹下使用MaterialsProject的构象编号mp-xxx命名文件夹,autotest会自动从MaterialsProject下载相应构象的POSCAR文件。
若通过MaterialsProject获得构象,需要给服务器配置API key。
如果您在没有配置MaterialsProject的API key时使用autotest,会看到这样的报错:
(base) ➜ autotest_demo dpgen autotest make relaxation.json
NOTE: Some configuration directories are not set up yet:
/root/.gromacswrapper
/root/.gromacswrapper/qscripts
/root/.gromacswrapper/templates
NOTE: You can create the configuration file and directories with:
>>> import gromacs
>>> gromacs.config.setup()
/opt/anaconda3/lib/python3.9/site-packages/gromacs/__init__.py:286: GromacsImportWarning: Some Gromacs commands were NOT found; maybe source GMXRC first? The following are missing:
['release']
warnings.warn("Some Gromacs commands were NOT found; "
DeepModeling
------------
Version: 0.10.6
Date: Jul-11-2022
Path: /opt/anaconda3/lib/python3.9/site-packages/dpgen
Dependency
------------
numpy 1.20.3 /opt/anaconda3/lib/python3.9/site-packages/numpy
dpdata 0.2.8 /opt/anaconda3/lib/python3.9/site-packages/dpdata
pymatgen unknown version or path
monty 2022.3.12 /opt/anaconda3/lib/python3.9/site-packages/monty
ase 3.22.1 /opt/anaconda3/lib/python3.9/site-packages/ase
paramiko 2.10.3 /opt/anaconda3/lib/python3.9/site-packages/paramiko
custodian 2022.2.13 /opt/anaconda3/lib/python3.9/site-packages/custodian
Reference
------------
Please cite:
Yuzhi Zhang, Haidi Wang, Weijie Chen, Jinzhe Zeng, Linfeng Zhang, Han Wang, and Weinan E,
DP-GEN: A concurrent learning platform for the generation of reliable deep learning
based potential energy models, Computer Physics Communications, 2020, 107206.
------------
Description
------------
You have to get a MAPI_KEY from materials.org
and execute following command:
echo "export MAPI_KEY=yourkey">> ~/.bashrc
source ~/.bashrc
当然,您在bohrium上也可以使用~/.zshrc来配置:
echo "export MAPI_KEY=yourkey">> ~/.zshrc
source ~/.zshrc
MaterialsProject的API key可以在这里获得(如果没注册/登录的话,登陆之后再点这个链接就可以了)
如果使用
std-xxx
命名,autotest也可以自动生成相应构象,DP-GEN 0.10.6及之后版本支持std-fcc
、std-hcp
、std-bcc
、std-dhcp
、std-diamond
和std-sc
。当然您也可以用其他的命名方式,在
confs/<your-conf-name>
下放置相应的POSCAR文件,然后使用同样的步骤(make-run-post)即可。
DP-GEN中POSCAR具体读取方式如下:
if len(ele_list) == 1 or 'single' in inter_param:
if 'single' in inter_param:
element_label = int(inter_param['single'])
else:
element_label = 0
for ii in conf_dirs:
os.chdir(ii)
crys_type = ii.split('/')[-1]
dlog.debug('crys_type: %s' % crys_type)
dlog.debug('pwd: %s' % os.getcwd())
if crys_type == 'std-fcc':
if not os.path.exists('POSCAR'):
crys.fcc1(ele_list[element_label]).to('POSCAR', 'POSCAR')
elif crys_type == 'std-hcp':
if not os.path.exists('POSCAR'):
crys.hcp(ele_list[element_label]).to('POSCAR', 'POSCAR')
elif crys_type == 'std-dhcp':
if not os.path.exists('POSCAR'):
crys.dhcp(ele_list[element_label]).to('POSCAR', 'POSCAR')
elif crys_type == 'std-bcc':
if not os.path.exists('POSCAR'):
crys.bcc(ele_list[element_label]).to('POSCAR', 'POSCAR')
elif crys_type == 'std-diamond':
if not os.path.exists('POSCAR'):
crys.diamond(ele_list[element_label]).to('POSCAR', 'POSCAR')
elif crys_type == 'std-sc':
if not os.path.exists('POSCAR'):
crys.sc(ele_list[element_label]).to('POSCAR', 'POSCAR')
os.chdir(cwd)
task_dirs = []
# make task directories like mp-xxx/relaxation/relax_task
# if mp-xxx/exists then print a warning and exit.
# ...
for ii in conf_dirs:
crys_type = ii.split('/')[-1]
dlog.debug('crys_type: %s' % crys_type)
if 'mp-' in crys_type and not os.path.exists(os.path.join(ii, 'POSCAR')):
get_structure(crys_type).to('POSCAR', os.path.join(ii, 'POSCAR'))
poscar = os.path.abspath(os.path.join(ii, 'POSCAR'))
准备文件都在您要进行autotest的文件夹下,比如我们就叫这个文件夹autotest,那么您通过以上步骤创建的文件和文件夹有:(文件夹名为粗体)
autotest ── relaxation.json
|── property.json
|── machine.json
|── confs ── mp-3034
└── graph.pb
步骤2:弛豫 relaxation
在autotest目录下,先准备relaxation.json,即autotest做弛豫需要的参数文件。
示例的relaxation.json如下:
{
"structures": ["confs/mp-3034"],
"interaction": {
"type": "deepmd",
"model": "graph.pb",
"in_lammps": "lammps_input/in.lammps",
"type_map": {"Mg":0,"Al": 1,"Cu":2}
},
"relaxation": {
"cal_setting":{"etol": 1e-12,
"ftol": 1e-6,
"maxiter": 5000,
"maximal": 500000,
"relax_shape": true,
"relax_vol": true}
}
}
接着在autotest目录下执行命令
dpgen autotest make relaxation.json
dpgen autotest run relaxation.json machine.json
dpgen autotest post relaxation.json
注:
- 旧版本的DP-GEN在make步骤生成脚本有问题,需要在pair_coeff后加" * *" 可使手动添加,也可以用如下命令添加
sed -i "s/pair_coeff/pair_coeff * */g" `grep pair_coeff -rl ${_Path}/${array_mp[${i}]}
- relaxation步骤仅做minimization,没有指定系综。
步骤3:计算性质 property
- 目前autotest可以计算的性质有
- EOS
- Elastic
- Vacancy
- Surface
- Interstitial
示例的property.json模板如下:
{
"structures": ["confs/mp-3034"],
"interaction": {
"type": "deepmd",
"model": "graph.pb",
"deepmd_version":"2.1.0",
"type_map": {"Mg":0,"Al": 1,"Cu":2}
},
"properties": [
{
"type": "eos",
"vol_start": 0.9,
"vol_end": 1.1,
"vol_step": 0.01,
"fix_shape":true
},
{
"type": "elastic",
"norm_deform": 2e-2,
"shear_deform": 5e-2
},
{
"type": "vacancy",
"supercell": [1, 1, 1]
},
{
"type": "interstitial",
"supercell": [3, 3, 3],
"insert_ele": ["Mg","Al","Cu"],
"conf_filters":{"min_dist": 1.5},
"cal_setting": {"input_prop": "lammps_input/lammps_high"}
},
{
"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
}
]
}
接着在autotest目录下运行
dpgen autotest make property.json
nohup dpgen autotest run property.json machine.json &
dpgen autotest post property.json
注:旧版本的DP-GEN在make步骤后生成的脚本有问题,需要在pair_coeff后加" * *" 可使手动添加,也可以用如下命令添加:
sed -i "s/pair_coeff/pair_coeff * */g" `grep pair_coeff -rl ${_Path}/${array_mp[${i}]}
步骤3:监测任务状态与运行结果
监测任务状态参考监控任务。
至此,autotest完成,可在confs/mp-3034/<property-name>
文件夹下的result
文件中查看结果。比如本例中eos的结果在confs/mp-3034/eos_00/result.out
中。