forked from QMCPACK/qmcpack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlotBsplConv.pl
executable file
·238 lines (203 loc) · 6.18 KB
/
PlotBsplConv.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
#!/usr/bin/env perl
use strict;
use POSIX qw/floor/;
use Getopt::Long;
use FileHandle;
# This tool uses energy.pl to plot the energy of a series of VMC optimizations.
# Simply give it the filename of one of the .scalar.dat files and it will plot
# the energy as a function of sequence. The locations of gnuplot and energy.pl
# may need to be configured on the next lines
my $exactke;
my $epsfile;
GetOptions('ke=f' => \$exactke,
'eps=s' => \$epsfile);
my %config = do "/gprojects/qmcpack/qmcpack/utils/setup-qmc-conf.pl";
my $gnuplot = $config{gnuplot};
my $energytool = $config{energytool};
my $template = shift || die "Must give a template file name as the first argument here\n";
my $start = 50;
$start = shift;
(defined $start) || ($start = 0);
my $plotstart = shift @ARGV;
if (!(defined $plotstart)) {
$plotstart = 1;
}
$template =~ /(.*f)(\d\.\d\d)(.*\.s\d\d\d\.scalar\.dat)/;
my $prefix = $1;
my $fact = $2;
my $suffix = $3;
#print "prefix = $prefix, factor = $fact, suffix = $suffix\n";
opendir DIR, ".";
my @files = grep { $_ ne '.' && $_ ne '..' } readdir DIR;
closedir DIR;
my @rawfiles;
foreach my $str (@files) {
if ($str =~ /(.*f)(\d\.\d\d)(.*\.s\d\d\d\.scalar\.dat)/) {
push @rawfiles, $str;
}
}
my @factors;
my @fulldata;
my $varmin = 10000000000;
my $varmax = -1;
my $kemin = 1000000000;
my $kemax = -100000000;
my $minen = 1000000000;
my $maxen = -1000000000;
foreach my $file (sort byFactor @rawfiles) {
$file =~ /(.*f)(\d\.\d\d)(.*\.s\d\d\d\.scalar\.dat)/;
my $factor = $2;
push @factors, $factor;
my $str = `$energytool $file $start`;
# print "String = $str\n";
my @data = split(/\n/, $str);
# print "data[0] = $data[0]\n";
my $en;
my $ke;
my $var;
foreach my $line (@data) {
if ($line =~ /LocalEnergy/) {
# print "LocEnLine = $line\n";
my @linedata = split(/\s+/,$line);
$en = "$linedata[2] $linedata[4]";
# print "en = $en\n";
if ($linedata[2] < $minen) {
$minen = $linedata[2];
}
if ($linedata[2] > $maxen) {
$maxen = $linedata[2];
}
} elsif ($line =~ /Variance/) {
my @linedata = split(/\s+/,$line);
# print "VarLine = $line\n";
$var = "$linedata[2] $linedata[4]";
if ($linedata[2] < $varmin) {
$varmin = $linedata[2];
}
if ($linedata[2] > $varmax) {
$varmax = $linedata[2];
}
} elsif ($line =~ /Kinetic/) {
my @linedata = split(/\s+/,$line);
$ke = "$linedata[2] $linedata[4]";
if ($linedata[2] < $kemin) {
$kemin = $linedata[2];
}
if ($linedata[2] > $kemax) {
$kemax = $linedata[2];
}
# print "KELine = $line\n";
}
}
$str = "$factor $en $var $ke";
# print "data = $str\n";
push(@fulldata, $str);
# my $str = `$energytool $file $start | head -1`;
# my @data = split(/\s+/,$str);
# my $energy = "$data[2] $data[4]";
# push @energies, $energy;
# $str = `$energytool $file $start | grep Kinetic`;
# @data = split(/\s+/, $str);
# my $kenergy = "$data[2] $data[4]";
# push @kenergies, $kenergy;
}
my $plotstring;
if ($epsfile) {
$plotstring .= "set term post color enhanced 16\n set output \"$epsfile\" \n";
}
$plotstring .= "set title \"B-spline factor vs energies for VMC\" \n";
$plotstring .= "set multiplot \n set origin 0,0.6\n set size 1,0.4\n";
$plotstring .= "set ylabel \"total energy (Ha)\"\n unset xtics\n";
$plotstring .= "set lmargin 15\n";
my $st = $factors[0]-0.05;
my $ed = $factors[$#factors]+0.05;
my $xtics = "set xtics (";
for (my $i = 0; $i <= $#factors; $i++) {
$xtics .= "\"$factors[$i]\" $factors[$i]";
if ($i < $#factors) {
$xtics .= ", " ;
}
}
$plotstring .= "$xtics )\n";
my $yincr = ($maxen-$minen)/4.0;
$plotstring .= "set ytics $yincr\n";
$plotstring .= "plot [$st:$ed] \"-\" u 1:2:3 notitle w e \n";
for (my $i = 0; $i <= $#factors; $i++) {
# $plotstring .= "$factors[$i] $energies[$i]\n";
$plotstring .= "$fulldata[$i]\n";
}
$plotstring .= "end \n";
# Do plot of variance
$plotstring .= "set origin 0,0.33\n set size 1,0.3\n";
$plotstring .= "unset title\n";
$plotstring .= "set ylabel \"LocEn Variance\"\n set logscale y\n";
$yincr = ($varmax-$varmin)/4.0;
$plotstring .= "set ytics (";
for (my $yticval = $varmin; $yticval <= $varmax; $yticval += $yincr) {
$plotstring .= "\"$yticval\" $yticval";
if ($yticval + $yincr <= $varmax) {
$plotstring .= ", ";
}
}
$plotstring .= ")\n";
$plotstring .= "plot [$st:$ed][0.95*$varmin:1.05*$varmax] \"-\" u 1:4:5 notitle w e \n";
for (my $i = 0; $i <= $#factors; $i++) {
# $plotstring .= "$factors[$i] $kenergies[$i]\n";
$plotstring .= "$fulldata[$i]\n";
}
$plotstring .= "end \n";
$plotstring .= "unset logscale y\n";
# Do plot of kinetic energy
$plotstring .= "set origin 0,0\n set size 1,0.35\n";
$plotstring .= "unset title\n";
$plotstring .= "set xlabel \"b-spline factor\"\n";
$plotstring .= "set ylabel \"kinetic energy (Ha)\"\n";
$yincr = ($kemax-$kemin)/4.0;
$plotstring .= "set ytics $yincr\n";
if ($exactke) {
$plotstring .= "f(x) = $exactke\n";
$plotstring .= "plot [$st:$ed] f(x) lw 3 lt 1 notitle, \"-\" u 1:6:7 notitle w e \n";
} else {
$plotstring .= "plot [$st:$ed] \"-\" u 1:6:7 notitle w e \n";
}
for (my $i = 0; $i <= $#factors; $i++) {
# $plotstring .= "$factors[$i] $kenergies[$i]\n";
$plotstring .= "$fulldata[$i]\n";
}
$plotstring .= "end \n";
$plotstring .= "unset multiplot\n";
unless($epsfile) {
$plotstring .= "pause -1\n";
}
open(GPL, "|$gnuplot");
GPL->autoflush(1);
print GPL $plotstring;
unless($epsfile) {
my $redundantString = <>; # Hack to leave graph up until user hits a key
}
close(GPL);
#############################################################################
sub byFactor {
my $left = $a;
my $right = $b;
$left =~ /(.*f)(\d\.\d\d)(.*\.s\d\d\d\.scalar\.dat)/;
my $leftseq = $2;
$right =~ /(.*f)(\d\.\d\d)(.*\.s\d\d\d\.scalar\.dat)/;
my $rightseq = $2;
$leftseq <=> $rightseq;
}
sub getColumn {
my $matrix = shift;
my $colnum = shift;
my $startnum = shift;
my $end = shift;
if ($end < 0) {
$end = $#{$matrix};
}
$startnum || ($startnum = 0);
my @outmat;
for (my $i = $startnum+1; $i <= $end; $i++) {
push @outmat, ${$matrix}[$i][$colnum];
}
return @outmat;
}