source: util/src/BOSSMatcher.pl.in@ a3ffb44

Last change on this file since a3ffb44 was 74baec, checked in by Frederik Heber <heber@…>, 17 years ago

fft_3d_create_plan: small BUGFIX - local_data was free'd twice and work not at all

  • Property mode set to 100755
File size: 4.2 KB
Line 
1#!@PERL@ -w
2#
3# In the course of numerous fragment calculations with breaks and interrupts in between, there might
4# arise some hickhack and mess with the sequence of the calculations. BOSSMatcher compares the nuclear
5# coordinates given in the config files of each fragment with those written out in the forces file of
6# ESPACK and prints which fragments do not match with their config file coordinates.
7
8use strict;
9
10use Getopt::Long;
11use File::Copy;
12
13my ($Help, $Prefix, $Inputdir);
14
15GetOptions("help" => \$Help,
16 "prefix=s", => \$Prefix,
17 "inputdir=s" => \$Inputdir);
18
19if ($Help) { usage(); }
20
21sub usage {
22 print STDERR <<"EOF";
23Usage: $0 [OPTIONS]
24 compares the nuclear
25 coordinates given in the config files of each fragment with those written out in the forces file of
26 ESPACK and prints which fragments do not match with their config file coordinates.
27 --prefix <prefix> prefix in front of .forces.all and .energy.all
28 --inputdir <inputdir> read data from this directory
29 --help this help
30EOF
31 exit 1;
32}
33
34if ((!defined $Inputdir) || (!defined $Prefix)) {
35 print "Inputdir and/or Prefix not specified! See --help.\n";
36 exit 1;
37}
38
39# 1. find the digits of the fragment number
40print "Finding the correct number of digits.\n";
41my $digits="";
42my $digit=0;
43my $file;
44do {
45 $digits=$digits."0"; # add a zero
46 $digit++;
47 $file=$Inputdir."/BondFragment".$digits.".conf";
48 print "Looking for $file ... \n";
49} while ((! -e $file) && ($digit < 10));
50
51if (!($digit < 10)) {
52 print "In the directory specified no initial fragment config file was found, typo?\n";
53 exit 1;
54}
55
56# 2. loop over all fragments and parse config and forces file, comparing the coordinates
57
58my $number=0;
59my $failures=0;
60my $failflag=0;
61my @lines;
62my $i;
63my @configcoordinates;
64my @forcecoordinates;
65my @line;
66my $IsAngstroem=0;
67do {
68 @configcoordinates = ();
69 @forcecoordinates = ();
70 $failflag=0;
71 $file = sprintf("%s%0${digit}d%s", $Inputdir."/BondFragment",$number,".conf");
72 if (-e $file) {
73 print "Scanning $file ... ";
74 # 2a. parse the config file
75 open(CONFIG, $file);
76 @lines = <CONFIG>;
77 for ($i=0; $i < scalar(@lines); $i++) {
78 if (${lines[$i]} =~ /Ion_Type._/) {
79 @line = split(/[ \t]+/,${lines[$i]});
80 my @coord = (${line[1]}, ${line[2]}, ${line[3]});
81 push(@configcoordinates, \@coord);
82 }
83 if (${lines[$i]} =~ /IsAngstroem/) {
84 @line = split(/[ \t]+/,${lines[$i]});
85 if (${line[1]} == 0) {
86 $IsAngstroem = 1;
87 } else {
88 $IsAngstroem = 1.8897261;
89 }
90 #print "Found IsAngstroem ".${line[1]}.", setting to $IsAngstroem.\n";
91 }
92 }
93 close(CONFIG);
94 # 2b. parse the pcp.forces.file
95 $file = sprintf("%s%0${digit}d%s", $Inputdir."/BondFragment",$number,"/${Prefix}.forces.all");
96 if (-e $file) {
97 open(FORCES, $file);
98 @lines = <FORCES>; # read file into buffer
99 for ($i=1; $i < (scalar(@lines)-1); $i++) { # skip first and last line
100 @line = split(/[ \t]+/,${lines[$i]});
101 my @coord = (${line[2]}, ${line[3]}, ${line[4]});
102 push(@forcecoordinates, \@coord);
103 }
104 close(FORCES);
105 } else {
106 $failflag = 1;
107 }
108 # 2c. compare both coordinates and sum up the deviation
109 if (scalar(@configcoordinates) != scalar(@forcecoordinates) ) {
110 $failflag = 1;
111 print "mismatch in number of ions ".scalar(@configcoordinates)." vs. ".scalar(@forcecoordinates)." ... ";
112 } else {
113 #print "match in number of ions ".scalar(@configcoordinates)." vs. ".scalar(@forcecoordinates)." ... ";
114 }
115 my $forces;
116 my $configs;
117 my $error = 0;
118 do {
119 $forces = pop(@forcecoordinates);
120 $configs = pop(@configcoordinates);
121 my $currenterror = 0;
122 for ($i=0;$i<3;$i++) {
123 @$configs[$i] *= $IsAngstroem;
124 $currenterror += (@$configs[$i]-@$forces[$i])*(@$configs[$i]-@$forces[$i]);
125 }
126 $error += sqrt($currenterror);
127 #print "$currenterror ";
128 } while (scalar(@configcoordinates) > 0);
129 print "deviation: ";
130 if ($error > 1e-4) {
131 $failflag=1;
132 print "$error ";
133 } else {
134 printf "<1e-4 ";
135 }
136
137 # 2d. print final status
138 if ($failflag) {
139 $failures++;
140 print "failed.\n";
141 } else {
142 print "done.\n";
143 }
144 $number++;
145 } else {
146 print "Last config file nr. $number reached, done.\n";
147 }
148} while (-e $file);
149
150# 3. finish
151print "Done checking, I noticed $failures failure(s).\n";
152exit 0
Note: See TracBrowser for help on using the repository browser.