6 |
|
use Getopt::Std; |
7 |
|
|
8 |
|
# some variables to get things going |
9 |
< |
$line1 = 1; |
10 |
< |
$line2 = 0; |
9 |
> |
$startSnap = 0; |
10 |
> |
$startFrame = 0; |
11 |
> |
$startStunts = 0; |
12 |
|
|
13 |
|
# get our options |
14 |
|
getopts('hv', \%opts); |
18 |
|
|
19 |
|
# our option output |
20 |
|
if ($opts{h}){ |
21 |
< |
print "affineScale: performs an affine transform on an OOPSE .in or .eor\n"; |
22 |
< |
print "\tand writes to a new file named [file name].scale\n\n"; |
23 |
< |
print "usage: affineScale [-hv] [file name] [new volume (Ang^3)]\n\n"; |
24 |
< |
print " -h : show this message\n"; |
25 |
< |
die " -v : more verbose output\n"; |
21 |
> |
print "affineScale: performs an affine transform on an OOPSE .in or .eor\n"; |
22 |
> |
print "\tand writes to a new file named [file name].scale\n\n"; |
23 |
> |
print "usage: affineScale [-hv] [file name] [new volume (Ang^3)]\n\n"; |
24 |
> |
print " -h : show this message\n"; |
25 |
> |
die " -v : more verbose output\n"; |
26 |
|
} |
27 |
|
|
28 |
|
# set some variables to be used in the code |
32 |
|
# some crazy input checking |
33 |
|
if ($newVolume =~ /^[0-9]/){ |
34 |
|
} else { |
35 |
< |
die "\t[new volume] value ($newVolume) is not a valid number\n\tPlease choose a non-negative numeric value for [new volume]\n"; |
35 |
> |
die "\t[new volume] value ($newVolume) is not a valid number\n\tPlease choose a non-negative numeric value for [new volume]\n"; |
36 |
|
} |
37 |
|
|
38 |
|
# split up the name to obtain an output filename |
44 |
|
open (SCALEFILE, ">./$outName") || die "\tError: can't open $outName"; |
45 |
|
|
46 |
|
while (<STATFILE>){ |
47 |
< |
if ($line1 == 1){ |
48 |
< |
print SCALEFILE; |
49 |
< |
$line1 = 0; |
49 |
< |
$line2 = 1; |
47 |
> |
$startSnap = 0 if /\/Snapshot/; |
48 |
> |
$startFrame = 0 if /\/FrameData/; |
49 |
> |
$startStunts = 0 if /\/StuntDoubles/; |
50 |
|
|
51 |
< |
} elsif ($line2 == 1){ |
52 |
< |
@line = split; |
53 |
< |
chop $line[9]; |
54 |
< |
$oldVolume = $line[1]*$line[5]*$line[9]; |
55 |
< |
|
56 |
< |
$scale = ($newVolume/$oldVolume)**0.333333333333333; |
57 |
< |
# scale the hmat vectors (only orthorhombic) |
58 |
< |
$line[1] *= $scale; |
59 |
< |
$line[5] *= $scale; |
60 |
< |
$line[9] *= $scale; |
61 |
< |
$volume = $line[1]*$line[5]*$line[9]; |
62 |
< |
|
63 |
< |
print SCALEFILE "$line[0]"; |
64 |
< |
for ($i=1; $i<=$#line; $i++) { |
65 |
< |
print SCALEFILE "\t$line[$i]"; |
66 |
< |
if ($i == 9) {print SCALEFILE ";";} |
67 |
< |
} |
68 |
< |
print SCALEFILE "\n"; |
69 |
< |
$line2 = 0; |
70 |
< |
|
71 |
< |
} else { |
72 |
< |
@line = split /\s+/; |
73 |
< |
$line[1] *= $scale; |
74 |
< |
$line[2] *= $scale; |
75 |
< |
$line[3] *= $scale; |
76 |
< |
print SCALEFILE "$line[0]"; |
77 |
< |
for ($i=1; $i<=$#line; $i++) { |
78 |
< |
print SCALEFILE "\t$line[$i]"; |
79 |
< |
} |
80 |
< |
print SCALEFILE "\n"; |
51 |
> |
if ($startSnap == 1){ |
52 |
> |
if ($startFrame == 1){ |
53 |
> |
if (/Hmat/){ |
54 |
> |
@line = split; |
55 |
> |
|
56 |
> |
chop $line[2]; |
57 |
> |
chop $line[8]; |
58 |
> |
$oldVolume = $line[2]*$line[8]*$line[14]; |
59 |
> |
|
60 |
> |
$scale = ($newVolume/$oldVolume)**0.333333333333333; |
61 |
> |
# scale the hmat vectors (only orthorhombic) |
62 |
> |
$line[2] *= $scale; |
63 |
> |
$line[8] *= $scale; |
64 |
> |
$line[14] *= $scale; |
65 |
> |
$volume = $line[2]*$line[8]*$line[14]; |
66 |
> |
|
67 |
> |
print SCALEFILE "\t$line[0]"; |
68 |
> |
for ($i=1; $i<=$#line; $i++) { |
69 |
> |
print SCALEFILE " $line[$i]"; |
70 |
> |
if ($i == 2 || $i == 8) {print SCALEFILE ",";} |
71 |
> |
} |
72 |
> |
print SCALEFILE "\n"; |
73 |
> |
} else { |
74 |
> |
print SCALEFILE; |
75 |
> |
} |
76 |
|
} |
77 |
+ |
if ($startStunts == 1){ |
78 |
+ |
@line = split; |
79 |
+ |
$line[2] *= $scale; |
80 |
+ |
$line[3] *= $scale; |
81 |
+ |
$line[4] *= $scale; |
82 |
+ |
print SCALEFILE "$line[0]\t$line[1]\t"; |
83 |
+ |
for ($i=2; $i<=$#line; $i++) { |
84 |
+ |
print SCALEFILE "$line[$i] "; |
85 |
+ |
} |
86 |
+ |
print SCALEFILE "\n"; |
87 |
+ |
} |
88 |
+ |
if ($startFrame == 0 && $startStunts == 0) { |
89 |
+ |
print SCALEFILE; |
90 |
+ |
} |
91 |
+ |
} else { |
92 |
+ |
print SCALEFILE; |
93 |
+ |
} |
94 |
+ |
$startSnap = 1 if /Snapshot/; |
95 |
+ |
$startFrame = 1 if /FrameData/; |
96 |
+ |
$startStunts = 1 if /StuntDoubles/; |
97 |
+ |
# check again since "/value" contains "value" |
98 |
+ |
$startSnap = 0 if /\/Snapshot/; |
99 |
+ |
$startFrame = 0 if /\/FrameData/; |
100 |
+ |
$startStunts = 0 if /\/StuntDoubles/; |
101 |
|
} |
102 |
|
|
103 |
|
print "Affine transformed configuration written to $outName\n"; |
104 |
|
|
105 |
|
if (defined($opts{v})){ |
106 |
< |
print "New Volume : $volume\n"; |
107 |
< |
print "Old Volume : $oldVolume\n"; |
108 |
< |
print "Scale Factor : $scale\n"; |
106 |
> |
print "New Volume : $volume\n"; |
107 |
> |
print "Old Volume : $oldVolume\n"; |
108 |
> |
print "Scale Factor : $scale\n"; |
109 |
|
} |
110 |
|
|