示例#1
0
def test_find_repetetive_patterns_created_tree_no_patterns(
        default_config, mock_stock, shared_datadir):
    mock_stock(default_config, Molecule(smiles="CC"), Molecule(smiles="CCCO"))

    # Try with a short tree (3 nodes, 1 reaction)
    search_tree = SearchTree.from_json(
        shared_datadir / "tree_without_repetition.json", default_config)
    analysis = TreeAnalysis(search_tree)

    rt = ReactionTree.from_analysis(analysis)

    assert not rt.has_repeating_patterns
    hidden_nodes = [
        node for node in rt.graph if rt.graph.nodes[node].get("hide", False)
    ]
    assert len(hidden_nodes) == 0

    # Try with something longer
    search_tree = SearchTree.from_json(
        shared_datadir / "tree_without_repetition_longer.json", default_config)
    analysis = TreeAnalysis(search_tree)

    rt = ReactionTree.from_analysis(analysis)

    assert not rt.has_repeating_patterns
示例#2
0
def test_find_repetetive_patterns_created_tree(default_config, mock_stock,
                                               shared_datadir):
    mock_stock(default_config, Molecule(smiles="CC"), Molecule(smiles="C"))

    # Try one with 2 repetetive units
    search_tree = SearchTree.from_json(
        shared_datadir / "tree_with_repetition.json", default_config)
    analysis = TreeAnalysis(search_tree)

    rt = ReactionTree.from_analysis(analysis)

    assert rt.has_repeating_patterns
    hidden_nodes = [
        node for node in rt.graph if rt.graph.nodes[node].get("hide", False)
    ]
    assert len(hidden_nodes) == 5

    # Try one with 3 repetetive units
    search_tree = SearchTree.from_json(
        shared_datadir / "tree_with_3_repetitions.json", default_config)
    analysis = TreeAnalysis(search_tree)

    rt = ReactionTree.from_analysis(analysis)

    assert rt.has_repeating_patterns
    hidden_nodes = [
        node for node in rt.graph if rt.graph.nodes[node].get("hide", False)
    ]
    assert len(hidden_nodes) == 10
示例#3
0
def test_reactiontree_to_json(setup_complete_tree, shared_datadir):
    filename = str(shared_datadir / "sample_reaction.json")
    with open(filename, "r") as fileobj:
        expected = json.load(fileobj)
    tree, nodes = setup_complete_tree
    analysis = TreeAnalysis(tree)

    resp = ReactionTree.from_analysis(analysis).to_json()
    assert json.loads(resp) == expected
示例#4
0
def test_route_to_reactiontree(setup_analysis):
    analysis, _ = setup_analysis()

    reaction_tree = ReactionTree.from_analysis(analysis)

    mol_nodes = list(reaction_tree.molecules())
    assert len(mol_nodes) == 6

    reaction_nodes = list(reaction_tree.reactions())
    assert len(reaction_nodes) == 2

    leaf_nodes = list(reaction_tree.leafs())
    assert len(leaf_nodes) == 4
    assert set(node.smiles for node in leaf_nodes) == {
        "N#Cc1cccc(N)c1F",
        "O=C(Cl)c1ccc(F)cc1",
        "CN1CCC(Cl)CC1",
        "O",
    }
示例#5
0
def test_route_node_depth_from_analysis(default_config, mock_stock,
                                        shared_datadir):
    mock_stock(default_config, Molecule(smiles="CC"), Molecule(smiles="CCCO"))
    search_tree = SearchTree.from_json(
        shared_datadir / "tree_without_repetition.json", default_config)
    analysis = TreeAnalysis(search_tree)
    rt = ReactionTree.from_analysis(analysis)

    mols = list(rt.molecules())

    assert rt.depth(mols[0]) == 0
    assert rt.depth(mols[1]) == 2
    assert rt.depth(mols[2]) == 2

    rxns = list(rt.reactions())
    assert rt.depth(rxns[0]) == 1

    for mol in rt.molecules():
        assert rt.depth(mol) == 2 * rt.graph.nodes[mol]["transform"]
示例#6
0
def test_route_to_reactiontree(setup_complete_tree):
    tree, nodes = setup_complete_tree
    analysis = TreeAnalysis(tree)

    reaction_tree = ReactionTree.from_analysis(analysis).graph

    reaction_nodes = [
        node.inchi_key for node in reaction_tree if isinstance(node, Molecule)
    ]
    tree_nodes = [
        mol.inchi_key for mol in nodes[0].state.mols + nodes[1].state.mols +
        nodes[2].state.mols
    ]
    assert len(reaction_nodes) == 6
    assert reaction_nodes == tree_nodes

    reaction_nodes = [
        node for node in reaction_tree if isinstance(node, Reaction)
    ]
    assert len(reaction_nodes) == 2
示例#7
0
def test_reactiontree_to_json(setup_analysis, load_reaction_tree):
    expected = load_reaction_tree("sample_reaction.json")
    analysis, _ = setup_analysis()

    resp = ReactionTree.from_analysis(analysis).to_json()
    assert json.loads(resp) == expected