rmgpy.molecule.graph.Graph

class rmgpy.molecule.graph.Graph(vertices=None)

A graph data type. The vertices of the graph are stored in a list vertices; this provides a consistent traversal order. A single edge can be accessed using the get_edge() method or by accessing specific vertices using vertex1.edges[vertex2]; in either case, an exception will be raised if the edge does not exist. All edges of a vertex can be accessed using the get_edges() method or vertex.edges.

add_edge(self, Edge edge) Edge

Add an edge to the graph. The two vertices in the edge must already exist in the graph, or a ValueError is raised.

add_vertex(self, Vertex vertex) Vertex

Add a vertex to the graph. The vertex is initialized with no edges.

copy(self, bool deep=False) Graph

Create a copy of the current graph. If deep is True, a deep copy is made: copies of the vertices and edges are used in the new graph. If deep is False or not specified, a shallow copy is made: the original vertices and edges are used in the new graph.

copy_and_map(self) dict

Create a deep copy of the current graph, and return the dict ‘mapping’. Method was modified from Graph.copy() method

find_isomorphism(self, Graph other, dict initial_map=None, bool save_order=False, bool strict=True) list

Returns True if other is subgraph isomorphic and False otherwise, and the matching mapping. Uses the VF2 algorithm of Vento and Foggia.

Parameters:
  • initial_map (dict, optional) – initial atom mapping to use

  • save_order (bool, optional) – if True, reset atom order after performing atom isomorphism

  • strict (bool, optional) – if False, perform isomorphism ignoring electrons

find_subgraph_isomorphisms(self, Graph other, dict initial_map=None, bool save_order=False) list

Returns True if other is subgraph isomorphic and False otherwise. Also returns the lists all of valid mappings.

Uses the VF2 algorithm of Vento and Foggia.

get_all_cycles(self, Vertex starting_vertex) list

Given a starting vertex, returns a list of all the cycles containing that vertex.

This function returns a duplicate of each cycle because [0,1,2,3] is counted as separate from [0,3,2,1]

get_all_cycles_of_size(self, int size) list

Return a list of the all non-duplicate rings with length ‘size’. The algorithm implements was adapted from a description by Fan, Panaye, Doucet, and Barbu (doi: 10.1021/ci00015a002)

B. T. Fan, A. Panaye, J. P. Doucet, and A. Barbu. “Ring Perception: A New Algorithm for Directly Finding the Smallest Set of Smallest Rings from a Connection Table.” J. Chem. Inf. Comput. Sci. 33, p. 657-662 (1993).

get_all_cyclic_vertices(self) list

Returns all vertices belonging to one or more cycles.

get_all_edges(self) list

Returns a list of all edges in the graph.

get_all_polycyclic_vertices(self) list

Return all vertices belonging to two or more cycles, fused or spirocyclic.

get_all_simple_cycles_of_size(self, int size) list

Return a list of all non-duplicate monocyclic rings with length ‘size’.

Naive approach by eliminating polycyclic rings that are returned by getAllCyclicsOfSize.

get_disparate_cycles(self) tuple

Get all disjoint monocyclic and polycyclic cycle clusters in the molecule. Takes the RC and recursively merges all cycles which share vertices.

Returns: monocyclic_cycles, polycyclic_cycles

get_edge(self, Vertex vertex1, Vertex vertex2) Edge

Returns the edge connecting vertices vertex1 and vertex2.

get_edges(self, Vertex vertex) dict

Return a dictionary of the edges involving the specified vertex.

get_edges_in_cycle(self, list vertices, bool sort=False) list

For a given list of atoms comprising a ring, return the set of bonds connecting them, in order around the ring.

If sort=True, then sort the vertices to match their connectivity. Otherwise, assumes that they are already sorted, which is true for cycles returned by get_relevant_cycles or get_smallest_set_of_smallest_rings.

get_largest_ring(self, Vertex vertex) list

returns the largest ring containing vertex. This is typically useful for finding the longest path in a polycyclic ring, since the polycyclic rings returned from get_polycycles are not necessarily in order in the ring structure.

get_max_cycle_overlap(self) int

Return the maximum number of vertices that are shared between any two cycles in the graph. For example, if there are only disparate monocycles or no cycles, the maximum overlap is zero; if there are “spiro” cycles, it is one; if there are “fused” cycles, it is two; and if there are “bridged” cycles, it is three.

get_monocycles(self) list

Return a list of cycles that are monocyclic.

get_polycycles(self) list

