Skip to content

graphchem.preprocessing.get_ring_size

Determine the size of the smallest ring that an atom or bond is part of.

Parameters

obj : Union[rdkit.Chem.Atom, rdkit.Chem.Bond] An RDKit Atom or Bond object to check for ring membership. max_size : Optional[int], default 12 The maximum size of the ring to consider. If no ring is found with a size less than or equal to max_size, this value will be returned.

Returns

int The size of the smallest ring that the atom or bond is part of, or max_size if no smaller ring is found.

Source code in graphchem/preprocessing/features.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
def get_ring_size(
        obj: Union["rdkit.Chem.Atom", "rdkit.Chem.Bond"],
        max_size: Optional[int] = 12
     ) -> int:
    """
    Determine the size of the smallest ring that an atom or bond is part of.

    Parameters
    ----------
    obj : Union[rdkit.Chem.Atom, rdkit.Chem.Bond]
        An RDKit Atom or Bond object to check for ring membership.
    max_size : Optional[int], default 12
        The maximum size of the ring to consider. If no ring is found with a
        size less than or equal to `max_size`, this value will be returned.

    Returns
    -------
    int
        The size of the smallest ring that the atom or bond is part of, or
        `max_size` if no smaller ring is found.
    """
    if not obj.IsInRing():
        return 0
    for i in range(max_size):
        if obj.IsInRingSize(i):
            return i
    return max_size