|
|
本帖最后由 刘喜洋 于 2026-4-3 21:59 编辑
图1图2如图所示,可以看到同样的代码运行,计算时间天差地别,很奇怪,无法解决
脚本如下
#!perl
use strict;
use Getopt::Long;
use MaterialsScript qw(:all);
our %Documents;
# ================= 配置参数 =================
my $start_probe = 0.0; # 初始探针半径 (Å)
my $end_probe = 5.0; # 终止探针半径 (Å,可根据活性炭孔径调整)
my $step_probe = 0.5; # 探针半径递增步长 (Å)
my $grid_interval = 0.4; # 网格间隔 (Å,保持原脚本推荐值)
# ================= 活性炭建模 =================
my $acConstruction = Modules->AmorphousCell->Construction;
# 添加环状结构组分
my $component1 = $Documents{"7ring.xsd"};
$acConstruction->AddComponent($component1);
$acConstruction->Loading($component1) = 3;
my $component2 = $Documents{"19ring.xsd"};
$acConstruction->AddComponent($component2);
$acConstruction->Loading($component2) = 3;
my $component3 = $Documents{"37ring.xsd"};
$acConstruction->AddComponent($component3);
$acConstruction->Loading($component3) = 3;
foreach my $i (1..2) {
my $min = 1; # 或者你想要的固定值
my $max = 10; # 或者你想要的固定值
my $val1 = int($min + rand() * ($max - $min + 1));
my $val2 = int($min + rand() * ($max - $min + 1));
my $val3 = int($min + rand() * ($max - $min + 1));
# ================= 活性炭建模 =================
my $acConstruction = Modules->AmorphousCell->Construction;
$acConstruction->Loading($component1) = $val1;
$acConstruction->Loading($component2) = $val2;
$acConstruction->Loading($component3) = $val3;
# 运行无定形胞建模
my $results = $acConstruction->Run(Settings(
Quality => 'Fine',
TargetDensity => 0.55,
CurrentForcefield => 'COMPASSIII'));
my $doc = $results->Trajectory;
# 几何优化
my $go_results = Modules->Forcite->GeometryOptimization->Run($doc, Settings(
ChargeAssignment => 'Use current'));
$doc = $go_results->Trajectory; # 更新为优化后的结构
$doc->SaveAs("ActivatedCarbon_Optimized-$i-$val1-$val2-$val3.xtd");
# ================= 1.84A计算 计算出比表面积等参数 =================
my $fieldConnolly = Tools->AtomVolumesSurfaces->Connolly->Calculate($doc, Settings(
GridInterval => $grid_interval,
ConnollyRadius => 1.84 # 动态设置探针半径
));
$fieldConnolly->Style = "None";
# 提取总体积与占据体积,计算自由体积
my $field_volume = $fieldConnolly->FieldVolume;
my $isosurface = $fieldConnolly->CreateIsosurface([
IsoValue => 0.0,
HasFlippedNormals => "No"
]);
my $enclosed_volume = $isosurface->EnclosedVolume;
my $Surface_Area=$isosurface->SurfaceArea;
my $free_volume = $field_volume - $enclosed_volume;
printf "自由体积 %.2f ų | 整体体积 %.2f Ų | 表面积 %.2f ų |loading1%.2f|loading2%.2f|loading3%.2f\n",
$free_volume, $field_volume,$Surface_Area,$val1,$val2,$val3;
#转换为xyz文件
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_$i.txt");
#get atoms in the structure
my $atoms = $doc->DisplayRange->Atoms;
my $Natoms = scalar(@$atoms); # 修复:定义原子总数
# loops over the frames
my $framebegin = 1;
my $frameend = $trajectory->NumFrames;
# 如需只转前10帧,去掉下面一行的 #
# 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;
print "转换完成!已生成 trj.txt\n";
}
else {
print "The " . $doc->Name . " is not a multiframe trajectory file \n";
}
#吸附等温线计算模块
my $sorptionAdsorptionIsotherm = Modules->Sorption->AdsorptionIsotherm;
my $component_H2 = $Documents{"H2-2020.xsd"};
$sorptionAdsorptionIsotherm->AddComponent($component_H2);
$sorptionAdsorptionIsotherm->FugacityStart($component_H2) = 10;
$sorptionAdsorptionIsotherm->FugacityEnd($component_H2) = 1000;
my $results = $sorptionAdsorptionIsotherm->Run($doc, Settings(
ChargeAssignment => 'Use current',
Temperature => 50,
UseFugacityLogScale => 'Yes'));
}
|
|