mirror of https://github.com/QMCPACK/qmcpack.git
Multiple perl scripts including setup-qmc.pl for automating common tasks when using pwscf as a starting point. Also performance improvements for energy.pl
git-svn-id: https://subversion.assembla.com/svn/qmcdev/trunk@5374 e5b18d87-469d-4833-9cc0-8cdfa06e9491
This commit is contained in:
parent
b48c6c2819
commit
89188b7850
|
@ -1,15 +1,16 @@
|
|||
#!/usr/bin/perl -w
|
||||
#!/usr/bin/env perl
|
||||
use POSIX qw/floor/;
|
||||
use strict;
|
||||
use FileHandle;
|
||||
use Getopt::Long;
|
||||
|
||||
# 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 %config = do "/remote/lshulen/sharedmaintenance/qmcpack/utils/setup-qmc-conf.pl";
|
||||
|
||||
my $gnuplot = "/usr/bin/gnuplot";
|
||||
my $energytool = "/bin/energy.pl";
|
||||
my $gnuplot = $config{gnuplot};
|
||||
my $energytool = $config{energytool};
|
||||
|
||||
my $epsfile;
|
||||
GetOptions('eps=s' => \$epsfile);
|
||||
|
||||
my $template = shift || die "Must give a template file name as the first argument here\n";
|
||||
my $start = shift;
|
||||
|
@ -20,6 +21,7 @@ if (!(defined $plotstart)) {
|
|||
}
|
||||
|
||||
|
||||
|
||||
$template =~ /(.*\.s)(\d\d\d)(\.scalar\.dat)/;
|
||||
my $prefix = $1;
|
||||
my $tnum = $2;
|
||||
|
@ -49,22 +51,28 @@ foreach my $file (sort bySequence @rawfiles) {
|
|||
my $str = `$energytool $file $start | head -1`;
|
||||
my @data = split(/\s+/,$str);
|
||||
my $energy = "$data[2] $data[4]";
|
||||
print "$sequence $energy\n";
|
||||
push @energies, $energy;
|
||||
$str = `$energytool $file $start | tail -1`;
|
||||
@data = split(/\s+/,$str);
|
||||
my $correnergy = "$data[3] $data[5]";
|
||||
push @correnergies, $correnergy;
|
||||
# $str = `$energytool $file $start | tail -1`;
|
||||
# @data = split(/\s+/,$str);
|
||||
# my $correnergy = "$data[3] $data[5]";
|
||||
# push @correnergies, $correnergy;
|
||||
}
|
||||
|
||||
my $plotstring = "set title \"Sequence vs Energy for VMC optimization\" \n";
|
||||
|
||||
if ($epsfile) {
|
||||
$plotstring .= "set term post color enhanced 20\n set output \"$epsfile\"\n";
|
||||
}
|
||||
$plotstring .= "set xlabel \"sequence\"; set ylabel \"energy (Ha)\"\n";
|
||||
my $st = $plotstart-1.2;
|
||||
my $ed = $#sequences+0.2;
|
||||
my $xtics = "set xtics (";
|
||||
$plotstring .= "plot [$st:$ed] \"-\" u 1:2:3 notitle w e \n";
|
||||
for (my $i = 0; $i <= $#sequences; $i++) {
|
||||
$plotstring .= "$i $correnergies[$i]\n";
|
||||
|
||||
# $plotstring .= "$i $correnergies[$i]\n";
|
||||
$plotstring .= "$i $energies[$i]\n";
|
||||
|
||||
$xtics .= "\"$sequences[$i]\" $i";
|
||||
if ($i < $#sequences) {
|
||||
$xtics .= ", " ;
|
||||
|
@ -72,13 +80,17 @@ for (my $i = 0; $i <= $#sequences; $i++) {
|
|||
}
|
||||
$xtics .= ")\n";
|
||||
$plotstring .= "end \n";
|
||||
$plotstring .= "pause -1\n";
|
||||
unless ($epsfile) {
|
||||
$plotstring .= "pause -1\n";
|
||||
}
|
||||
$plotstring = "$xtics $plotstring";
|
||||
|
||||
open(GPL, "|$gnuplot");
|
||||
GPL->autoflush(1);
|
||||
print GPL $plotstring;
|
||||
my $redundantString = <>; # Hack to leave graph up until user hits a key
|
||||
unless($epsfile) {
|
||||
my $redundantString = <>; # Hack to leave graph up until user hits a key
|
||||
}
|
||||
close(GPL);
|
||||
|
||||
|
||||
|
@ -113,9 +125,8 @@ sub getColumn {
|
|||
}
|
||||
|
||||
|
||||
#***************************************************************************
|
||||
#**************************************************************************
|
||||
# $RCSfile$ $Author: lshulenburger $
|
||||
# $Revision: 5115 $ $Date: 2011-2-7 8:15:23 -0700 (Mon, 7 Feb 2011) $
|
||||
# $Id: OptProgress.pl 5115 2011-2-7 8:15:23 lshulenburger $
|
||||
# $Revision: 5115 $ $Date: 2011-9-15 10:19:08 -0700 (Thu, 15 Sep 2011) $
|
||||
# $Id: OptProgress.pl 5115 2011-9-15 10:19:08 lshulenburger $
|
||||
#*************************************************************************/
|
||||
|
||||
|
|
|
@ -1,15 +1,14 @@
|
|||
#!/usr/bin/perl -w
|
||||
#!/usr/bin/env perl
|
||||
use POSIX qw/floor/;
|
||||
use strict;
|
||||
use FileHandle;
|
||||
use Getopt::Long;
|
||||
|
||||
# this is a drop in replacement for PlotDMC.py which can be useful when python
|
||||
# libraries are not available on a system. Simply give the script the name
|
||||
# of a .dmc.dat file to analyze and the step at which to start analysis and
|
||||
# it will plot the local energy, population and histograms of the same.
|
||||
# The location of gnuplot on the next line need to be updated
|
||||
|
||||
my $gnuplot = "/usr/bin/gnuplot";
|
||||
my %config = do "/remote/lshulen/sharedmaintenance/qmcpack/utils/setup-qmc-conf.pl";
|
||||
my $gnuplot = $config{gnuplot};
|
||||
|
||||
my $epsfile;
|
||||
GetOptions('eps=s' => \$epsfile);
|
||||
|
||||
my $file = shift;
|
||||
my $start = shift;
|
||||
|
@ -38,14 +37,25 @@ my $popmax;
|
|||
($popmin, $popmax) = getMinMax(\@filedata, 5, $start, $end);
|
||||
my $popTicString = getTicString($popmin,$popmax);
|
||||
|
||||
my $plotstring = "set title \"$file\"\n set multiplot\n";
|
||||
$plotstring .= "set ylabel \"Energy (Hartrees)\"\n ";
|
||||
my $plotstring = "set title \"$file\"\n";
|
||||
if ($epsfile) {
|
||||
$plotstring .= "set term post color enhanced 20\n set output \"$epsfile\"\n";
|
||||
}
|
||||
$plotstring .= "set multiplot\n set ylabel \"Energy (Hartrees)\"\n ";
|
||||
$plotstring .= "set origin 0,0.5\n set size 0.82,0.5\n";
|
||||
$plotstring .= "set format x \"\"\n set ytics $enTicString \n unset y2tics\n set lmargin 12\n";
|
||||
$plotstring .= "plot [$start:][$min:$max] \"$file\" u 1:2 w l notitle, \"\" u 1:6 lt 3 notitle w l \n";
|
||||
if ($end < 0) {
|
||||
$plotstring .= "plot [$start:][$min:$max] \"$file\" u 1:2 w l notitle, \"\" u 1:5 lt 3 notitle w l \n";
|
||||
} else {
|
||||
$plotstring .= "plot [$start:$end][$min:$max] \"$file\" u 1:2 w l notitle, \"\" u 1:5 lt 3 notitle w l \n";
|
||||
}
|
||||
$plotstring .= "set format x \n unset title\n set xlabel \"DMC step\"\n set ylabel \"Population (Walkers)\"\n";
|
||||
$plotstring .= "set xtics\n set ytics $popTicString\n set bmargin 4\n";
|
||||
$plotstring .= "set origin 0,0\n plot [$start:][$popmin:$popmax] \"\" u 1:5 w l notitle\n";
|
||||
if ($end < 0) {
|
||||
$plotstring .= "set origin 0,0\n plot [$start:][$popmin:$popmax] \"\" u 1:5 w l notitle\n";
|
||||
} else {
|
||||
$plotstring .= "set origin 0,0\n plot [$start:$end][$popmin:$popmax] \"\" u 1:5 w l notitle\n";
|
||||
}
|
||||
$plotstring .= "set format x \"\"\n";
|
||||
$plotstring .= "set origin 0.8,0.5\n set size 0.2, 0.5\n set title \"histogram\"\n";
|
||||
$plotstring .= "set lmargin 0\n unset xlabel\n unset ylabel \n set bmargin 1\n";
|
||||
|
@ -54,13 +64,17 @@ $plotstring .= getGPLHistString(\@filedata, 2, $start, $end);
|
|||
$plotstring .= "set origin 0.8,0.0\n set size 0.2, 0.5\n unset title \n set y2tics $popTicString \n";
|
||||
$plotstring .= "set format y2 \"\"\n set xlabel \"counts\"\n set bmargin 4\n";
|
||||
$plotstring .= getGPLHistString(\@filedata, 5, $start, $end);
|
||||
$plotstring .= "unset multiplot\n pause -1\n";
|
||||
|
||||
$plotstring .= "unset multiplot\n";
|
||||
unless($epsfile) {
|
||||
$plotstring .= "pause -1\n";
|
||||
}
|
||||
|
||||
open(GPL, "|$gnuplot");
|
||||
GPL->autoflush(1);
|
||||
print GPL $plotstring;
|
||||
my $blah = <>; # Hack to leave graph up until user hits a key
|
||||
unless($epsfile) {
|
||||
my $blah = <>; # Hack to leave graph up until user hits a key
|
||||
}
|
||||
close(GPL);
|
||||
|
||||
|
||||
|
@ -188,7 +202,8 @@ sub getColumn {
|
|||
return @outmat;
|
||||
}
|
||||
|
||||
#**************************************************************************
|
||||
|
||||
#***************************************************************************
|
||||
# $RCSfile$ $Author: lshulenburger $
|
||||
# $Revision: 5115 $ $Date: 2011-2-7 8:15:23 -0700 (Mon, 7 Feb 2011) $
|
||||
# $Id: PlotDMC.pl 5115 2011-2-7 8:15:23 lshulenburger $
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/perl -w
|
||||
#!/usr/bin/env perl
|
||||
use POSIX qw/floor/;
|
||||
use strict;
|
||||
use FileHandle;
|
||||
|
@ -8,7 +8,8 @@ use FileHandle;
|
|||
# to the script and it will plot all matching files it can find. Before using the
|
||||
# script, the location of gnuplot may need to be set on the previous line
|
||||
|
||||
my $gnuplot = "/usr/bin/gnuplot";
|
||||
my %config = do "/remote/lshulen/sharedmaintenance/qmcpack/utils/setup-qmc-conf.pl";
|
||||
my $gnuplot = $config{gnuplot};
|
||||
|
||||
my $template = shift || die "Must give a template file name as the first argument here\n";
|
||||
my $start = shift;
|
||||
|
@ -96,7 +97,8 @@ sub getColumn {
|
|||
|
||||
#**************************************************************************
|
||||
# $RCSfile$ $Author: lshulenburger $
|
||||
# $Revision: 5115 $ $Date: 2011-2-7 8:15:23 -0700 (Mon, 7 Feb 2011) $
|
||||
# $Id: PlotTwists.pl 5115 2011-2-7 8:15:23 lshulenburger $
|
||||
# $Revision: 5115 $ $Date: 2011-9-15 10:19:08 -0700 (Thu, 15 Sep 2011) $
|
||||
# $Id: PlotTwists.pl 5115 2011-9-15 10:19:08 lshulenburger $
|
||||
#*************************************************************************/
|
||||
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/perl -w
|
||||
#!/usr/bin/env perl
|
||||
use POSIX qw/floor/;
|
||||
use strict;
|
||||
|
||||
|
@ -25,10 +25,10 @@ if (!(defined $end)) {
|
|||
#print "template = $template\n";
|
||||
#print "numfiles = $numfiles\n";
|
||||
|
||||
$template =~ /(.*-tw)(\d+)\..*(\.s...\.scalar\.dat)/;
|
||||
$template =~ /(.*-tw)(\d+)(\..*)?(\.s...\.scalar\.dat)/;
|
||||
my $prefix = $1;
|
||||
my $tnum = $2;
|
||||
my $suffix = $3;
|
||||
my $suffix = $4;
|
||||
|
||||
#print "prefix = $prefix, tnum = $tnum, suffix = $suffix\n";
|
||||
|
||||
|
@ -40,19 +40,27 @@ closedir DIR;
|
|||
my @twistens;
|
||||
my @twisterrs;
|
||||
my @rawfiles;
|
||||
for (my $i = $tnum; $i < $tnum+$numfiles; $i++) {
|
||||
my @match = grep /$prefix$i\..+$suffix/, @files;
|
||||
if ($numfiles > 1) {
|
||||
|
||||
my $curfile;
|
||||
if ($match[0]) {
|
||||
$curfile = shift @match;
|
||||
push @rawfiles, $curfile;
|
||||
push @twistens, 0.0;
|
||||
push @twisterrs, 0.0;
|
||||
} else {
|
||||
die "Cannot find enough raw data files to satsify this request\n";
|
||||
}
|
||||
for (my $i = $tnum; $i < $tnum+$numfiles; $i++) {
|
||||
my @match = grep /$prefix$i(\..*)?$suffix/, @files;
|
||||
|
||||
my $curfile;
|
||||
if ($match[0]) {
|
||||
$curfile = shift @match;
|
||||
push @rawfiles, $curfile;
|
||||
push @twistens, 0.0;
|
||||
push @twisterrs, 0.0;
|
||||
} else {
|
||||
die "Cannot find enough raw data files to satsify this request\n";
|
||||
}
|
||||
# print "Looking for a file like $prefix" . $i . ".????$suffix: found $curfile\n";
|
||||
}
|
||||
} else {
|
||||
$tnum = 0;
|
||||
push @rawfiles, $template;
|
||||
push @twistens, 0.0;
|
||||
push @twisterrs, 0.0;
|
||||
}
|
||||
|
||||
open (FILE, "$template") || die "Cannot open file $template\n";
|
||||
|
@ -292,7 +300,7 @@ sub formatString {
|
|||
|
||||
#**************************************************************************
|
||||
# $RCSfile$ $Author: lshulenburger $
|
||||
# $Revision: 5115 $ $Date: 2011-2-7 8:15:23 -0700 (Mon, 7 Feb 2011) $
|
||||
# $Id: TwistAvg.pl 5115 2011-2-7 8:15:23 lshulenburger $
|
||||
# $Revision: 5115 $ $Date: 2011-9-15 10:19:08 -0700 (Thu, 15 Sep 2011) $
|
||||
# $Id: TwistAvg.pl 5115 2011-9-15 10:19:08 lshulenburger $
|
||||
#*************************************************************************/
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/perl -w
|
||||
#!/usr/bin/env perl
|
||||
use POSIX qw/floor/;
|
||||
use strict;
|
||||
|
||||
|
@ -43,22 +43,20 @@ my $blockweight=0;
|
|||
for (my $i = 2; $i <= $#{$filedata[0]}; $i++) {
|
||||
my $colname = $filedata[0][$i];
|
||||
my @arr = getColumn(\@filedata,$i,$start,$end);
|
||||
for (my $j = 0; $j <= $#arr; $j++) {
|
||||
if ($colname eq 'AcceptRatio' || $colname eq 'BlockCPU' || $colname eq 'BlockWeight') {
|
||||
$arr[$j] *= 1;
|
||||
} else {
|
||||
$arr[$j] /= $factor;
|
||||
}
|
||||
}
|
||||
|
||||
my $avg;
|
||||
my $error;
|
||||
($avg, $error) = stats(\@arr);
|
||||
if ($colname eq 'AcceptRatio' || $colname eq 'BlockCPU' || $colname eq 'BlockWeight' || $colname eq 'Efficiency') {
|
||||
($avg, $error) = simplestats(\@arr);
|
||||
} else {
|
||||
($avg, $error) = stats(\@arr, $factor);
|
||||
}
|
||||
if ($colname eq 'LocalEnergy_sq') {
|
||||
$colname = 'Variance';
|
||||
my @arr2 = getColumn(\@filedata, $i-1, $start, $end);
|
||||
my $avg2;
|
||||
my $err2;
|
||||
($avg2, $err2) = stats(\@arr2);
|
||||
($avg2, $err2) = stats(\@arr2, $factor);
|
||||
$avg = $avg - $avg2*$avg2/$factor;
|
||||
}
|
||||
if ($colname eq 'LocalEnergy') {
|
||||
|
@ -101,10 +99,24 @@ if (abs($correction) > 1.0e-12) {
|
|||
printf("%-21s = $formatStr +/- $formatStr\n", "Corrected Energy", $Locen+$correction, $enerr);
|
||||
}
|
||||
|
||||
sub simplestats {
|
||||
my $arr = shift;
|
||||
my $avg;
|
||||
my $sqavg;
|
||||
($avg, $sqavg) = getAvgAndSqAv($arr);
|
||||
my $var = $sqavg-$avg*$avg;
|
||||
return ($avg, sqrt($var/$#{$arr}));
|
||||
}
|
||||
|
||||
|
||||
sub stats {
|
||||
my $arr = shift;
|
||||
my $avg = getAvg($arr);
|
||||
my $sqav = getSqAvg($arr);
|
||||
my $locfac = shift;
|
||||
my $avg;
|
||||
my $sqav;
|
||||
($avg, $sqav) = getAvgAndSqAv($arr);
|
||||
$avg /= $locfac;
|
||||
$sqav /= $locfac*$locfac;
|
||||
my $var = $sqav-$avg*$avg;
|
||||
my $c=0;
|
||||
my $N = $#{$arr}+1;
|
||||
|
@ -113,7 +125,7 @@ sub stats {
|
|||
while($tempC > 0 and $c < ($N-1)) {
|
||||
$kappa+=2*$tempC;
|
||||
$c += 1;
|
||||
$tempC=corr($c, $arr, $avg, $var);
|
||||
$tempC=corr($c, $arr, $avg*$locfac, $var*$locfac*$locfac);
|
||||
}
|
||||
if ($kappa == 0.0) {
|
||||
$kappa = 1.0;
|
||||
|
@ -168,21 +180,19 @@ sub getSum {
|
|||
return $outval;
|
||||
}
|
||||
|
||||
sub getAvg {
|
||||
|
||||
sub getAvgAndSqAv {
|
||||
my $arr = shift;
|
||||
my $size = $#{$arr};
|
||||
return getSum($arr)/($size+1);
|
||||
my $sum;
|
||||
my $sumsq;
|
||||
for (my $i = 0; $i <= $#{$arr}; $i++) {
|
||||
$sum += ${$arr}[$i];
|
||||
$sumsq += ${$arr}[$i]*${$arr}[$i];
|
||||
}
|
||||
return ($sum/($#{$arr}+1), $sumsq/($#{$arr}+1));
|
||||
}
|
||||
|
||||
sub getSqAvg {
|
||||
my $arr = shift;
|
||||
my @newarr;
|
||||
for (my $i = 0; $i <= $#{$arr}; $i++) {
|
||||
my $val = ${$arr}[$i];
|
||||
push @newarr, $val*$val;
|
||||
}
|
||||
return getAvg(\@newarr);
|
||||
}
|
||||
|
||||
|
||||
sub corr {
|
||||
my $i = shift;
|
||||
|
@ -219,7 +229,6 @@ sub formatString {
|
|||
|
||||
#**************************************************************************
|
||||
# $RCSfile$ $Author: lshulenburger $
|
||||
# $Revision: 5115 $ $Date: 2011-2-7 8:15:23 -0700 (Mon, 7 Feb 2011) $
|
||||
# $Id: energy.pl 5115 2011-2-7 8:15:23 lshulenburger $
|
||||
# $Revision: 5115 $ $Date: 2011-9-15 10:19:08 -0700 (Thu, 15 Sep 2011) $
|
||||
# $Id: energy.pl 5115 2011-9-15 10:19:08 lshulenburger $
|
||||
#*************************************************************************/
|
||||
|
||||
|
|
Loading…
Reference in New Issue