From c6c9e22c3307d10fad1bcaa8975328bbc5eb54b6 Mon Sep 17 00:00:00 2001 From: sfluegel Date: Mon, 16 Nov 2026 11:39:56 +0100 Subject: [PATCH 1/2] remove ring predicates --- chebi_utils/extract_properties.py | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/chebi_utils/extract_properties.py b/chebi_utils/extract_properties.py index c96f351..d85ba1d 100644 --- a/chebi_utils/extract_properties.py +++ b/chebi_utils/extract_properties.py @@ -9,8 +9,6 @@ from rdkit import Chem from rdkit.Chem import Descriptors -MAX_RING_SIZE = 8 - # Gonane core SMARTS (C1–C17, IUPAC steroid numbering). # [#6] matches any carbon; ~ matches any bond — handles unsaturated steroids # (Δ4, Δ5), ketones, and estrogens (aromatic ring A) without modification. @@ -199,14 +197,19 @@ def get_molecule_level_properties(mol: Chem.Mol) -> set[str]: def get_rings(mol: Chem.Mol) -> dict[str, list]: """Extract ring-membership predicates. - Emits three kinds of predicate: + Emits two kinds of predicate, both unary, for rings of every size: - - ``ring{N}(A1, …, AN)`` – ``A1…AN`` form an N-membered ring, stored for all - rotations in both directions. Only for ``N <= MAX_RING_SIZE``. - - ``in_ring{N}(A)`` – ``A`` belongs to some N-membered ring - (``N <= MAX_RING_SIZE``). + - ``in_ring{N}(A)`` – ``A`` belongs to some N-membered ring. - ``in_ring(A)`` – ``A`` belongs to some ring of any size. + There is deliberately no N-ary ``ring{N}(A1, …, AN)``. Naming a ring's atoms in + order requires storing every rotation in both directions, so a 6-ring costs 12 + facts, and the ILP search pays for that twice over: Popper's ``deduce_recalls`` + walks ``2**arity - 2`` argument subsets per fact, and ``build_props`` pairs the + predicate with every other one. Measured over 100 ChEBI classes that came to a + median 24.4s of the 120s per-class budget, against zero uses of ``ring{N}`` in + any learned rule. + Parameters ---------- mol : Chem.Mol @@ -215,22 +218,14 @@ def get_rings(mol: Chem.Mol) -> dict[str, list]: Returns ------- dict[str, list] - Mapping from predicate name to its extension: ``ring{N}`` maps to a - ``list[tuple[int, ...]]`` of atom-index tuples; ``in_ring`` and - ``in_ring{N}`` map to a sorted ``list[int]`` of atom indices. + Mapping from predicate name to a sorted ``list[int]`` of atom indices. """ atom_extensions: dict[str, list] = {} in_ring_atoms: set[int] = set() in_ringN_atoms: dict[int, set[int]] = {} for ring in mol.GetRingInfo().AtomRings(): - n = len(ring) in_ring_atoms.update(ring) - if n <= MAX_RING_SIZE: - for start_atom in range(n): - ring_permutation = ring[start_atom:] + ring[:start_atom] - atom_extensions.setdefault(f"ring{n}", []).append(tuple(ring_permutation)) - atom_extensions[f"ring{n}"].append(tuple(reversed(ring_permutation))) - in_ringN_atoms.setdefault(n, set()).update(ring) + in_ringN_atoms.setdefault(len(ring), set()).update(ring) if in_ring_atoms: atom_extensions["in_ring"] = sorted(in_ring_atoms) for n, atoms in in_ringN_atoms.items(): From c4c43bb2c71aa28c69d6e349b58656cffe77c2b4 Mon Sep 17 00:00:00 2001 From: sfluegel Date: Mon, 16 Nov 2026 11:42:36 +0100 Subject: [PATCH 2/2] remove comment --- chebi_utils/extract_properties.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/chebi_utils/extract_properties.py b/chebi_utils/extract_properties.py index d85ba1d..88401ac 100644 --- a/chebi_utils/extract_properties.py +++ b/chebi_utils/extract_properties.py @@ -202,14 +202,6 @@ def get_rings(mol: Chem.Mol) -> dict[str, list]: - ``in_ring{N}(A)`` – ``A`` belongs to some N-membered ring. - ``in_ring(A)`` – ``A`` belongs to some ring of any size. - There is deliberately no N-ary ``ring{N}(A1, …, AN)``. Naming a ring's atoms in - order requires storing every rotation in both directions, so a 6-ring costs 12 - facts, and the ILP search pays for that twice over: Popper's ``deduce_recalls`` - walks ``2**arity - 2`` argument subsets per fact, and ``build_props`` pairs the - predicate with every other one. Measured over 100 ChEBI classes that came to a - median 24.4s of the 120s per-class budget, against zero uses of ``ring{N}`` in - any learned rule. - Parameters ---------- mol : Chem.Mol