GPTFF(基于图形的预训练变压器力场)可以模拟任意无机系统,具有良好的精度和通用性。
使用conda
创建一个新的 python 虚拟环境(不是必须的):
conda create -n gptff python=3.8
然后克隆GPTFF
存储库并安装:
git clone https://github.com/atomly-materials-research-lab/GPTFF.git
cd GPTFF
pip install .
快速能量(eV)、力(eV/Å)、应力(GPa)计算:
from gptff . model . mpredict import ASECalculator
from pymatgen . core import Structure
from pymatgen . io . ase import AseAtomsAdaptor
model_weight = "pretrained/gptff_v1.pth"
device = 'cuda' # or cpu
p = ASECalculator ( model_weight , device ) # Initialize the model and load weights
adp = AseAtomsAdaptor ()
struc = Structure . from_file ( 'POSCAR_structure' )
atoms = adp . get_atoms ( struc )
atoms . set_calculator ( p )
energy = atoms . get_potential_energy () # unit (eV)
forces = atoms . get_forces () # unit (eV/Å)
stress = atoms . get_stress () # unit (GPa)
结构优化:
晶格向量将会改变
from gptff . model . mpredict import ASECalculator
from pymatgen . core import Structure
from pymatgen . io . ase import AseAtomsAdaptor
from ase . optimize . fire import FIRE
from ase . constraints import ExpCellFilter , StrainFilter
model_weight = "pretrained/gptff_v1.pth"
device = 'cuda' # or cpu
p = ASECalculator ( model_weight , device ) # Initialize the model and load weights
struc = Structure . from_file ( 'POSCAR_structure' ) # Read structure
adp = AseAtomsAdaptor ()
atoms = adp . get_atoms ( struc )
atoms . set_calculator ( p )
optimizer = ExpCellFilter ( atoms )
FIRE ( optimizer ). run ( fmax = 0.01 , steps = 100 )
晶格向量不会改变,只有原子位置会被优化
from gptff . model . mpredict import ASECalculator
from pymatgen . core import Structure
from pymatgen . io . ase import AseAtomsAdaptor
from ase . optimize . fire import FIRE
from ase . optimize . bfgs import BFGS
model_weight = "pretrained/gptff_v1.pth"
device = 'cuda' # or cpu
p = ASECalculator ( model_weight , device ) # Initialize the model and load weights
struc = Structure . from_file ( 'POSCAR_structure' ) # Read structure
adp = AseAtomsAdaptor ()
atoms = adp . get_atoms ( struc )
atoms . set_calculator ( p )
optimizer = BFGS ( atoms )
optimizer . run ( fmax = 0.01 , steps = 1000 )
分子动力学(ASE):稍后我们将通过GPTFF
支持LAMMPS
。
from gptff . model . mpredict import ASECalculator
from pymatgen . core import Structure
from pymatgen . io . ase import AseAtomsAdaptor
from ase import Atoms , units
from ase . md . nvtberendsen import NVTBerendsen
import os
model_weight = "pretrained/gptff_v1.pth"
device = 'cuda' # or cpu
p = ASECalculator ( model_weight , device ) # Initialize the model and load weights
struc = Structure . from_file ( 'POSCAR_structure' ) # Read structure
adp = AseAtomsAdaptor ()
atoms = adp . get_atoms ( struc )
atoms . set_calculator ( p )
save_dir = './results_path'
os . makedirs ( save_dir , exist_ok = True )
temp = 430 # unit (K)
dyn = NVTBerendsen ( atoms = atoms ,
timestep = 2 * units . fs ,
temperature = temp , # unit (K)
taut = 200 * units . fs ,
loginterval = 20 , # Save md information and trajectory every 20 steps
logfile = os . path . join ( save_dir , f'output.txt' ), # Information printer
trajectory = os . path . join ( save_dir , f'Li3PO4_nvt_out_ { temp } K.trj' ), # Trajectory recorder
append_trajectory = True )
dyn . run ( 100000 )
config.json
将是训练参数,您可以在此文件中指定数据路径。
gptff_trainer config.json
如果您想根据自己的数据集预训练或微调力场,您可以准备自己的数据集,如下所示:
数据集必须存储在.csv
格式文件中,有几列:
struct_id
:唯一的结构ID,例如0、1、2、..
energy
: 结构的总能量 (eV)
forces
:每个原子的力 (eV/Å)
stress
:结构的应力(kBar,直接与VASP应力输出对齐)
structure
:结构的 dict 格式。
from pymatgen . core import Structure
struc = Structure . from_file ( 'POSCAR' )
struc_data = struc . as_dict ()
fold
:您可以指定要训练哪个折叠以及要验证哪个折叠。如果您在 config.json 中设置 Fold 为0
,则fold !=0
为训练数据集, fold == 0
为验证数据集。
ref_energy
:结构的参考能量,例如结构式为8
3
Li和O的原子序, 2
和4
是结构中的原子序数。
在我们预训练的模型中, atom_refs
是:
atom_refs = np . array ([
0.00000000e+00 , - 3.46535853e+00 , - 7.56101906e-01 , - 3.46224791e+00 ,
- 4.77600176e+00 , - 8.03619240e+00 , - 8.40374071e+00 , - 7.76814618e+00 ,
- 7.38918302e+00 , - 4.94725878e+00 , - 2.92883670e-02 , - 2.47830716e+00 ,
- 2.02015956e+00 , - 5.15479820e+00 , - 7.91209653e+00 , - 6.91345095e+00 ,
- 4.62278149e+00 , - 3.01552069e+00 , - 6.27971322e-02 , - 2.31732442e+00 ,
- 4.75968073e+00 , - 8.17421803e+00 , - 1.14207788e+01 , - 8.92294483e+00 ,
- 8.48981509e+00 , - 8.16635547e+00 , - 6.58248850e+00 , - 5.26139665e+00 ,
- 4.48412068e+00 , - 3.27367370e+00 , - 1.34976438e+00 , - 3.62637456e+00 ,
- 4.67270042e+00 , - 4.13166577e+00 , - 3.67546394e+00 , - 2.80302539e+00 ,
6.47272418e+00 , - 2.24681188e+00 , - 4.25110577e+00 , - 1.02452951e+01 ,
- 1.16658385e+01 , - 1.18015760e+01 , - 8.65537518e+00 , - 9.36409198e+00 ,
- 7.57165084e+00 , - 5.69907599e+00 , - 4.97159232e+00 , - 1.88700594e+00 ,
- 6.79483530e-01 , - 2.74880153e+00 , - 3.79441765e+00 , - 3.38825264e+00 ,
- 2.55867271e+00 , - 1.96213610e+00 , 9.97909972e+00 , - 2.55677995e+00 ,
- 4.88030347e+00 , - 8.86033743e+00 , - 9.05368602e+00 , - 7.94309693e+00 ,
- 8.12585485e+00 , - 6.31826210e+00 , - 8.30242223e+00 , - 1.22893251e+01 ,
- 1.73097460e+01 , - 7.55105974e+00 , - 8.19580521e+00 , - 8.34926874e+00 ,
- 7.25911206e+00 , - 8.41697224e+00 , - 3.38725429e+00 , - 7.68222088e+00 ,
- 1.26297007e+01 , - 1.36257602e+01 , - 9.52985029e+00 , - 1.18396814e+01 ,
- 9.79914325e+00 , - 7.55608603e+00 , - 5.46902454e+00 , - 2.65092136e+00 ,
4.17472161e-01 , - 2.32548971e+00 , - 3.48299933e+00 , - 3.18067109e+00 ,
3.57605604e-15 , 9.96350211e-16 , 1.18278079e-15 , - 1.44201673e-15 ,
- 6.73760309e-18 , - 5.48347781e+00 , - 1.03346396e+01 , - 1.11296117e+01 ,
- 1.43116273e+01 , - 1.47003999e+01 , - 1.54726487e+01 ])
或者你可以适合你自己的atom_refs
。
文件config.json
包含训练设置,
cpu
或cuda
transformer
块0
如果您发现 GPTFF 有用,请引用我们的文章:
@article{XIE2024,
title = {GPTFF: A high-accuracy out-of-the-box universal AI force field for arbitrary inorganic materials},
journal = {Science Bulletin},
year = {2024},
issn = {2095-9273},
doi = {https://doi.org/10.1016/j.scib.2024.08.039},
url = {https://www.sciencedirect.com/science/article/pii/S2095927324006327},
author = {Fankai Xie and Tenglong Lu and Sheng Meng and Miao Liu},
keywords = {Data Science, Molecular Dynamics, Graph Neural Network, Universal Fore Field},
}