免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3520 | 回复: 1
打印 上一主题 下一主题

请求帮助:代码查错 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2018-01-29 16:00 |只看该作者 |倒序浏览
请走过路过的大神们帮忙查找一下为什么不能输出Script.txt文件以及内容,代码如下:附件中是调运子程序castepcalculation计算得到的1.castep文件。
  1. #!perl

  2. use strict;
  3. use Getopt::Long;
  4. use MaterialsScript qw(:all);

  5. my $a     = 1;
  6. my $myDoc = $Documents{"$a.xsd"};
  7. my $stressz;

  8. sub castepcalculation ($stressz) {
  9.     my ($stressz) = @_;

  10.     my $castep = Modules->CASTEP;
  11.     $castep->ChangeSettings(
  12.         Settings(
  13.             Task                  => "Geometry Optimization",
  14.             NonLocalFunctional    => "PBE",
  15.             UseCustomEnergyCutoff => "Yes",
  16.             EnergyCutoff          => 350,
  17.             SCFConvergence        => 5e-002,
  18.             MaximumSCFCycles      => 200,
  19.             CalculateStress       => "Yes",
  20.             OptimizeCell          => "Yes",
  21.             EnergyConvergence     => 5e-001,
  22.             Sxx                   => 0,
  23.             Syy                   => 0,
  24.             Szz                   => "$stressz",
  25.             Quality               => "Ultra-fine",

  26.             # PropertiesKPointQuality => "Fine"
  27.             KPointDerivation => "CustomGrid",
  28.             ParameterA       => 1,
  29.             ParameterB       => 1,
  30.             ParameterC       => 1
  31.         )
  32.     );
  33.     $castep->GeometryOptimization->Run($myDoc);
  34. }

  35. for ( my $stressz = 0 ; $stressz <= 3 ; ++$stressz ) {
  36.     &castepcalculation($stressz);  #calculate the results files by castep module     

  37.     #Processing result file
  38.     open( result, "$a.castep" || die("open 1.castep fasiled") );
  39.     open( OUTFILE, ">>Script.txt" );
  40.     my @line  = ();
  41.     my $count = 1;
  42.     my $perlscript = "/Documents/script/try2";
  43.     my $outputName;
  44.     @line = <result>;

  45.     while ( $count <= @line )      #$line[count]
  46.     {
  47.         if ($line[$count] =~ /" BFGS : Geometry optimization completed successfully."/ )
  48.         {
  49.             open (OUTFILE, ">>Script.txt") || die ("write Script.out fasiled");
  50.             printf OUTFILE ("stressz=%d Lattice=%2.8f \n",$stressz,$line[$count+17]);
  51.             opendir(filedir,"$perlscript" || die "open dir-try2 fasiled" );
  52.             last;
  53.         }
  54.         else{
  55.              if ( $count < @line ){
  56.                 $count++;
  57.              }
  58.              redo &castepcalculation if($count = @line);
  59.         }
  60.     }
  61. }
复制代码


论坛徽章:
0
2 [报告]
发表于 2018-01-29 19:55 |只看该作者
目前发现问题一:
if ($line[$count] =~ /" BFGS : Geometry optimization completed successfully."/ )应将字符串的引号去掉;
目前发现问题二:printf输出的Lattice应改为%s,且利用sunstr函数抓取部分;
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP