将Material Studio的xtd轨迹文件导出为xyz轨迹文件的方法
文/Sobereva @北京科音 First release: 2012-May-23
Material Studio(MS)的xtd文件包含了原子或者粗粒化模拟中的bead的轨迹信息。这是MS的私有格式,为了能将轨迹放到其它程序,比如VMD中做更灵活细致的分析,需要转换为通用轨迹格式。xtd文件内含的实际轨迹信息实际上储存在同目录下的同名的.trj隐藏文件里(二进制文件),一种转换成通用格式的方法是利用MS自带的trj2ascii.exe程序将.trj文件内容转换成普通文本文件,然后再写个程序将其转换成其它轨迹格式。但这样步骤稍微麻烦些。
另一种做法是直接利用MS内部支持的Perl脚本,循环每一帧每一个原子或Bead,将其坐标属性写入到外部文本文件。比如按照常见的xyz坐标格式来写,就可以生成xyz轨迹了,可以被VMD等程序直接载入。
在上有人提供了现成的这样的Perl脚本将原子轨迹转换成xyz轨迹。我进一步对其进行了修改使之用起来更方便些,另外加入了对周期性体系的支持。脚本如下所示
#!perl
#**********************************************************
#* *
#* XTD2XYZ - Convert XTD files into XYZ ormat *
#* *
#**********************************************************
# Version: 0.1
# Author: Andrea Minoia
# Date: 08/09/2010
#
# Convert MS trajectory xtd file into xYZ trajectory file.
# Backup of files that are about to be overwritten is managed
# by MS. The most recent file is that with higher index number (N)
# The script has to be in the same directory of the
# structure to modify and the user has to update the
# variable $doc (line 31) according to the name of the
# file containing the trajectory.
# The xmol trajectory is stored in trj.txt file and it is not
# possible to rename the file within MS, nor it is possible to
# automatically export it as xyz or car file. You should manage
# the new trajectory manually for further use (e.g. VMD)
#
# Modificator: Sobereva (sobereva@sina.com)
# Date: 2012-May-23
# The range of the frames to be outputted can be altered by line 49 and 51
use strict;
use MaterialsScript qw(:all);
#open the multiframe trajectory structure file or die
my $doc = $Documents{"./benzene.xtd"};
if (!$doc) {die "no document";}
my $trajectory = $doc->Trajectory;
if ($trajectory->NumFrames>1) {
print "Found ".$trajectory->NumFrames." frames in the trajectory\n";
# Open new xmol trajectory file
my $xmolFile=Documents->New("trj.txt");
#get atoms in the structure
# my $atoms = $doc->Atoms;
my $atoms = $doc->DisplayRange->Atoms;
my $Natoms=@$atoms;
# loops over the frames
my $framebegin=1;
my $frameend=$trajectory->NumFrames;
# my $frameend=10;
for (my $frame=$framebegin; $frame<=$frameend; ++$frame){
$trajectory->CurrentFrame = $frame;
#write header xyz
$xmolFile->Append(sprintf "%i \n", $Natoms);
$xmolFile->Append(sprintf "%s %i \n", "Frame",$frame);
foreach my $atom (@$atoms) {
# write atom symbol and x-y-z- coordinates
$xmolFile->Append(sprintf "%s %f %f %f \n",$atom->ElementSymbol, $atom->X, $atom->Y,