#!/usr/bin/perl

foreach (@ARGV)
  {
  open FILE_IN, "<$_" or die "Unable to read file $_";

  s/.pdb//;
  open FILE_OUT, ">$_.xml" or die "Unable to write file $_.xml";
  printf FILE_OUT "<gml>\n<molecule name=\"$_\">\n";

  while (<FILE_IN>)
    {
    s{\s*(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s*}
    {<atom element=\"\3\" x=\"\6\" y=\"\7\" z=\"\8\"/>\n}g;

    printf FILE_OUT;
    }

  printf FILE_OUT "</molecule>\n</gml>\n";

  close FILE_IN;
  close FILE_OUT;
  }
