repair_pdb.pl 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #! /usr/bin/perl -w
  2. # Fix errors pdb-file generate by modeller
  3. # Usage: repair_pdb.pl pdb-file
  4. use strict;
  5. my @res;
  6. # check arguments
  7. if ( @ARGV < 1 ) {
  8. error();
  9. exit(1);
  10. }
  11. open( IN, "$ARGV[0]" ) or die("Cannot open!");
  12. @res = <IN>;
  13. close IN;
  14. for (my $a = 0; $a < scalar(@res); $a++) {
  15. if ($res[$a] =~ /^(ATOM.{50})(.{6})/) {
  16. my $begin = $1;
  17. if ($2 ne " 1.00") {
  18. $res[$a] =~ s/$begin.{6}/$begin 1.00/;
  19. }
  20. }
  21. }
  22. my $i = scalar(@res) - 2;
  23. my $line = $res[$i];
  24. $line =~ s/^ATOM(\s+\d+)\s+\S+\s+(\S+\s+\d+).*\s+(\S+)\s*$/TER $1 $2 $3/;
  25. $line =~ /^\S+\s+(\d+)/;
  26. my $tmp = $1;
  27. my $tmp1 = $tmp + 1;
  28. my $tmp2 = $tmp + 2;
  29. $line =~ s/$tmp1/$tmp2/;
  30. $line =~ s/$tmp/$tmp1/;
  31. $i++;
  32. $res[$i] = "$line\n";
  33. $i++;
  34. $res[$i] = "END";
  35. open( OUT, ">$ARGV[0]" ) or die("Cannot open!");
  36. print OUT @res;
  37. close OUT;
  38. print "FINISHED!!!!\n";
  39. exit(0);
  40. #####################################################
  41. #### sub functions
  42. sub error {
  43. print("Usage: repair_pdb.pl pdb-file \n");
  44. print("\n");
  45. }