上一篇文章中介绍了
ASE转换文件格式的功能,接着我想研究一下ASE是否具有灵活构建吸附结构,无意中发现ASE的图形显示功能,且可以与matplotlib模块对接使用,非常方便,这对于绘制美观的二维结构图形非常重要。下面,我主要记录一下Visualization模块的常规功能,方便后续学习查用。
ase.visualize.view
ase.visualize.view(atoms, data=None, viewer=None, repeat=None)
导入结构文件,调用view查看图形
from ase.io import read,write
from ase.visualize import view
CN=read('POSCAR0',format='vasp')
view(CN)
write('image.png',CN)
调用ase.build建立surface
建立多层特定晶面的结构,并调用matplotlib绘制图形
from ase.build import fcc111
import matplotlib.pyplot as plt
from ase.visualize.plot import plot_atoms
slab = fcc111('Pt', size=(4,4,3), vacuum=16.0)
fig, ax = plt.subplots(dpi=300,figsize=(2, 5))
plot_atoms(slab, ax, radii=0.3, rotation=('0x,0y,0z'))
fig.savefig("ase_slab.png")
结构显示角度调整
from ase.build import fcc111
import matplotlib.pyplot as plt
from ase.visualize.plot import plot_atoms
slab = fcc111('Pt', size=(4,4,3), vacuum=16.0)
fig, axarr = plt.subplots(1,4, dpi=300,figsize=(15, 10))
plot_atoms(slab, axarr[0], radii=0.3, rotation=('0x,0y,0z'))
plot_atoms(slab, axarr[1], scale=0.7, offset=(3, 4), radii=0.3, rotation=('0x,0y,0z'))
plot_atoms(slab, axarr[2], scale=0.3, offset=(3, 4), radii=0.3, rotation=('0x,0y,0z'))
plot_atoms(slab, axarr[3], radii=0.3, rotation=('45x,45y,0z'))
axarr[0].set_title("radii=0.3")
axarr[1].set_title("offset=(3, 4)")
axarr[2].set_title("scale=0.3")
axarr[3].set_title("rotation=('45x,45y,0z')")
fig, axarr = plt.subplots(1,4, dpi=300,figsize=(15, 10))
plot_atoms(slab, axarr[0], radii=0.5, rotation=('0x,0y,0z'))
plot_atoms(slab, axarr[1], scale=0.7, offset=(1, 2), radii=0.3, rotation=('0x,0y,0z'))
plot_atoms(slab, axarr[2], scale=0.7, offset=(3, 4), radii=0.3, rotation=('0x,0y,0z'))
plot_atoms(slab, axarr[3], radii=0.5, rotation=('45x,45y,0z'))
axarr[0].set_title("radii=0.5")
axarr[1].set_title("offset=(1, 2)")
axarr[2].set_title("scale=0.7")
axarr[3].set_title("rotation=('45x,45y,0z')")
构建吸附结构
ase.build.add_adsorbate(slab, adsorbate, height, position=(0, 0), offset=None, mol_index=0)
例如在Pt(111)平面吸附O 下面考察几种吸附形式:‘ontop’,‘fcc’,‘hcp’,‘bridge’
from ase.visualize import view
from ase.build import fcc111, add_adsorbate
site_list=['ontop','fcc','hcp','bridge']
fig, axarr = plt.subplots(1,4, dpi=300,figsize=(20, 5))
for i in range(0,len(site_list)):
slab = fcc111('Pt', size=(4,4,3), vacuum=16.0)
adsorption=add_adsorbate(slab, 'O', 1.5, site_list[i])
plot_atoms(slab, axarr[i], radii=0.5, rotation=('0x,0y,0z'))
fig, axarr = plt.subplots(1,4, dpi=300,figsize=(20, 5))
for i in range(0,len(site_list)):
slab = fcc111('Pt', size=(4,4,3), vacuum=16.0)
adsorption=add_adsorbate(slab, 'O', 1.5, site_list[i])
plot_atoms(slab, axarr[i], radii=0.5, rotation=('-90x,-90y,0z'))
|