如何做一次AIMD
我认为AIMD其实就是用DFT计算的分子动力学模拟,精度高但时间长。下面完整地给出Ti-Al合金进行AIMD模拟的方法。
1、准备文件
既然是跑vasp就必须要POSCAR、INCAR、POTCAR和KPOINTS文件
①POSCAR(不超过50个原子)
②INCAR(300K)
# basic parameters
SYSTEM = TiAlB.nvt
#NCORE = 13 # 52cores=13*4
NPAR = 4
KGAMMA = .TRUE. # GAMMA point
KSPACING = 2.0 # number of k-points, 0.3 is ok
ENCUT = 450.0 # cutoff energy for the PWB set
PREC = Normal # precision-mode, Accurate is ok
ISTART = 0 # read the WAVECAR file or not (ICHARG=2)
LWAVE = .FALSE. # write WAVECAR or not
LCHARG = .FALSE. # write CHGCAR or not
# Electronic Relaxation
ISMEAR = 1 # (1,2)=Methfessel-Paxton order N, (bulk)
SIGMA = 0.1 # width of the smearing in eV, (bulk)
EDIFF = 1e-4 # global break for electronic SC-loop, eV
LREAL = Auto # projection operators, "Auto" is ok
NELM = 200 # maximum number of electronic SC
NELMIN = 5 # avoid breaking after 2 steps
# Molecular Dynamics
IBRION = 0 # Activate MD
MDALGO = 2 # 2=Nose-Hoover, 3=Langevin
ISIF = 2 # 1=NVE, 2=NVT, 3=NpT
ALGO = Fast # IALGO=48 (RMM-DIIS)
ISYM = 0 # no symmetry for MD, completely
TEBEG = 300 # Begin temperature K
TEEND = 300 # Final temperature K
NSW = 5000 # Max ionic steps
POTIM = 3 # Timestep in fs
SMASS = 1.0 # For SMASS≥0, a canonical ensemble is simulated using the algorithm of Nosé
NWRITE = 1 # long MD-runs use NWRITE=0 or 1
NBLOCK = 1 # output write PCF and DOS, scale kinetic energy
③POTCAR(按照原子顺序即可)
④KPOINTS(取1 1 1即可)
KPOINTS for Ti-Al-B system # 注释行,不参与计算
0 # 这里 0 表示自动生成
Gamma # Γ 点方式
1 1 1 # 网格数:相当于只取 Γ 点
0.0 0.0 0.0 # 网格偏移
提交任务即可。
2、提取XDATCAR
import os
import shutil# 定义原始文件夹和目标文件夹
source_folder = './'
destination_folder = 'path/to/your/folder'# 确保目标文件夹存在,如果不存在则创建
if not os.path.exists(destination_folder):os.makedirs(destination_folder)# 递归遍历原始文件夹中的所有文件和子文件夹
for root, dirs, files in os.walk(source_folder):for file in files:# 判断文件名是否以'XDATCAR'结尾if file.endswith('XDATCAR'):# 构建文件的完整路径source_path = os.path.join(root, file)# 获取子文件夹的名称subfolder_name = os.path.basename(root)# 构建目标文件的完整路径,使用子文件夹的名称命名destination_file = f'{subfolder_name}_XDATCAR'destination_path = os.path.join(destination_folder, destination_file)# 将文件复制到目标文件夹中shutil.copy(source_path, destination_path)print(f"File '{file}' copied to destination folder as '{destination_file}'.")print("Task completed.")
3、抽取轨迹文件(我这里选的是interval=4)
import os
import shutil
from glob import glob
from ase.io import read
from ase.io.vasp import write_vaspdef get_ends_list(path, filetype):"""返回匹配 *<filetype> 的完整路径列表(排序),例如 *_XDATCAR。例:get_ends_list('./', '_XDATCAR')"""return sorted(glob(os.path.join(path, f'*{filetype}')))def safe_reset_dir(d):"""安全清空/创建输出目录"""if os.path.isdir(d):for name in os.listdir(d):p = os.path.join(d, name)if os.path.isdir(p):shutil.rmtree(p)else:os.remove(p)else:os.makedirs(d, exist_ok=True)def extra_aimd_trag(outFolders, interval, src='./', include_first=True, include_last=False, clear_output=True):"""从 src 目录的 *_XDATCAR 轨迹中,每隔 interval 帧抽一帧导出为 .vasp(VASP5,Direct)。- include_first: 是否包含第 0 帧- include_last: 是否额外包含最后一帧(若不在步长采样上)- clear_output: 是否在写出前清空输出目录"""if clear_output:safe_reset_dir(outFolders)else:os.makedirs(outFolders, exist_ok=True)files = get_ends_list(path=src, filetype='_XDATCAR')if not files:print(f'No *_XDATCAR found under: {src}')returnfor file in files:base = os.path.basename(file)print(f'Reading file: {base}')traj = read(file, index=':', format='vasp-xdatcar') # 全部帧n = len(traj)print(n)start = 0 if include_first else intervalindices = list(range(start, n, interval))if include_last and (n - 1) not in indices:indices.append(n - 1)for ID in indices:out_path = os.path.join(outFolders, f'{base}.{ID}.vasp')a = traj[ID].copy()a.wrap() # 手动 wrap 到晶胞(兼容老版 ASE:write_vasp 无 wrap 参数)write_vasp(out_path, a, direct=True, vasp5=True)def copyfile(dst_dir='2-1-AIMD-trg'):"""可选:把 100/400/700/1000/1300 目录下的 XDATCAR 复制并重命名到 dst_dir。仅当你需要把不同温度的轨迹集中到一个目录时使用。"""os.makedirs(dst_dir, exist_ok=True)for T in range(100, 1400, 300): # 100, 400, 700, 1000, 1300src = os.path.join(str(T), 'XDATCAR')if os.path.isfile(src):shutil.copy2(src, os.path.join(dst_dir, f'{T}.XDATCAR'))else:print(f'Warning: missing {src}')if __name__ == '__main__':# 按需修改 src 为你的 AIMD 轨迹所在目录extra_aimd_trag(outFolders='Ti-Al-B-AIMD-trg',interval=4,src='./', # 例如:'/home/mengx/MengX/TiAlB-MLP/Ti-B-random_replace/AIMD'include_first=True,include_last=False,clear_output=True)
4、做静态自洽