-
Notifications
You must be signed in to change notification settings - Fork 0
/
numDer.pl
142 lines (119 loc) · 3.53 KB
/
numDer.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
#!/usr/local/bin/perl
#Calculates the force on the first atom in the system by numerical differentiation
#for checking the units of gaussian and seeing where the numerical differentiation breaks down
use Cwd;
my $file_name = $ARGV[0];
my $cwd = getcwd();
my $seperator=0;
my $bohr=0.529;
my $dx=$ARGV[0];
my $status=system("g09 ref.com");
my $energy;
my $force;
my $forces;
my $refEnegry;
my $refForces;
my $energy;
my $factor=1;
my $delta=1;
my $coord;
my $factor=27.211;
$delta=0;
open(INPUT,"<$cwd/ref.log") or die "Cannot open $cwd/ref.log to read: $!\n";
while (my $line = <INPUT>) {
#print $line;
if($line =~ /E\(\w+\)\s+=\s+(\S+)/){
$refEnergy=$1;
#print "E0=$refEnergy\n";
}
if($line =~ /Forces/){
$delta=1;
}
if($delta && $line =~ /(\d+)( +)(\d+)( +)(-?\d+\.\d+([Ee][+-]?\d+)?)( +)(-?\d+\.\d+([Ee][+-]?\d+)?)( +)(-?\d+\.\d+([Ee][+-]?\d+)?)/){
$forces="$5$6"." "."$8$9"." "."$11$12";
$refForces=$forces;
#print "Gaussian force (Hartree/bohr): $refForces\n";
$delta=0;
}
}
close(INPUT);
$delta=1;
open(INPUT,"<$cwd/ref.com") or die "Cannot open $cwd/ref.com to read: $!\n";
open(OUTPUT,">$cwd/tempx.com") or die "Cannot open $cwd/temxp.com to read: $!\n";
while (my $line = <INPUT>) {
if($delta && $line =~/( +)(\w+)( +)(-?\d+\.\d+([Ee][+-]?\d+)?)( +)(-?\d+\.\d+([Ee][+-]?\d+)?)( +)(-?\d+\.\d+([Ee][+-]?\d+)?)/){
$coord="$4$5"+($dx*$bohr);
#print "$4$5 -> $coord\n";
print OUTPUT "$1$2$3"."$coord"."$6$7$8$9$10$11\n";
$delta=0;
}else{
print OUTPUT "$line";
}
}
close(INPUT);
close(OUTPUT);
$status=system("g09 tempx.com");
open(INPUT,"<$cwd/tempx.log") or die "Cannot open $cwd/ref.log to read: $!\n";
while (my $line = <INPUT>) {
if($line =~ /E\(\w+\)\s+=\s+(\S+)/){
$energy=$1;
#print "Ex=$energy\n";
}
$force=-($energy-$refEnergy)/$dx;#Fx
}
close(INPUT);
$forces=$force;
$delta=1;
open(INPUT,"<$cwd/ref.com") or die "Cannot open $cwd/ref.com to read: $!\n";
open(OUTPUT,">$cwd/tempy.com") or die "Cannot open $cwd/temp.com to read: $!\n";
while (my $line = <INPUT>) {
if($delta && $line =~/( +)(\w+)( +)(-?\d+\.\d+([Ee][+-]?\d+)?)( +)(-?\d+\.\d+([Ee][+-]?\d+)?)( +)(-?\d+\.\d+([Ee][+-]?\d+)?)/){
$coord="$7$8"+($dx*$bohr);
#print "$7$8 -> $coord\n";
print OUTPUT "$1$2$3$4$5$6"."$coord"."$9$10$11\n";
$delta=0;
}else{
print OUTPUT "$line";
}
}
close(INPUT);
close(OUTPUT);
$status=system("g09 tempy.com");
open(INPUT,"<$cwd/tempy.log") or die "Cannot open $cwd/ref.log to read: $!\n";
while (my $line = <INPUT>) {
if($line =~ /E\(\w+\)\s+=\s+(\S+)/){
$energy=$1;
#print "Ey=$energy\n";
}
$force=-($energy-$refEnergy)/$dx;#Fy
}
close(INPUT);
$forces="$forces $force";
$delta=1;
open(INPUT,"<$cwd/ref.com") or die "Cannot open $cwd/ref.com to read: $!\n";
open(OUTPUT,">$cwd/tempz.com") or die "Cannot open $cwd/temp.com to read: $!\n";
while (my $line = <INPUT>) {
if($delta && $line =~/( +)(\w+)( +)(-?\d+\.\d+([Ee][+-]?\d+)?)( +)(-?\d+\.\d+([Ee][+-]?\d+)?)( +)(-?\d+\.\d+([Ee][+-]?\d+)?)/){
$coord="$10$11"+($dx*$bohr);
#print "$10$11 -> $coord\n";
print OUTPUT "$1$2$3$4$5$6$7$8$9"."$coord\n";
$delta=0;
}else{
print OUTPUT "$line";
}
}
close(INPUT);
close(OUTPUT);
$status=system("g09 tempz.com");
open(INPUT,"<$cwd/tempz.log") or die "Cannot open $cwd/ref.log to read: $!\n";
while (my $line = <INPUT>) {
if($line =~ /E\(\w+\)\s+=\s+(\S+)/){
$energy=$1;
#print "Ez=$energy\n";
}
$force=-($energy-$refEnergy)/$dx;#Fz
}
close(INPUT);
$forces="$forces $force";
print "Gaussian force (Hartree/bohr): $refForces\n";
print "Numerical Force (Hartree/bohr): $forces\n"