Molecular Graphs#

class autode.mol_graphs.MolecularGraph(incoming_graph_data=None, **attr)#
property active_bonds: List[Tuple[int, int]]#

Extract the active bonds from the graph into a flat list of pairs of atom indices

add_active_edge(u: int, v: int) None#

Add an ‘active’ edge between two atoms, where an active edge is one that is made or broken in a reaction

connected_components()#

Generate the separate connected components

property eqm_bond_distance_matrix: ndarray#

An n_atoms x n_atoms matrix of ideal bond lengths. All non-bonded atoms will have zero ideal bond lengths

property expected_planar_geometry: bool#

Is the 3D structure of the molecule corresponding to this graph expected to be planar?

property is_connected: bool#

Is this graph fully connected (i.e. not separate parts)

is_isomorphic_to(other: MolecularGraph) bool#

Is this graph isomorphic to another?

property node_matcher#

Default node matcher

autode.mol_graphs.connected_components(graph)#

Connected sections of the nx.Graph

autode.mol_graphs.find_cycles(graph)#

Finds all the cycles in a graph

Returns:

each list has the atoms in a cycle

Return type:

list(list)

autode.mol_graphs.get_bond_type_list(graph)#

Finds the types (i.e CH) of all the bonds in a molecular graph

Returns:

key = bond type, value = list of bonds of this

type

Return type:

bond_list_dict (dict)

autode.mol_graphs.get_fbonds(graph, key)#

Get all the possible forming bonds of a certain type

Parameters:

key (str) – string representing the bond type to be examined

Returns:

list of bonds that can be made of this type

Return type:

list

autode.mol_graphs.get_graph_no_active_edges(graph)#

Get a molecular graph without the active edges

Return type:

(nx.Graph)

autode.mol_graphs.get_graphs_ignoring_active_edges(graph1, graph2)#

Remove any active edges that are in either graph1 or graph2 from both graphs

Parameters:

graph2 (nx.Graph) –

Returns:

(tuple(nx.Graph))

autode.mol_graphs.get_mapping(graph1, graph2)#

Get a sorted mapping of nodes between two graphs

Parameters:

graph2 (nx.Graph) –

Returns:

(dict)

autode.mol_graphs.get_mapping_ts_template(larger_graph: MolecularGraph, smaller_graph: MolecularGraph)#

Find the mapping for a graph onto a TS template (smaller). Can raise StopIteration with no match!

Parameters:

smaller_graph (nx.Graph) –

Returns:

Mapping

Return type:

(dict)

autode.mol_graphs.get_separate_subgraphs(graph)#

Find all the unconnected graphs in a graph

Returns:

list of graphs separate graphs

Return type:

list

autode.mol_graphs.get_truncated_active_mol_graph(graph, active_bonds=None)#

Generate a truncated graph of a graph that only contains the active bond atoms and their nearest neighbours

Parameters:

active_bonds (list(tuple(int)) –

autode.mol_graphs.gm_is_isomorphic(gm, result)#
autode.mol_graphs.graph_matcher(graph1: MolecularGraph, graph2: MolecularGraph)#

Generate a networkX graph matcher between two graphs, matching on atom types and active bonds

Parameters:

graph2 (nx.Graph) –

Returns:

(nx.GraphMatcher)

autode.mol_graphs.is_subgraph_isomorphic(larger_graph: MolecularGraph, smaller_graph: MolecularGraph)#

Is the smaller graph subgraph isomorphic to the larger graph?

Parameters:

smaller_graph (nx.Graph) –

Returns:

(bool)

autode.mol_graphs.make_graph(species: Species, rel_tolerance: float = 0.3, bond_list: List[tuple] | None = None, allow_invalid_valancies: bool = False) None#

Make the molecular graph from the ‘bonds’ determined on a distance criteria or a SMILES parser object. All attributes default to false:

Nodes attributes;
    (0) atom_label: Atomic symbol of this atom
    (1) stereo: Is this atom part of some stereochemistry e.g. R/S or
                E/Z

Edge attributes;
    (1) pi: Is this bond a pi bond. If it is then there should be no
            rotation the bond axis in conformer generation
    (2) active: Is this bond being made/broken
               (applies only to TransitionState objects)

0.3 means anything 1.3 x r0(i, j) is not ‘bonded’. Subject to the other restrictions on valency

Parameters:
  • bond_list – Explicit bonds between atoms, overriding any attempt to evaluate bonds

  • allow_invalid_valancies – Should invalid atomic valencies be allowed? If false then e.g. a carbon atom with 5 atoms close enough to be bonded will have only 4 bonds

Raises:

NoAtomsInMolecule

autode.mol_graphs.reac_graph_to_prod_graph(reac_graph, bond_rearrang)#

Makes the graph of the product from the reactant and the bond rearrangement, so it has the indices of the reactant

Parameters:

bond_rearrang (autode.bond_rearrangement.BondRearrangement) – The bond rearrangement linking reactants and products

Returns:

Graph of the product with each atom indexed as in the

reactants

Return type:

(nx.Graph)

autode.mol_graphs.remove_bonds_invalid_valancies(species)#

Remove invalid valencies for atoms that exceed their maximum valencies e.g. H should have no more than 1 ‘bond’

autode.mol_graphs.reorder_nodes(graph, mapping)#

Reorder the nodes in a graph using a mapping. NetworkX uses the inverse mapping so the dict is swapped before the nodes are relabeled

Parameters:

mapping (dict) –

Returns:

(nx.Graph)

autode.mol_graphs.species_are_isomorphic(species1, species2)#

Check if two complexes are isomorphic in at least one of their conformers

Parameters:

species2 (autode.species.Species) –

Return type:

(bool)

autode.mol_graphs.split_mol_across_bond(graph, bond)#

Gets a list of atoms on either side of a bond. Should be separable into two graphs

Parameters:

bond (tuple(int)) – Bond to be split across e.g. (0, 1)

Returns:

List of atom indexes (as a list of integers)

Return type:

(list(list(int)))

autode.mol_graphs.union(graphs)#

Return the union of two graphs. The disjoint union is returned