|
本帖最后由 冰释之川 于 2020-12-29 22:11 编辑
最近想利用xtb优化一些周期性体系,可惜xtb软件的周期性模块比较弱,而且支持的优化引擎也只有“engine=inertial”,因而转向Atomic Simulation Environment(ASE) [https://wiki.fysik.dtu.dk/ase/],利用其接口调用xtb来进行优化,并且支持的优化算法相对比较多( BFGS, BFGSLineSearch, LBFGS, LBFGSLineSearch, GPMin, MDMin and FIRE),还能开启 1D,2D和3D的PBC,用起来真心美滋滋。
2020.11.18 新增xtb-6.3.0(pre.2)版对应的xtb-python模块安装教程:
1. 编辑 ~/.bashrc 增加xtb-6.3.0(pre.2)版动态库的环境变量并source ~/.bashrc:
- export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/mnt/d/xtb_Linux/xtb_6.3.pre2/lib64
复制代码
2. 切换至xtb主体目录下的python子目录并运行:- $ python3 setup.py install --prefix=/home/yjy/.local
复制代码
下面提供ASE与xtb联用的py脚本,供有需求的童鞋参考借鉴:
(1) py脚本:
- #!/usr/bin/python3
- def labels_convertion(input_string):
- new_string = []
- tmp = input_string.split(",")
- for i in tmp:
- if "-" in i:
- start = int(i.split("-")[0]) - 1
- end = int(i.split("-")[1])
- for j in range(start,end):
- new_string.append(j)
- else:
- new_string.append(int(i) - 1)
- return new_string
- from ase import Atoms
- from ase.units import Hartree
- from ase.constraints import FixAtoms
- from ase.optimize import BFGS
- from ase.io import read,write,iread
- from xtb import GFN1
- import os,sys,datetime
- start_time = datetime.datetime.now()
- name = sys.argv[1]
- mol = read(name+".xyz", format='xyz')
- total_atoms = len(mol.get_atomic_numbers())
- # orthorhombic cell parameter
- a, b, c = 7.8598, 7.8598, 19.5257
- mol.cell = [a, b, c]
- # PBC: periodic boundary conditions
- mol.pbc = (True, True, True)
- print('*** ASE program with xTB started at {0} ***\n'.format(start_time.strftime("%Y-%m-%d %H:%M:%S")))
- print('-> Task name: %50s' %name)
- print('-> Orthorhombic cell parameters: %31s' %mol.get_cell())
- print('-> Total number of atoms in a cell: %27s' %total_atoms)
- print('-> PBC dimensions: %45s' %mol.get_pbc())
- # fix atoms (index starts from 1)
- fixed_atoms = "1,3-4,6-17,19-20,22-33,35-36,38-49,51-52,54-64"
- fix = FixAtoms(indices=labels_convertion(fixed_atoms))
- mol.set_constraint(fix)
- print('-> The atoms with following labels are fixed:\n{0}'.format(labels_convertion(fixed_atoms)))
- # set calculation level, charge, and magnetic moment
- total_charges = 0
- total_unpaired_electrons = 0
- mol.calc = GFN1(accuracy=1, electronic_temperature=300, max_iterations=250)
- mol.set_initial_charges(charges=[total_charges/total_atoms,]*total_atoms)
- mol.set_initial_magnetic_moments(magmoms=[total_unpaired_electrons/total_atoms,]*total_atoms)
- # calculate single point energy (SPE) of the initial geometry
- e_mol = mol.get_potential_energy()
- print('\nTotal energy of the initial geomertry: \n{0:.6f} eV <==> {1:.8f} Hartree\n'.format(e_mol, e_mol/Hartree))
- print('~~~ Geometry optimization started... ~~~')
- opt = BFGS(mol, trajectory=name+".traj", restart=name+".pckl")
- opt.run(fmax=0.001, steps=800)
- print('~~~ Geometry optimization terminated... ~~~')
- # calculate single point energy (SPE) of the optimized geometry
- e_mol_opted = mol.get_potential_energy()
- print('\nTotal energy of the optimized geometry: \n{0:.6f} eV <==> {1:.8f} Hartree\n'.format(e_mol_opted, e_mol_opted/Hartree))
- write(name+"_opted.xyz", read(name+".traj"))
- write(name+"_traj.xyz", iread(name+".traj"))
- os.remove('xtbrestart')
- os.remove('wbo')
- end_time = datetime.datetime.now()
- print('*** ASE program with xTB ended at {0} ***'.format(end_time.strftime("%Y-%m-%d %H:%M:%S")))
- tot_seconds = (end_time - start_time).seconds
- days = tot_seconds // 86400
- hours = (tot_seconds % 86400) // 3600
- minutes = (tot_seconds % 86400 % 3600)// 60
- seconds = tot_seconds % 60
- print(">> Elapsed time: {0:2d} days {1:2d} hours {2:2d} minutes {3:4.1f} seconds <<".format(days,hours,minutes,seconds))
复制代码 (2)调用py脚本的PBS作业提交脚本:
- #!/bin/bash
- #PBS -N ASE_xtb
- #PBS -l nodes=1:ppn=12
- #PBS -l walltime=1440:00:00
- #PBS -q GPU
- export OMP_NUM_THREADS=12 # CPU cores
- export MKL_NUM_THREADS=12 # CPU cores
- export OMP_STACKSIZE=3000m # memory
- ulimit -s unlimited
- source /home/yjy/intel/parallel_studio_xe_2020/psxevars.sh
- cd $PBS_O_WORKDIR
- touch jobID.$PBS_JOBID
- FILENAME=Cell.py # input file name
- python3 ${FILENAME} ${FILENAME%.py} | tee ${FILENAME/%py/log} # running python script
复制代码 实例包:
ASE_xtb_test.7z
(607.17 KB, 下载次数 Times of downloads: 162)
diamond_test.7z
(6.03 KB, 下载次数 Times of downloads: 89)
|
评分 Rate
-
查看全部评分 View all ratings
|