#!/usr/sbin/perl
# Reformat AMBER PDB file to STAR format 
#
# USAGE pdb_to_star.pl infile outfile 
# pdb_to_star.pl 
# 
#                             D.E. VOLK  02/27/2003
$infile = shift(@ARGV);
$outfile = shift(@ARGV);
#
open(INFILE, "$infile") || die "Cannot open file $infile1";
#
# Remove the old outfile file if it exits:
#
   if (-e "$outfile") {
     unlink("$outfile");
   }
#
open(OUT,">$outfile") || die "Cannot open file $outfile";
#
# Print the outfile file header:
#
#
#	READ THE OLD AMBER FILE 
foreach (<INFILE>)
  {
   /^TER/ && (print OUT "$_");   # preserve TER
   /^TITLE/ && (print OUT "$_");   # preserve TITLE
   /^MODEL/ && (print OUT "$_");   # preserve MODEL
   /^END/  && (print OUT "$_");   # preserve END/ENDMDL
   /^CONECT/  && (print OUT "$_");   # preserve CONECT
   next unless (/ATOM/ || /HETATM/);  # only do ATOM containing lines
   /\bQ/ && next;
   s/\+/ /;
   s/H2\'1/1H2\*/;         # change atom names 
   s/H2\'2/2H2\*/;
   s/H5\'1/1H5\*/;
   s/H5\'2/2H5\*/;
   s/C7 /C5M/;
   s/H71 /1H5M/;
   s/H72 /2H5M/;
   s/H73 /3H5M/;
   s/H41/1H4/;
   s/H42/2H4/;
   s/H21/1H2/;
   s/H22/2H2/;
   s/\'/\*/;           # last step, change all remaining quotes to stars
#
   chomp;         # get rid of newline
    s/^\s+//;
   ($v1,$v2,$v3,$v4,$v5,$v6,$v7,$v8,$v9)= split(/\s+/,$_);
    write OUT;
   }
close(OUT);
close(INFILE);
#
format OUT =
@<<<<<@>>>> @<<< @>> @@>>>    @>>>>>>>@>>>>>>>@>>>>>>>
$v1,   $v2, $v3,$v4,$v5   ,$v6, $v7,    $v8,     $v9    
.
# That's all folks!!
