13
13
import sys
14
14
import subprocess
15
15
import pickle
16
- from rdkit import rdBase
16
+ from rdkit import rdBase , Chem
17
17
## Disable rdkit Logs
18
18
rdBase .DisableLog ('rdApp.error' )
19
19
from .jtvae import Vocab , JTNNVAE
74
74
dock (ligs , docking_dir , prmfile , p .docking_prm , p .npose , p .prefix )
75
75
ranked_poses = sort_pose (docking_dir , p .sort_by , p .prefix )
76
76
save_pose (ranked_poses , design_dir )
77
-
77
+
78
78
## Generate new design list
79
- for energy , name , mol in ranked_poses :
80
- smi = mol .GetProp ('SMILES' )
81
- design_list = []
82
- try :
83
- print ('[INFO]: Generating new designs \t ' , end = '\r ' )
84
- sys .stdout .flush ()
85
- design_list = jtvae .smiles_gen (smi , p .ndesign )
86
- # go to the second best candidate if the best does not give any return
87
- except KeyError as key :
88
- print ('[KeyError]' ,key ,'is not part of the vocabulary' )
89
- continue
90
-
91
- if len (design_list ) != 0 :
92
- break
93
-
94
- else :
95
- print ('Current design (%s) has no offspring; trying the next one \r ' % name )
96
-
97
- print ("[INFO]: Cycle %s: %s %s kcal/mol" % (j , smi , energy )+ '\t ' * 6 )
79
+ if p .ensemble > 1 :
80
+ top_smi_list = [Chem .MolToSmiles (mol ) for _ , _ , mol in ranked_poses [:p .ensemble ]]
81
+ smi = jtvae .find_ensemble (top_smi_list )
82
+ design_list = jtvae .smiles_gen (smi , p .ndesign )
83
+ best_score = ranked_poses [0 ][0 ]
84
+ print ("[INFO]: Cycle %s: %s Best Score: %s kcal/mol" % (j , smi , best_score )+ '\t ' * 6 )
85
+ else :
86
+ for energy , name , mol in ranked_poses :
87
+ smi = mol .GetProp ('SMILES' )
88
+ try :
89
+ print ('[INFO]: Generating new designs \t ' , end = '\r ' )
90
+ sys .stdout .flush ()
91
+ # get new design list for the nex cycle
92
+ design_list = jtvae .smiles_gen (smi , p .ndesign )
93
+ # This is due to difference in parsing of SMILES (especially rings)
94
+ ## TODO: Convert sampledock to OOP structure and use the vectors directly
95
+ except KeyError as key :
96
+ print ('[KeyError]' ,key ,'is not part of the vocabulary (the model was not trained with this scaffold)' )
97
+ continue
98
+ # if there are offspring designs, break the loop
99
+ if len (design_list ) != 0 :
100
+ break
101
+ # go to the next candidate if the current one does not give any return
102
+ else :
103
+ print ('Current design (%s) has no offspring; trying the next one \r ' % name )
104
+
105
+ print ("[INFO]: Cycle %s: %s %s kcal/mol" % (j , smi , energy )+ '\t ' * 6 )
98
106
99
107
print ("\n " , p .ncycle , "cycles of design finished. Starting post-processing." )
100
108
# Create post-process working directory
117
125
pickle .dump ((x ,y ,s ,t ),f )
118
126
# Create tmap on faerun
119
127
f = df_to_faerun (allscores ,x ,y ,s ,t )
120
-
128
+ f .plot ("SampleDock" + '_space' , path = postproc_wd , # name and path of the .html file
129
+ template = "smiles" )
121
130
with open (os .path .join (postproc_wd ,'SampleDock.faerun' ), 'wb' ) as handle :
122
131
pickle .dump (f .create_python_data (), handle , protocol = pickle .HIGHEST_PROTOCOL )
0 commit comments