Diagram
ehreact.diagram contains custom classes for Hasse diagrams, as well as functions to plot a Hasse diagram to file.
Diagram
Classes and functions from ehreact.diagram.diagram.py.
- class ehreact.diagram.diagram.Diagram[source]
Custom-made diagram class for extended Hasse diagrams.
- Variables:
nodes (dict) – Dictionary of all nodes.
root (ehreact.diagram.diagram.Node) – Root node.
mode (str) – Mode in which diagram was calculated.
- add_node(key_node, rule, is_leaf, key_parent_node, quiet)[source]
Function to add a new node to the diagram.
- Parameters:
key_node (str) – Key of the newly created node.
rule (rdkit.Chem.Mol) – RDKit molecule of the substructure/reaction rule of the node
is_leaf (bool) – Boolean whether new node is a leaf node.
key_parent_node (str) – Key of the parent node of the newly created node.
- delete_edges_around_node(key_node)[source]
Function to remove a node from the diagram, with removing all edges. The node will still be saved in the diagram, but without any edges connected to it. This is only meaningful for plotting, not a useful function elsewhere!
- Parameters:
key_node (str) – Key of the node that is to be removed.
- insert_node(key_node, rule, is_leaf, key_parent_node, key_child_node)[source]
Function to insert a node between an existing parent-child pair.
- Parameters:
key_node (str) – Key of the newly created node.
rule (rdkit.Chem.Mol) – RDKit molecule of the substructure/reaction rule of the node
is_leaf (bool) – Boolean whether new node is a leaf node.
key_parent_node (str) – Key of the parent node of the newly created node.
key_child_node (str) – Key of the child node of the newly created node.
- class ehreact.diagram.diagram.Edge(parent_node, child_node)[source]
An Edge connecting the parent to the child node.
- Variables:
parent_node (ehreact.diagram.diagram.Node) – Parent node of the edge (more general template).
child_node (ehreact.diagram.diagram.Node) – Child node of the edge (more specific template).
- class ehreact.diagram.diagram.Node(key, rule, is_leaf)[source]
A Node holding information to which parent and child(s) it relates to, which rule it was derived from and additional data.
- Variables:
edges_to_child (List[ehreact.diagram.diagram.Edge]) – List of edges to child nodes.
edges_to_parent (listList[ehreact.diagram.diagram.Edge]) – List of edges to parent nodes.
key (str) – Name of node.
is_leaf (bool) – Whether the node is a leaf node (has no children).
rule (rdkit.Chem.Mol) – RDKit molecule object of template (molecule or pseudomolecule).
rule_reac (rdkit.Chem.Mol) – RDKit molecule object of reactant side of template (for transition state mode).
rule_prod (rdkit.Chem.Mol) – RDKit molecule object of product side of template (for transition state mode).
all_leafs (List[str]) – List of all SMILES strings of leaf nodes.
min_dist_leafs (int) – Minimum distance to nearest leaf node.
fp_reac (List[rdkit.DataStructs.cDataStructs.ExplicitBitVect]) – List of fingerprints of reactants without stereoinformation.
fp_reac_stereo (List[rdkit.DataStructs.cDataStructs.ExplicitBitVect]) – List of fingerprints of reactants with stereoinformation.
fp_prod (List[rdkit.DataStructs.cDataStructs.ExplicitBitVect]) – List of fingerprints of products without stereoinformation.
fp_prod_stereo (List[rdkit.DataStructs.cDataStructs.ExplicitBitVect]) – List of fingerprints of products with stereoinformation.
diversity_reac (float) – Mean pair similarity of all reactants of leaf nodes in the branch without stereoinformation.
diversity_prod (float) – Mean pair similarity of all products of leaf nodes in the branch without stereoinformation.
diversity_reac_stereo (float) – Mean pair similarity of all reactants of leaf nodes in the branch with stereoinformation.
diversity_prod_stereo (float) – Mean pair similarity of all products of leaf nodes in the branch with stereoinformation.
tags_core (List[str]) – A list of the atom map numbers in the reaction center.
fragment_reac (dict) – A dictionary of fragments for a reaction.
change_dict (dict) – A dictionary of all changes upon going from reactants to products.
lowest_template (str) – Name of the lowest template of the current branch.
- create_new_node(rule, is_leaf)[source]
Function to create a new node.
- Parameters:
key (str) – Key of the newly created node.
rule (rdkit.Chem.Mol) – RDKit molecule of the substructure/reaction rule of the node
is_leaf (bool) – Boolean whether new node is a leaf node.
- Returns:
A new node
- Return type:
Plot Hasse
Classes and functions from ehreact.diagram.plot_hasse.py
- ehreact.diagram.plot_hasse.double_quoted(s)[source]
Function to put double quotes around a string.
- Parameters:
s (str) – String.
- Returns:
String in double quotes.
- Return type:
str
- ehreact.diagram.plot_hasse.draw_mol(mol, path, change_dict)[source]
Function to transform and draw a smiles string using rdkit.
- Parameters:
mol (rdkit.Chem.Mol) – RDKit molecule.
path (str) – Path to which a PNG image is saved.
change_dict (dict) – A dictionary of all changes upon going from reactants to products.
- ehreact.diagram.plot_hasse.plot_hasse(d, temp_dir_img, save_plot, plot_only_branches)[source]
Function to plot a Hasse diagram.
- Parameters:
d (ehreact.diagram.diagram.Diagram) – A Hasse diagram.
temp_dir_img (str) – Directory to save images to temporarily.
save_plot (str) – File name to save PNG image to.
plot_only_branches (bool) – Whether to remove linear chain nodes.
- ehreact.diagram.plot_hasse.plot_iteration(temp_dir_img, d, smiles, mol, is_leaf, file_numbers, seed)[source]
Recursive function to plot the diagram. Per call, all current child nodes and corresponding edges are plotted.
- Parameters:
temp_dir_img (str) – Directory to save images to temporarily.
d (ehreact.diagram.diagram.Diagram) – A Hasse diagram.
smiles (str) – SMILES string of the current node.
mol (rdkit.Chem.Mol) – RDKit molecule to be drawn.
is_leaf (bool) – Whether the current node is a leaf node.
file_numbers (int) – Consecutive file identifier.
seed (int) – Name of the minimal template of the current branch.
- ehreact.diagram.plot_hasse.remove_linear_chains(d)[source]
Function to remove nodes that have exactly one parent and one child.
- Parameters:
d (ehreact.diagram.diagram.Diagram) – A Hasse diagram.
- Returns:
d – The modified Hasse diagram without linear chain nodes.
- Return type:
- ehreact.diagram.plot_hasse.run_dot(temp_dir_img, save_plot)[source]
Runs graphviz to plot the Hasse diagram.
- Parameters:
temp_dir_img (str) – Directory to save images to temporarily.
save_plot (str) – File name to save PNG image to.
- ehreact.diagram.plot_hasse.write_beginning_dotfile(temp_dir_img)[source]
Write the beginning of the dotfile (graphviz input).
- Parameters:
temp_dir_img (str) – Directory to save images to temporarily.
- ehreact.diagram.plot_hasse.write_edge(temp_dir_img, smiles1, smiles2)[source]
Function to write a single edge information to the image specification file
- Parameters:
temp_dir_img (str) – Directory to save images to temporarily.
smiles1 (str) – SMILES string of the parent node.
smiles2 (str) – SMILES string of the child node.
- ehreact.diagram.plot_hasse.write_end_dotfile(temp_dir_img)[source]
Write the end of the dotfile (graphviz input).
- Parameters:
temp_dir_img (str) – Directory to save images to temporarily.
- ehreact.diagram.plot_hasse.write_node(temp_dir_img, smiles, mol, is_leaf, file_numbers, change_dict)[source]
Function to write a single node information to the image specification file
- Parameters:
temp_dir_img (str) – Directory to save images to temporarily.
smiles (str) – SMILES string of the current node.
mol (rdkit.Chem.Mol) – RDKit molecule to be drawn.
is_leaf (bool) – Whether the current node is a leaf node.
file_numbers (int) – Consecutive file identifier.
change_dict (dict) – A dictionary of all changes upon going from reactants to products.