tqchem.molgraph

Classes

MolecularSystem

Class representing a system of one or more molecules.

Functions

molecule_from_ase(→ MolecularSystem)

Construct MolecularSystem from ase.Atoms object.

molecule_from_rdkit(→ MolecularSystem)

Construct MolecularSystem from rdkit.Mol object.

molecule_from_file(→ MolecularSystem)

Construct MolecularSystem from molecule file.

molecule_from_smiles(→ MolecularSystem)

Construct MolecularSystem from SMILES string.

molecularSystem(→ MolecularSystem)

Smart factory for MolecularSystem

drawGraph(→ None)

Visualize the graph used for the molecule

tree_from_graph(→ networkx.Graph)

Make tree from graph by opening cycles in the graph

longest_path_in_tree(→ list[int])

Find longest path going from one end of the tree to the other

ase_to_graph(→ networkx.Graph)

Convert an ase molecule to a networkx graph

remove_cycle_overlap(→ list[list[int]])

Remove overlap between cycles.

residual_trees(→ list[list[int]])

Find remaining trees in the graph after removing cycles and bridges.

cycle_bridge_tree_decomposition(→ list[list[int]])

Decompose a graph into cycles, bridges, and trees

dfs_sweep(graph)

perform a depth-first search and return the sweep order

in_list_of_lists(→ bool)

index_list_of_lists(→ int)

component_type(→ str)

Determine whether component is a ring, bridge, or tree.

sorted_components(→ list[list[int]])

Sort components according to order in sweep

get_root(→ int)

Get the root of the graph which serves as the beginning of the sweep

sorted_ring(→ list[int])

Sort the ring so that the first element connects to previous component.

sort_tree_component(component, sweep)

Sort the tree component according to the sweep order

open_multiring_graph(→ networkx.Graph)

Open multirings (overlapping rings) of a graph to simple rings

sorted_atoms_within_components(components, sweep, graph)

Sort atoms within components according to sweep order.

get_component_sweep(graph[, single_batframe])

Determine the component sweep based on the graph representation of the molecule.

get_component_of_atom(atom, component_sweep)

Return the component in which the atom is.

linearized_component_sweep(→ list[int])

Convert component sweep to simple list

get_start_frame(→ list[int])

Get first 3 (or less) atoms of the component sweep

get_path(→ list[int])

Find path from root to node, or the start frame if the path is shorter than 3.

is_node_in_cycle(→ bool)

split_bond_to_components(→ set[int])

Split graph at the specified bond and return the resulting connected components

split_bond_to_subgraphs(→ networkx.Graph)

Split graph at the specified bond and return the connected subgraphs

bond_component(→ set[int])

Split graph at bond and return component that contains the specified element

is_terminal_atom_bond(→ bool)

Is the edge an edge to a single atom at some end of the graph

is_edge_in_cycle(→ bool)

Are both atoms of an edge inside a single cycle

is_single_bond_from_cycle(→ bool)

Is exactly one of the atoms in a cycle and the bond order below a threshold

is_single_bond(bond_order)

Is the bond order below a set threshold

set_rotatable_bond_grids(→ None)

Assign grid to rotatable bonds in the graph

Module Contents

class tqchem.molgraph.MolecularSystem(molecule: MolecularSystem = None)

Class representing a system of one or more molecules.

Serves as the central management class in tqchem, containing an ase.Atoms object for energy evaluations and setting dihedral values, the molecular graph and an opened version of the graph, where either multirings are opened to single rings are opened or the entire graph is opened to a tree. Additionally it contains the component sweep directing the iteration through the components (rings, batframes, bridges) of the graph

graph

representation of the molecule by atoms & bonds.

Type:

nx.Graph

open_graph

graph with removed bonds to remove multirings in case of fragmentation or open the entire graph to a tree in case of fragmentation turned off

Type:

nx.Graph

component_sweep

List containing the components (rings, bridges, trees) as list of atom indices

Type:

list[list[int]]

component_type:

Get type (ring, batframe, bridge) for a given component

