def to_visjs_page(
        self,
        filename,
        in_stock_colors={
            True: "green",
            False: "orange"
        },
    ):
        """
        Create a visualization of the combined reaction tree using the vis.js network library.

        The HTML page and all the images will be put into a tar-ball.

        :param filename: the name of the tarball
        :type filename: str
        :param in_stock_colors: the colors around molecules, defaults to {True: "green", False: "orange"}
        :type in_stock_colors: dict, optional
        """
        molecules = [node for node in self.graph if isinstance(node, Molecule)]
        reactions = [
            node for node in self.graph if not isinstance(node, Molecule)
        ]
        frame_colors = [
            in_stock_colors[self.graph.nodes[node].get("in_stock", False)]
            for node in molecules
        ]
        make_visjs_page(filename, molecules, reactions, self.graph.edges,
                        frame_colors)
Exemple #2
0
def test_visjs_page(mocker, tmpdir, setup_graphviz_graph):
    mkdtemp_patch = mocker.patch("aizynthfinder.utils.image.tempfile.mkdtemp")
    mkdtemp_patch.return_value = str(tmpdir / "tmp")
    os.mkdir(tmpdir / "tmp")
    molecules, reactions, edges, frame_colors = setup_graphviz_graph
    filename = str(tmpdir / "arch.tar")

    image.make_visjs_page(filename, molecules, reactions, edges, frame_colors)

    assert os.path.exists(filename)
    with TarFile(filename) as tarobj:
        assert "./route.html" in tarobj.getnames()
        assert len([name for name in tarobj.getnames() if name.endswith(".png")]) == 1