参考
Modules
https://wiki.fysik.dtu.dk/ase/ase/ase.html
ATOMS
建结构
>>> atoms = Atoms('H2',
... positions=[(0, 0, 0),
... (0, 0, d)],
... cell=(a, a, a))
平移原子
atoms.center()
读取位置
>>> atoms.get_positions()
array([[3. , 3. , 2.63],
[3. , 3. , 3.37]])
>>> atoms.get_chemical_formula()
'H2'
>>> atoms.get_chemical_symbols()
['H', 'H']
下面的需要计算获得,计算完第一个后,后续如果不需要重复计算可直接显示结果,修改calc后会重新计算
>>> atoms.get_magnetic_moment()
0.0
>>> atoms.get_total_energy()
-6.627349275455906
读写vasp
from ase import Atoms
from ase.io import read, write
molecule = read("center.frac.car.roat.8883.vasp",format="vasp")
#write(molecule,"out.vasp",format="vasp")#这行报错???
molecule.write("out.vasp")#保存到out.vasp
读取后就是Atoms类型
>>> molecule
Atoms(symbols='C10H16', pbc=True, cell=[15.0, 15.0, 15.0])
不过写出的结构,缺少原子标注,如10 16的上一行缺少 C H
C H
1.0000000000000000
15.0000000000000000 0.0000000000000000 0.0000000000000000
0.0000000000000000 15.0000000000000000 0.0000000000000000
0.0000000000000000 0.0000000000000000 15.0000000000000000
10 16
Cartesian
8.9822077500000006 7.5817357500000018 6.7195537500000002
6.8290642500000001 6.2047867500000002 6.7125397500000004
7.5578482500000010 7.4264887500000007 8.8350322500000011
组合操作示例
平移POSCAR中原子到中心
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@author: cndaqiang 2020-
POSCAR中的原子坐标平移到中心
"""
import sys
import os
#-----Input File
if len(sys.argv) > 1:
inputfile = str(sys.argv[1])
else:
inputfile = "POSCAR"
if os.path.exists(inputfile):
print("read from",inputfile)
else:
print(inputfile+" not exists")
exit()
from ase import Atoms
from ase.io import read,write
atoms = read(inputfile,format="vasp")
atoms.center()
atoms.write("center."+inputfile,format="vasp")
print("Save center POSCAR to "+"center."+inputfile)
本文首发于我的博客@cndaqiang.
本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!