draw:

Draw molecular graph in initial and/or opened form

root:

Get root atom of the graph

copy:

Deepcopy of the molecular object

write:

Write geometry to file. Wrapper for ase.io.write

get_positions:

Get atomic positions. Wrapper for ase.atoms.get_positions

get_path:

Get path from the root of the graph to a given atom

ase: _typeshed.Incomplete
graph: _typeshed.Incomplete
open_graph: _typeshed.Incomplete
component_sweep: _typeshed.Incomplete
component_type(component: list[int]) str

For a given component return if it’s a batframe, ring or bridge

draw(graph: bool = True, open_graph: bool = False) None

Draw the graph and/or the open graph of the system using matplotlib

root() int

Return root node of the graph

copy() MolecularSystem

Deepcopy of the molecular system

write(filename) None

Wrapper for ase.io.write

get_positions()

Return atomic positions of the molecule

get_path(atom: int) list[int]

Get path from the root node to the given atom/node-id

add_rotatable_bonds(bond_grids=...) None

Set bonds to be rotatable, but don’t overwrite previously rotatable bonds

overwrite_rotatable_bonds(bond_grids=...) None

Unset all rotatable bonds and only set the ones specified in the dict

set_bond_orders() None

Determine Bond orders and set them as edge attributes

set_rotatable_bond_grids(include_amide_bonds: bool = False, add_rotatable_bonds: dict[tuple[int, int], numpy.array] = None, set_rotatable_bonds: dict[tuple[int, int], numpy.array] = None, amide_grid: numpy.array = None, amino_grid: numpy.array = None, alkane_grid: numpy.array = None, t_butyl_grid: numpy.array = None, iso_propyl_grid: numpy.array = None, chalcogen_grid: numpy.array = None, default_grid: numpy.array = None, overwrite_grids: numpy.array = None) None

Determine rotatable bonds in the system and assign corresponding bond grids

Parameters:
  • include_amide_bonds (bool = False,) – Include amide bonds as rotatable bonds

  • add_rotatable_bonds (dict[tuple[int, int], np.array] = None,) – Adds rotatable bonds to the default ones in terms of a dict relating bonds to an array of allowed dihedral values

  • set_rotatable_bonds (dict[tuple[int, int], np.array] = None,) – Overwrites rotatable bonds with a dict relating bonds to an array of allowed dihedral values

  • amide_grid (np.array, default=[0.0, 180.0]) – Grid of allowed dihedral values for amide bonds

  • amino_grid (np.array, default=[0, 60, 120, 180, 240, 300]) – Grid of allowed dihedral values for amino bods

  • alkane_grid (np.array, default=[0, 60, 120, 180, 240, 300]) – Grid of allowed dihedral values for alkane bonds

  • t_butyl_grid (np.array, default=[0.0, 60.0]) – Grid of allowed dihedral values for t_butyl

  • iso_propyl_grid (np.array, default=[0.0, 60.0, 120.0]) – Grid of allowed dihedral values for iso_propyl

  • chalcogen_grid (np.array, default=[0, 60, 120, 180, 240, 300]) – Grid of allowed dihedral values for chalcogen bonds

  • default_grid (np.array, default=[0, 30, 60, 90, 120, 150, 180, 210, 240, 270, 300, 330]) – Grid of allowed dihedral values for all other bonds

  • overwrite_grids (np.array, default=None) – Overwrite all bond specific grids with this grid

tqchem.molgraph.molecule_from_ase(mol_ase: ase.Atoms, single_batframe: bool = False) MolecularSystem

Construct MolecularSystem from ase.Atoms object.

Parameters:
  • mol_ase (ase.Atoms) – The molecular system

  • single_batframe (bool = False,) – Use a single batframe for the entire molecule instead of using special puckering coordinates for the rings

Return type:

MolecularSystem

tqchem.molgraph.molecule_from_rdkit(rd_mol: rdkit.Chem.Mol, single_batframe: bool = False) MolecularSystem

