|
| 1 | +## TODO: this will definitely need to be restructured as the additional features have cluterred code. |
1 | 2 | import argparse
|
2 | 3 |
|
3 | 4 | parser = argparse.ArgumentParser(prog='sampledock')
|
|
21 | 22 | from .SnD import prep_prm
|
22 | 23 | from .SnD import dock, sort_pose, save_pose
|
23 | 24 | from .SnD import hyperparam_loader, create_wd, smiles_to_sdfile
|
| 25 | +from .SnD import single_generator, distributed_generator |
24 | 26 | from .SnD import combine_designs, mkdf
|
25 | 27 | from .SnD import LSH_Convert, tree_coords, df_to_faerun
|
26 | 28 | # Load hyper parameters
|
|
44 | 46 | design_list = jtvae.smiles_gen(p.seed_smi, p.ndesign)
|
45 | 47 | except KeyError as err:
|
46 | 48 | print('[KeyError]',err,
|
47 |
| - 'does not exist in the current JTVAE model vocabulary "%s" (the training set of the model did not contain this structure),'%p.vocab_loc, |
| 49 | + 'does not exist in the current JTVAE model vocabulary "%s" \ |
| 50 | + (the training set of the model did not contain this structure),'%p.vocab_loc, |
48 | 51 | 'thus "%s" failed to initialize the model as seeding molecule!'%p.seed_smi)
|
49 | 52 | exit()
|
50 | 53 |
|
| 54 | +# Check if design generations are ditributed among the top n designs (nseeds) |
| 55 | +sub_ndesign = int(p.ndesign)//int(p.nseeds) if p.nseeds > 1 else False |
| 56 | + |
51 | 57 | # Create working directory
|
52 | 58 | wd = create_wd(a.output,p.receptor_name)
|
53 | 59 |
|
|
75 | 81 | ranked_poses = sort_pose(docking_dir, p.sort_by, p.prefix)
|
76 | 82 | save_pose(ranked_poses, design_dir)
|
77 | 83 |
|
| 84 | + ## Report the top design |
| 85 | + top_energy, top_name, top_mol = ranked_poses[0] |
| 86 | + top_smi = top_mol.GetProp('SMILES') |
| 87 | + print("[INFO]: Cycle %s: %s %s kcal/mol"%(j, top_smi, top_energy)+'\t'*6) |
| 88 | + |
78 | 89 | ## Generate new design list
|
79 |
| - if p.ensemble > 1: |
80 |
| - top_smi_list = [Chem.MolToSmiles(mol) for _, _, mol in ranked_poses[:p.ensemble]] |
| 90 | + if sub_ndesign: |
| 91 | + design_list = distributed_generator(ranked_poses, p.nseeds, sub_ndesign, jtvae) |
| 92 | + elif p.ensemble > 1: |
| 93 | + top_smi_list = [mol.GetProp('SMILES') for _, _, mol in ranked_poses[:p.ensemble]] |
81 | 94 | smi = jtvae.find_ensemble(top_smi_list)
|
82 | 95 | 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 | 96 | 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) |
106 |
| - |
| 97 | + design_list = single_generator(ranked_poses, p.ndesign, jtvae) |
| 98 | + |
| 99 | + |
107 | 100 | print("\n", p.ncycle, "cycles of design finished. Starting post-processing.")
|
108 | 101 | # Create post-process working directory
|
109 | 102 | postproc_wd = os.path.join(wd, "All_Designs_Processed")
|
|
0 commit comments