def test_set_reactants_list_of_list(): mol = UniqueMolecule(smiles="N#Cc1cccc(NC(=O)c2ccc(F)cc2)c1F") reactant1 = UniqueMolecule(smiles="N#Cc1cccc(N)c1F") reactant2 = UniqueMolecule(smiles="O=C(Cl)c1ccc(F)cc1") rxn = FixedRetroReaction(mol) rxn.reactants = ((reactant1, reactant2), ) assert rxn.reactants == ((reactant1, reactant2), )
def _parse_tree_dict(self, tree_dict, ncalls=0): product_node = UniqueMolecule(smiles=tree_dict["smiles"]) self._add_node( product_node, depth=2 * ncalls, transform=ncalls, hide=tree_dict.get("hide", False), in_stock=tree_dict["in_stock"], ) rxn_tree_dict = tree_dict.get("children", []) if not rxn_tree_dict: return product_node rxn_tree_dict = rxn_tree_dict[0] reaction_node = FixedRetroReaction( product_node, smiles=rxn_tree_dict["smiles"], metadata=rxn_tree_dict.get("metadata", {}), ) self._add_node(reaction_node, depth=2 * ncalls + 1, hide=rxn_tree_dict.get("hide", False)) self.tree.graph.add_edge(product_node, reaction_node) reactant_nodes = [] for reactant_tree in rxn_tree_dict.get("children", []): reactant_node = self._parse_tree_dict(reactant_tree, ncalls + 1) self.tree.graph.add_edge(reaction_node, reactant_node) reactant_nodes.append(reactant_node) reaction_node.reactants = reactant_nodes return product_node
def test_create_fixed_reaction(): smiles = "[C:1](=[O:2])([cH3:3])[N:4][cH3:5]>>Cl[C:1](=[O:2])[cH3:3].[N:4][cH3:5]" mol = UniqueMolecule(smiles="N#Cc1cccc(NC(=O)c2ccc(F)cc2)c1F") rxn = FixedRetroReaction(mol, smiles=smiles) assert rxn.smiles == smiles
def test_scorers_tree_one_node_route(default_config): tree = ReactionTree() tree.root = UniqueMolecule(smiles="CCCCOc1ccc(CC(=O)N(C)O)cc1") tree.graph.add_node(tree.root) assert pytest.approx(StateScorer(default_config)(tree), abs=1e-3) == 0.0497 assert NumberOfReactionsScorer(default_config)(tree) == 0 assert NumberOfPrecursorsScorer(default_config)(tree) == 1 assert NumberOfPrecursorsInStockScorer(default_config)(tree) == 0 assert PriceSumScorer(default_config)(tree) == 10 assert RouteCostScorer(default_config)(tree) == 10
def _parse_tree_dict(tree_dict, rt_object, reaction_cls): if tree_dict["type"] == "mol": node = UniqueMolecule(smiles=tree_dict["smiles"]) if not rt_object.root: rt_object.root = node if tree_dict["in_stock"]: rt_object._stock.append(node) else: node = reaction_cls(smiles=tree_dict["smiles"], metadata=tree_dict.get("metadata", {})) rt_object.graph.add_node(node) for child_dict in tree_dict.get("children", []): child = ReactionTree._parse_tree_dict(child_dict, rt_object, reaction_cls) rt_object.graph.add_edge(node, child) return node