用Perl脚本实现MS批量任务
1. 截断能收敛测试脚本
#!perl
use strict;
use MaterialsScript qw(:all);
# initial files preparation
my $myDoc=$Documents{"WO3.xsd"};#定义要计算的模型文件
my $myStudyTable=Documents->new("energy-encut.std");#新建StudyTable存放计算结构,第一列是截断能,第二列是体系总能
my $mySheet=$myStudyTable->ActiveSheet;
$mySheet->ColumnHeading(0)="Enegy Cutoff(eV)";
$mySheet->ColumnHeading(1)="Final Enegy(eV)";
# castep single calculation
my $castep=Modules->CASTEP;
my $startEnergy=200;#测试起点:200 eV
my $endEnergy=500;#测试终点: 500 eV
my $intervalEnergy=20;#测试点间隔
my $sumIteration=($endEnergy-$startEnergy)/$intervalEnergy;
#循环计算每个截断能测试点的单点能
for(my $counter=0;$counter<=$sumIteration;++$counter){
my $energyCutoff=$startEnergy+$intervalEnergy*$counter;
$castep->ChangeSettings(
Settings(Quality=>"Fine",
UseCustomEnergyCutoff=>"Yes",
EnergyCutoff=>$energyCutoff));#这里设置截断能为测试点的截断能
$castep->Energy->Run($myDoc);
$mySheet->Cell($counter,0)=$energyCutoff;
#read final energy from castep output files
#下面这一段提取castep文件中的总能,即Final energy后面的结果
foreach my $line (@{$Documents{"WO3.castep"}->Lines}) {
if ($line=~/^Final energy/){
my $finalEnergy = substr($line,31,15);
print $energyCutoff,"",$finalEnergy,"";
$mySheet->Cell($counter,1)=$finalEnergy;#将总能结果放入StudyTable
}}
}
2. k点收敛测试脚本
#!perl
use strict;
use MaterialsScript qw(:all);
# initial files preparation
my $myDoc=$Documents{"WO3.xsd"};
my $myStudyTable=Documents->new("energy-kpts.std");
my $mySheet=$myStudyTable->ActiveSheet;
$mySheet->ColumnHeading(0)="k-points";
$mySheet->ColumnHeading(1)="Final Enegy(eV)";
# castep single calculation
my $castep=Modules->CASTEP;
my $start=1;
my $end=12;
my $interval=1;
my $sum=($end-$start)/$interval;
for(my $counter=0;$counter<=$sum;++$counter){
my $kpts=$start+$interval*$counter;
$castep->ChangeSettings(
Settings(Quality=>"Fine",
UseCustomEnergyCutoff=>"Yes",EnergyCutoff=>400,
KPointDerivation=>"CustomGrid",ParameterA=>$kpts,ParameterB=>$kpts,ParameterC=>$kpts));
$castep->Energy->Run($myDoc);
$Documents{"WO3.castep"}->SaveAs("$kpts.txt");
$mySheet->Cell($counter,0)=$kpts."x".$kpts."x".$kpts;
#read final energy from castep output files
foreach my $line (@{$Documents{"$kpts.txt"}->Lines}) {
if ($line=~/^Final energy/){
my $finalEnergy = substr($line,31,15);
print $kpts."x".$kpts."x".$kpts."".$finalEnergy,"";
$mySheet->Cell($counter,1)=$finalEnergy;
}}
}