tqchem.molgraph =============== .. py:module:: tqchem.molgraph Classes ------- .. autoapisummary:: tqchem.molgraph.MolecularSystem Functions --------- .. autoapisummary:: tqchem.molgraph.molecule_from_ase tqchem.molgraph.molecule_from_rdkit tqchem.molgraph.molecule_from_file tqchem.molgraph.molecule_from_smiles tqchem.molgraph.molecularSystem tqchem.molgraph.drawGraph tqchem.molgraph.tree_from_graph tqchem.molgraph.longest_path_in_tree tqchem.molgraph.ase_to_graph tqchem.molgraph.remove_cycle_overlap tqchem.molgraph.residual_trees tqchem.molgraph.cycle_bridge_tree_decomposition tqchem.molgraph.dfs_sweep tqchem.molgraph.in_list_of_lists tqchem.molgraph.index_list_of_lists tqchem.molgraph.component_type tqchem.molgraph.sorted_components tqchem.molgraph.get_root tqchem.molgraph.sorted_ring tqchem.molgraph.sort_tree_component tqchem.molgraph.open_multiring_graph tqchem.molgraph.sorted_atoms_within_components tqchem.molgraph.get_component_sweep tqchem.molgraph.get_component_of_atom tqchem.molgraph.linearized_component_sweep tqchem.molgraph.get_start_frame tqchem.molgraph.get_path tqchem.molgraph.is_node_in_cycle tqchem.molgraph.split_bond_to_components tqchem.molgraph.split_bond_to_subgraphs tqchem.molgraph.bond_component tqchem.molgraph.is_terminal_atom_bond tqchem.molgraph.is_edge_in_cycle tqchem.molgraph.is_single_bond_from_cycle tqchem.molgraph.is_single_bond tqchem.molgraph.set_rotatable_bond_grids Module Contents --------------- .. py:class:: 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 .. attribute:: graph representation of the molecule by atoms & bonds. :type: nx.Graph .. attribute:: 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 .. attribute:: component_sweep List containing the components (rings, bridges, trees) as list of atom indices :type: list[list[int]] .. method:: component_type: Get type (ring, batframe, bridge) for a given component .. method:: draw: Draw molecular graph in initial and/or opened form .. method:: root: Get root atom of the graph .. method:: copy: Deepcopy of the molecular object .. method:: write: Write geometry to file. Wrapper for ase.io.write .. method:: get_positions: Get atomic positions. Wrapper for ase.atoms.get_positions .. method:: get_path: Get path from the root of the graph to a given atom .. py:attribute:: ase :type: _typeshed.Incomplete .. py:attribute:: graph :type: _typeshed.Incomplete .. py:attribute:: open_graph :type: _typeshed.Incomplete .. py:attribute:: component_sweep :type: _typeshed.Incomplete .. py:method:: component_type(component: list[int]) -> str For a given component return if it's a batframe, ring or bridge .. py:method:: draw(graph: bool = True, open_graph: bool = False) -> None Draw the graph and/or the open graph of the system using matplotlib .. py:method:: root() -> int Return root node of the graph .. py:method:: copy() -> MolecularSystem Deepcopy of the molecular system .. py:method:: write(filename) -> None Wrapper for ase.io.write .. py:method:: get_positions() Return atomic positions of the molecule .. py:method:: get_path(atom: int) -> list[int] Get path from the root node to the given atom/node-id .. py:method:: add_rotatable_bonds(bond_grids=...) -> None Set bonds to be rotatable, but don't overwrite previously rotatable bonds .. py:method:: overwrite_rotatable_bonds(bond_grids=...) -> None Unset all rotatable bonds and only set the ones specified in the dict .. py:method:: set_bond_orders() -> None Determine Bond orders and set them as edge attributes .. py:method:: 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 :param include_amide_bonds: Include amide bonds as rotatable bonds :type include_amide_bonds: bool = False, :param add_rotatable_bonds: Adds rotatable bonds to the default ones in terms of a dict relating bonds to an array of allowed dihedral values :type add_rotatable_bonds: dict[tuple[int, int], np.array] = None, :param set_rotatable_bonds: Overwrites rotatable bonds with a dict relating bonds to an array of allowed dihedral values :type set_rotatable_bonds: dict[tuple[int, int], np.array] = None, :param amide_grid: Grid of allowed dihedral values for amide bonds :type amide_grid: np.array, default=[0.0, 180.0] :param amino_grid: Grid of allowed dihedral values for amino bods :type amino_grid: np.array, default=[0, 60, 120, 180, 240, 300] :param alkane_grid: Grid of allowed dihedral values for alkane bonds :type alkane_grid: np.array, default=[0, 60, 120, 180, 240, 300] :param t_butyl_grid: Grid of allowed dihedral values for t_butyl :type t_butyl_grid: np.array, default=[0.0, 60.0] :param iso_propyl_grid: Grid of allowed dihedral values for iso_propyl :type iso_propyl_grid: np.array, default=[0.0, 60.0, 120.0] :param chalcogen_grid: Grid of allowed dihedral values for chalcogen bonds :type chalcogen_grid: np.array, default=[0, 60, 120, 180, 240, 300] :param default_grid: Grid of allowed dihedral values for all other bonds :type default_grid: np.array, default=[0, 30, 60, 90, 120, 150, 180, 210, 240, 270, 300, 330] :param overwrite_grids: Overwrite all bond specific grids with this grid :type overwrite_grids: np.array, default=None .. py:function:: molecule_from_ase(mol_ase: ase.Atoms, single_batframe: bool = False) -> MolecularSystem Construct MolecularSystem from ase.Atoms object. :param mol_ase: The molecular system :type mol_ase: ase.Atoms :param single_batframe: Use a single batframe for the entire molecule instead of using special puckering coordinates for the rings :type single_batframe: bool = False, :rtype: MolecularSystem .. py:function:: molecule_from_rdkit(rd_mol: rdkit.Chem.Mol, single_batframe: bool = False) -> MolecularSystem Construct MolecularSystem from rdkit.Mol object. :param rd_mol: Rdkit Molecule object :type rd_mol: Chem.Mol :param single_batframe: Use a single batframe for the entire molecule instead of using special puckering coordinates for the rings :type single_batframe: bool = False, .. py:function:: molecule_from_file(file_: str | pathlib.Path, format_: str = None, single_batframe: bool = False) -> MolecularSystem Construct MolecularSystem from molecule file. :param file_: Path to molecule file :type file_: Path | str, :param format_: File format in case the input is a str or Path and the format cannot be inferred from the file suffix. :type format_: str = None, :param single_batframe: Use a single batframe for the entire molecule instead of using special puckering coordinates for the rings :type single_batframe: bool = False, .. py:function:: molecule_from_smiles(smiles: str, single_batframe: bool = False) -> MolecularSystem Construct MolecularSystem from SMILES string. :param smiles: Smiles string :type smiles: str :param single_batframe: Use a single batframe for the entire molecule instead of using special puckering coordinates for the rings :type single_batframe: bool = False, .. py:function:: molecularSystem(input_: pathlib.Path | str | ase.Atoms | rdkit.Chem.Mol, format_: str = None, single_batframe: bool = False) -> MolecularSystem Smart factory for MolecularSystem :param input_: Input for the molecular system :type input_: Path | str | ase.Atoms | Chem.Mol, :param format_: File format in case the input is a str or Path and the format cannot be inferred from the file suffix. :type format_: str = None, :param single_batframe: Use a single batframe for the entire molecule instead of using special puckering coordinates for the rings :type single_batframe: bool = False, :rtype: MolecularSystem .. py:function:: drawGraph(graph: networkx.Graph) -> None Visualize the graph used for the molecule :param graph: Graph representing the molecule :type graph: nx.Graph .. py:function:: tree_from_graph(graph: networkx.Graph) -> networkx.Graph Make tree from graph by opening cycles in the graph :param graph: Graph representing the molecule :type graph: nx.Graph :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. .. py:function:: longest_path_in_tree(tree: networkx.Graph) -> list[int] Find longest path going from one end of the tree to the other :param tree: Tree representing the molecule :type tree: nx.Graph :returns: **longest_path** -- Longest path in the tree as a list of nodes :rtype: list[int] .. py:function:: ase_to_graph(molecule: ase.Atoms) -> networkx.Graph Convert an ase molecule to a networkx graph :param molecule: Atoms representing the molecule :type molecule: ase.Atoms :returns: **graph** -- networkx Graph representing the connectivities in the molecule :rtype: nx.Graph .. py:function:: remove_cycle_overlap(cycles: list[list[int]]) -> list[list[int]] Remove overlap between cycles. :param cycles: list of lists containing the nodes that each cycle consits of :type cycles: list[list[int]] :returns: **orthogonal_cycles** -- list of lists containing the cycle nodes, but without duplicate nodes :rtype: list[list[int]] .. py:function:: residual_trees(graph: networkx.Graph, cycles_bridges: list[list[int]]) -> list[list[int]] Find remaining trees in the graph after removing cycles and bridges. .. py:function:: cycle_bridge_tree_decomposition(graph: networkx.Graph) -> list[list[int]] Decompose a graph into cycles, bridges, and trees .. py:function:: dfs_sweep(graph: networkx.Graph) perform a depth-first search and return the sweep order .. py:function:: in_list_of_lists(element: Any, list_of_lists: list[list[Any]]) -> bool .. py:function:: index_list_of_lists(element: Any, list_of_lists: list[list[Any]]) -> int .. py:function:: component_type(component: list[int], graph: networkx.Graph) -> str Determine whether component is a ring, bridge, or tree. .. py:function:: sorted_components(components: list[list[int]], sweep: list[int]) -> list[list[int]] Sort components according to order in sweep .. py:function:: get_root(component_sweep: list[list[int]]) -> int Get the root of the graph which serves as the beginning of the sweep .. py:function:: 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. .. py:function:: sort_tree_component(component: list[int], sweep: list[int]) Sort the tree component according to the sweep order .. py:function:: open_multiring_graph(graph: networkx.Graph) -> networkx.Graph Open multirings (overlapping rings) of a graph to simple rings .. py:function:: sorted_atoms_within_components(components, sweep, graph) Sort atoms within components according to sweep order. .. py:function:: get_component_sweep(graph: networkx.Graph, single_batframe: bool = False) Determine the component sweep based on the graph representation of the molecule. .. py:function:: get_component_of_atom(atom: int, component_sweep: list[list[int]]) Return the component in which the atom is. .. py:function:: linearized_component_sweep(component_sweep: list[list[int]]) -> list[int] Convert component sweep to simple list .. py:function:: 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 .. py:function:: 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. .. py:function:: is_node_in_cycle(graph: networkx.Graph, node: int) -> bool .. py:function:: 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 :param bond: Bond where graph should be split :type bond: tuple[int, int] :param graph: graph that should be split :type graph: nx.Graph :returns: **components** -- A generator of sets of nodes, one for each component of G. :rtype: generator of sets .. py:function:: split_bond_to_subgraphs(bond: tuple[int, int], graph: networkx.Graph) -> networkx.Graph Split graph at the specified bond and return the connected subgraphs .. py:function:: 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 .. py:function:: 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 .. py:function:: is_edge_in_cycle(edge: tuple[int, int], cycles: list[list[int]]) -> bool Are both atoms of an edge inside a single cycle .. py:function:: 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 .. py:function:: is_single_bond(bond_order: float) Is the bond order below a set threshold .. py:function:: 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