forked from jczapatat/p-containing_molecules
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_input.py
More file actions
496 lines (473 loc) · 16.7 KB
/
create_input.py
File metadata and controls
496 lines (473 loc) · 16.7 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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
# Dictionary saving the def2-SVPD basis set.
# The code for generating the input file is down below this dictionary.
# https://stackoverflow.com/questions/61465411/save-a-multiple-lines-in-a-dict-in-python-question
def2SVPD_basis = {
1 : r"""H 0
S 3 1.00
13.0107010 0.19682158D-01
1.9622572 0.13796524
0.44453796 0.47831935
S 1 1.00
0.12194962 1.0000000
P 1 1.00
0.8000000 1.0000000
P 1 1.00
0.11704099050 1.0000000
****""",
6 : r"""C 0
S 5 1.00
1238.4016938 0.54568832082D-02
186.29004992 0.40638409211D-01
42.251176346 0.18025593888
11.676557932 0.46315121755
3.5930506482 0.44087173314
S 1 1.00
0.40245147363 1.0000000
S 1 1.00
0.13090182668 1.0000000
S 1 1.00
0.67053540256D-01 1.0000000
P 3 1.00
9.4680970621 0.38387871728D-01
2.0103545142 0.21117025112
0.54771004707 0.51328172114
P 1 1.00
0.15268613795 1.0000000
D 1 1.00
0.8000000 1.0000000
D 1 1.00
0.11713185140 1.0000000
****""",
7 : r"""N 0
S 5 1.00
1712.8415853 -0.53934125305D-02
257.64812677 -0.40221581118D-01
58.458245853 -0.17931144990
16.198367905 -0.46376317823
5.0052600809 -0.44171422662
S 1 1.00
0.58731856571 1.0000000
S 1 1.00
0.18764592253 1.0000000
S 1 1.00
0.96171241529D-01 1.0000000
P 3 1.00
13.571470233 -0.40072398852D-01
2.9257372874 -0.21807045028
0.79927750754 -0.51294466049
P 1 1.00
0.21954348034 1.0000000
D 1 1.00
1.0000000 1.0000000
D 1 1.00
0.16697708112 1.0000000
****""",
8 : r"""O 0
S 5 1.00
2266.1767785 -0.53431809926D-02
340.87010191 -0.39890039230D-01
77.363135167 -0.17853911985
21.479644940 -0.46427684959
6.6589433124 -0.44309745172
S 1 1.00
0.80975975668 1.0000000
S 1 1.00
0.25530772234 1.0000000
S 1 1.00
0.76572453250D-01 1.0000000
P 3 1.00
17.721504317 0.43394573193D-01
3.8635505440 0.23094120765
1.0480920883 0.51375311064
P 1 1.00
0.27641544411 1.0000000
P 1 1.00
0.69002276350D-01 1.0000000
D 1 1.00
1.2000000 1.0000000
D 1 1.00
0.17992024323 1.0000000
****""",
9 : r"""F 0
S 5 1.00
2894.8325990 -0.53408255515D-02
435.41939120 -0.39904258866D-01
98.843328866 -0.17912768038
27.485198001 -0.46758090825
8.5405498171 -0.44653131020
S 1 1.00
1.0654578038 1.0000000
S 1 1.00
0.33247346748 1.0000000
S 1 1.00
0.98097752264D-01 1.0000000
P 3 1.00
22.696633924 -0.45212874436D-01
4.9872339257 -0.23754317067
1.3491613954 -0.51287353587
P 1 1.00
0.34829881977 1.0000000
P 1 1.00
0.83372148304D-01 1.0000000
D 1 1.00
1.4000000 1.0000000
D 1 1.00
0.22301361948 1.0000000
****""",
15 : r"""P 0
S 5 1.00
8002.4795106 0.57503489302D-02
1203.6813590 0.43007628959D-01
273.44227031 0.19363986252
76.655541517 0.49651693399
23.516927435 0.44983262479
S 3 1.00
39.791683439 0.95188129789D-01
4.2770343323 -0.57649840368
1.6940256888 -0.54239583865
S 1 1.00
0.27567674644 1.0000000
S 1 1.00
0.10495590099 1.0000000
S 1 1.00
0.64309734755D-01 1.0000000
P 5 1.00
219.50755823 0.92100565257D-02
51.274155030 0.65409765745D-01
15.921595892 0.24033730279
5.5069913481 0.46318321788
1.9537719426 0.37392563382
P 1 1.00
0.47803397932 1.0000000
P 1 1.00
0.13657952621 1.0000000
D 1 1.00
0.4500000 1.0000000
D 1 1.00
0.99587311089D-01 1.0000000
****""",
16 : r"""S 0
S 5 1.00
9184.9303010 -0.22294387756D-02
1381.5105503 -0.16683029937D-01
313.87147580 -0.75262436116D-01
88.053870623 -0.19376827038
27.039914905 -0.17718020803
S 3 1.00
45.648731303 -0.10736062573
4.9664522326 0.65066293018
2.0116242047 0.59712155354
S 1 1.00
0.35661077013 1.0000000
S 1 1.00
0.13507221477 1.0000000
S 1 1.00
0.44999823506D-01 1.0000000
P 5 1.00
261.98233439 -0.92729929822D-02
61.306894736 -0.66547669241D-01
19.103729887 -0.24828595903
6.6567720378 -0.48703847402
2.3959635161 -0.39337850312
P 1 1.00
0.61776161679 1.0000000
P 1 1.00
0.16993376871 1.0000000
P 1 1.00
0.41706793676D-01 1.0000000
D 1 1.00
0.5500000 1.0000000
D 1 1.00
0.10172853717 1.0000000
****""",
17 : r"""Cl 0
S 5 1.00
10449.8275660 0.19708362484D-02
1571.7365221 0.14754727977D-01
357.12065523 0.66679112875D-01
100.25185935 0.17228924084
30.812727554 0.15883786100
S 3 1.00
51.923789434 -0.10009298909
5.7045760975 0.60841752753
2.3508376809 0.54352153355
S 1 1.00
0.44605124672 1.0000000
S 1 1.00
0.16848856190 1.0000000
S 1 1.00
0.55344229413D-01 1.0000000
P 5 1.00
307.66790569 -0.87801484118D-02
72.102015515 -0.63563355471D-01
22.532680262 -0.24016428276
7.8991765444 -0.47798866557
2.8767268321 -0.38515850005
P 1 1.00
0.77459363955 1.0000000
P 1 1.00
0.21037699698 1.0000000
P 1 1.00
0.50046271086D-01 1.0000000
D 1 1.00
0.6500000 1.0000000
D 1 1.00
0.12284803390 1.0000000
****""",
34 : r"""Se 0
S 6 1.00
106612.2002700 0.14274889113D-02
16007.6047010 0.10943525114D-01
3642.1699707 0.54374171596D-01
1028.5912993 0.19018092947
335.30298888 0.38913021696
115.80129154 0.30620207088
S 3 1.00
222.93325020 -0.11198808009
26.726257934 0.64752124207
11.124501923 0.44241976651
S 3 1.00
19.888520061 -0.22857227762
3.3668473803 0.73591359951
1.5249277839 0.44330199577
S 1 1.00
0.29630037912 1.0000000
S 1 1.00
0.11009288974 1.0000000
S 1 1.00
0.42167294728D-01 1.0000000
P 5 1.00
1455.9068120 0.88203597043D-02
343.75101831 0.66875851967D-01
109.29554964 0.26640578080
39.707711022 0.53834928422
14.950185232 0.36303281993
P 3 1.00
8.0208962094 0.34153807025
3.2934649756 0.57257906583
1.4058602438 0.25549813222
P 1 1.00
0.45076123226 1.0000000
P 1 1.00
0.13353413325 1.0000000
P 1 1.00
0.34396697938D-01 1.0000000
D 4 1.00
94.494024044 0.23490101098D-01
27.188185260 0.13747735767D+00
9.5091567352 0.36649929124D+00
3.4170516853 0.48750989884D+00
D 1 1.00
1.1479590083 .27657943383D+00
D 1 1.00
0.3380000 1.0000000
D 1 1.00
0.82767380906D-01 1.0000000
****""",
35 : r"""Br 0
S 6 1.00
113286.3877600 0.14283037779D-02
17009.6263030 0.10950417496D-01
3870.1842567 0.54421006604D-01
1093.0357227 0.19047907695
356.39721797 0.39024642737
123.12539643 0.30814432514
S 3 1.00
236.74084007 -0.11228065671
28.468661070 0.64775962312
11.883443722 0.44235575986
S 3 1.00
21.269633312 -0.22642576323
3.6129226841 0.73823712008
1.6626648969 0.42683868694
S 1 1.00
0.34823793232 1.0000000
S 1 1.00
0.13019031394 1.0000000
S 1 1.00
0.50966709763D-01 1.0000000
P 5 1.00
1560.2801881 0.87166669072D-02
368.47859205 0.66243637420D-01
117.22978849 0.26495610385
42.648909248 0.53839160587
16.087225096 0.36579387888
P 3 1.00
8.6352810058 0.34248787366
3.5613665502 0.57500678213
1.5292626609 0.24330394172
P 1 1.00
0.53064294848 1.0000000
P 1 1.00
0.15702758965 1.0000000
P 1 1.00
0.39636841846D-01 1.0000000
D 4 1.00
104.85518642 0.22650147581D-01
30.281143688 0.13455483230
10.651394267 0.36474454537
3.8699456233 0.49044587056
D 1 1.00
1.3240876762 .27137289040
D 1 1.00
0.3890000 1.0000000
D 1 1.00
0.96543342393D-01 1.0000000
****""",
53 : r"""I 0
S 6 1.00
445.90489176 0.20037290389D-02
23.336842412 -0.14989397324
19.583446104 0.36436474913
8.5112089186 -0.75538138199
2.1996161861 0.82816359356
1.0668970454 0.42161048110
S 2 1.00
11.720547572 -0.16160234511D-01
1.7625986449 0.35271525193
S 1 1.00
0.28697476318 1.0000000
S 1 1.00
0.11227609607 1.0000000
S 1 1.00
0.45123635492D-01 1.0000000
P 4 1.00
20.499027254 0.77159335656D-01
10.558754576 -0.38370372780
1.5015895485 0.83554174719
0.64597173095 0.16787259488
P 1 1.00
3.0288656771 1.0000000
P 1 1.00
0.34506591841 1.0000000
P 1 1.00
0.11134513813 1.0000000
P 1 1.00
0.29795507230D-01 1.0000000
D 5 1.00
51.235354920 0.40345130346D-02
15.616239482 -0.50768108881D-02
4.5266002139 0.29151065356
2.0529808766 0.51145783605
0.87640281623 0.31232025297
D 1 1.00
0.30900000000 1.0000000
D 1 1.00
0.77987255180D-01 1.0000000
****
I 0
I-ECP 3 28
f potential
4
2 19.45860900 -21.84204000
2 19.34926000 -28.46819100
2 4.82376700 -0.24371300
2 4.88431500 -0.32080400
s-f potential
7
2 40.01583500 49.99429300
2 17.42974700 281.02531700
2 9.00548400 61.57332600
2 19.45860900 21.84204000
2 19.34926000 28.46819100
2 4.82376700 0.24371300
2 4.88431500 0.32080400
p-f potential
8
2 15.35546600 67.44284100
2 14.97183300 134.88113700
2 8.96016400 14.67505100
2 8.25909600 29.37566600
2 19.45860900 21.84204000
2 19.34926000 28.46819100
2 4.82376700 0.24371300
2 4.88431500 0.32080400
d-f potential
10
2 15.06890800 35.43952900
2 14.55532200 53.17605700
2 6.71864700 9.06719500
2 6.45639300 13.20693700
2 1.19177900 0.08933500
2 1.29115700 0.05238000
2 19.45860900 21.84204000
2 19.34926000 28.46819100
2 4.82376700 0.24371300
2 4.88431500 0.32080400
****"""
}
# ------------------------------------------
# CODE FOR AUTOMATING INPUT FILE GENERATION
# ------------------------------------------
# This code only works for the wB97X-D/def2-SVPD model chemistry.
# To run this script the following files are needed:
# - molecules.txt: contains a list with all molecules that will be considering
# - vpt2_def2.gjf: input file template for VPT2 jobs with wB97X-D/def2-SVPD model chemistry in Gaussian
# - subtem.pbs: template submission file
# - geomtries folder: constains all geometries (in z-matrix) for the molecules listed in molecules.txt
import os
import re
import shutil
from mendeleev import element
failed_jobs = []
# Creates outputs folder
# https://stackabuse.com/creating-and-deleting-directories-with-python/
os.mkdir('outputs')
# Reads molecules.txt file and loops over all molecules present in the file.
with open('molecules.txt','r') as inp_molecules:
for molecule in inp_molecules:
try:
basis_data = []
elements_list = []
atomic_numbers = []
basis_str = ''
# Moves to outputs folder and copies the template file, changing its name to the one
# for the molecule being considered.
# https://thispointer.com/python-how-to-copy-files-from-one-location-to-another-using-shutil-copy/
os.chdir('outputs')
shutil.copy('../vpt2_def2.gjf', molecule.rstrip()+'_vpt2.gjf')
# Reads the elements present in the molecular formula and saves them into the elemens_list.
for letter in re.findall('[A-Z][^A-Z]*', molecule.rstrip()):
symbol = re.split(r'[0-9]', letter.split()[0])[0]
poss_under = re.split(r'(_)', symbol.split()[0])[0]
elements_list.append(poss_under)
# Creates a new list where stores the atomic numbers for each element present in the molecular formula.
# The list is then sorted from the smallers to the largest value.
for atom in elements_list:
symbol = element(atom)
atomic_numbers.append(symbol.atomic_number)
atomic_numbers.sort()
# Reads over each atomic number and saves the corresponding basis set for each element in the basis_data list.
# The basis_data is organised with increasing atomic number, as required by Gaussian for the input file.
for number in atomic_numbers:
if number in def2SVPD_basis:
basis_data.append(def2SVPD_basis[number])
# The basis is joined into a single string to be pasted in the input file template.
basis_str = '\n'.join(basis_data)
# Saves the info for the respective geometry into the geom_data list.
with open('../10_nISeBr/'+molecule.rstrip()+'.zmax','r') as inp_geom:
geom_data = inp_geom.read()
inp_geom.close()
# Replaces the selected keywords (i.e. {molecule}, {geometry} and {def2_basis}) with the
# corresponding values.
# https://www.kite.com/python/answers/how-to-update-and-replace-text-in-a-file-in-python
with open(molecule.rstrip()+'_vpt2.gjf','r+') as inp_template:
template_data = inp_template.read()
template_data = re.sub('{geometry}', geom_data, template_data)
template_data = re.sub('{molecule}', molecule.rstrip(), template_data)
template_data = re.sub('{def2_basis}', basis_str, template_data)
# writes the new templates.
inp_template.seek(0)
inp_template.write(template_data)
inp_template.truncate()
# Copies submission file template and pastes the appropriate input file name.
shutil.copy('../subtem.pbs', molecule.rstrip()+'_vpt2.pbs')
with open(molecule.rstrip()+'_vpt2.pbs','r+') as inp_sub:
submission_data = inp_sub.read()
submission_data = re.sub('{file_name}', molecule.rstrip()+'_vpt2', submission_data)
inp_sub.seek(0)
inp_sub.write(submission_data)
inp_sub.truncate()
except:
failed_jobs.append(molecule.rstrip())
os.chdir('../')