宜宾建设网站/网络营销的含义特点
OVITO是非常常用的分子动力学模型可视化软件,自带共近邻原子分析(Common Neighbour Analysis),可以获得原子结构信息。一般来说,分子动力学结果文件包含在数十、甚至数百个时刻的原子模型。为了体现模型结构随时间变化,通常要逐帧对模型进行分析。例如对于应力诱发钢的马氏体相变模拟,通过查看各原子结构所占比例,即可了解相变进行的程度,如图1所示。

对于一个可视化专用软件,这种时程显然是非常耗时的(上图可能对应了逾1000个原子模型)。不过OVITO给出了python接口,由python script模块调用,可以比较方便与高效地调用后处理相关函数来处理大量同名模型文件。Ovito官方对python接口的介绍可见https://www.ovito.org/docs/current/python/ 本文仅是其中内容的浅显应用。
py文件分为三个部分:
定义序列(pipeline)与引用模块(modifier);
在序列内进行for循环,获得关键信息并写入矩阵;
输出矩阵为文本。
对于本应用,模块名称为CommonNeighborAnalysisModifier();关键信息为data.attributes['CommonNeighborAnalysis.counts.FCC']等;另调用numpy库方便数据读写。将该程序输入pythob script运行,输出不同结构原子数的统计文件。
参考代码如下:
from ovito.io import import_file
from ovito.modifiers import CommonNeighborAnalysisModifier
import numpy# Load a simulation trajectory consisting of several frames:
pipeline = import_file("dump.tensile_*.cfg")# Insert the modifier into the pipeline:
modifier = CommonNeighborAnalysisModifier()
pipeline.modifiers.append(modifier)# Initialize array.
CNA = numpy.zeros((1,4))# Iterate over all frames of the sequence.
for frame in range(pipeline.source.num_frames):# Evaluate pipeline to let the modifier compute the RDF of the current frame:data = pipeline.compute(frame)n_temp = [(data.attributes['CommonNeighborAnalysis.counts.FCC'],data.attributes['CommonNeighborAnalysis.counts.BCC'],data.attributes['CommonNeighborAnalysis.counts.HCP'],data.attributes['CommonNeighborAnalysis.counts.OTHER'])]CNA = numpy.append(CNA,n_temp,axis = 0)
# Export the CNA results to a text file:
CNA = numpy.delete(CNA,0,axis = 0) #To delete the initial zero array created by numpy.zeros
numpy.savetxt("CNA.txt", CNA)
这种后处理方法在相关论文中常见,相信早有人写过这样的脚本,不过我尚未见到。大概许多课题组都有这样的小小的不传之秘吧。许多软件都有类似的接口,基于matlab与python等,门槛较低,相当便利,但这些小小的脚本又很少能汇集起来,被发现与利用。围绕分子动力学,有许多开源软件,如Lammps,Atomsk,Ovito等,我也遥遥领会了一些早期互联网精神,谢谢他们的贡献。