ASE使用笔记

553 阅读1分钟

1. 使用ASE对分子创建cell

有时候会用需要给.xyz的分子创建一个CELL,可用以下命令: 并且这个命令可以覆盖上一个的cell.

from ase.io import read,write
s = read('molecule.xyz') 
s.set_cell([length,length,lenth])

2. 进行原子(分子)的平移与旋转

a. 平移translate

#例如往z轴正方向平移3\AA
#定义 
from ase import Atoms
translation_vector = [0,0,3]
molecule.translate(translation_vector)

b. 旋转rotate

from ase import Atoms
rotation_axis = [0,0,1] # 定义旋转轴位z轴
rotation_angle = 60 #定义旋转角度,正为逆时针,负位顺时针
molecule.rotate(rotation_axis, rotation_angle, rotate_cell=False)

3.快速获取Cell的信息

from ase import Atoms
parameter = system.cell #通过python列表工具可以获得每个CELL的向量与

4. 将储存在一个.xyz的所有结构生成gif文件

from ase.io import read,write
from ase.io.animation import *

structures = read('final_structures',** index=":")** # 使用":"将每个结构隔开 这个非常重要,不然生成不了动画
write_gif('s.gif',s,save_count=15,rotation="90x,0y,0z") #制作gif动画的命令

获得结构内每个原子的邻近原子数

例如我想起得graphene某个原子的邻近原子

from ase.build import graphene
from ase.neighborlist import NewPrimitiveNeighborList
from ase.neighborlist import natural_cutoffs

s=graphene('C2',a=2.47,vacuum=10,size=(3,3,1)) #构建graphene
cutoffs = natural_cutoffs(s) #获取S中每个原子的cutoff
nl = NewPrimitiveNeighborList(cutoffs,bothways=True) #设置nl器,bothways 计算双向原子
nl.update(s.pbc,s.get_cell(),s.positions) # 输入结构信息对nl器进行更新
#对S中每个原子进行循环,得到其临近个数
for i in range(len(s)):
    indices, offset = nl.get_neighbor(i)
    print(indices)
#此处indices表示对于索引为的个原子,与其相邻的原子索引的列表(包含自身)