Return a list of cycles that are polycyclic. In other words, merge the cycles which are fused or spirocyclic into a single polycyclic cycle, and return only those cycles. Cycles which are not polycyclic are not returned.

get_relevant_cycles(self) list

Returns the set of relevant cycles as a list of lists. Uses RingDecomposerLib for ring perception.

Kolodzik, A.; Urbaczek, S.; Rarey, M. Unique Ring Families: A Chemically Meaningful Description of Molecular Ring Topologies. J. Chem. Inf. Model., 2012, 52 (8), pp 2013-2021

Flachsenberg, F.; Andresen, N.; Rarey, M. RingDecomposerLib: An Open-Source Implementation of Unique Ring Families and Other Cycle Bases. J. Chem. Inf. Model., 2017, 57 (2), pp 122-126

get_smallest_set_of_smallest_rings(self) list

Returns the smallest set of smallest rings as a list of lists. Uses RingDecomposerLib for ring perception.

Kolodzik, A.; Urbaczek, S.; Rarey, M. Unique Ring Families: A Chemically Meaningful Description of Molecular Ring Topologies. J. Chem. Inf. Model., 2012, 52 (8), pp 2013-2021

Flachsenberg, F.; Andresen, N.; Rarey, M. RingDecomposerLib: An Open-Source Implementation of Unique Ring Families and Other Cycle Bases. J. Chem. Inf. Model., 2017, 57 (2), pp 122-126

has_edge(self, Vertex vertex1, Vertex vertex2) bool

Returns True if vertices vertex1 and vertex2 are connected by an edge, or False if not.

has_vertex(self, Vertex vertex) bool

Returns True if vertex is a vertex in the graph, or False if not.

is_cyclic(self) bool

Return True if one or more cycles are present in the graph or False otherwise.

is_edge_in_cycle(self, Edge edge) bool

Return True if the edge between vertices vertex1 and vertex2 is in one or more cycles in the graph, or False if not.

is_isomorphic(self, Graph other, dict initial_map=None, bool generate_initial_map=False, bool save_order=False, bool strict=True) bool

Returns True if two graphs are isomorphic and False otherwise. Uses the VF2 algorithm of Vento and Foggia.

Parameters:
  • initial_map (dict, optional) – initial atom mapping to use

  • generate_initial_map (bool, optional) – if True, initialize map by pairing atoms with same labels

  • save_order (bool, optional) – if True, reset atom order after performing atom isomorphism

  • strict (bool, optional) – if False, perform isomorphism ignoring electrons

is_mapping_valid(self, Graph other, dict mapping, bool equivalent=True, bool strict=True) bool

Check that a proposed mapping of vertices from self to other is valid by checking that the vertices and edges involved in the mapping are mutually equivalent. If equivalent is True it checks if atoms and edges are equivalent, if False it checks if they are specific cases of each other. If strict is True, electrons and bond orders are considered, and ignored if False.

is_subgraph_isomorphic(self, Graph other, dict initial_map=None, bool save_order=False) bool

Returns True if other is subgraph isomorphic and False otherwise. Uses the VF2 algorithm of Vento and Foggia.

is_vertex_in_cycle(self, Vertex vertex) bool

Return True if the given vertex is contained in one or more cycles in the graph, or False if not.

merge(self, Graph other) Graph

Merge two graphs so as to store them in a single Graph object.

ordered_vertices

list

Type:

ordered_vertices

remove_edge(self, Edge edge)

Remove the specified edge from the graph. Does not remove vertices that no longer have any edges as a result of this removal.

remove_vertex(self, Vertex vertex)

Remove vertex and all edges associated with it from the graph. Does not remove vertices that no longer have any edges as a result of this removal.

reset_connectivity_values(self)

Reset any cached connectivity information. Call this method when you have modified the graph.

restore_vertex_order(self)

reorder the vertices to what they were before sorting if you saved the order

sort_cyclic_vertices(self, list vertices) list

Given a list of vertices comprising a cycle, sort them such that adjacent entries in the list are connected to each other. Warning: Assumes that the cycle is elementary, ie. no bridges.

sort_vertices(self, bool save_order=False)

Sort the vertices in the graph. This can make certain operations, e.g. the isomorphism functions, much more efficient.

split(self) list

Convert a single Graph object containing two or more unconnected graphs into separate graphs.

update_connectivity_values(self)

Update the connectivity values for each vertex in the graph. These are used to accelerate the isomorphism checking.

vertices

list

Type:

vertices