#!/usr/bin/perl
#
# Usage:
#      perl mWMS.pl h2o.xyz 
#       

$mem='memory,800,m';

$workdir=`pwd`;
chomp $workdir;
$basis1 = 'basis, aug-cc-pV(D+d)Z, H=VDZ';
$basis2 = 'basis, aug-cc-pV(T+d)Z, H=VTZ';
$basis3 = 'basis,cc-pwCVDZ';
$basis4 = 'basis,cc-pwCVTZ';
$WM = 'WMS';

for $i (0 .. @ARGV-1){
  $name = $ARGV[$i];
  @out=split(/\./, $name);
  open(FILE2,">$out[0]_$WM.com") || die "can't open $!"; 
  print FILE2 "***,$out[0]\n";
  print FILE2 "$mem\n";
  
  open(FILE4, "<$name") || die "can't open $!";
  @lines = (<FILE4>);
  close FILE4;
  print "$WM \n";

  @cm = split(/\s+/, $lines[1]); 
  @temp = split(/\s+/, $lines[0]);
  $noa = $temp[0];
  $spin = $cm[1]-1 ;
  print FILE2 "Set,Charge=$cm[0],Spin=$spin;\n";
  print FILE2 "geomtyp=xyz\n";  
  print FILE2 'geometry={';
  print FILE2 "\n$noa \n";
  print FILE2 "$out[0]\n";
  for $i (2 .. $noa+1){
     print FILE2 "$lines[$i]";
   }
  print FILE2 "}\n";
  print FILE2 "$basis1 \n";
  if ($spin == 0) {
    print FILE2 "HF \n{ccsd(t)-f12,gem_beta=0.9 ,df_basis=vdz/mp2fit,df_basis_exch=vdz/jkfit,ri_basis=vdz/jkfit}\n";
  } else {
    print FILE2 "HF \n{uccsd(t)-f12,gem_beta=0.9,df_basis=vdz/mp2fit,df_basis_exch=vdz/jkfit,ri_basis=vdz/jkfit}\n";
  }

  print FILE2 "SHOW,ENERG*,EMP2*,EF12* \n\n";
  print FILE2 "$basis2 \n";
  if ($spin == 0) {
    print FILE2 "HF \n{ccsd(t)-f12,gem_beta=1.0,df_basis=vtz/mp2fit,df_basis_exch=vtz/jkfit,ri_basis=vtz/jkfit}\n";
  } else {
    print FILE2 "HF \n{uccsd(t)-f12,gem_beta=1.0,df_basis=vtz/mp2fit,df_basis_exch=vtz/jkfit,ri_basis=vtz/jkfit}\n";
  }

  print FILE2 "SHOW,ENERG*,EMP2*,EF12* \n\n";

  print FILE2 "$basis3 \n";

  if ($spin == 0) {
    print FILE2 "HF; \nccsd(t)\nSHOW,ENERG*,EMP2* \nHF;\n{ccsd(t); Core,c1,c2,c3,c4,c5,c6,c7,c8;}\nSHOW,ENERG*,EMP2*\n\n";
  } else {
    print FILE2 "HF; \nuccsd(t)\nSHOW,ENERG*,EMP2* \nHF;\n{uccsd(t); Core,c1,c2,c3,c4,c5,c6,c7,c8;}\nSHOW,ENERG*,EMP2*\n\n";
  }

  print FILE2 "$basis4 \n";
  print FILE2 "HF; \nRMP2;\nSHOW,ENERG*,EMP2* \nHF;\n{RMP2; Core,c1,c2,c3,c4,c5,c6,c7,c8;}\nSHOW,ENERG*,EMP2* \n\n";
  
  print FILE2 "basis, AVDZ-DK, h=VDZ-DK \ndkroll=1 \nHF \nRMP2; \nSHOW,ENERG*,EMP2*  \n\n";
  print FILE2 "basis, AVDZ, h=VDZ \ndkroll=0 \nHF \nRMP2;\nSHOW,ENERG*,EMP2*   \n\n";

  print FILE2 "basis, AVTZ-DK, h=VTZ-DK \ndkroll=1 \nHF \nRMP2; \nSHOW,ENERG*,EMP2*  \n\n";
  print FILE2 "basis, AVTZ, h=VTZ \ndkroll=0 \nHF \nRMP2;\nSHOW,ENERG*,EMP2*   \n\n";

  print FILE2 "---";
  close FILE2;

 }

   

