-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcompile-conformer-data.py
More file actions
335 lines (293 loc) · 10.6 KB
/
Copy pathcompile-conformer-data.py
File metadata and controls
335 lines (293 loc) · 10.6 KB
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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
#!/usr/bin/env python
from __future__ import print_function
import sys, os
import glob
import time
# uses open babel 3.0
from openbabel import pybel
mmff = pybel._forcefields["mmff94"]
mmffS = pybel._forcefields["mmff94s"] # unused
uff = pybel._forcefields["uff"]
gaff = pybel._forcefields["gaff"]
# data with per-atom SCF energies
import atomization
hartree_to_kcal = 627.509469
eV_to_kcal = 23.06035
kj_to_kcal = 1.0 / 4.184
def is_number(s):
try:
float(s)
return True
except ValueError:
return False
def key(dir, file):
subdir = dir
if '/' in dir:
# remove the "CHG" or "Neutral" top-level directory
# if it's part of the string
top, subdir = dir.split('/')
if '.' in file:
# remove the extension if it's still part of the filename
file = file.split('.')[0]
# returns something like astex_1gm8-rmsd112-opt
return "{}-{}".format(subdir, file)
# we need to read through all the energy files
ccsdt = {}
with open('energies/ccsdt.txt') as file:
for line in file:
# astex_1gm8 rmsd112-opt.out.bz2 FINAL SINGLE POINT ENERGY -1501.5
items = line.split()
if len(items) > 7:
continue
k = key(items[0], items[1])
ccsdt[k] = float(items[6]) # in Hartrees
mp2 = {}
with open('energies/mp2.txt') as file:
for line in file:
# astex_1gm8 rmsd112-opt.out.bz2 FINAL SINGLE POINT ENERGY -1501.5
items = line.split()
if len(items) > 7:
continue
k = key(items[0], items[1])
mp2[k] = float(items[6]) # in Hartrees
pbe = {}
with open('energies/pbe.txt') as file:
for line in file:
# astex_1gm8 rmsd112-opt.out.bz2 FINAL SINGLE POINT ENERGY -1501.5
items = line.split()
if len(items) > 7:
continue
k = key(items[0], items[1])
pbe[k] = float(items[6]) # in Hartrees
pbe_svp = {}
with open('energies/pbe-svp.txt') as file:
for line in file:
# astex_1gm8 rmsd112-opt.out.bz2 FINAL SINGLE POINT ENERGY -1501.5
items = line.split()
if len(items) > 7:
continue
k = key(items[0], items[1])
pbe_svp[k] = float(items[6]) # in Hartrees
wb97 = {}
with open('energies/wb97xd.txt') as file:
for line in file:
# astex_1gm8 rmsd112-opt.out.bz2 FINAL SINGLE POINT ENERGY -1501.5
items = line.split()
if len(items) != 7:
continue
k = key(items[0], items[1])
wb97[k] = float(items[6]) # in Hartrees
b3lyp_tz = {}
with open('energies/b3lyp-tz.txt') as file:
for line in file:
# astex_1gm8 rmsd112-opt.out.bz2 FINAL SINGLE POINT ENERGY -1501.5
items = line.split()
if len(items) > 7:
continue
k = key(items[0], items[1])
b3lyp_tz[k] = float(items[6]) # in Hartrees
b3lyp_svp = {}
with open('energies/b3lyp-svp.txt') as file:
for line in file:
# astex_1gm8 rmsd112-opt.out.bz2 FINAL SINGLE POINT ENERGY -1501.5
items = line.split()
if len(items) > 7:
continue
k = key(items[0], items[1])
b3lyp_svp[k] = float(items[6]) # in Hartrees
b973c = {}
with open('energies/b97-3c.txt') as file:
for line in file:
# astex_1gm8 rmsd112-opt.out.bz2 FINAL SINGLE POINT ENERGY -1501.5
items = line.split()
if len(items) > 7:
continue
k = key(items[0], items[1])
b973c[k] = float(items[6]) # in Hartrees
pbeh3c = {}
with open('energies/pbeh-3c.txt') as file:
for line in file:
# astex_1gm8 rmsd112-opt.out.bz2 FINAL SINGLE POINT ENERGY -1501.5
items = line.split()
if len(items) > 7:
continue
k = key(items[0], items[1])
pbeh3c[k] = float(items[6]) # in Hartrees
pm7 = {} # total energies to convert to atomization energy
with open('energies/pm7-total.txt') as file:
for line in file:
items = line.split()
if len(items) != 6:
continue
# CHG_jobs/astex_1gm8/rmsd1-mmff.pm7:
dir = items[0].split('/')[1]
file = items[0].split('/')[2]
k = key(dir,file)
pm7[k] = float(items[4]) # in eV
pm7hof = {} # heats of formation
with open('energies/pm7-hof.txt') as file:
for line in file:
items = line.split()
if len(items) != 11:
continue
# CHG_jobs/astex_1gm8/rmsd1-mmff.pm7:
dir = items[0].split('/')[1]
file = items[0].split('/')[2]
k = key(dir,file)
pm7hof[k] = float(items[6]) # in kcal/mol
gfn0 = {}
with open('energies/gfn0.txt') as file:
for line in file:
# parse it
items = line.split()
k = key(items[0], items[1])
gfn0[k] = float(items[5]) # in Hartrees
# older XTB fortunately outputs atomization energies in Hartree and kcal/mol
gfn = {}
with open('energies/gfn.txt') as file:
for line in file:
# parse it
items = line.split()
k = key(items[0], items[1])
gfn[k] = float(items[5]) # in kcal/mol
gfn2 = {}
with open('energies/gfn2.txt') as file:
for line in file:
# parse it
items = line.split()
k = key(items[0], items[1])
gfn2[k] = float(items[5]) # in kcal/mol
ani1 = {}
with open('energies/ani-1x.txt') as file:
for line in file:
items = line.split(',')
name = items[0].split('/')[-1]
dir = '/'.join(items[0].split('/')[0:2])
k = key(dir, name)
ani1[k] = float(items[1]) # in kcal/mol
ani1cc = {}
with open('energies/ani-1ccx.txt') as file:
for line in file:
items = line.split(',')
name = items[0].split('/')[-1]
dir = '/'.join(items[0].split('/')[0:2])
k = key(dir, name)
ani1cc[k] = float(items[1]) # in kcal/mol
ani2 = {}
with open('energies/ani-2x.txt') as file:
for line in file:
items = line.split(',')
name = items[0].split('/')[-1]
dir = '/'.join(items[0].split('/')[0:2])
k = key(dir, name)
ani2[k] = float(items[1]) # in kcal/mol
# open up some timing files:
mmffTime = open("timing/mmff-time.csv", 'w')
uffTime = open("timing/uff-time.csv", 'w')
gaffTime = open("timing/gaff-time.csv", 'w')
# okay, now we use pybel to open and parse the .mol files
print("name,geom,natoms,dlpno,mp2,wb97,b973c,pbe,pbeSVP,pbeh3c,b3lypTZ,b3lypSVP,gfn0,gfn1,gfn2,pm7E,pm7HOF,mmff,uff,gaff,ani1x,ani1cc,ani2")
for filename in glob.iglob("geometries/*_jobs/*/*opt.mol"):
name = filename.split('/')[-2]
geom = filename.split('/')[-1]
mol = next(pybel.readfile("mol", filename))
elements = [0] * 118
for atom in mol.atoms: # how many of each element are there?
elements[atom.atomicnum] = elements[atom.atomicnum] + 1
# okay, we can use elements[] to calculate atomization energies if needed
dlpnoE = mp2E = b3lypSVPE = b3lypTZE = float('nan')
wb97E = pbeE = gfnE = gfn2E = pm7E = pm7HOFE = float('nan')
pbeSVPE = pbeh3cE = b973cE = float('nan')
ani1E = ani1ccE = ani2E = float('nan')
k = key(name, geom)
# now each of the energies / dictionaries in turn
if k in ccsdt:
totalAtomE = 0.0
for e in range(len(elements)):
totalAtomE = totalAtomE + elements[e] * atomization.dlpnoE[e]
dlpnoE = (totalAtomE - float(ccsdt[k])) * hartree_to_kcal
if k in mp2:
totalAtomE = 0.0
for e in range(len(elements)):
totalAtomE = totalAtomE + elements[e] * atomization.mp2E[e]
mp2E = (totalAtomE - float(mp2[k])) * hartree_to_kcal
if k in pbe:
totalAtomE = 0.0
for e in range(len(elements)):
totalAtomE = totalAtomE + elements[e] * atomization.pbeE[e]
pbeE = (totalAtomE - float(pbe[k])) * hartree_to_kcal
if k in pbe_svp:
totalAtomE = 0.0
for e in range(len(elements)):
totalAtomE = totalAtomE + elements[e] * atomization.pbe_svpE[e]
pbeSVPE = (totalAtomE - float(pbe_svp[k])) * hartree_to_kcal
if k in pbeh3c:
totalAtomE = 0.0
for e in range(len(elements)):
totalAtomE = totalAtomE + elements[e] * atomization.pbeh3cE[e]
pbeh3cE = (totalAtomE - float(pbeh3c[k])) * hartree_to_kcal
if k in wb97:
totalAtomE = 0.0
for e in range(len(elements)):
totalAtomE = totalAtomE + elements[e] * atomization.wb97E[e]
wb97E = (totalAtomE - float(wb97[k])) * hartree_to_kcal
if k in b973c:
totalAtomE = 0.0
for e in range(len(elements)):
totalAtomE = totalAtomE + elements[e] * atomization.b973cE[e]
b973cE = (totalAtomE - float(b973c[k])) * hartree_to_kcal
if k in b3lyp_tz:
totalAtomE = 0.0
for e in range(len(elements)):
totalAtomE = totalAtomE + elements[e] * atomization.b3lypTZE[e]
b3lypTZE = (totalAtomE - float(b3lyp_tz[k])) * hartree_to_kcal
if k in b3lyp_svp:
totalAtomE = 0.0
for e in range(len(elements)):
totalAtomE = totalAtomE + elements[e] * atomization.b3lypE[e]
b3lypSVPE = (totalAtomE - float(b3lyp_svp[k])) * hartree_to_kcal
if k in gfn0:
totalAtomE = 0.0
for e in range(len(elements)):
totalAtomE = totalAtomE + elements[e] * atomization.gfn0E[e]
gfn0E = (totalAtomE - float(gfn0[k])) * hartree_to_kcal
if k in pm7:
totalAtomE = 0.0
for e in range(len(elements)):
totalAtomE = totalAtomE + elements[e] * atomization.pm7E[e]
pm7E = (totalAtomE - float(pm7[k])) * eV_to_kcal
# already in kcal/mol
if k in gfn:
gfnE = gfn[k]
if k in gfn2:
gfn2E = gfn2[k]
if k in ani1:
ani1E = ani1[k]
if k in ani1cc:
ani1ccE = ani1cc[k]
if k in ani2:
ani2E = ani2[k]
if k in pm7hof:
pm7HOFE = pm7hof[k]
# get the force field energies
t0 = time.perf_counter()
mmff.Setup(mol.OBMol)
mmffE = mmff.Energy() # in kcal/mol
t1 = time.perf_counter()
print(name, geom, t1-t0, sep=',', file=mmffTime)
t0 = time.perf_counter()
uff.Setup(mol.OBMol)
uffE = uff.Energy() * kj_to_kcal
t1 = time.perf_counter()
print(name, geom, t1-t0, sep=',', file=uffTime)
t0 = time.perf_counter()
gaff.Setup(mol.OBMol)
gaffE = gaff.Energy() * kj_to_kcal
t1 = time.perf_counter()
print(name, geom, t1-t0, sep=',', file=gaffTime)
# energies
print(name, geom, len(mol.atoms), dlpnoE, mp2E, wb97E, b973cE, pbeE, pbeSVPE, pbeh3cE, b3lypTZE, b3lypSVPE, gfn0E, gfnE, gfn2E, pm7E, pm7HOFE, mmffE, uffE, gaffE, ani1E,ani1ccE,ani2E, sep=',')
# print(items[0], items[1], ccE, items[2], items[3], pm7E, gfnE, gfn2E, items[4].strip(), sep=',')
mmffTime.close()
uffTime.close()
gaffTime.close()