def _process_multi_smiles(filename: str, finder: AiZynthFinder, output_name: str, do_clustering: bool) -> None: output_name = output_name or "output.hdf5" with open(filename, "r") as fileobj: smiles = [line.strip() for line in fileobj.readlines()] results = defaultdict(list) for smi in smiles: finder.target_smiles = smi finder.prepare_tree() search_time = finder.tree_search() finder.build_routes() stats = finder.extract_statistics() logger().info(f"Done with {smi} in {search_time:.3} s") if do_clustering: _do_clustering(finder, stats, detailed_results=True) for key, value in stats.items(): results[key].append(value) results["top_scores"].append(", ".join( "%.4f" % score for score in finder.routes.scores)) results["trees"].append(finder.routes.dicts) data = pd.DataFrame.from_dict(results) with warnings.catch_warnings(): # This wil suppress a PerformanceWarning warnings.simplefilter("ignore") data.to_hdf(output_name, key="table", mode="w") logger().info(f"Output saved to {output_name}")
def _process_single_smiles( smiles: str, finder: AiZynthFinder, output_name: str, do_clustering: bool, route_distance_model: str = None, ) -> None: output_name = output_name or "trees.json" finder.target_smiles = smiles finder.prepare_tree() finder.tree_search(show_progress=True) finder.build_routes() with open(output_name, "w") as fileobj: json.dump(finder.routes.dicts, fileobj, indent=2) logger().info(f"Trees saved to {output_name}") scores = ", ".join("%.4f" % score for score in finder.routes.scores) logger().info(f"Scores for best routes: {scores}") stats = finder.extract_statistics() if do_clustering: _do_clustering(finder, stats, detailed_results=False, model_path=route_distance_model) stats_str = "\n".join(f"{key.replace('_', ' ')}: {value}" for key, value in stats.items()) logger().info(stats_str)
def process_smiles_list(finder: AiZynthFinder, target_smiles: List[str]) -> List[Dict[str, str]]: stats_list: List[Dict[str, str]] = [] for smiles in target_smiles: finder.target_smiles = smiles finder.tree_search() finder.build_routes() stats_list.append(finder.extract_statistics()) return stats_list