标题: 把MS里的xtd文件转置成xyz文件时,可以把水去掉吗,不计算在内? [打印本页] 作者Author: 深爱小李 时间: 2021-10-13 09:30 标题: 把MS里的xtd文件转置成xyz文件时,可以把水去掉吗,不计算在内? 盒子里有1000个水分子,20个前药分子,1个金属离子,我想把1000个水分子去掉,不转置水,只要剩下的坐标信息,该怎么做呀,这是我用的脚本
#!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,
$atom->Z);
}
}
#close trajectory file
$xmolFile->Close;
}
else {
print "The " . $doc->Name . " is not a multiframe trajectory file \n";
}作者Author: AaronO_o 时间: 2021-10-13 10:36 本帖最后由 AaronO_o 于 2021-10-13 17:04 编辑
我认为可以先将所有水分子设置为一个set,然后在55的循环处,参考
$set1Doc->CopyFrom($doc);
my $cell = $set1Doc->UnitCell;
my $objects = $cell->$ObjectTypes;
foreach (@{$objects}) { $_->Name = "Delete"; }
foreach (@{$cell->Sets($i)->$ObjectTypes}) { $_->Name = "Keep"; }
foreach (@{$objects}) { $_->Delete if ($_->Name eq "Delete"); }和
sub SetsAreOK
{
my ($doc, $ObjectType) = @_;
my $objects = $ObjectType ."s";
my $items = $doc->UnitCell->$objects;
my $sets = $doc->UnitCell->Sets;
# Get the total number of atoms or beads
my $total = $items->Count;
# Cache their names
my @name;
foreach my $item (@{$items})
{
push @name, $item->Name;
}
# Go through each set and each item and rename them
my $tot_in_sets=0;
foreach my $set (@{$sets})
{
my $items = $set->$objects;
my $n = $items->Count;
if ($n == 0)
{
print "Set ".$set->Name." is empty (UnitCell)\n";
return 0;
}
$tot_in_sets += $n;
foreach my $item (@{$items})
{
if ($item->Name =~ /^Member of set /)
{
my $otherset = $item->Name;
$otherset =~ s/^Member of set //;
print "Overlap between sets ".$set->Name." and $otherset\n";
return 0;
};
$item->Name = "Member of set ".$set->Name;
}
}
# Put their names back
my $i=0;
foreach my $item (@{$items})
{
$item->Name = $name[$i];
$i++;
}
if ($total < $tot_in_sets)
{
print "More $objects in sets than in document\n";
return 0;
}
return 1;
}
试试在输出xyz前直接删掉水分子。
或者不进行删除操作,加一个判断语句,原子属于水set、则不输出xyz并继续循环。
脚本来源:
#################################################################################
#
# Authors: Stephen Todd, Jason DeJoannis
# Modified by: Aaron Wang, 2020 Mar. 15
# Date: Apr. 22, 2013
# Purpose: Interaction energies between each pair of sets
# Requirements: Trajectory with sets defined
# The sets must be non-overlapping (no two can contain the same atom or bead)
# A Forcite/Mesocite settings file with the same name as the trajectory
#
# Works for Forcite or Mesocite and with standard MS or OFF forcefields
#
# Outputs: A study table with a summary page and one page for each interaction
# van der Waals and Coulomb energy components
# Hydrogen bond counts
#Update:
#2020 Apr. 22: Fix sets loop probelm at line 147.
#2020 Apr. 25: Adding set unfixing at line 187.
#################################################################################