rings
Ring detection algorithms for molecular graphs.
Implements SSSR (Smallest Set of Smallest Rings) using a modified version of Horton's algorithm, and all-rings enumeration.
find_all_rings(graph, max_size=12)
Find all rings in a molecular graph up to a maximum size.
Uses depth-limited DFS to enumerate all cycles.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
MolecularGraph
|
A MolecularGraph instance. |
required |
max_size
|
int
|
Maximum ring size to consider (default 12). |
12
|
Returns:
| Type | Description |
|---|---|
list[tuple[int, ...]]
|
List of tuples, each containing atom indices forming a ring. |
Source code in chmpy/graph/rings.py
find_sssr(graph)
Find the Smallest Set of Smallest Rings (SSSR) in a molecular graph.
Uses a modified Horton's algorithm: 1. Find all fundamental cycles from shortest path trees 2. Select a minimal linearly independent set
The SSSR size equals M - N + C where: - M = number of edges (bonds) - N = number of vertices (atoms) - C = number of connected components
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
MolecularGraph
|
A MolecularGraph instance. |
required |
Returns:
| Type | Description |
|---|---|
list[tuple[int, ...]]
|
List of tuples, each containing atom indices forming a ring. |
Source code in chmpy/graph/rings.py
fused_ring_systems(graph)
Find fused ring systems (groups of rings sharing bonds).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
MolecularGraph
|
A MolecularGraph instance. |
required |
Returns:
| Type | Description |
|---|---|
list[set[int]]
|
List of sets, each set containing atom indices of a fused ring system. |
Source code in chmpy/graph/rings.py
is_in_ring(graph, atom_idx)
Check if an atom is part of any ring.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
MolecularGraph
|
A MolecularGraph instance. |
required |
atom_idx
|
int
|
Index of the atom to check. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the atom is in at least one ring. |
Source code in chmpy/graph/rings.py
is_ring_bond(graph, atom_i, atom_j)
Check if a bond is part of any ring.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
MolecularGraph
|
A MolecularGraph instance. |
required |
atom_i
|
int
|
First atom index. |
required |
atom_j
|
int
|
Second atom index. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the bond is part of at least one ring. |
Source code in chmpy/graph/rings.py
ring_membership(graph)
Count ring membership for each atom.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
MolecularGraph
|
A MolecularGraph instance. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Array of shape (n_atoms,) with count of SSSR rings each atom belongs to. |
Source code in chmpy/graph/rings.py
ring_sizes(graph)
Get the sizes of all rings in the SSSR.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
MolecularGraph
|
A MolecularGraph instance. |
required |
Returns:
| Type | Description |
|---|---|
list[int]
|
Sorted list of ring sizes. |
Source code in chmpy/graph/rings.py
smallest_ring_containing_atom(graph, atom_idx)
Find the smallest ring containing a given atom.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
MolecularGraph
|
A MolecularGraph instance. |
required |
atom_idx
|
int
|
Index of the atom. |
required |
Returns:
| Type | Description |
|---|---|
tuple[int, ...] | None
|
Tuple of atom indices forming the smallest ring, or None if not in any ring. |