Exemplo n.º 1
0
    def evaluate_synthesis_trees(self, trees):
        if self.celery:  # Call celery worker
            working = time.time()
            res = evaluate_trees.apply_async(args=(trees,), kwargs={'context_scoring_method': self.context_prioritization,
                                                                    'context_recommender': self.context_recommender,
                                                                    'forward_scoring_method': self.forward_scoring_method,
                                                                    'tree_scoring_method': self.tree_scoring_method,
                                                                    'rank_threshold': self.rank_threshold_inclusion,
                                                                    'prob_threshold': self.prob_threshold_inclusion,
                                                                    'mincount': self.synth_mincount,
                                                                    'batch_size': 500, 'n': self.max_total_contexts,
                                                                    'template_count': self.template_count,
                                                                    })
            while not res.ready():
                if int(time.time() - working) % 10 == 0:
                    MyLogger.print_and_log('Evaluating trees...', makeit_loc)
                time.sleep(1)
            evaluated_trees = res.get()
        else:  # Create a tree evaluation object and run it
            if self.forward_scoring_method == gc.templatebased:
                # nproc = number of parallel forward enumeration workers
                # nproc_t = number of trees to be evaluated in parallel.
                # Only use an nproc different from 1 if using the template base forward evaluation method. Otherwise
                # evaluation is fast enough to do without additional
                # parallelization
                if len(trees) > 2 or self.parallel_tree:
                    nproc_t = 2
                    nproc = max(1, self.nproc/2)
                else:
                    nproc_t = 1
                    nproc = self.nproc
            else:
                nproc_t = max(1, self.nproc)
                nproc = 1
            tree_evaluator = TreeEvaluator(
                celery=False, context_recommender=self.context_recommender)
            evaluated_trees = tree_evaluator.evaluate_trees(trees, context_recommender=self.context_recommender, context_scoring_method=self.context_prioritization,
                                                            forward_scoring_method=self.forward_scoring_method, tree_scoring_method=self.tree_scoring_method,
                                                            rank_threshold=self.rank_threshold_inclusion, prob_threshold=self.prob_threshold_inclusion,
                                                            mincount=self.synth_mincount, batch_size=500, n=self.max_total_contexts, nproc_t=nproc_t,
                                                            nproc=nproc, parallel=self.parallel_tree, template_count=self.template_count,
                                                            )
        plausible_trees = []
        print(evaluated_trees)
        for tree in evaluated_trees:
            if tree['plausible']:
                plausible_trees.append(tree)

        if plausible_trees:
            MyLogger.print_and_log(
                'Feasible synthesis route discovered!', makeit_loc)
        else:
            MyLogger.print_and_log(
                'No feasible routes from buyables have been discovered. Consider changing inclusion thesholds.', makeit_loc)

        return plausible_trees
Exemplo n.º 2
0
def configure_coordinator(options={}, **kwargs):
    if 'queues' not in options:
        return
    if CORRESPONDING_QUEUE not in options['queues'].split(','):
        return
    print('### STARTING UP A TREE EVALUATION COORDINATOR ###')

    global evaluator

    evaluator = TreeEvaluator(celery=True)
    print('### TREE EVALUATION COORDINATOR STARTED UP ###')
Exemplo n.º 3
0
print(len(truncated_mol_lib))  # for name in dataset['SMILES']:
#     try:
#         mol = name_parser.name_to_molecule(name)
#         mol_lib.append(mol)
#     except:
#         continue
print("{} target molecules to expand".format(len(truncated_mol_lib)))
celery = False
NCPUS = 4
# treeBuilder = TreeBuilder(celery=celery, mincount=25, mincount_chiral=10)
Tree = MCTS(nproc=NCPUS,
            mincount=gc.RETRO_TRANSFORMS_CHIRAL['mincount'],
            mincount_chiral=gc.RETRO_TRANSFORMS_CHIRAL['mincount_chiral'],
            celery=celery)
treeEvaluator = TreeEvaluator(context_recommender=gc.neural_network,
                              celery=celery)
all_routes = []
all_trees = []
all_routes_contexts = []
index_list_all_routes = []
is_first_target = True
status = 0
results_folder = "/home/hanyug/Combined_synthesis_planning/pathways/small_and_buyable/"

status_file = open(results_folder + 'status for molecules.dat', 'w')
status_file.write('SMILES\tnumberofpaths\tnotes\n')
reaction_dict = {}
for mol in truncated_mol_lib:
    # for mol in [Chem.MolFromSmiles('OC(C1CCCCN1)c2cc(nc3c2cccc3C(F)(F)F)C(F)(F)F')]:
    if is_first_target:
        soft_reset = False