mooonpy.molspace.graph_theory.ring_analysis module

This module provides basic support for finding cycles/rings in an undirected graph.

mooonpy.molspace.graph_theory.ring_analysis.find_rings(graph: dict[int, list[int]], ring_sizes: tuple[int] = (3, 4, 5, 6, 7))[source]

Finds all cycles/rings in a graph that are specified in the ring_sizes parameter.

Note

Each ring will be sorted in the order it was traversed in the graph and will be in the canonical form (e.g., canonical=(1,2,3) vs non_canonical=(2,3,1)).

Parameters:
  • graph (dict[int, list[int]]) – An undirected graph

  • ring_sizes (tuple[int]) – Tuple containing ring sizes to search for in graph

Returns:

rings

Return type:

list[tuple[int]]

mooonpy.molspace.graph_theory.ring_analysis.ring_canonical(ring: list) tuple[source]

Sort list of ring ID’s to canonical form of “lowest ID, lower neighbor-wise” ie [5,254,6,12,4,3] -> (3,4,12,6,254,5) with 3 as lowest, and 4 as the lower of 4 and 5, reversing the direction