计算化学公社

 找回密码 Forget password
 注册 Register
Views: 4950|回复 Reply: 3
打印 Print 上一主题 Last thread 下一主题 Next thread

[Material Studio] 把MS里的xtd文件转置成xyz文件时,可以把水去掉吗,不计算在内?

[复制链接 Copy URL]

78

帖子

0

威望

94

eV
积分
172

Level 3 能力者

跳转到指定楼层 Go to specific reply
楼主
盒子里有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";
}

33

帖子

0

威望

709

eV
积分
742

Level 4 (黑子)

2#
发表于 Post on 2021-10-13 10:36:29 | 只看该作者 Only view this author
本帖最后由 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.
#################################################################################

评分 Rate

参与人数
Participants 1
eV +2 收起 理由
Reason
sobereva + 2

查看全部评分 View all ratings

78

帖子

0

威望

94

eV
积分
172

Level 3 能力者

3#
 楼主 Author| 发表于 Post on 2021-10-13 14:14:32 | 只看该作者 Only view this author
AaronO_o 发表于 2021-10-13 10:36
我认为可以先将所有水分子设置为一个set,然后在55的循环处,参考

                             $set1D ...

谢谢你的回复,你写的这个脚本是删掉水分子之后再输出吗?我在输出xyz前对水分子设立了set,IsHidden选择了Yes,IsIndisplayRange选择了No,不知道这样是否可以

33

帖子

0

威望

709

eV
积分
742

Level 4 (黑子)

4#
发表于 Post on 2021-10-13 23:40:26 | 只看该作者 Only view this author
深爱小李 发表于 2021-10-13 14:14
谢谢你的回复,你写的这个脚本是删掉水分子之后再输出吗?我在输出xyz前对水分子设立了set,IsHidden选择 ...

我手头没有能用到的MS,暂时无法测试这个方法是否可行。不过我认为是可行的,而且更好。

本版积分规则 Credits rule

手机版 Mobile version|北京科音自然科学研究中心 Beijing Kein Research Center for Natural Sciences|京公网安备 11010502035419号|计算化学公社 — 北京科音旗下高水平计算化学交流论坛 ( 京ICP备14038949号-1 )|网站地图

GMT+8, 2026-2-23 05:09 , Processed in 0.151809 second(s), 21 queries , Gzip On.

快速回复 返回顶部 返回列表 Return to list