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

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

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

getSmallestSetOfSmallestRings(self) → list

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

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

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(self, Graph other, dict initialMap=None) → 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.

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.

sortVertices(self)

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