Construct MolecularSystem from rdkit.Mol object.

Parameters:
  • rd_mol (Chem.Mol) – Rdkit Molecule object

  • single_batframe (bool = False,) – Use a single batframe for the entire molecule instead of using special puckering coordinates for the rings

tqchem.molgraph.molecule_from_file(file_: str | pathlib.Path, format_: str = None, single_batframe: bool = False) MolecularSystem

Construct MolecularSystem from molecule file.

Parameters:
  • file (Path | str,) – Path to molecule file

  • format (str = None,) – File format in case the input is a str or Path and the format cannot be inferred from the file suffix.

  • single_batframe (bool = False,) – Use a single batframe for the entire molecule instead of using special puckering coordinates for the rings

tqchem.molgraph.molecule_from_smiles(smiles: str, single_batframe: bool = False) MolecularSystem

Construct MolecularSystem from SMILES string.

Parameters:
  • smiles (str) – Smiles string

  • single_batframe (bool = False,) – Use a single batframe for the entire molecule instead of using special puckering coordinates for the rings

tqchem.molgraph.molecularSystem(input_: pathlib.Path | str | ase.Atoms | rdkit.Chem.Mol, format_: str = None, single_batframe: bool = False) MolecularSystem

Smart factory for MolecularSystem

Parameters:
  • input (Path | str | ase.Atoms | Chem.Mol,) – Input for the molecular system

  • format (str = None,) – File format in case the input is a str or Path and the format cannot be inferred from the file suffix.

  • single_batframe (bool = False,) – Use a single batframe for the entire molecule instead of using special puckering coordinates for the rings

Return type:

MolecularSystem

tqchem.molgraph.drawGraph(graph: networkx.Graph) None

Visualize the graph used for the molecule

Parameters:

graph (nx.Graph) – Graph representing the molecule

tqchem.molgraph.tree_from_graph(graph: networkx.Graph) networkx.Graph

Make tree from graph by opening cycles in the graph

Parameters:

graph (nx.Graph) – Graph representing the molecule

Returns:

  • oepn_graph (nx.Graph) – Copy of the Graph with opened cycles

  • @todo (a clear greedy algorithm for maintaining the longest path in the tree) – might be preferable. The current implementation just arbitrarily removes edges until no cycles are left.

tqchem.molgraph.longest_path_in_tree(tree: networkx.Graph) list[int]

Find longest path going from one end of the tree to the other

Parameters:

tree (nx.Graph) – Tree representing the molecule

Returns:

longest_path – Longest path in the tree as a list of nodes

Return type:

list[int]

tqchem.molgraph.ase_to_graph(molecule: ase.Atoms) networkx.Graph

Convert an ase molecule to a networkx graph

Parameters:

molecule (ase.Atoms) – Atoms representing the molecule

Returns:

graph – networkx Graph representing the connectivities in the molecule

Return type:

nx.Graph

tqchem.molgraph.remove_cycle_overlap(cycles: list[list[int]]) list[list[int]]

Remove overlap between cycles.

Parameters:

cycles (list[list[int]]) – list of lists containing the nodes that each cycle consits of

Returns:

orthogonal_cycles – list of lists containing the cycle nodes, but without duplicate nodes

Return type:

list[list[int]]

tqchem.molgraph.residual_trees(graph: networkx.Graph, cycles_bridges: list[list[int]]) list[list[int]]

Find remaining trees in the graph after removing cycles and bridges.

tqchem.molgraph.cycle_bridge_tree_decomposition(graph: networkx.Graph) list[list[int]]

Decompose a graph into cycles, bridges, and trees

tqchem.molgraph.dfs_sweep(graph: networkx.Graph)

perform a depth-first search and return the sweep order

tqchem.molgraph.in_list_of_lists(element: Any, list_of_lists: list[list[Any]]) bool
tqchem.molgraph.index_list_of_lists(element: Any, list_of_lists: list[list[Any]]) int
tqchem.molgraph.component_type(component: list[int], graph: networkx.Graph) str

