forked from vtlim/off_psi4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecutor.py
More file actions
125 lines (99 loc) · 4.62 KB
/
executor.py
File metadata and controls
125 lines (99 loc) · 4.62 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
#!/usr/bin/env python
import os, sys
import argparse
import smi2confs
import filterConfs
import confs2psi
import getPsiResults
#
# Envisioned pipeline stages with this script:
# I. feed in smiles file > generate confs > MM optimize > generate psi4 inputs
# II. process psi4 results
# III. generate new Psi4 inputs from II (e.g. SPE or OPT2)
# IV. process psi4 results
#
# Example usage:
# python executor.py -f /path/to/inputfile --setup -m 'mp2' -b 'def2-sv(p)'
# python executor.py -f /path/to/inputfile --results -m 'mp2' -b 'def2-sv(p)'
# python executor.py -f /path/to/inputfile --setup --spe -m 'b3lyp-d3mbj' -b 'def2-tzvp'
# python executor.py -f /path/to/inputfile --results --spe -m 'b3lyp-d3mbj' -b 'def2-tzvp'
#
# Note 1: This pipeline uses some preset parameters, such as
# resClash=True and quickOpt=True (with SD opt) in smi2confs, and
# MP2/def2-sv(p) for QM opt1. These can be modified in the argument
# inputs here, or in the parent code itself.
# Note 2: The input file must be in the same directory that the script is
# called. The directory tree goes (pwd)/molName/confNum .
# Note 3: can sort of setup mol2 files (e.g. for one mol and all its confs) but
# check that molecule name and total charge is correct in Psi4 input files.
#
def main(**kwargs):
_, extension = os.path.splitext(opt['filename'])
adir, fname = os.path.split(opt['filename'])
hdir = os.getcwd()
if adir == '' or adir is None or adir == '.':
fullname = os.path.join(hdir,opt['filename'])
else:
fullname = opt['filename']
base = fname.replace('-', '.').split('.')[0]
if opt['setup']:
if extension == '.smi': ### MM opt & filter
print("\nGenerating and filtering conformers for %s" % opt['filename'])
msdf = base + '.sdf'
smi2confs.smi2confs(os.path.join(hdir,opt['filename']))
filterConfs.filterConfs(os.path.join(hdir, msdf), "MM Szybki SD Energy", suffix='200')
msdf = base+'-200.sdf'
else:
msdf = fullname
### Generate Psi4 inputs.
print("\nCreating Psi4 input files for %s..." % base)
confs2psi.confs2psi(msdf,opt['method'],opt['basisset'],opt['spe'],"5.0 Gb")
else: # ========== AFTER QM =========== #
### Specify output file name
if "220" not in fname:
osdf = os.path.join(hdir,base + '-210.sdf')
suffix = '220'
else:
osdf = os.path.join(hdir,base + '-221.sdf')
suffix = '222'
### Get results.
print("Getting Psi4 results for %s ..." %(fname))
method, basisset = getPsiResults.getPsiResults(fullname, osdf, spe=opt['spe'])
if method is None or basisset is None:
method = opt['method']
basisset = opt['basisset']
### Filter optimized results.
print("Filtering Psi4 results for %s ..." %(osdf))
if not opt['spe']:
tag = "QM Psi4 Final Opt. Energy (Har) %s/%s" % (method, basisset)
filterConfs.filterConfs(osdf, tag, suffix)
# else:
# tag = "QM Psi4 Single Pt. Energy (Har) %s/%s" % (method, basisset)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
req = parser.add_argument_group('required arguments')
req.add_argument("-f", "--filename",
help="SDF file (with FULL path) to be set up or processed.")
parser.add_argument("--setup", action="store_true", default=False,
help="If True (default=False), generate and filter conformers (if\
starting from *.smi), then generate Psi4 input files.")
parser.add_argument("--results", action="store_true", default=False,
help="If True (default=False), process Psi4 output files\
and filter conformers.")
parser.add_argument("--spe", action="store_true", default=False,
help="If True, either set up or process single point energy\
calculations. If False, will set up or process geometry optimizations.\
Can be used with either the --setup flag or the --results flag.")
req.add_argument("-m", "--method",
help="Name of QM method. Put this in 'quotes'.")
req.add_argument("-b", "--basisset",
help="Name of QM basis set. Put this in 'quotes'.")
args = parser.parse_args()
opt = vars(args)
### Check that both 'setup' and 'spe' are not both true or both false.
if opt['setup'] == opt['results']:
raise parser.error("Specify exactly one of either --setup or --results.")
### Check that input file exists.
if not os.path.exists(opt['filename']):
raise parser.error("Input file %s does not exist. Try again." % opt['filename'])
main(**opt)