#!/usr/bin/perl 
use strict;
my @clust;
my @atom;
my @number;
my $fname;

print "Hello! \n";
while ()
 {
  print "What's the name of your list file?\n\n";
  $fname=<STDIN>;
  chomp $fname;
  print "\n";

  if (-e $fname)
   {
    open FILE, "<$fname" or die ("File can't be opened! $!\n\n");
    last;
   }
  
   else
   {
    print "File doesn't exist! Write another name!\n\n";
   }
 } 
while (my $line=<FILE>)
 {
   chomp $line;
   if ($line=~m/^(\d+)\s+.+\s+(\d+)\s+A\s+(.+\d*)\s*$/)
    {
     push @clust, $2;
     push @atom, $3;
     push @number, $1;
    }
   else
    {
    }
 }

close FILE, "<$fname" or die ("File can't be closed! $!\n\n");

open FILE, ">>clust.pml" or die ("File can't be opened! $!\n\n");

print FILE "load 2pue_1.pdb\n";
print FILE "hide all\n";
print FILE "select ob1, chain a+d\n";
print FILE "select contactzone, chain a and (chain d around 5.5)\n";
print FILE "remove chain d\n";
print FILE "show surface, contactzone\n";
print FILE "set surface_color, white, contactzone\n";
print FILE "show ribbon, chain a\n";

for (my $w=0; $w<@clust; $w++)
 {
  if ($number[$w] eq "2")
   {
    print FILE "set surface_color, purple, A/$clust[$w]/$atom[$w]\n";
    print $clust[$w];
    print "\n";
    print $atom[$w];
   }
  elsif ($number[$w] eq "3")
   {
    print FILE "set surface_color, red, A/$clust[$w]/$atom[$w]\n";
    print $clust[$w];
    print "\n";
    print $atom[$w];
   }
  elsif ($number[$w] eq "6")
   {
    print FILE "set surface_color, blue, A/$clust[$w]/$atom[$w]\n";
    print $clust[$w];
    print "\n";
    print $atom[$w];
   }
  elsif ($number[$w] eq "7")
   {
    print FILE "set surface_color, green, A/$clust[$w]/$atom[$w]\n";
    print $clust[$w];
    print "\n";
    print $atom[$w];
   }
  elsif ($number[$w] eq "8")
   {
    print FILE "set surface_color, orange, A/$clust[$w]/$atom[$w]\n";
    print $clust[$w];
    print "\n";
    print $atom[$w];
   }
  elsif ($number[$w] eq "10")
   {
    print FILE "set surface_color, yellow, A/$clust[$w]/$atom[$w]\n";
    print $clust[$w];
    print "\n";
    print $atom[$w];
   }
  else
   {
   }
 }

print FILE "set transparency, 0.2\n";
  
close FILE, ">>clust.pml" or die ("File can't be closed! $!\n\n");


<STDIN>;   