Determine whether component is a ring, bridge, or tree.

tqchem.molgraph.sorted_components(components: list[list[int]], sweep: list[int]) list[list[int]]

Sort components according to order in sweep

tqchem.molgraph.get_root(component_sweep: list[list[int]]) int

Get the root of the graph which serves as the beginning of the sweep

tqchem.molgraph.sorted_ring(ring: list[int], component_sweep: list[list[int]], molgraph: networkx.Graph) list[int]

Sort the ring so that the first element connects to previous component.

tqchem.molgraph.sort_tree_component(component: list[int], sweep: list[int])

Sort the tree component according to the sweep order

tqchem.molgraph.open_multiring_graph(graph: networkx.Graph) networkx.Graph

Open multirings (overlapping rings) of a graph to simple rings

tqchem.molgraph.sorted_atoms_within_components(components, sweep, graph)

Sort atoms within components according to sweep order.

tqchem.molgraph.get_component_sweep(graph: networkx.Graph, single_batframe: bool = False)

Determine the component sweep based on the graph representation of the molecule.

tqchem.molgraph.get_component_of_atom(atom: int, component_sweep: list[list[int]])

Return the component in which the atom is.

tqchem.molgraph.linearized_component_sweep(component_sweep: list[list[int]]) list[int]

Convert component sweep to simple list

tqchem.molgraph.get_start_frame(component_sweep: list[list[int]]) list[int]

Get first 3 (or less) atoms of the component sweep

If the component sweep contains 3 or more atoms return these, otherwise return as many as possible

tqchem.molgraph.get_path(molgraph: networkx.Graph, component_sweep: list[list[int]], root: int, node: int) list[int]

Find path from root to node, or the start frame if the path is shorter than 3.

This routine provides the path of “root” to “node” used to setup coordinate systems.

tqchem.molgraph.is_node_in_cycle(graph: networkx.Graph, node: int) bool
tqchem.molgraph.split_bond_to_components(bond: tuple[int, int], graph: networkx.Graph) set[int]

Split graph at the specified bond and return the resulting connected components

Parameters:
  • bond (tuple[int, int]) – Bond where graph should be split

  • graph (nx.Graph) – graph that should be split

Returns:

components – A generator of sets of nodes, one for each component of G.

Return type:

generator of sets

tqchem.molgraph.split_bond_to_subgraphs(bond: tuple[int, int], graph: networkx.Graph) networkx.Graph

Split graph at the specified bond and return the connected subgraphs

tqchem.molgraph.bond_component(bond: tuple[int, int], element_in_component: int, graph: networkx.Graph) set[int]

Split graph at bond and return component that contains the specified element

tqchem.molgraph.is_terminal_atom_bond(graph: networkx.Graph, edge: tuple[int, int]) bool

Is the edge an edge to a single atom at some end of the graph

tqchem.molgraph.is_edge_in_cycle(edge: tuple[int, int], cycles: list[list[int]]) bool

Are both atoms of an edge inside a single cycle

tqchem.molgraph.is_single_bond_from_cycle(edge: tuple[int, int, dict[str, Any]], cycles: list[list[int]]) bool

Is exactly one of the atoms in a cycle and the bond order below a threshold

This is used because single bonds from aromatic cycles can be very close to

tqchem.molgraph.is_single_bond(bond_order: float)

Is the bond order below a set threshold

tqchem.molgraph.set_rotatable_bond_grids(graph: networkx.Graph, bond_type_grids: dict[str, numpy.ndarray], include_amide_bonds: bool) None

Assign grid to rotatable bonds in the graph

Bonds in cycles are currently excluded because rotations around those lead to a rotation of the entire molecule around this bond.

Parameters:

bond_type_grids: dict[str, np.ndarray],

Specify the grid (allowed dihedral values) for specific bond types: default_grid, chalcogen_grid, amino_grid, alkane_grid, t_butyl_grid, iso_propyl_grid, amide_grid

include_amide_bonds: bool

Include amide bonds as rotatable bonds