-
Notifications
You must be signed in to change notification settings - Fork 1
/
Fcst_ParaEngine.py
186 lines (143 loc) · 5.32 KB
/
Fcst_ParaEngine.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
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
import sys
import os
import time
import socket
from os import listdir
from os.path import isfile, join
hostname = socket.gethostname()
PWD=os.getcwd()
SRC=PWD+"/src"
BAK=PWD+"/database/trained-models"
PLYfile=PWD+"/database/polyfitted/data.TOTpolyfitted.2"
# add the runtime environments
print(SRC)
sys.path.append(SRC)
sys.path.append(PWD+"/tools")
# originally import
import torch
import Models
import Configs
import PredictTime
import Magnification
import DecideRefSpace
import SplitPDB
# rdkit for chem-informatics
from rdkit import Chem
from rdkit.Chem import AllChem
def add_nitrogen_charges(smiles):
m = Chem.MolFromSmiles(smiles,sanitize=False)
m.UpdatePropertyCache(strict=False)
ps = Chem.DetectChemistryProblems(m)
if not ps:
Chem.SanitizeMol(m)
return m
for p in ps:
if p.GetType()=='AtomValenceException':
at = m.GetAtomWithIdx(p.GetAtomIdx())
if at.GetAtomicNum()==7 and at.GetFormalCharge()==0 and at.GetExplicitValence()==4:
at.SetFormalCharge(1)
Chem.SanitizeMol(m)
return m
# parameters to be used (IO later)
QC_packages = ["G09"]
Machines = ["ERA"]
functionals = ["M062x"]
bases = ["6-31gss"]
#target_mols = ["./example/Arxiv1911.05569v1_sdfs_H_Part2"]
target_PDB = ["./example/LBtest29-6-80A_para.pdb"]
#target_mols = ["./updatedSDFs"]
#target_smil = ["./TestSMI2"]
ML_models = ["MPNN"] # Maybe bug in MGCN
ifmols = False
ifsmil = False
if "target_PDB" in dir():
SplitPDB.split(target_PDB[0],"./tmpPDB")
print("target_PDB is defined")
target_mols = ["./tmpPDB"]
infiles = [f for f in listdir(target_mols[0]) if isfile(join(target_mols[0], f))]
ifmols = True
if "target_smil" in dir():
print("target_smil is defined")
infiles = [f for f in listdir(target_smil[0]) if isfile(join(target_smil[0], f))]
ifsmil = True
if "target_mols" in dir():
print("target_mols is defined")
infiles = [f for f in listdir(target_mols[0]) if isfile(join(target_mols[0], f))]
ifmols = True
# rdkit treatment of input molecule
mols = []
NAMmol = []
for i in range(len(infiles)):
if ifmols:
tarfile = target_mols[0] + "/" + infiles[i]
print(i, " tarfile : ", tarfile)
mols.append(Chem.SDMolSupplier(tarfile))
PWDmol = PWD + "/" + target_mols[0]
NAMmol.append(infiles[i])
if ifsmil:
tarfile = target_smil[0] + "/" + infiles[i]
print(i, " tarfile : ", tarfile)
with open(tarfile, 'r') as fsmiles:
lines = fsmiles.readlines()
#print("lines : ", lines)
for line in lines:
ismi = line.split()[0]
iname = line.split()[1]
print("ismi : ", ismi )
msmi = add_nitrogen_charges(ismi)
ismi2= Chem.MolToSmiles(msmi)
qmol = Chem.MolFromSmiles(ismi2)
print("qmol : ", qmol)
#qmol.UpdatePropertyCache(strict=False)
mols.append(qmol)
NAMmol.append(iname)
PWDmol = PWD + "/" + target_smil[0]
#mol = mols[0]
#print(mols)
print(" ")
#print("PWDmol : ",PWDmol)
#print("NAMmol : ",NAMmol)
#print("BAKmod : ",BAK )
print(" ")
#exit(0)
# chemical space and many-world interpretation for predicting
for qc in QC_packages:
for imachine in Machines:
# QC_package@Machine
print(" ===> " )
print(" ===> QC_package : ", qc, " | Machine : " , imachine)
print(" ===> " )
for mod in ML_models: # models
#Models.prepare(mod)
print(" ")
print(" =====================================================")
print(" ===",mod,"===",mod,"===",mod,"===",mod,"===",mod,"===")
print(" =====================================================")
print(" ")
for funct in functionals: # functionals
for basis in bases:
# == the target chemspace == *
chemspace=funct+'_'+basis
#print("mols : ",mols[0])
# == decide the ref_chemspace == *
# ref_funct & ref_basis
ref_funct,ref_basis=DecideRefSpace.RefBasisfunct(basis,funct,mols[0][0])
#ref_funct,ref_basis=DecideRefSpace.RefBasisfunct(basis,funct,mols[0])
print(" ===> Target Space : ", funct,"/",basis)
print(" ===> Reference Space : ", ref_funct,"/",ref_basis)
print(" ")
# ref_chemspace = ref_funct + ref_basis
ref_chemspace=ref_funct+"_"+ref_basis
for mol in mols:
# Predict basing on the ref_chemspace
Ptime = PredictTime.EvalSuit(mod,ref_chemspace,PWDmol,NAMmol,BAK,QC_packages[0],Machines[0])
exit(0)
# MWI correction for the predicted results
corr1 = PredictTime.MWIbasis(ref_chemspace,chemspace,PWDmol,NAMmol,PLYfile)
corr2 = PredictTime.MWIfunct(ref_chemspace,chemspace)
print(" ===> The correction for funct/basis are ",corr2," and ",corr1," , respectively.")
Ptime=Ptime*corr1*corr2
print(" ===> The predicted computational CPU time is ", Ptime)
print(" ")
print(" ")
exit(0)