# 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 getEdge() 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 getEdges() method or vertex.edges.

addEdge(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.

addVertex(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.

copyAndMap(self) → dict

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

findIsomorphism(self, Graph other, dict initialMap=None, bool saveOrder=False) → list

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

findSubgraphIsomorphisms(self, Graph other, dict initialMap=None, bool saveOrder=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.

getAllCycles(self, Vertex startingVertex) → 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]

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

getAllCyclicVertices(self) → list

Returns all vertices belonging to one or more cycles.

getAllEdges(self) → list

Returns a list of all edges in the graph.

getAllPolycyclicVertices(self) → list

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

getAllSimpleCyclesOfSize(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.

getDisparateRings(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

getEdge(self, Vertex vertex1, Vertex vertex2) → Edge

Returns the edge connecting vertices vertex1 and vertex2.

getEdges(self, Vertex vertex) → dict

Return a dictionary of the edges involving the specified vertex.

getLargestRing(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 getPolycyclicRings are not necessarily in order in the ring structure.

getMonocyclicRings(self) → list

Return a list of cycles that are monocyclic.

getPolycyclicRings(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.

getRelevantCycles(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

getSmallestSetOfSmallestRings(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

hasEdge(self, Vertex vertex1, Vertex vertex2) → bool

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

hasVertex(self, Vertex vertex) → bool

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

isCyclic(self) → bool

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

isEdgeInCycle(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.

isIsomorphic(self, Graph other, dict initialMap=None, bool saveOrder=False) → bool

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

isMappingValid(self, Graph other, dict mapping, bool equivalent=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.

isSubgraphIsomorphic(self, Graph other, dict initialMap=None, bool saveOrder=False) → bool

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

isVertexInCycle(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

ordered_vertices – list

removeEdge(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.

removeVertex(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.

resetConnectivityValues(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

sortVertices(self, bool saveOrder=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.

updateConnectivityValues(self)

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

vertices

vertices – list