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
示例#2
0
def test_set_reactants_single():
    mol = TreeMolecule(parent=None, smiles="N#Cc1cccc(NC(=O)c2ccc(F)cc2)c1F")
    reactant1 = TreeMolecule(parent=mol, smiles="N#Cc1cccc(N)c1F")
    rxn = FixedRetroReaction(mol)

    rxn.reactants = reactant1

    assert rxn.reactants == ((reactant1), )
示例#3
0
def test_set_reactants_list_of_list():
    mol = TreeMolecule(parent=None, smiles="N#Cc1cccc(NC(=O)c2ccc(F)cc2)c1F")
    reactant1 = TreeMolecule(parent=mol, smiles="N#Cc1cccc(N)c1F")
    reactant2 = TreeMolecule(parent=mol, smiles="O=C(Cl)c1ccc(F)cc1")
    rxn = FixedRetroReaction(mol)

    rxn.reactants = ((reactant1, reactant2), )

    assert rxn.reactants == ((reactant1, reactant2), )
示例#4
0
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 = TreeMolecule(parent=None, smiles="N#Cc1cccc(NC(=O)c2ccc(F)cc2)c1F")

    rxn = FixedRetroReaction(mol, smiles=smiles)

    assert rxn.smiles == smiles

    with pytest.raises(ValueError):
        rxn.rd_reaction

    with pytest.raises(NotImplementedError):
        rxn.apply()
示例#5
0
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
示例#6
0
 def _unique_reaction(self, reaction: RetroReaction) -> FixedRetroReaction:
     id_ = id(reaction)
     if id_ not in self._unique_reactions:
         self._unique_reactions[id_] = FixedRetroReaction(
             self._unique_mol(reaction.mol),
             smiles=reaction.smiles,
             metadata=reaction.metadata,
         )
     return self._unique_reactions[id_]
    def _add_bipartite(self, child, action):

        reaction_obj = FixedRetroReaction(self._unique_mol(action.mol),
                                          smiles=action.smiles,
                                          metadata=action.metadata)
        self._add_node(reaction_obj, depth=action.mol.transform + 1)
        self.tree.graph.add_edge(self._unique_mol(action.mol), reaction_obj)
        reactant_nodes = []
        for mol in child.state.mols:
            if mol.parent is action.mol:
                self._add_node(
                    self._unique_mol(mol),
                    depth=2 * mol.transform,
                    transform=mol.transform,
                    in_stock=mol in child.state.stock,
                )
                self.tree.graph.add_edge(reaction_obj, self._unique_mol(mol))
                reactant_nodes.append(self._unique_mol(mol))
        reaction_obj.reactants = reactant_nodes