def _draw_node(self, node: Molecule): import os self._node_counter += 1 if self._draw_mode == "smiles": self._dot.node(name=node.to_smiles(), label=node.to_smiles()) elif self._draw_mode == "formula": self._dot.node(name=node.to_smiles(), label=node.to_formula()) elif self._draw_mode == "plot": mol_img_path = os.path.join(self._sub_dir, str(self._node_counter) + ".png") visualize_mol(node, path=mol_img_path) self._dot.node(name=node.to_smiles(), label="", image=mol_img_path, shape="plaintext")
def __init__(self, mol: Molecule, draw_mode: str): """ :param mol: the molecule to draw synthesis path for :param draw_mode: "smiles" | "formula" | "plot" way of plotting each single molecule Examples:: >>> drawer = SynPathDrawer(root_mol, "smiles") # or "formula" or "plot" >>> drawer.render("some_output_dir/some_file_name") # please, no file extension """ assert draw_mode in ["smiles", "formula", "plot"] from graphviz import Digraph self._mol = mol self._dot = Digraph(comment="Synthesis path for {}".format( mol.to_smiles()), format="pdf") self._draw_mode = draw_mode self._node_counter = 0 self._sub_dir = None
def _draw_edge(self, tail: Molecule, head: Molecule): self._dot.edge(tail_name=tail.to_smiles(), head_name=head.to_smiles())