-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIQADI.awk
267 lines (240 loc) · 6.22 KB
/
IQADI.awk
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
#############################################################################
#
# IQADI
#
# Script for extracting delocaliztion indexes from AIMALL calculation
# Tutorial:
# 1) Fill in user edit section
# 2) Run "awk -f IQADI.awk" in the terminal
# 3) For text output run as "awk -f IQAExtractor.awk > file.txt"
# 4) Carefully check results, especially your selection of fragments
#
# Author: Ivo Durnik
# Contact: [email protected]
#
#############################################################################
BEGIN {
#############################################################################
# START OF USER EDIT SECTION
# Specify Sum file
sumFile = "examples/at.sum"
# Specify selection for desired fragments
# Syntax: "1,2,3" OR "1-3" OR "1-2,3"
fragmentA = "1-15"
fragmentB = "16-30"
# Produce xyz files to check fragment selection? (yes = 1 / no = 0)
#
# If control=1, script will write three structure files: AB.xyz, A.xyz and B.xyz
# Geometries are extracted from ABSumFile, complex is splitted according to user selection
control = 1;
# END OF USER EDIT SECTION
#############################################################################
#############################################################################
# PREPARE ANALYSIS
#############################################################################
# a.u. -> Angstrom
au = 0.529177249;
# a.u. -> kcal/mol
kcal = 627.509608;
# Helper variables
currentFile = "";
i = 0;
myNR = 1;
N = 1;
NA = 1;
NB = 1;
pos1 = 0;
pos2 = 0;
bool1 = 0;
bool2 = 0;
bool3 = 0;
bool4 = 0;
# Tell awk which files to process (order matters)
ARGV[1] = sumFile;
ARGC=2;
# Split atom numbers defining molecular fragments into arrays
NsetA = split(fragmentA,setA,",");
for(i in setA) {
NSubSet = split(setA[i],subSet,"-");
if(NSubSet > 1) {
for(j=subSet[1]; j<=subSet[2]; j++) {
if( j == subSet[1] ){
delete setA[i];
NsetA++
}
setA[NsetA] = j;
NsetA++;
}
}
}
NsetB = split(fragmentB,setB,",");
for(i in setB) {
NSubSet = split(setB[i],subSet,"-");
if(NSubSet > 1) {
for(j=subSet[1]; j<=subSet[2]; j++) {
if( j == subSet[1] ){
delete setB[i];
NsetB++
}
setB[NsetB] = j;
NsetB++;
}
}
}
# Check if fragments overlap
for(i in setA) {
for(j in setB) {
if( setA[i]==setB[j] ) {
printf("Fragment selection overlaps!\n");
printf("A: %s\n", fragmentA);
printf("B: %s\n", fragmentB)
exitSwitch = 1;
exit 1;
}
}
}
}
#############################################################################
# COLLECT DATA
#############################################################################
{
#
# Check which file is being processed
#
if(currentFile != FILENAME) {
fileN++;
myNR = 1
currentFile = FILENAME;
}
#
# Process Sum File
#
if(fileN == 1) {
# Get Atom Info
if($0 == "Nuclear Charges and Cartesian Coordinates:"){
bool1 = 1;
pos1 = myNR;
}
if(bool1 == 1 && NF != 0 && myNR > pos1+3){
AB[N] = $1;
ABx[N] = $3;
ABy[N] = $4;
ABz[N] = $5;
for(atom in setA) {
if(setA[atom] == N) {
A[NA] = $1;
Ax[NA] = $3;
Ay[NA] = $4;
Az[NA] = $5;
NA++;
break;
}
}
for(atom in setB) {
if(setB[atom] == N) {
B[NB] = $1;
Bx[NB] = $3;
By[NB] = $4;
Bz[NB] = $5;
NB++;
break;
}
}
N++;
}
if(NF == 0) {
bool1=0;
}
# Get Delocalization Indexes
if($0 == "Diatomic Electron Pair Contributions and Delocalization Data:"){
bool2 = 1;
pos1 = myNR;
# Initialize variables for first cycle
ABDI = 0.0;
}
if( bool2 == 1 && NF != 0 && myNR > pos1+14){
posA = 0;
atomA = -1;
for( atom in A) {
if(A[atom] == $1){
posA = 1;
atomA = atom;
} else if(A[atom] == $2) {
posA = 2;
atomA = atom;
}
}
posB = 0;
atomB = -1;
for(atom in B){
if(B[atom] == $1){
posB = 1;
atomB = atom;
} else if(B[atom] == $2){
posB = 2;
atomB = atom;
}
}
if( (posA==1 && posB==2) || (posB==1 && posA==2) ) {
ABDI += $4;
}
}
if( NF == 0 ) {
bool2 = 0;
}
} else {
print "Too many files on the input!"
exitSwitch = 1;
exit 1;
}
myNR++;
}
#############################################################################
# CALCULATE AND PRINT RESULTS
#############################################################################
END {
# Check for error during data colection
if( exitSwitch == 1) {
exit 1;
}
# A(Complex)B(Complex)
totABDI = 0.0;
# Print final output, calculate sums
# AB Interaction
printf("\n");
printf("DI between fragment A and fragment B:\n")
printf("%20.10f\n", ABDI);
# Print xyz files for control of correct selection of FragmentA and FragmentB
if( control == 1 ) {
printf("\n");
printf("Control output is ON\n");
printf("Writing:\n")
# Complex AB
printf("== AB.xyz\n")
print N-1 > "AB.xyz";
print "" >> "AB.xyz";
for(i=1; i<N; i++){
element = AB[i];
sub(/[0-9]{1,}/, "", element);
printf("%s\t%f\t%f\t%f\n", element, ABx[i]*au, ABy[i]*au, ABz[i]*au) >> "AB.xyz";
}
# Fragment A
printf("== A.xyz\n")
print NA-1 > "A.xyz";
print "" >> "A.xyz";
for(i=1; i<NA; i++){
element = A[i];
sub(/[0-9]{1,}/, "", element);
printf("%s\t%f\t%f\t%f\n", element, Ax[i]*au, Ay[i]*au, Az[i]*au) >> "A.xyz";
}
# Fragment B
printf("== B.xyz\n")
print NB-1 > "B.xyz";
print "" >> "B.xyz";
for(i=1; i<NB; i++){
element = B[i];
sub(/[0-9]{1,}/, "", element);
printf("%s\t%f\t%f\t%f\n", element, Bx[i]*au, By[i]*au, Bz[i]*au) >> "B.xyz";
}
}
}