#!/usr/bin/perl 
use strict;
my @cluster;
my @atom;
my @number;
my $fname;
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 file name!\n\n";
   }
 } 
while (my $line=<FILE>)
 {
   chomp $line;
   if ($line=~m/^(\d+)\s+.+\s+(\d+)\s+A\s+(.+\d*)\s*$/)
    {
     push @cluster, $2;
     push @atom, $3;
     push @number, $1;
    }
   else
    {
    }
 }
close FILE, "<$fname" or die ("File can't be closed! $!\n\n");
open FILE, ">>cluster.pml" or die ("File can't be opened! $!\n\n");
print FILE "load 1qqb_1.mmol\n";
print FILE "hide\n";
print FILE "select contact, chain a and (chain c around 5.0)\n";
print FILE "remove chain c\n";
print FILE "show surface, contact\n";
print FILE "set surface_color, white, contact\n";
print FILE "show ribbon, chain a\n";
for (my $cl=0; $cl<@cluster; $cl++)
 {
  if ($number[$cl] eq "1")
   {
    print FILE "set surface_color, green, A/$cluster[$cl]/$atom[$cl]\n";
   }
  elsif ($number[$cl] eq "2")
   {
    print FILE "set surface_color, yellow, A/$cluster[$cl]/$atom[$cl]\n";
   }
  elsif ($number[$cl] eq "7")
   {
    print FILE "set surface_color, red, A/$cluster[$cl]/$atom[$cl]\n";
   }
  elsif ($number[$cl] eq "9")
   {
    print FILE "set surface_color, blue, A/$cluster[$cl]/$atom[$cl]\n";
   }
  elsif ($number[$cl] eq "11")
   {
    print FILE "set surface_color, magenta, A/$cluster[$cl]/$atom[$cl]\n";
   }
  elsif ($number[$cl] eq "12")
   {
    print FILE "set surface_color, orange, A/$cluster[$cl]/$atom[$cl]\n";
   }
  else
   {
   }
 }
print FILE "set transparency, 0.2\n";
print FILE "set surface_quality, 2\n";  
close FILE, ">>cluster.pml" or die ("File can't be closed! $!\n\n");
<STDIN>;   





