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. A single edge can be accessed using the
get_edge()
method or by accessing specific vertices usingvertex1.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 theget_edges()
method orvertex.edges
.- add_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(vertex)¶
Add a vertex to the graph. The vertex is initialized with no edges.
- copy(deep)¶
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 isFalse
or not specified, a shallow copy is made: the original vertices and edges are used in the new graph.
- copy_and_map()¶
Create a deep copy of the current graph, and return the dict ‘mapping’. Method was modified from Graph.copy() method
- find_isomorphism(other, initial_map, save_order, strict)¶
Returns
True
if other is subgraph isomorphic andFalse
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 isomorphismstrict (bool, optional) – if
False
, perform isomorphism ignoring electrons
- find_subgraph_isomorphisms(other, initial_map, save_order)¶
Returns
True
if other is subgraph isomorphic andFalse
otherwise. Also returns the lists all of valid mappings.Uses the VF2 algorithm of Vento and Foggia.
- get_all_cycles(starting_vertex)¶
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(size)¶
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()¶
Returns all vertices belonging to one or more cycles.
- get_all_edges()¶
Returns a list of all edges in the graph.
- get_all_polycyclic_vertices()¶
Return all vertices belonging to two or more cycles, fused or spirocyclic.
- get_all_simple_cycles_of_size(size)¶
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()¶
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(vertex1, vertex2)¶
Returns the edge connecting vertices vertex1 and vertex2.
- get_edges(vertex)¶
Return a dictionary of the edges involving the specified vertex.
- get_edges_in_cycle(vertices, sort)¶
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(vertex)¶
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()¶
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()¶
Return a list of cycles that are monocyclic.
- get_polycycles()¶
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()¶
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()¶
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(vertex1, vertex2)¶
Returns
True
if vertices vertex1 and vertex2 are connected by an edge, orFalse
if not.
- has_vertex(vertex)¶
Returns
True
if vertex is a vertex in the graph, orFalse
if not.
- is_cyclic()¶
Return
True
if one or more cycles are present in the graph orFalse
otherwise.
- is_edge_in_cycle(edge)¶
Return
True
if the edge between vertices vertex1 and vertex2 is in one or more cycles in the graph, orFalse
if not.
- is_isomorphic(other, initial_map, generate_initial_map, save_order, strict)¶
Returns
True
if two graphs are isomorphic andFalse
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 labelssave_order (bool, optional) – if
True
, reset atom order after performing atom isomorphismstrict (bool, optional) – if
False
, perform isomorphism ignoring electrons
- is_mapping_valid(other, mapping, equivalent, strict)¶
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, ifFalse
it checks if they are specific cases of each other. If strict isTrue
, electrons and bond orders are considered, and ignored ifFalse
.
- is_subgraph_isomorphic(other, initial_map, save_order)¶
Returns
True
if other is subgraph isomorphic andFalse
otherwise. Uses the VF2 algorithm of Vento and Foggia.
- is_vertex_in_cycle(vertex)¶
Return
True
if the given vertex is contained in one or more cycles in the graph, orFalse
if not.
- merge(other)¶
Merge two graphs so as to store them in a single Graph object.
- remove_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(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()¶
Reset any cached connectivity information. Call this method when you have modified the graph.
- restore_vertex_order()¶
reorder the vertices to what they were before sorting if you saved the order
- sort_cyclic_vertices(vertices)¶
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(save_order)¶
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.
- update_connectivity_values()¶
Update the connectivity values for each vertex in the graph. These are used to accelerate the isomorphism checking.