# rmgpy.molecule.graph.Graph¶

class rmgpy.molecule.graph.Graph

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

addEdge()

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

addVertex()

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

copy()

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.

findIsomorphism()

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

findSubgraphIsomorphisms()

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.

getAllCycles()

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]

getAllCyclesOfSize()

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).

getAllCyclicVertices()

Returns all vertices belonging to one or more cycles.

getAllPolycyclicVertices()

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

getDisparateRings()

Return a list of distinct polycyclic and monocyclic rings within the graph. There is some code duplication in this function in order to maximize speed up so as to call self.getSmallestSetOfSmallestRings() only once.

Returns: monocyclicRingsList, polycyclicRingsList

getEdge()

Returns the edge connecting vertices vertex1 and vertex2.

getEdges()

Return a list of the edges involving the specified vertex.

getMonocyclicRings()

Return a list of cycles that are monocyclic.

getPolycyclicRings()

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.

getSmallestSetOfSmallestRings()

Return a list of the smallest set of smallest rings in the graph. 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).

hasEdge()

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

hasVertex()

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

isCyclic()

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

isEdgeInCycle()

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

isIsomorphic()

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

isMappingValid()

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.

isSubgraphIsomorphic()

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

isVertexInCycle()

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

merge()

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

removeEdge()

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

removeVertex()

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.

resetConnectivityValues()

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

sortVertices()

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

split()

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

updateConnectivityValues()

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