-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathheckQM_CLI.py
153 lines (121 loc) · 5.45 KB
/
heckQM_CLI.py
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
# MIT License
#
# Copyright (c) 2022 Nicolai Ree
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import os
import numpy as np
import submitit
import argparse
from rdkit import Chem
from rdkit.Chem.Draw import MolsToGridImage
from rdkit import RDLogger
lg = RDLogger.logger()
lg.setLevel(RDLogger.CRITICAL)
from heckQM import run_heck_reaction
# CPU usage
# -- change this in heckQM.py. Note, that ORCA is set to use 8 cpu cores and 2 conformers are running in parallel
# resulting in a total of 16 cpu cores per task. Memory per ORCA calculation is set to (mem_gb/2)*1000 MB.
def parse_args():
"""
Argument parser so this can be run from the command line
"""
parser = argparse.ArgumentParser(description='Run regioselectivity predictions from the command line')
parser.add_argument('-sa', '--alkene_smi', default='[H]C([H])=C([H])c1c([H])c([H])c([H])c([H])c1[H]',
help='SMILES input for alkene containing molecule')
parser.add_argument('-sh', '--halogen_smi', default='[H]c1c([H])c([H])c(Cl)c([H])c1[H]',
help='SMILES input for halogen containing molecule')
parser.add_argument('-n', '--name', default='testRXN', help='The name of the reaction (one word without "_")')
return parser.parse_args()
def html_output(svg_neu, svg_cat):
html = """<!DOCTYPE html>
<html lang="en">
<head>
<title>HeckQM</title>
<meta charset="utf-8">
<meta name="google" content="notranslate" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
</head>
<body>
<h1 style="color:black; font-family:verdana; text-align:center;">
HeckQM - Predicted Product(s)
</h1>
<h2 style="color:#e41a1c; font-family:verdana; text-align:center;">
NEUTRAL PATHWAY
</h2>
<div style="text-align:center;">
{0}
</div>
<hr size="2" noshade>
<h2 style="color:#e41a1c; font-family:verdana; text-align:center;">
CATIONIC PATHWAY
</h2>
<div style="text-align:center;">
{1}
</div>
</body>
</html>""".format(svg_neu, svg_cat)
return html
if __name__ == "__main__":
args = parse_args()
### SLURM SETTINGS ###
executor = submitit.AutoExecutor(folder="submitit_heckqm_cli")
executor.update_parameters(
name="heckQM",
cpus_per_task=16,
mem_gb=40,
timeout_min=6000,
slurm_partition="kemi1",
slurm_array_parallelism=50,
)
### END ###
### LOAD REACTANTS ###
# Load alkene containing molecule
alkene_mol = Chem.AddHs(Chem.MolFromSmiles(args.alkene_smi))
# Load halogen containing molecule
if args.halogen_smi:
halogen_mol = Chem.AddHs(Chem.MolFromSmiles(args.halogen_smi))
else:
halogen_mol = None
### END ###
### RUN CALCULATIONS ###
jobs = []
with executor.batch():
# Neutral reaction path
job = executor.submit(run_heck_reaction, alkene_mol, halogen_mol, name=args.name, chrg=0, neutral_path=True)
jobs.append(job)
# Cationic reaction path
job = executor.submit(run_heck_reaction, alkene_mol, halogen_mol, name=args.name, chrg=1, neutral_path=False)
jobs.append(job)
### END ###
### MAKE HECKQM OUTPUT ###
# Read results
energies_neu, complexes_neu, products_neu, legends_neu = jobs[0].result()
energies_cat, complexes_cat, products_cat, legends_cat = jobs[1].result()
# Generate graphical output
""" The generated html code can be displayed in a notebook with the following commands:
>>> from IPython.core.display import HTML
>>> HTML(html) """
svg_neu = MolsToGridImage(products_neu, legends=legends_neu, molsPerRow=4, subImgSize=(300,300), useSVG=True)#.data
svg_cat = MolsToGridImage(products_cat, legends=legends_cat, molsPerRow=4, subImgSize=(300,300), useSVG=True)#.data
html = html_output(svg_neu, svg_cat) # generate html code
os.makedirs(os.path.join(os.getcwd(), 'results'), exist_ok=True) # save graphical output in the results folder
with open(f'results/{args.name}.html', 'w') as f:
f.write(html)
### END ###