可视化 氮气分子能量 和 氮原子受力大小 与 两氮原子间距离的关系
from ase import Atoms #导入相应的包
from ase.calculators.emt import EMT
import matplotlib.pyplot as plt
#构建氮气分子并初始化相应参数
atoms = Atoms('N2', positions=[[0, 0, -1], [0, 0, 1]])
atoms.calc = EMT()
step = 0.05
nsteps = int(3 / step)
distance = []
energy = []
force = []
#进入循环,计算每步的能量和氮原子受力
for i in range(nsteps):
d = 0.5 + i * step
atoms.positions[1, 2] = atoms.positions[0, 2] + d
e = atoms.get_potential_energy()
f = atoms.get_forces()
f = f[0, 2]
distance.append(d)
energy.append(e)
force.append(f)
#绘图
fig = plt.figure()
plt.plot(distance, energy)
plt.plot(distance, force)
plt.show()
结果如下:
横坐标是距离,单位是埃
纵坐标蓝线是能量,单位是ev
纵坐标黄线是受力,负值为排斥力
可见,氮原子在相差1埃的时候能量最低,体系最稳定。
本代码参照ASE官方文档的例子,做小修改。
ase官方文档