背景:ovito图形界面下PTM使用简单,但是如果我们希望统计成千上万个轨迹文件的相分数,我们建议使用ovito提供的python接口进行计算并输出。
python代码:
#导入python模块from ovito.io import import_filefrom ovito.modifiers import PolyhedralTemplateMatchingModifierfrom ovito.data import DislocationNetworkimport time#读入lammps的轨迹文件,导入pipeline(ovito计算流), *通配符代表步长,从零开始pipeline = import_file("/home/lizhu/MD/dislocation_generation/011P_100D/a-20211217-poly/tem/poly+mix/dump-down.*")#打印轨迹文件总个数print("total_num_frames: %f" % pipeline.source.num_frames)#逐个读取轨迹文件,并进行DXA分析与输出for frame in range(pipeline.source.num_frames): #根据实际dump出来的步长,来定义步数,并打印出来(此处是每隔200步dump出轨迹一次) print("==========================================") steps = (frame)*200 print("step: %s" % steps) #定义PTM模块,设置rmsd_cutoff值 modifier = PolyhedralTemplateMatchingModifier(rmsd_cutoff=0.12) #将设置好的PTM模块赋予pipeline pipeline.modifiers.append(modifier) #pipeline计算启动 data = pipeline.compute(frame) #计算结果输出:bcc/fcc/hcp/other原子数, 原子总数 number_bcc=data.attributes['PolyhedralTemplateMatching.counts.BCC'] number_fcc=data.attributes['PolyhedralTemplateMatching.counts.FCC'] number_hcp=data.attributes['PolyhedralTemplateMatching.counts.HCP'] number_other=data.attributes['PolyhedralTemplateMatching.counts.OTHER'] total_number=data.particles.count #bcc/fcc/hcp/other相分数 phase_fraction_bcc= number_bcc / total_number phase_fraction_fcc= number_bcc / total_number phase_fraction_hcp= number_hcp / total_number phase_fraction_other= number_other / total_number #打印相分数到屏幕 print ("total_number: %f" %total_number) print ("phase_fraction_bcc: %f" %phase_fraction_bcc ) print ("phase_fraction_fcc: %f" %phase_fraction_fcc ) print ("phase_fraction_hcp: %f" %phase_fraction_hcp ) print ("phase_fraction_other: %f" %phase_fraction_other ) #输相分数到step-bcc-fcc-hcp-other.txt文件 f1 = open('step-bcc-fcc-hcp-other.txt','a+') f1.write(str(steps)) f1.write(" ") f1.write(str(phase_fraction_bcc)) f1.write(" ") f1.write(str(phase_fraction_fcc)) f1.write(" ") f1.write(str(phase_fraction_hcp)) f1.write(" ") f1.write(str(phase_fraction_other)) f1.write('\n')
执行命令:
ovitos **.py #ovitos默认调用所有处理器线程进行数据分析
屏幕打印:
输出文件:相分数输出到step-bcc-fcc-hcp-other.txt文件。
注:
文件输出为追加模式,若要重新计算轨迹文件的相密度,需提前将以前产生的step-bcc-fcc-hcp-other.txt删除。
支持python功能的的免费版ovito下载链接如下:
链接:https://pan.baidu.com/s/1gOnMs9u1x80l02LE64Tj_g
提取码:xfsh