计算化学公社

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

[Material Studio] 一个perl接枝脚本,但是运行却什么也没有,想请高手帮忙看一下

[复制链接 Copy URL]

611

帖子

2

威望

4455

eV
积分
5106

Level 6 (一方通行)

#!perl

use strict;
use MaterialsScript qw(:all);
use Math::Trig;
use Getopt::Long;

# Author: Reinier Akkermans
# Version: 1.0
# Materials Studio Version: 4.4
# Materials Studio Modules: Materials Visualizer
#
# This script attaches functional groups to the surface of a nanocluster.
# The input consists of:
# 1. A nanocluster in which broken bonds are capped with hydrogen atoms.
# 2. A fragment containing a linkage (such as those in .\share\Resources\Fragments\)
# 3. The surface coverage required as a fraction of the total surface

my $CLUSTER = $Documents{"Nanocluster.xsd"};
my %Args;
GetOptions(\%Args, "Fragment=s", "Coverage=f");
my $fragname = $Args{Fragment};
my $FRAGMENT = $Documents{"Toluene.xsd"};
my $COVERAGE = $Args{Coverage};
main();
#####################################################################
sub main(){
        # output document
        my $doc = Documents->New($CLUSTER->Name." + ".$FRAGMENT->Name.".xsd");
       
        # copy structure in
        $doc->CopyFrom($CLUSTER);
       
        # first fix hydrogens with two bonds (artefact of nanocluster builder)
        foreach my $atom (@{$doc->Atoms}) {
                if(($atom->ElementSymbol eq "H") && ($atom->Bonds->Count == 2)){
                        # get the two atoms attached to this hydrogen
                        my $attachedAtoms = $atom->attachedAtoms;
                       
                        # delete both bonds
                        $atom->Bonds->Delete;
                       
                        #create a new H-atom
                        my $newAtom = $doc->CreateAtom("H",$atom->XYZ);
                       
                        # create two new bonds
                        $doc->CreateBond($atom,$attachedAtoms->Item(0),"Single");
                        $doc->CreateBond($newAtom,$attachedAtoms->Item(1),"Single");
                       
                        # clean up steric hindrance
                        $newAtom->Clean;
                }
        }
       
        # attach fragments to the surface
        foreach my $atom (@{$doc->Atoms}) {
                if(($atom->ElementSymbol eq "H") && (rand()<$COVERAGE)){
                        # add a new fragment               
                        my $fragment = $doc->CopyFrom($FRAGMENT);
                       
                        # get the linkage atom
                        my $linkAtom = $fragment->Linkages(0)->LinkAtoms->Item(0);

                        # the two atoms between which to create a bond
                        my $atom1 = $atom->AttachedAtoms->Item(0);
                        my $atom2 = $linkAtom->AttachedAtoms->Item(0);
                       
                        # translate the fragment such that the linkage atom is
                        # on top of the hydrogen atom
                        my $centroid = $doc->CreateCentroid($fragment->Atoms);
                        $centroid->Translate(Point(X => -$linkAtom->X, Y => -$linkAtom->Y, Z => -$linkAtom->Z));
                        $centroid->Translate(Point(X => $atom->X, Y => $atom->Y, Z => $atom->Z));
                       
                        # rotate the fragment such that the linkage bond
                        # is parallel with the hydrogen bond
                        my $bond1 = Point(X => $atom1->X-$atom->X,Y => $atom1->Y-$atom->Y, Z => $atom1->Z-$atom->Z);
                        my $bond2 = Point(X => $atom2->X-$linkAtom->X,Y => $atom2->Y-$linkAtom->Y, Z =>$atom2->Z-$linkAtom->Z);
                        my $angle = 180-acos(InProduct($bond1,$bond2)/Length($bond1)/Length($bond2))*180/pi;
                        my $axis = CrossProduct($bond1,$bond2);
                        $centroid->RotateAboutPoint($angle,$axis,$atom->XYZ);
                       
                        # delete centroid,linkage atom and hydrogen atom
                        $centroid->Delete;
                        $atom->Delete;
                        $linkAtom->Delete;
                       
                        # attach to the nanocluster
                        $doc->CreateBond($atom1,$atom2,"Single");
                }
        }
        # give it a few shakes to remove steric hindrance
        for(my $i=0;$i<15;$i++){
                $doc->Clean;
        }
}

sub Length(){
        my ($a) = @_;
        return sqrt(InProduct($a,$a));
}
sub CrossProduct(){
        my ($a,$b) = @_;
        return Point(X => $a->Y*$b->Z-$a->Z*$b->Y, Y => $a->Z*$b->X-$a->X*$b->Z, Z => $a->X*$b->Y-$a->Y*$b->X);
}
sub InProduct(){
        my ($a,$b) = @_;
        return $a->X*$b->X+$a->Y*$b->Y+$a->Z*$b->Z;
}

Toluene.xsd

8.75 KB, 下载次数 Times of downloads: 11

Nanocluster.xsd

64.59 KB, 下载次数 Times of downloads: 10

125

帖子

0

威望

2897

eV
积分
3022

Level 5 (御坂)

2#
发表于 Post on 2020-3-6 17:21:29 | 只看该作者 Only view this author
我觉得吧,很可能是你的运行方式不对,运行脚本的时候没有加参数。

611

帖子

2

威望

4455

eV
积分
5106

Level 6 (一方通行)

3#
 楼主 Author| 发表于 Post on 2020-3-6 17:22:45 | 只看该作者 Only view this author
hxd_yi 发表于 2020-3-6 17:21
我觉得吧,很可能是你的运行方式不对,运行脚本的时候没有加参数。

我就是直接脚本运行的,没有加入界面运行,兄弟,你看这个脚本哪里需要修改?

125

帖子

0

威望

2897

eV
积分
3022

Level 5 (御坂)

4#
发表于 Post on 2020-3-8 16:57:09 | 只看该作者 Only view this author
my $COVERAGE = $Args{Coverage};这一句需要修改,改成你需要的数值,否则每次都是0,不会有结果出来的,虽然运行时不报错。

611

帖子

2

威望

4455

eV
积分
5106

Level 6 (一方通行)

5#
 楼主 Author| 发表于 Post on 2020-3-8 17:06:51 | 只看该作者 Only view this author
hxd_yi 发表于 2020-3-8 16:57
my $COVERAGE = $Args{Coverage};这一句需要修改,改成你需要的数值,否则每次都是0,不会有结果出来的,虽 ...

明白,这句话貌似是perl的语法规则?

125

帖子

0

威望

2897

eV
积分
3022

Level 5 (御坂)

6#
发表于 Post on 2020-3-11 13:55:51 | 只看该作者 Only view this author
zyj19831206 发表于 2020-3-8 17:06
明白,这句话貌似是perl的语法规则?

perl中的hash表

本版积分规则 Credits rule

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

GMT+8, 2026-2-20 13:09 , Processed in 0.164733 second(s), 23 queries , Gzip On.

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