FixOccupancy.pm 633 B

123456789101112131415161718192021222324252627282930313233343536
  1. #!/usr/bin/env perl
  2. package FixOccupancy;
  3. use strict;
  4. use warnings;
  5. use File::Copy;
  6. sub FixOccupancy {
  7. my $file = shift;
  8. open my $input, '<', $file or die "Could not open $file: $!";
  9. open my $output, '>', $file . '.occupancy_fix' or die "Could not open $file: $!";
  10. while ( my $line = <$input> ) {
  11. if ( $line !~ /^ATOM/ ) {
  12. print $output $line;
  13. next;
  14. }
  15. my $occupancy = substr($line, 54, 5);
  16. if ( $occupancy > 0.0 ) {
  17. print $output $line;
  18. next;
  19. }
  20. print $output substr($line, 0, 55) . " 0.01" . substr($line, 60, 21);
  21. }
  22. close $input;
  23. close $output;
  24. move($file . '.occupancy_fix', $file);
  25. }
  26. 1;