| 1 | chrisfen | 3037 | #!/usr/bin/env perl | 
| 2 |  |  |  | 
| 3 |  |  | # program that scales an OOPSE .in or .eor file to a new volume | 
| 4 |  |  |  | 
| 5 |  |  | # author    = "Chris Fennell | 
| 6 | chrisfen | 3038 | # version   = "$Revision: 1.2 $" | 
| 7 |  |  | # date      = "$Date: 2006-10-10 14:36:02 $" | 
| 8 | chrisfen | 3037 | # copyright = "Copyright (c) 2006 by the University of Notre Dame" | 
| 9 |  |  | # license   = "OOPSE" | 
| 10 |  |  |  | 
| 11 |  |  |  | 
| 12 |  |  | use Getopt::Std; | 
| 13 |  |  |  | 
| 14 |  |  | # some variables to get things going | 
| 15 |  |  | $startSnap = 0; | 
| 16 |  |  | $startFrame = 0; | 
| 17 |  |  | $startStunts = 0; | 
| 18 |  |  |  | 
| 19 |  |  | # get our options | 
| 20 |  |  | getopts('hv', \%opts); | 
| 21 |  |  |  | 
| 22 |  |  | # if we don't have a filename, drop to -h | 
| 23 |  |  | $opts{h} = 'true' if $#ARGV != 1; | 
| 24 |  |  |  | 
| 25 |  |  | # our option output | 
| 26 |  |  | if ($opts{h}){ | 
| 27 |  |  | print "affineScale: performs an affine transform on an OOPSE .in or .eor\n"; | 
| 28 |  |  | print "\tand writes to a new file named [file name].scale\n\n"; | 
| 29 |  |  | print "usage: affineScale [-hv] [file name] [new volume (Ang^3)]\n\n"; | 
| 30 |  |  | print "  -h : show this message\n"; | 
| 31 |  |  | die   "  -v : more verbose output\n"; | 
| 32 |  |  | } | 
| 33 |  |  |  | 
| 34 |  |  | # set some variables to be used in the code | 
| 35 |  |  | $fileName = $ARGV[0]; | 
| 36 |  |  | $newVolume = $ARGV[1]; | 
| 37 |  |  |  | 
| 38 |  |  | # some crazy input checking | 
| 39 |  |  | if ($newVolume =~ /^[0-9]/){ | 
| 40 |  |  | } else { | 
| 41 |  |  | die "\t[new volume] value ($newVolume) is not a valid number\n\tPlease choose a non-negative numeric value for [new volume]\n"; | 
| 42 |  |  | } | 
| 43 |  |  |  | 
| 44 |  |  | # split up the name to obtain an output filename | 
| 45 |  |  | @names = split('\.', $fileName); | 
| 46 |  |  | $names[$#names] = 'scale'; | 
| 47 |  |  | $outName = join('.',@names); | 
| 48 |  |  |  | 
| 49 |  |  | open(STATFILE, "./$fileName") || die "\tError: can't find file $fileName\n"; | 
| 50 |  |  | open (SCALEFILE, ">./$outName") || die "\tError: can't open $outName"; | 
| 51 |  |  |  | 
| 52 |  |  | while (<STATFILE>){ | 
| 53 |  |  | $startSnap = 0 if /\/Snapshot/; | 
| 54 |  |  | $startFrame = 0 if /\/FrameData/; | 
| 55 |  |  | $startStunts = 0 if /\/StuntDoubles/; | 
| 56 |  |  |  | 
| 57 |  |  | if ($startSnap == 1){ | 
| 58 |  |  | if ($startFrame == 1){ | 
| 59 |  |  | if (/Hmat/){ | 
| 60 |  |  | @line = split; | 
| 61 |  |  |  | 
| 62 |  |  | chop $line[2]; | 
| 63 |  |  | chop $line[8]; | 
| 64 |  |  | $oldVolume = $line[2]*$line[8]*$line[14]; | 
| 65 |  |  |  | 
| 66 |  |  | $scale = ($newVolume/$oldVolume)**0.333333333333333; | 
| 67 |  |  | # scale the hmat vectors (only orthorhombic) | 
| 68 |  |  | $line[2] *= $scale; | 
| 69 |  |  | $line[8] *= $scale; | 
| 70 |  |  | $line[14] *= $scale; | 
| 71 |  |  | $volume = $line[2]*$line[8]*$line[14]; | 
| 72 |  |  |  | 
| 73 |  |  | print SCALEFILE "\t$line[0]"; | 
| 74 |  |  | for ($i=1; $i<=$#line; $i++) { | 
| 75 |  |  | print SCALEFILE " $line[$i]"; | 
| 76 |  |  | if ($i == 2 || $i == 8) {print SCALEFILE ",";} | 
| 77 |  |  | } | 
| 78 |  |  | print SCALEFILE "\n"; | 
| 79 |  |  | } else { | 
| 80 |  |  | print SCALEFILE; | 
| 81 |  |  | } | 
| 82 |  |  | } | 
| 83 |  |  | if ($startStunts == 1){ | 
| 84 |  |  | @line = split; | 
| 85 |  |  | $line[2] *= $scale; | 
| 86 |  |  | $line[3] *= $scale; | 
| 87 |  |  | $line[4] *= $scale; | 
| 88 |  |  | print SCALEFILE "$line[0]\t$line[1]\t"; | 
| 89 |  |  | for ($i=2; $i<=$#line; $i++) { | 
| 90 |  |  | print SCALEFILE "$line[$i] "; | 
| 91 |  |  | } | 
| 92 |  |  | print SCALEFILE "\n"; | 
| 93 |  |  | } | 
| 94 |  |  | if ($startFrame == 0 && $startStunts == 0) { | 
| 95 |  |  | print SCALEFILE; | 
| 96 |  |  | } | 
| 97 |  |  | } else { | 
| 98 |  |  | print SCALEFILE; | 
| 99 |  |  | } | 
| 100 |  |  | $startSnap = 1 if /Snapshot/; | 
| 101 |  |  | $startFrame = 1 if /FrameData/; | 
| 102 |  |  | $startStunts = 1 if /StuntDoubles/; | 
| 103 |  |  | # check again since "/value" contains "value" | 
| 104 |  |  | $startSnap = 0 if /\/Snapshot/; | 
| 105 |  |  | $startFrame = 0 if /\/FrameData/; | 
| 106 |  |  | $startStunts = 0 if /\/StuntDoubles/; | 
| 107 |  |  | } | 
| 108 |  |  |  | 
| 109 |  |  | print "Affine transformed configuration written to $outName\n"; | 
| 110 |  |  |  | 
| 111 |  |  | if (defined($opts{v})){ | 
| 112 |  |  | print "New Volume   : $volume\n"; | 
| 113 |  |  | print "Old Volume   : $oldVolume\n"; | 
| 114 |  |  | print "Scale Factor : $scale\n"; | 
| 115 |  |  | } | 
| 116 |  |  |  |