操作deepmd工具包、vasp和lammps数据格式
dpdata的Python项目详细描述
dpdata是一个用于操作deepmd kit、vasp、lammps数据格式的python包。 dpdata仅适用于python 3.x。
安装
您可以通过
git clone https://github.com/deepmodeling/dpdata.git dpdata
然后使用setup.py安装模块
cd dpdata
python setup.py install
dpdata也可以通过pip安装
pip3 install dpdata
快速启动
本节给出了一些关于dpdata如何工作的示例。首先需要将模块导入到与Python3.x兼容的代码中。
importdpdata
dpdata的典型调用工作流是
- 从vasp或lammps或deepmd工具包数据文件加载数据。
- 操作数据
- 以所需格式将数据转储到
加载数据
d_poscar=dpdata.System('POSCAR',fmt='vasp/poscar')
或者让dpdata从文件扩展名推断文件的格式(vasp/poscar)
d_poscar=dpdata.System('my.POSCAR')
原子数、原子类型、坐标从POSCAR加载并存储到名为d_poscar的数据System。 数据System(由deepmd-kit使用的概念)包含具有相同类型原子数的帧。原子的顺序在一个System的帧之间应该是一致的。 注意,POSCAR只包含一个帧。 例如,如果需要存储在OUTCAR中的多个帧,
d_outcar=dpdata.LabeledSystem('OUTCAR')
在OUTCAR中提供的标签,即能量、力和病毒(如果有的话),由LabeledSystem加载。人们注意到原子的力总是假定存在的。LabeledSystem是System的派生类。
System或LabeledSystem可以由以下文件格式构造,表中的format key传递给参数fmt:
Software | format | multi frames | labeled | class | format key |
---|---|---|---|---|---|
vasp | poscar | False | False | System | ‘vasp/poscar’ |
vasp | outcar | True | True | LabeledSystem | ‘vasp/outcar’ |
vasp | xml | True | True | LabeledSystem | ‘vasp/xml’ |
lammps | lmp | False | False | System | ‘lammps/lmp’ |
lammps | dump | True | False | System | ‘lammps/dump’ |
deepmd | raw | True | True | LabeledSystem | ‘deepmd/raw’ |
gaussian | log | False | True | LabeledSystem | ‘gaussian/log’ |
cp2k | output | False | True | LabeledSystem | ‘cp2k/output’ |
访问数据
存储在System和LabeledSystem中的这些属性可以由运算符[]使用提供的属性键访问,例如
coords=d_outcar['coords']
可用属性为(nframe:系统中的帧数,natoms:系统中的原子总数)
key | type | dimension | are labels | description |
---|---|---|---|---|
‘atom_names’ | list of str | ntypes | False | The name of each atom type |
‘atom_numbs’ | list of int | ntypes | False | The number of atoms of each atom type |
‘atom_types’ | np.ndarray | natoms | False | Array assigning type to each atom |
‘cells’ | np.ndarray | nframes x 3 x 3 | False | The cell tensor of each frame |
‘coords’ | np.ndarray | nframes x natoms x 3 | False | The atom coordinates |
‘energies’ | np.ndarray | nframes | True | The frame energies |
‘forces’ | np.ndarray | nframes x natoms x 3 | True | The atom forces |
‘virials’ | np.ndarray | nframes x 3 x 3 | True | The virial tensor of each frame |
转储数据
存储在System或LabeledSystem中的数据可以转储为'lammps/lmp'或'vasp/poscar'格式,例如:
d_outcar.to_lammps_lmp('conf.lmp',frame_idx=0)
d_outcar的第一帧将转储到“conf.lmp”
d_outcar.to_vasp_poscar('POSCAR',frame_idx=-1)
d_outcar的最后一帧将转储到“poscar”。
存储在LabeledSystem中的数据可以转储为deepmd kit raw格式,例如
d_outcar.to_deepmd_raw('dpmd_raw')
或更简单的命令:
dpdata.LabeledSystem('OUTCAR').to_deepmd_raw('dpmd_raw')
帧选择可以通过
dpdata.LabeledSystem('OUTCAR').sub_system([0,-1]).to_deepmd_raw('dpmd_raw')
仅将第一帧和最后一帧转储到dpmd_raw。