CCL Home Page
Up Directory CCL g90-to-aces2
#!/usr/local/bin/perl

# Jan Labanowski, OSC, 1992
# converts Gaussian Z-matrix from output file to an input file for ACES2

#  First line shows the location of perl (usually: /usr/local/bin/perl)
#  On the OSC Cray it is #!/loclib/bin/perl 
#  remember to use chmod 700 gauss2aces.perl (i.e., set x bit)

# USAGE: gauss2aces.perl g90file.out which
#        gayss2aces.perl g90file.out which > aces2file.inp

#   g90file.out --- Gaussian90 output file
#   which --- which Z-matrix to take: 1: first
#                                      2: second 
#                                        .....
#                                      10000: last  (something big)
#               if which not given then last Z-matrix is taken
#


# This perl script scans the G90 output file. First it saves the title.
# Then string "Z-MATRIX (ANGSTROMS AND DEGREES)" is looked for (beginning
# of the Z-matrix) and the data saved in arrays. If there are more than one
# Z-matrices in the G90.OUT file, then the one pointed by "which" is chosen.
# The example of Z-matrix format in G90.OUT follows:
# ------------------------------------------------------------------------
#                         Z-MATRIX (ANGSTROMS AND DEGREES)
# CD Cent Atom  N1     Length/X     N2    Alpha/Y     N3     Beta/Z      J
# ------------------------------------------------------------------------
#   1   1  C
#   2   2  O     1   1.246971(  1)
#   3   3  H     2   0.960102(  2)   1  115.911(  6)
#   4   4  H     1   1.080432(  3)   2  116.612(  7)   3  179.998( 10)   0
#   5   5  O     1   1.256347(  4)   2  120.747(  8)   3   -0.003( 11)   0
#   6   6  H     5   0.956247(  5)   1  116.255(  9)   2 -179.989( 12)   0
# ------------------------------------------------------------------------
# Data from arrays are sent to STDOUT in a format required for ACES2 input.
# All variables are marked with a "*" for optimization and you must fill in
# appropriate ACES2 keywords.
#

open(G90OUT,"<$ARGV[0]") || die "Could not open $ARGV[0]\n";

if ($#ARGV < 1) {
  $which = 10000;
  }
else {
  $which = $ARGV[1];
  }

die "which (2nd argument) must be greated than 0 !\n" if ($which < 1);

$n_at = 0;
#now search for "Z-Matrix" line
$title_line = -1;
$n_z_mats = 0;
while () {
  if ((/enter 101/) && ($title_line == -1)) { #title is after line enter 101
    $title_line = 0;
    }
  if ($title_line > -1) {
    $title_line++;
    }
  if ($title_line == 3) {
    $title = $_;
    $title_line = -2;
    }
  if (/Z-MATRIX \(ANGSTROMS AND DEGREES\)/) {  #extracts last z-matrix from OUT
    $n_z_mats++;  #advance number of Z-matrices read in
    #skip 3 lines
    for ($i = 0; $i < 2; $i++ ) {
      $line = ;
      }
    #now collect Z-matrix
    $n_at = 0;
    while ($line = ) {
      chop ($line);  # throw away the new line
      $line =~ s/[\(\)]/ /g;  # substitute ( or ) with spaces
      last if ($line =~ /--------------------/);  # when last line of Z-mat
      $n_at++;
      @entries = split(/\s+/,$line);   #get all the fields
      $at_symbol[$n_at] = $entries[3]; 
      $r[$n_at] = $entries[5]; $r_n[$n_at] = $entries[4];
      $a[$n_at] = $entries[8]; $a_n[$n_at] = $entries[7];
      $t[$n_at] = $entries[11]; $t_n[$n_at] = $entries[10];
      }  #end while

    } #end if Z-MATRIX

    last if($n_z_mats >= $which); #exit loop when "which"'s Z-mat found

  } #end while G90OUT

$title =~ s/^\s+//;

print STDOUT $title;

# write Z-Matrix
print STDOUT $at_symbol[1], "\n";
if ($n_at > 1) {
  printf STDOUT "%s %d R1*\n", $at_symbol[2], $r_n[2];
  }
if ($n_at > 2) {
  printf STDOUT "%s %d R2* %d A%d*\n", $at_symbol[3], $r_n[3], $a_n[3], $n_at;
  }
for ($i = 4; $i <= $n_at; $i++) {
  printf STDOUT "%s %d R%d* %d A%d* %d T%d*\n", $at_symbol[$i], $r_n[$i],
  $i-1, $a_n[$i], $n_at+$i-3, $t_n[$i], 2*$n_at+$i-6;
  }
print STDOUT "\n";

# write variables
for ($i = 2; $i <= $n_at; $i++) {
  printf STDOUT "R%d=%f\n", $i-1, $r[$i];
  }

for ($i = 3; $i <= $n_at; $i++) {
  printf STDOUT "A%d=%f\n", $n_at+$i-3, $a[$i];
  }

for ($i = 4; $i <= $n_at; $i++) {
  if ($t[$i] > 180.0) {
    $t[$i] = $t[$i] - 360.0;
    }
  if ($t[$i] < -180.0) {
    $t[$i] = $t[$i] + 360.0;
    }
  printf STDOUT "T%d=%f\n", 2*$n_at+$i-6, $t[$i];
  }

print STDOUT "\n";

print STDOUT 
      "*ACES2(BASIS=DZP,CALCLEVEL=0)\n";

print STDOUT "\n";
print STDOUT "\n";
print STDOUT "\n";
print STDOUT "\n";
Modified: Fri Nov 13 17:00:00 1992 GMT
Page accessed 8987 times since Sat Apr 17 21:22:58 1999 GMT