From 8923c1f6769e1ced25a031a728dc2da2a03c72e8 Mon Sep 17 00:00:00 2001 From: Anton Siomchen <41703271+asiomchen@users.noreply.github.com.> Date: Sun, 9 Aug 2026 12:54:47 +0200 Subject: [PATCH 1/8] stabilize chache key generation --- src/molalchemy/bingo/types.py | 54 ++++++++++++++++++++++++++++++++--- src/molalchemy/rdkit/types.py | 51 ++++++++++++++++++++++++++++++--- tests/bingo/test_types.py | 50 ++++++++++++++++++++++++++++++++ tests/rdkit/test_types.py | 48 +++++++++++++++++++++++++++++++ 4 files changed, 195 insertions(+), 8 deletions(-) diff --git a/src/molalchemy/bingo/types.py b/src/molalchemy/bingo/types.py index 1b013c8..b8ac51d 100644 --- a/src/molalchemy/bingo/types.py +++ b/src/molalchemy/bingo/types.py @@ -11,10 +11,34 @@ from molalchemy.bingo.comparators import BingoMolComparator, BingoRxnComparator +_BINGO_BINARY_MOL_RETURN_TYPES = ("smiles", "molfile", "cml", "bytes") + + +def _validate_return_type(value: object) -> None: + if not isinstance(value, str): + raise TypeError(f"return_type must be a str, got {type(value).__name__}") + if value not in _BINGO_BINARY_MOL_RETURN_TYPES: + choices = ", ".join(repr(choice) for choice in _BINGO_BINARY_MOL_RETURN_TYPES) + raise ValueError(f"return_type must be one of {choices}, got {value!r}") + + +def _validate_preserve_pos(value: object) -> None: + if type(value) is not bool: + raise TypeError(f"preserve_pos must be a bool, got {type(value).__name__}") + class BingoBaseType(UserDefinedType): """Base class for Bingo types.""" + _immutable_options: frozenset[str] = frozenset() + + def __setattr__(self, name: str, value: Any) -> None: + # SQLAlchemy builds _static_cache_key from constructor-named attributes + # in __dict__; read-only properties backed by private names hide them. + if name in self._immutable_options and name in self.__dict__: + raise AttributeError(f"{name} is immutable") + super().__setattr__(name, value) + class BingoMol(BingoBaseType): """SQLAlchemy type for molecule data stored as text (varchar). @@ -100,6 +124,17 @@ class BingoBinaryMol(BingoBaseType): -------- When `preserve_pos=True`, only inputs with present atomic coordinates should be used, otherwise an error will occur during conversion. + Raises + ------ + TypeError + If `preserve_pos` is not a boolean or `return_type` is not a string. + ValueError + If `return_type` is not one of the supported values. + + Notes + ----- + `preserve_pos` and `return_type` are immutable after construction. + Examples -------- >>> from sqlalchemy import Integer, String @@ -136,12 +171,15 @@ class BingoBinaryMol(BingoBaseType): cache_ok = True comparator_factory = BingoMolComparator + _immutable_options = frozenset(("preserve_pos", "return_type")) def __init__( self, preserve_pos: bool = False, return_type: Literal["smiles", "molfile", "cml", "bytes"] = "smiles", ): + _validate_preserve_pos(preserve_pos) + _validate_return_type(return_type) self.preserve_pos = preserve_pos self.return_type = return_type super().__init__() @@ -164,10 +202,7 @@ def column_expression(self, colexpr): return func.Bingo.cml(colexpr) elif self.return_type == "bytes": return colexpr - else: - raise ValueError( - f"Invalid return_type: {self.return_type}. Available options are 'smiles', 'molfile', 'cml', 'bytes'." - ) + raise AssertionError("validated return_type was not handled") class BingoReaction(BingoBaseType): @@ -241,6 +276,15 @@ class BingoBinaryReaction(BingoBaseType): -------- When `preserve_pos=True`, only inputs with present atomic coordinates should be used, otherwise conversion can return `NULL`. + Raises + ------ + TypeError + If `preserve_pos` is not a boolean. + + Notes + ----- + `preserve_pos` is immutable after construction. + Examples -------- >>> from sqlalchemy import Integer, String @@ -277,8 +321,10 @@ class BingoBinaryReaction(BingoBaseType): cache_ok = True comparator_factory = BingoRxnComparator + _immutable_options = frozenset(("preserve_pos",)) def __init__(self, preserve_pos: bool = False): + _validate_preserve_pos(preserve_pos) self.preserve_pos = preserve_pos super().__init__() diff --git a/src/molalchemy/rdkit/types.py b/src/molalchemy/rdkit/types.py index dd19a03..c2122ad 100644 --- a/src/molalchemy/rdkit/types.py +++ b/src/molalchemy/rdkit/types.py @@ -19,10 +19,29 @@ RdkitReactionComparator, ) +_RDKIT_RETURN_TYPES = ("smiles", "bytes", "mol") + + +def _validate_return_type(value: object) -> None: + if not isinstance(value, str): + raise TypeError(f"return_type must be a str, got {type(value).__name__}") + if value not in _RDKIT_RETURN_TYPES: + choices = ", ".join(repr(choice) for choice in _RDKIT_RETURN_TYPES) + raise ValueError(f"return_type must be one of {choices}, got {value!r}") + class RdkitBaseType(UserDefinedType): """Base class for RDKit types.""" + _immutable_options: frozenset[str] = frozenset() + + def __setattr__(self, name: str, value: Any) -> None: + # SQLAlchemy builds _static_cache_key from constructor-named attributes + # in __dict__; read-only properties backed by private names hide them. + if name in self._immutable_options and name in self.__dict__: + raise AttributeError(f"{name} is immutable") + super().__setattr__(name, value) + class RdkitMol(RdkitBaseType): """SQLAlchemy type for RDKit molecule data stored in PostgreSQL. @@ -38,9 +57,21 @@ class RdkitMol(RdkitBaseType): - `"smiles"`: Return as SMILES string - `"bytes"`: Return as raw bytes - `"mol"`: Return as `rdkit.Chem.Mol` object + + Raises + ------ + TypeError + If `return_type` is not a string. + ValueError + If `return_type` is not one of the supported values. + + Notes + ----- + `return_type` is immutable after construction. """ cache_ok = True + _immutable_options = frozenset(("return_type",)) def get_col_spec(self, **kwargs: Any) -> str: return "mol" @@ -48,6 +79,7 @@ def get_col_spec(self, **kwargs: Any) -> str: comparator_factory = RdkitMolComparator def __init__(self, return_type: Literal["smiles", "bytes", "mol"] = "smiles"): + _validate_return_type(return_type) super().__init__() self.return_type = return_type @@ -59,8 +91,7 @@ def column_expression(self, colexpr): if self.return_type in ("mol", "bytes"): return rdkit_func.mol_send(colexpr, type_=self) - else: # smiles - return colexpr + return colexpr def bind_processor(self, dialect): del dialect @@ -154,10 +185,22 @@ class RdkitReaction(RdkitBaseType): - `"smiles"`: Return as reaction SMILES string - `"bytes"`: Return as raw bytes - `"mol"`: Return as `AllChem.ChemicalReaction` object + + Raises + ------ + TypeError + If `return_type` is not a string. + ValueError + If `return_type` is not one of the supported values. + + Notes + ----- + `return_type` is immutable after construction. """ impl = bytes cache_ok = True + _immutable_options = frozenset(("return_type",)) def get_col_spec(self, **kwargs: Any) -> str: return "reaction" @@ -172,6 +215,7 @@ def __init__(self, return_type: Literal["smiles", "bytes", "mol"] = "smiles"): return_type : Literal["smiles", "bytes", "mol"], default "smiles" The format in which to return reaction data from the database. """ + _validate_return_type(return_type) super().__init__() self.return_type = return_type @@ -210,8 +254,7 @@ def column_expression(self, colexpr): if self.return_type in ("mol", "bytes"): return rdkit_func.reaction_send(colexpr, type_=self) - else: # smiles - return colexpr + return colexpr def result_processor(self, dialect, coltype): del dialect, coltype diff --git a/tests/bingo/test_types.py b/tests/bingo/test_types.py index d23330d..671d20e 100644 --- a/tests/bingo/test_types.py +++ b/tests/bingo/test_types.py @@ -80,6 +80,39 @@ def test_bingo_binary_mol_in_table_definition(self): assert test_table.c.mol.type.__class__ == BingoBinaryMol assert isinstance(test_table.c.mol.type, BingoBinaryMol) + def test_rejects_unsupported_return_type_at_construction(self): + with pytest.raises( + ValueError, + match=r"return_type must be one of .* got 'invalid'", + ): + BingoBinaryMol(return_type="invalid") # type: ignore[arg-type] + + @pytest.mark.parametrize("return_type", [None, 1, b"smiles"]) + def test_rejects_non_string_return_type(self, return_type): + with pytest.raises(TypeError, match="return_type must be a str"): + BingoBinaryMol(return_type=return_type) + + @pytest.mark.parametrize("preserve_pos", [None, 0, 1, "true"]) + def test_rejects_non_boolean_preserve_pos(self, preserve_pos): + with pytest.raises(TypeError, match="preserve_pos must be a bool"): + BingoBinaryMol(preserve_pos=preserve_pos) + + def test_configuration_is_immutable_and_cacheable(self): + bingo_binary_mol = BingoBinaryMol() + + with pytest.raises(AttributeError, match="return_type is immutable"): + bingo_binary_mol.return_type = "bytes" # type: ignore[misc] + with pytest.raises(AttributeError, match="preserve_pos is immutable"): + bingo_binary_mol.preserve_pos = True # type: ignore[misc] + + assert bingo_binary_mol.return_type == "smiles" + assert bingo_binary_mol.preserve_pos is False + assert bingo_binary_mol._static_cache_key == ( + BingoBinaryMol, + ("preserve_pos", False), + ("return_type", "smiles"), + ) + @pytest.mark.parametrize( "return_type, expected_sql", [ @@ -162,6 +195,23 @@ def test_bingo_binary_reaction_in_table_definition(self): assert test_table.c.rxn.type.__class__ == BingoBinaryReaction assert isinstance(test_table.c.rxn.type, BingoBinaryReaction) + def test_preserve_pos_is_immutable_and_cacheable(self): + bingo_binary_reaction = BingoBinaryReaction() + + with pytest.raises(AttributeError, match="preserve_pos is immutable"): + bingo_binary_reaction.preserve_pos = True # type: ignore[misc] + + assert bingo_binary_reaction.preserve_pos is False + assert bingo_binary_reaction._static_cache_key == ( + BingoBinaryReaction, + ("preserve_pos", False), + ) + + @pytest.mark.parametrize("preserve_pos", [None, 0, 1, "true"]) + def test_rejects_non_boolean_preserve_pos(self, preserve_pos): + with pytest.raises(TypeError, match="preserve_pos must be a bool"): + BingoBinaryReaction(preserve_pos=preserve_pos) + @pytest.mark.parametrize( "preserve_pos", [ diff --git a/tests/rdkit/test_types.py b/tests/rdkit/test_types.py index 470d9ea..39b2708 100644 --- a/tests/rdkit/test_types.py +++ b/tests/rdkit/test_types.py @@ -51,6 +51,30 @@ def test_rdkit_mol_custom_return_types(self): assert mol_bytes.return_type == "bytes" assert mol_mol.return_type == "mol" + def test_rdkit_mol_rejects_unsupported_return_type(self): + with pytest.raises( + ValueError, + match=r"return_type must be one of .* got 'invalid'", + ): + RdkitMol(return_type="invalid") # type: ignore[arg-type] + + @pytest.mark.parametrize("return_type", [None, 1, b"smiles"]) + def test_rdkit_mol_rejects_non_string_return_type(self, return_type): + with pytest.raises(TypeError, match="return_type must be a str"): + RdkitMol(return_type=return_type) + + def test_rdkit_mol_return_type_is_immutable(self): + rdkit_mol = RdkitMol() + + with pytest.raises(AttributeError, match="return_type is immutable"): + rdkit_mol.return_type = "bytes" # type: ignore[misc] + + assert rdkit_mol.return_type == "smiles" + assert rdkit_mol._static_cache_key == ( + RdkitMol, + ("return_type", "smiles"), + ) + def test_rdkit_mol_in_table_definition(self): """Test RdkitMol can be used in table definition.""" metadata = MetaData() @@ -263,6 +287,30 @@ def test_rdkit_reaction_custom_return_types(self): assert rxn_bytes.return_type == "bytes" assert rxn_mol.return_type == "mol" + def test_rdkit_reaction_rejects_unsupported_return_type(self): + with pytest.raises( + ValueError, + match=r"return_type must be one of .* got 'invalid'", + ): + RdkitReaction(return_type="invalid") # type: ignore[arg-type] + + @pytest.mark.parametrize("return_type", [None, 1, b"smiles"]) + def test_rdkit_reaction_rejects_non_string_return_type(self, return_type): + with pytest.raises(TypeError, match="return_type must be a str"): + RdkitReaction(return_type=return_type) + + def test_rdkit_reaction_return_type_is_immutable(self): + rdkit_reaction = RdkitReaction() + + with pytest.raises(AttributeError, match="return_type is immutable"): + rdkit_reaction.return_type = "bytes" # type: ignore[misc] + + assert rdkit_reaction.return_type == "smiles" + assert rdkit_reaction._static_cache_key == ( + RdkitReaction, + ("return_type", "smiles"), + ) + def test_rdkit_reaction_in_table_definition(self): """Test RdkitReaction can be used in table definition.""" metadata = MetaData() From 76adb0070311084ecbdd6af914224780232f8551 Mon Sep 17 00:00:00 2001 From: Anton Siomchen <41703271+asiomchen@users.noreply.github.com.> Date: Sun, 9 Aug 2026 14:50:24 +0200 Subject: [PATCH 2/8] refactor typing --- .github/workflows/ci.yaml | 44 ++ README.md | 21 +- data/bingo/general_extra.txt | 32 +- data/bingo/general_header.txt | 8 + data/bingo/internal_header.txt | 1 + data/rdkit/general_extra.txt | 42 +- data/rdkit/general_header.txt | 9 + data/rdkit/internal_header.txt | 1 + dev_scripts/gen_functions.py | 93 +++- dev_scripts/templates/bingo_function.j2 | 16 +- dev_scripts/templates/rdkit_function.j2 | 14 +- docs/index.md | 21 +- docs/tutorials/05_Reactions_rdkit_ORM.ipynb | 4 +- src/molalchemy/bingo/functions/_types.py | 7 +- src/molalchemy/bingo/functions/general.py | 280 +++++----- src/molalchemy/bingo/functions/internal.py | 177 ++++--- src/molalchemy/bingo/search.py | 4 +- src/molalchemy/bingo/types.py | 33 +- src/molalchemy/protocols.py | 56 +- src/molalchemy/rdkit/functions/_types.py | 27 +- src/molalchemy/rdkit/functions/general.py | 550 ++++++++++---------- src/molalchemy/rdkit/functions/internal.py | 110 ++-- src/molalchemy/rdkit/search.py | 16 +- src/molalchemy/rdkit/types.py | 52 +- src/molalchemy/types.py | 2 +- tests/bingo/test_integration.py | 2 +- tests/bingo/test_types.py | 7 +- tests/rdkit/test_functions.py | 20 + tests/test_helpers.py | 2 +- tests/typing/consumer.py | 88 ++++ 30 files changed, 1082 insertions(+), 657 deletions(-) create mode 100644 tests/typing/consumer.py diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index cf7fe8b..bb40374 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -12,6 +12,50 @@ concurrency: cancel-in-progress: true jobs: + typing: + name: Installed-wheel typing surface + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v6 + with: + fetch-depth: 0 + + - name: Set up Python + uses: actions/setup-python@v6 + with: + python-version: "3.10" + + - name: Install UV + uses: astral-sh/setup-uv@v7 + with: + version: "0.9.9" + python-version: "3.10" + + - name: Check source and consumer types + run: uv run ty check src tests/typing/consumer.py + + - name: Check generated functions are current + run: | + uv run python dev_scripts/gen_functions.py rdkit + uv run python dev_scripts/gen_functions.py bingo + uv run ruff format src/molalchemy/rdkit/functions src/molalchemy/bingo/functions + uv run ruff check --fix src/molalchemy/rdkit/functions src/molalchemy/bingo/functions + uv run ruff format src/molalchemy/rdkit/functions src/molalchemy/bingo/functions + git diff --exit-code -- src/molalchemy/rdkit/functions src/molalchemy/bingo/functions + + - name: Build and install wheel in an isolated environment + run: | + uv build --wheel --out-dir dist-typing + uv venv /tmp/molalchemy-typing-venv --python 3.10 + uv pip install --python /tmp/molalchemy-typing-venv dist-typing/*.whl ty + mkdir -p /tmp/molalchemy-typing-consumer + cp tests/typing/consumer.py /tmp/molalchemy-typing-consumer/consumer.py + + - name: Check the installed consumer surface + working-directory: /tmp/molalchemy-typing-consumer + run: /tmp/molalchemy-typing-venv/bin/ty check consumer.py + test: name: Test on Python ${{ matrix.python-version }} - ${{ matrix.os }} runs-on: ${{ matrix.os }} diff --git a/README.md b/README.md index 7933252..4af4eb8 100644 --- a/README.md +++ b/README.md @@ -243,6 +243,8 @@ Use the matching helper for the cartridge and data kind: ### Configurable Return Types ```python +from rdkit import Chem + from molalchemy.rdkit.types import RdkitMol class MoleculeWithFormats(Base): @@ -252,11 +254,28 @@ class MoleculeWithFormats(Base): # Return as SMILES string (default) structure_smiles: Mapped[str] = mapped_column(RdkitMol()) # Return as RDKit Mol object - structure_mol: Mapped[bytes] = mapped_column(RdkitMol(return_type="mol")) + structure_mol: Mapped[Chem.Mol] = mapped_column(RdkitMol(return_type="mol")) # Return as raw bytes structure_bytes: Mapped[bytes] = mapped_column(RdkitMol(return_type="bytes")) ``` +The SQL type describes how PostgreSQL stores the value; `Mapped[...]` describes +the Python value returned to the model. SQLAlchemy 2.0 does not infer +`mapped_column()` attributes from the supplied type, so ORM models should always +spell out `Mapped[T]`. Core `Column(...)` and generated SQL expressions infer +the result directly from MolAlchemy's types. + +| Type configuration | Python result | +| --- | --- | +| `RdkitMol()` / `return_type="smiles"` | `str` | +| `RdkitMol(return_type="bytes")` | `bytes` | +| `RdkitMol(return_type="mol")` | `Chem.Mol` | +| `RdkitReaction()` / `return_type="smiles"` | `str` | +| `RdkitReaction(return_type="bytes")` | `bytes` | +| `RdkitReaction(return_type="mol")` | `ChemicalReaction` | +| `BingoBinaryMol(return_type="smiles" | "molfile" | "cml")` | `str` | +| `BingoBinaryMol(return_type="bytes")` | `bytes` | + ### RDKit Cartridge Settings RDKit PostgreSQL uses GUC variables to control similarity, substructure matching, and fingerprint sizes. Use an immutable settings object to establish a baseline whenever a pooled connection is checked out: diff --git a/data/bingo/general_extra.txt b/data/bingo/general_extra.txt index 59042fa..510c263 100644 --- a/data/bingo/general_extra.txt +++ b/data/bingo/general_extra.txt @@ -1,5 +1,5 @@ def mol_has_substructure( - mol: ColumnElement[AnyBingoMol], query: TextLike, parameters: TextLike = "" + mol: BingoMolSqlOperand, query: TextLike, parameters: TextLike = "" ) -> ColumnElement[bool]: """ Perform substructure search on a molecule column. @@ -24,14 +24,14 @@ def mol_has_substructure( def mol_has_smarts( - mol: ColumnElement[AnyBingoMol], query: TextLike, parameters: TextLike = "" + mol: BingoMolSqlOperand, query: TextLike, parameters: TextLike = "" ) -> ColumnElement[bool]: """ Perform SMARTS pattern matching on a molecule column. Parameters ---------- - mol : ColumnElement[AnyBingoMol] + mol : BingoMolSqlOperand SQLAlchemy column containing molecule data (SMILES, Molfile, or binary). query : TextLike SMARTS pattern string for matching. @@ -48,14 +48,14 @@ def mol_has_smarts( def mol_equals( - mol: ColumnElement[AnyBingoMol], query: TextLike, parameters: TextLike = "" + mol: BingoMolSqlOperand, query: TextLike, parameters: TextLike = "" ) -> ColumnElement[bool]: """ Perform exact structure matching on a molecule column. Parameters ---------- - mol : ColumnElement[AnyBingoMol] + mol : BingoMolSqlOperand SQLAlchemy column containing molecule data (SMILES, Molfile, or binary). query : TextLike Query molecule as SMILES or Molfile string for exact matching. @@ -73,14 +73,14 @@ def mol_equals( def mol_not_equals( - mol: ColumnElement[AnyBingoMol], query: TextLike, parameters: TextLike = "" + mol: BingoMolSqlOperand, query: TextLike, parameters: TextLike = "" ) -> ColumnElement[bool]: """Perform negated exact structure matching on a molecule column.""" return ~mol_equals(mol, query, parameters) def mol_similar_to( - mol: SqlOperand, + mol: BingoMolSqlOperand, query: BingoOperand, minimum: BingoSimilarityBound = 0.0, maximum: BingoSimilarityBound = 1.0, @@ -113,7 +113,7 @@ def mol_similar_to( def mol_similarity( - mol: SqlOperand, + mol: BingoMolSqlOperand, query: BingoOperand, bottom: BingoSimilarityBound = 0.0, top: BingoSimilarityBound = 1.0, @@ -128,7 +128,7 @@ def mol_similarity( def mol_similarity_score( - mol: SqlOperand, + mol: BingoMolSqlOperand, query: BingoOperand, metric: BingoParameters = "Tanimoto", ) -> ColumnElement[float]: @@ -137,14 +137,14 @@ def mol_similarity_score( def rxn_has_substructure( - rxn: ColumnElement[AnyBingoReaction], query: TextLike, parameters: TextLike = "" + rxn: BingoReactionSqlOperand, query: TextLike, parameters: TextLike = "" ) -> ColumnElement[bool]: """ Perform substructure search on a reaction column. Parameters ---------- - rxn : ColumnElement[AnyBingoReaction] + rxn : BingoReactionSqlOperand SQLAlchemy column containing reaction data (reaction SMILES, RXN, or binary). query : TextLike Query reaction as reaction SMILES, SMARTS, or RXN string. @@ -161,14 +161,14 @@ def rxn_has_substructure( def rxn_has_smarts( - rxn: ColumnElement[AnyBingoReaction], query: TextLike, parameters: TextLike = "" + rxn: BingoReactionSqlOperand, query: TextLike, parameters: TextLike = "" ) -> ColumnElement[bool]: """ Perform SMARTS pattern matching on a reaction column. Parameters ---------- - rxn : ColumnElement[AnyBingoReaction] + rxn : BingoReactionSqlOperand SQLAlchemy column containing reaction data (reaction SMILES, RXN, or binary). query : TextLike Reaction SMARTS pattern string for matching. @@ -185,14 +185,14 @@ def rxn_has_smarts( def rxn_equals( - rxn: ColumnElement[AnyBingoReaction], query: TextLike, parameters: TextLike = "" + rxn: BingoReactionSqlOperand, query: TextLike, parameters: TextLike = "" ) -> ColumnElement[bool]: """ Perform exact matching on a reaction column. Parameters ---------- - rxn : ColumnElement[AnyBingoReaction] + rxn : BingoReactionSqlOperand SQLAlchemy column containing reaction data (reaction SMILES, RXN, or binary). query : TextLike Query reaction as reaction SMILES or RXN string for exact matching. @@ -209,7 +209,7 @@ def rxn_equals( def rxn_not_equals( - rxn: ColumnElement[AnyBingoReaction], query: TextLike, parameters: TextLike = "" + rxn: BingoReactionSqlOperand, query: TextLike, parameters: TextLike = "" ) -> ColumnElement[bool]: """Perform negated exact matching on a reaction column.""" return ~rxn_equals(rxn, query, parameters) diff --git a/data/bingo/general_header.txt b/data/bingo/general_header.txt index a0787f4..5e80639 100644 --- a/data/bingo/general_header.txt +++ b/data/bingo/general_header.txt @@ -10,10 +10,18 @@ from sqlalchemy.sql.functions import GenericFunction from molalchemy.bingo.search import _bingo_search_values from molalchemy.protocols import ( + BinaryOperand, + BingoMolSqlOperand, BingoOperand, BingoParameters, + BingoReactionSqlOperand, BingoSimilarityBound, + BooleanOperand, + FloatOperand, + IntegerOperand, SqlOperand, + TextOperand, + TextOrBinaryOperand, ) from ._types import ( diff --git a/data/bingo/internal_header.txt b/data/bingo/internal_header.txt index 78ef830..fe011fa 100644 --- a/data/bingo/internal_header.txt +++ b/data/bingo/internal_header.txt @@ -3,6 +3,7 @@ This file defines internal Bingo PostgreSQL function wrappers for use with SQLAl """ from molalchemy.types import CString +from molalchemy.protocols import BinaryOperand, BooleanOperand, FloatOperand, IntegerOperand, SqlOperand, TextOperand, TextOrBinaryOperand from molalchemy.bingo.types import BingoBinaryMol, BingoBinaryReaction, BingoMol, BingoReaction from sqlalchemy import types as sqltypes from sqlalchemy.sql import cast, text diff --git a/data/rdkit/general_extra.txt b/data/rdkit/general_extra.txt index 06bf385..0166aa0 100644 --- a/data/rdkit/general_extra.txt +++ b/data/rdkit/general_extra.txt @@ -1,7 +1,7 @@ def fp_similar_to( - fp_column: SqlOperand, + fp_column: RdkitFingerprintSqlOperand, query: RdkitFingerprintOperand, minimum: RdkitSimilarityBound = 0.0, maximum: RdkitSimilarityBound = 1.0, @@ -17,7 +17,7 @@ def fp_similar_to( def fp_similarity_score( - fp_column: SqlOperand, + fp_column: RdkitFingerprintSqlOperand, query: RdkitFingerprintOperand, metric: RdkitSimilarityMetric = "Tanimoto", ) -> ColumnElement[float]: @@ -26,7 +26,7 @@ def fp_similarity_score( def mol_has_substructure( - mol_column: ColumnElement[RdkitMol], query: AnyRdkitMolLike + mol_column: RdkitMolSqlOperand, query: AnyRdkitMolLike ) -> ColumnElement[bool]: """ Perform substructure search. @@ -36,7 +36,7 @@ def mol_has_substructure( Parameters ---------- - mol_column : ColumnElement[molalchemy.rdkit.types.RdkitMol] + mol_column : RdkitMolSqlOperand The database column containing the molecular structure to search. query : AnyRdkitMolLike The query structure. Plain Python strings are treated as SMILES-like @@ -59,7 +59,9 @@ def mol_has_substructure( return _rdkit_predicate(mol_column, "@>", query) -def mol_has_smarts(mol_column: ColumnElement, pattern: str) -> ColumnElement[bool]: +def mol_has_smarts( + mol_column: RdkitMolSqlOperand, pattern: str +) -> ColumnElement[bool]: """ Perform molecule SMARTS search. @@ -89,7 +91,7 @@ def mol_has_smarts(mol_column: ColumnElement, pattern: str) -> ColumnElement[boo def mol_is_substructure_of( - mol_column: ColumnElement[RdkitMol], query: AnyRdkitMolLike + mol_column: RdkitMolSqlOperand, query: AnyRdkitMolLike ) -> ColumnElement[bool]: """ Perform reverse substructure search. @@ -99,7 +101,7 @@ def mol_is_substructure_of( Parameters ---------- - mol_column : ColumnElement[molalchemy.rdkit.types.RdkitMol] + mol_column : RdkitMolSqlOperand The database column containing the molecular structure to search. query : AnyRdkitMolLike The query structure. Plain Python strings are treated as SMILES-like @@ -115,7 +117,7 @@ def mol_is_substructure_of( def mol_equals( - mol_column: ColumnElement[RdkitMol], query: AnyRdkitMolLike + mol_column: RdkitMolSqlOperand, query: AnyRdkitMolLike ) -> ColumnElement[bool]: """ Perform exact structure matching. @@ -127,7 +129,7 @@ def mol_equals( Parameters ---------- - mol_column : ColumnElement[molalchemy.rdkit.types.RdkitMol] + mol_column : RdkitMolSqlOperand The database column containing the molecular structure to compare. query : AnyRdkitMolLike The query structure. Plain Python strings are treated as SMILES-like @@ -142,7 +144,7 @@ def mol_equals( def mol_not_equals( - mol_column: ColumnElement[RdkitMol], query: AnyRdkitMolLike + mol_column: RdkitMolSqlOperand, query: AnyRdkitMolLike ) -> ColumnElement[bool]: """ Perform negative exact structure matching. @@ -155,7 +157,7 @@ def mol_not_equals( def mol_has_query_substructure( - mol_column: ColumnElement[RdkitMol], + mol_column: RdkitMolSqlOperand, query: AnyRdkitMolLike | AnyRdkitQMolLike | AnyRdkitXQMolLike, ) -> ColumnElement[bool]: """ @@ -169,7 +171,7 @@ def mol_has_query_substructure( def mol_is_query_substructure_of( - mol_column: ColumnElement[RdkitMol], + mol_column: RdkitMolSqlOperand, query: AnyRdkitMolLike | AnyRdkitQMolLike | AnyRdkitXQMolLike, ) -> ColumnElement[bool]: """ @@ -183,7 +185,7 @@ def mol_is_query_substructure_of( def rxn_has_substructure( - rxn_column: ColumnElement[RdkitReaction], query: AnyRdkitReactionLike + rxn_column: RdkitReactionSqlOperand, query: AnyRdkitReactionLike ) -> ColumnElement[bool]: """ Perform reaction substructure search. @@ -195,7 +197,7 @@ def rxn_has_substructure( def rxn_is_substructure_of( - rxn_column: ColumnElement[RdkitReaction], query: AnyRdkitReactionLike + rxn_column: RdkitReactionSqlOperand, query: AnyRdkitReactionLike ) -> ColumnElement[bool]: """ Perform reverse reaction substructure search. @@ -207,7 +209,7 @@ def rxn_is_substructure_of( def rxn_equals( - rxn_column: ColumnElement[RdkitReaction], query: AnyRdkitReactionLike + rxn_column: RdkitReactionSqlOperand, query: AnyRdkitReactionLike ) -> ColumnElement[bool]: """ Perform exact reaction matching. @@ -219,7 +221,7 @@ def rxn_equals( def rxn_not_equals( - rxn_column: ColumnElement[RdkitReaction], query: AnyRdkitReactionLike + rxn_column: RdkitReactionSqlOperand, query: AnyRdkitReactionLike ) -> ColumnElement[bool]: """ Perform negative exact reaction matching. @@ -231,7 +233,7 @@ def rxn_not_equals( def rxn_has_substructure_fp( - rxn_column: ColumnElement[RdkitReaction], query: AnyRdkitReactionLike + rxn_column: RdkitReactionSqlOperand, query: AnyRdkitReactionLike ) -> ColumnElement[bool]: """ Perform fingerprint-backed reaction substructure search. @@ -243,7 +245,7 @@ def rxn_has_substructure_fp( def rxn_is_substructure_fp_of( - rxn_column: ColumnElement[RdkitReaction], query: AnyRdkitReactionLike + rxn_column: RdkitReactionSqlOperand, query: AnyRdkitReactionLike ) -> ColumnElement[bool]: """ Perform reverse fingerprint-backed reaction substructure search. @@ -254,7 +256,9 @@ def rxn_is_substructure_fp_of( return _rdkit_predicate(rxn_column, "?<", query) -def rxn_has_smarts(rxn_column: ColumnElement, pattern: str) -> ColumnElement[bool]: +def rxn_has_smarts( + rxn_column: RdkitReactionSqlOperand, pattern: str +) -> ColumnElement[bool]: """ Perform reaction substructure search. diff --git a/data/rdkit/general_header.txt b/data/rdkit/general_header.txt index d86bd46..ea780d7 100644 --- a/data/rdkit/general_header.txt +++ b/data/rdkit/general_header.txt @@ -19,10 +19,19 @@ from molalchemy.rdkit.search import ( _rdkit_similarity_score, ) from molalchemy.protocols import ( + BinaryOperand, + BooleanOperand, + FloatOperand, + IntegerOperand, RdkitFingerprintOperand, + RdkitFingerprintSqlOperand, + RdkitMolSqlOperand, + RdkitReactionSqlOperand, RdkitSimilarityBound, RdkitSimilarityMetric, SqlOperand, + TextOperand, + TextOrBinaryOperand, ) from molalchemy.rdkit.types import ( RdkitBitFingerprint, diff --git a/data/rdkit/internal_header.txt b/data/rdkit/internal_header.txt index 547a92a..5e2b8b5 100644 --- a/data/rdkit/internal_header.txt +++ b/data/rdkit/internal_header.txt @@ -9,6 +9,7 @@ from sqlalchemy.sql.elements import ColumnElement from molalchemy.rdkit.types import RdkitBitFingerprint, RdkitMol, RdkitSparseFingerprint, RdkitQMol, RdkitXQMol, RdkitReaction from molalchemy.types import CString +from molalchemy.protocols import BinaryOperand, BooleanOperand, FloatOperand, IntegerOperand, SqlOperand, TextOperand, TextOrBinaryOperand from ._types import AnyRdkitFingerprintLike, AnyRdkitMolLike, AnyRdkitQMolLike, AnyRdkitSparseFingerprintLike, AnyRdkitBitFingerprintLike, AnyRdkitReactionLike, AnyRdkitXQMolLike diff --git a/dev_scripts/gen_functions.py b/dev_scripts/gen_functions.py index 375ebbf..bc7ba88 100755 --- a/dev_scripts/gen_functions.py +++ b/dev_scripts/gen_functions.py @@ -15,6 +15,81 @@ UNDOCUMENTED_PARAM_DESCRIPTION = "Undocumented cartridge parameter." +ARGUMENT_TYPE_MAP = { + "bool | sqltypes.Boolean": "BooleanOperand", + "sqltypes.Boolean": "BooleanOperand", + "sqltypes.Boolean | bool": "BooleanOperand", + "float": "FloatOperand", + "float | sqltypes.Float": "FloatOperand", + "sqltypes.Float": "FloatOperand", + "int | sqltypes.Integer": "IntegerOperand", + "sqltypes.Integer": "IntegerOperand", + "bytes | sqltypes.LargeBinary": "BinaryOperand", + "sqltypes.LargeBinary": "BinaryOperand", + "str | sqltypes.Text": "TextOperand", + "sqltypes.Text": "TextOperand", + "str | sqltypes.Text | bytes | sqltypes.LargeBinary": "TextOrBinaryOperand", + "CString": "TextOperand", + "CString | Cast[Any]": "str | SqlOperand[Any]", + "sqltypes.Text | CString": "TextOperand", + "sqltypes.Text | CString | Cast[Any]": "str | SqlOperand[Any]", + "sqltypes.Text | CString | Cast[Any] | str": "str | SqlOperand[Any]", + "sqltypes.Text | Literal['CLEAR', 'DISCARD', 'ALTER', 'KEEP']": ( + "Literal['CLEAR', 'DISCARD', 'ALTER', 'KEEP'] | SqlOperand[str]" + ), +} + +RETURN_TYPE_MAP = { + "CString": ("str", "CString()"), + "None | sqltypes.NullType": ("None", "sqltypes.NullType()"), + "bytes | sqltypes.LargeBinary": ("bytes", "sqltypes.LargeBinary()"), + "float | sqltypes.Float": ("float", "sqltypes.Float()"), + "int | sqltypes.Integer": ("int", "sqltypes.Integer()"), + "sqltypes.Boolean": ("bool", "sqltypes.Boolean()"), + "sqltypes.Float": ("float", "sqltypes.Float()"), + "sqltypes.LargeBinary": ("bytes", "sqltypes.LargeBinary()"), + "sqltypes.Text": ("str", "sqltypes.Text()"), + "str | sqltypes.Text": ("str", "sqltypes.Text()"), +} + + +def normalize_argument_type(type_name: str) -> str: + """Translate metadata types into accepted Python values/SQL operands.""" + if type_name.startswith("Rdkit"): + if "Sparse" in type_name and "Bit" in type_name: + return "AnyRdkitFingerprintLike" + return " | ".join( + f"Any{part.replace(' ', '')}Like" for part in type_name.split("|") + ) + return ARGUMENT_TYPE_MAP.get(type_name, type_name) + + +def normalize_return_type(type_name: str) -> tuple[str, str]: + """Return the Python result and runtime SQLAlchemy type expression.""" + if type_name in RETURN_TYPE_MAP: + return RETURN_TYPE_MAP[type_name] + if "RdkitBitFingerprint" in type_name: + return "bytes", "RdkitBitFingerprint()" + if "RdkitSparseFingerprint" in type_name: + return "bytes", "RdkitSparseFingerprint()" + if "RdkitReaction" in type_name: + return "str", "RdkitReaction()" + if "RdkitMol" in type_name: + return "str", "RdkitMol()" + if "RdkitQMol" in type_name: + return "str", "RdkitQMol()" + if "RdkitXQMol" in type_name: + return "str", "RdkitXQMol()" + if "BingoBinaryMol" in type_name: + return "str", "BingoBinaryMol()" + if "BingoMol" in type_name: + return "str", "BingoMol()" + if "BingoBinaryReaction" in type_name: + return "bytes", "BingoBinaryReaction()" + if "BingoReaction" in type_name: + return "str", "BingoReaction()" + raise ValueError(f"Unsupported function return type: {type_name}") + def format_doc_param(param: dict) -> str: """Format a JSON argument definition as a NumPy-style docstring parameter.""" @@ -46,20 +121,13 @@ def json_to_function_code(func_name: str, data: dict, template) -> str: # Process function arguments for param in data["args"]: - if param["type"].startswith("Rdkit"): - if "Sparse" in param["type"] and "Bit" in param["type"]: - param["type"] = "AnyRdkitFingerprintLike" - else: - param_t = param["type"].split("|") - param["type"] = " | ".join( - [f"Any{t.replace(' ', '')}Like" for t in param_t] - ) - param_str = f"{param['name']}: {param['type']}" + argument_type = normalize_argument_type(param["type"]) + param_str = f"{param['name']}: {argument_type}" if param["default"] is not None: param_str += f" = {param['default']}" params_list.append(param_str) - doc_param_list.append(format_doc_param(param)) + doc_param_list.append(format_doc_param({**param, "type": argument_type})) arg_names.append(param["name"]) # Format parameters for template @@ -73,6 +141,9 @@ def json_to_function_code(func_name: str, data: dict, template) -> str: arg_names_str = "" # Render the template + python_return_type, sqlalchemy_return_type = normalize_return_type( + data["return_type"]["type"] + ) generated_code = template.render( func_name=func_name, description=description, @@ -80,6 +151,8 @@ def json_to_function_code(func_name: str, data: dict, template) -> str: arg_inits=params, arg_names=arg_names_str, return_type=data["return_type"]["type"], + python_return_type=python_return_type, + sqlalchemy_return_type=sqlalchemy_return_type, return_description=data["return_type"]["description"], ) return generated_code diff --git a/dev_scripts/templates/bingo_function.j2 b/dev_scripts/templates/bingo_function.j2 index fdd0a96..b442594 100644 --- a/dev_scripts/templates/bingo_function.j2 +++ b/dev_scripts/templates/bingo_function.j2 @@ -1,15 +1,5 @@ -class {{ func_name }}(GenericFunction): - {% if '|' not in return_type %} - type = {{ return_type }}() - {% elif 'BingoMol' in return_type %} - type = BingoMol() - {% elif 'BingoBinaryMol' in return_type %} - type = BingoBinaryMol() - {% elif 'BingoReaction' in return_type %} - type = BingoReaction() - {% elif 'BingoBinaryReaction' in return_type %} - type = BingoBinaryReaction() - {% endif %} +class {{ func_name }}(GenericFunction[{{ python_return_type }}]): + type = {{ sqlalchemy_return_type }} inherit_cache = True name = "{{ func_name.lower() }}" @@ -28,4 +18,4 @@ class {{ func_name }}(GenericFunction): {{ return_description }} """ super().__init__({{ arg_names }}**kwargs) - self.packagenames = ("bingo",) \ No newline at end of file + self.packagenames = ("bingo",) diff --git a/dev_scripts/templates/rdkit_function.j2 b/dev_scripts/templates/rdkit_function.j2 index 964554a..53f4a02 100644 --- a/dev_scripts/templates/rdkit_function.j2 +++ b/dev_scripts/templates/rdkit_function.j2 @@ -1,13 +1,5 @@ -class {{ func_name }}(GenericFunction): - {% if '|' not in return_type %} - type = {{ return_type }}() - {% elif 'RdkitMol' in return_type %} - type = RdkitMol() - {% elif 'RdkitReaction' in return_type %} - type = RdkitReaction() - {% elif 'RdkitBitFingerprint' in return_type %} - type = RdkitBitFingerprint() - {% endif %} +class {{ func_name }}(GenericFunction[{{ python_return_type }}]): + type = {{ sqlalchemy_return_type }} inherit_cache = True def __init__(self, {{ arg_inits }}**kwargs: Any) -> None: @@ -24,4 +16,4 @@ class {{ func_name }}(GenericFunction): Function[{{ return_type }}] {{ return_description }} """ - super().__init__({{ arg_names }}**kwargs) \ No newline at end of file + super().__init__({{ arg_names }}**kwargs) diff --git a/docs/index.md b/docs/index.md index 7933252..4af4eb8 100644 --- a/docs/index.md +++ b/docs/index.md @@ -243,6 +243,8 @@ Use the matching helper for the cartridge and data kind: ### Configurable Return Types ```python +from rdkit import Chem + from molalchemy.rdkit.types import RdkitMol class MoleculeWithFormats(Base): @@ -252,11 +254,28 @@ class MoleculeWithFormats(Base): # Return as SMILES string (default) structure_smiles: Mapped[str] = mapped_column(RdkitMol()) # Return as RDKit Mol object - structure_mol: Mapped[bytes] = mapped_column(RdkitMol(return_type="mol")) + structure_mol: Mapped[Chem.Mol] = mapped_column(RdkitMol(return_type="mol")) # Return as raw bytes structure_bytes: Mapped[bytes] = mapped_column(RdkitMol(return_type="bytes")) ``` +The SQL type describes how PostgreSQL stores the value; `Mapped[...]` describes +the Python value returned to the model. SQLAlchemy 2.0 does not infer +`mapped_column()` attributes from the supplied type, so ORM models should always +spell out `Mapped[T]`. Core `Column(...)` and generated SQL expressions infer +the result directly from MolAlchemy's types. + +| Type configuration | Python result | +| --- | --- | +| `RdkitMol()` / `return_type="smiles"` | `str` | +| `RdkitMol(return_type="bytes")` | `bytes` | +| `RdkitMol(return_type="mol")` | `Chem.Mol` | +| `RdkitReaction()` / `return_type="smiles"` | `str` | +| `RdkitReaction(return_type="bytes")` | `bytes` | +| `RdkitReaction(return_type="mol")` | `ChemicalReaction` | +| `BingoBinaryMol(return_type="smiles" | "molfile" | "cml")` | `str` | +| `BingoBinaryMol(return_type="bytes")` | `bytes` | + ### RDKit Cartridge Settings RDKit PostgreSQL uses GUC variables to control similarity, substructure matching, and fingerprint sizes. Use an immutable settings object to establish a baseline whenever a pooled connection is checked out: diff --git a/docs/tutorials/05_Reactions_rdkit_ORM.ipynb b/docs/tutorials/05_Reactions_rdkit_ORM.ipynb index 9e552d6..d148c79 100644 --- a/docs/tutorials/05_Reactions_rdkit_ORM.ipynb +++ b/docs/tutorials/05_Reactions_rdkit_ORM.ipynb @@ -788,7 +788,9 @@ " Integer, primary_key=True, autoincrement=True, init=False\n", " )\n", " name: Mapped[str] = mapped_column(String(100), unique=True)\n", - " rxn: Mapped[bytes] = mapped_column(types.RdkitReaction(return_type=\"mol\"))\n", + " rxn: Mapped[AllChem.ChemicalReaction] = mapped_column(\n", + " types.RdkitReaction(return_type=\"mol\")\n", + " )\n", "\n", "\n", "ReactionMol.__table__.drop(eng, checkfirst=True)\n", diff --git a/src/molalchemy/bingo/functions/_types.py b/src/molalchemy/bingo/functions/_types.py index e816658..25a35cd 100644 --- a/src/molalchemy/bingo/functions/_types.py +++ b/src/molalchemy/bingo/functions/_types.py @@ -2,12 +2,11 @@ from typing import Any, TypeAlias, TypeVar -from sqlalchemy.orm import InstrumentedAttribute -from sqlalchemy.sql.elements import ColumnElement +from molalchemy.protocols import SqlOperand T = TypeVar("T") -SQLAlchemyCoercible: TypeAlias = ColumnElement[T] | InstrumentedAttribute[T] -SqlExpression: TypeAlias = ColumnElement[Any] | InstrumentedAttribute[Any] +SQLAlchemyCoercible: TypeAlias = SqlOperand[T] +SqlExpression: TypeAlias = SqlOperand[Any] LiteralStrBytes: TypeAlias = str | bytes TextLike: TypeAlias = str | bytes | SqlExpression diff --git a/src/molalchemy/bingo/functions/general.py b/src/molalchemy/bingo/functions/general.py index 4832a28..153f0e3 100644 --- a/src/molalchemy/bingo/functions/general.py +++ b/src/molalchemy/bingo/functions/general.py @@ -10,10 +10,15 @@ from molalchemy.bingo.search import _bingo_search_values from molalchemy.protocols import ( + BingoMolSqlOperand, BingoOperand, BingoParameters, + BingoReactionSqlOperand, BingoSimilarityBound, + BooleanOperand, SqlOperand, + TextOperand, + TextOrBinaryOperand, ) from ._types import ( @@ -32,7 +37,7 @@ def mol_has_substructure( - mol: ColumnElement[AnyBingoMol], query: TextLike, parameters: TextLike = "" + mol: BingoMolSqlOperand, query: TextLike, parameters: TextLike = "" ) -> ColumnElement[bool]: """ Perform substructure search on a molecule column. @@ -57,14 +62,14 @@ def mol_has_substructure( def mol_has_smarts( - mol: ColumnElement[AnyBingoMol], query: TextLike, parameters: TextLike = "" + mol: BingoMolSqlOperand, query: TextLike, parameters: TextLike = "" ) -> ColumnElement[bool]: """ Perform SMARTS pattern matching on a molecule column. Parameters ---------- - mol : ColumnElement[AnyBingoMol] + mol : BingoMolSqlOperand SQLAlchemy column containing molecule data (SMILES, Molfile, or binary). query : TextLike SMARTS pattern string for matching. @@ -81,14 +86,14 @@ def mol_has_smarts( def mol_equals( - mol: ColumnElement[AnyBingoMol], query: TextLike, parameters: TextLike = "" + mol: BingoMolSqlOperand, query: TextLike, parameters: TextLike = "" ) -> ColumnElement[bool]: """ Perform exact structure matching on a molecule column. Parameters ---------- - mol : ColumnElement[AnyBingoMol] + mol : BingoMolSqlOperand SQLAlchemy column containing molecule data (SMILES, Molfile, or binary). query : TextLike Query molecule as SMILES or Molfile string for exact matching. @@ -106,14 +111,14 @@ def mol_equals( def mol_not_equals( - mol: ColumnElement[AnyBingoMol], query: TextLike, parameters: TextLike = "" + mol: BingoMolSqlOperand, query: TextLike, parameters: TextLike = "" ) -> ColumnElement[bool]: """Perform negated exact structure matching on a molecule column.""" return ~mol_equals(mol, query, parameters) def mol_similar_to( - mol: SqlOperand, + mol: BingoMolSqlOperand, query: BingoOperand, minimum: BingoSimilarityBound = 0.0, maximum: BingoSimilarityBound = 1.0, @@ -146,7 +151,7 @@ def mol_similar_to( def mol_similarity( - mol: SqlOperand, + mol: BingoMolSqlOperand, query: BingoOperand, bottom: BingoSimilarityBound = 0.0, top: BingoSimilarityBound = 1.0, @@ -161,7 +166,7 @@ def mol_similarity( def mol_similarity_score( - mol: SqlOperand, + mol: BingoMolSqlOperand, query: BingoOperand, metric: BingoParameters = "Tanimoto", ) -> ColumnElement[float]: @@ -170,14 +175,14 @@ def mol_similarity_score( def rxn_has_substructure( - rxn: ColumnElement[AnyBingoReaction], query: TextLike, parameters: TextLike = "" + rxn: BingoReactionSqlOperand, query: TextLike, parameters: TextLike = "" ) -> ColumnElement[bool]: """ Perform substructure search on a reaction column. Parameters ---------- - rxn : ColumnElement[AnyBingoReaction] + rxn : BingoReactionSqlOperand SQLAlchemy column containing reaction data (reaction SMILES, RXN, or binary). query : TextLike Query reaction as reaction SMILES, SMARTS, or RXN string. @@ -194,14 +199,14 @@ def rxn_has_substructure( def rxn_has_smarts( - rxn: ColumnElement[AnyBingoReaction], query: TextLike, parameters: TextLike = "" + rxn: BingoReactionSqlOperand, query: TextLike, parameters: TextLike = "" ) -> ColumnElement[bool]: """ Perform SMARTS pattern matching on a reaction column. Parameters ---------- - rxn : ColumnElement[AnyBingoReaction] + rxn : BingoReactionSqlOperand SQLAlchemy column containing reaction data (reaction SMILES, RXN, or binary). query : TextLike Reaction SMARTS pattern string for matching. @@ -218,14 +223,14 @@ def rxn_has_smarts( def rxn_equals( - rxn: ColumnElement[AnyBingoReaction], query: TextLike, parameters: TextLike = "" + rxn: BingoReactionSqlOperand, query: TextLike, parameters: TextLike = "" ) -> ColumnElement[bool]: """ Perform exact matching on a reaction column. Parameters ---------- - rxn : ColumnElement[AnyBingoReaction] + rxn : BingoReactionSqlOperand SQLAlchemy column containing reaction data (reaction SMILES, RXN, or binary). query : TextLike Query reaction as reaction SMILES or RXN string for exact matching. @@ -242,20 +247,22 @@ def rxn_equals( def rxn_not_equals( - rxn: ColumnElement[AnyBingoReaction], query: TextLike, parameters: TextLike = "" + rxn: BingoReactionSqlOperand, query: TextLike, parameters: TextLike = "" ) -> ColumnElement[bool]: """Perform negated exact matching on a reaction column.""" return ~rxn_equals(rxn, query, parameters) -class aam(GenericFunction): +class aam(GenericFunction[str]): + type = sqltypes.Text() inherit_cache = True name = "aam" def __init__( self, rxn: AnyBingoReactionLike | AnyBingoBinaryReactionLike, - strategy: sqltypes.Text | Literal["CLEAR", "DISCARD", "ALTER", "KEEP"] = "KEEP", + strategy: Literal["CLEAR", "DISCARD", "ALTER", "KEEP"] + | SqlOperand[str] = "KEEP", **kwargs: Any, ) -> None: """Creates an atom-atom mapping for a reaction. @@ -264,7 +271,7 @@ def __init__( ---------- rxn : AnyBingoReactionLike | AnyBingoBinaryReactionLike Input reaction - strategy : sqltypes.Text | Literal['CLEAR', 'DISCARD', 'ALTER', 'KEEP'] + strategy : Literal['CLEAR', 'DISCARD', 'ALTER', 'KEEP'] | SqlOperand[str] Strategy for handling existing atom mapping (default is 'KEEP'). - 'CLEAR': Remove all existing mappings and compute new ones - 'DISCARD': Remove all mappings without computing new ones @@ -282,7 +289,8 @@ def __init__( self.packagenames = ("bingo",) -class cansmiles(GenericFunction): +class cansmiles(GenericFunction[str]): + type = sqltypes.Text() inherit_cache = True name = "cansmiles" @@ -307,7 +315,8 @@ def __init__( self.packagenames = ("bingo",) -class checkmolecule(GenericFunction): +class checkmolecule(GenericFunction[str]): + type = sqltypes.Text() inherit_cache = True name = "checkmolecule" @@ -332,7 +341,8 @@ def __init__( self.packagenames = ("bingo",) -class checkreaction(GenericFunction): +class checkreaction(GenericFunction[str]): + type = sqltypes.Text() inherit_cache = True name = "checkreaction" @@ -357,7 +367,8 @@ def __init__( self.packagenames = ("bingo",) -class cml(GenericFunction): +class cml(GenericFunction[str]): + type = sqltypes.Text() inherit_cache = True name = "cml" @@ -382,14 +393,15 @@ def __init__( self.packagenames = ("bingo",) -class compactmolecule(GenericFunction): +class compactmolecule(GenericFunction[bytes]): + type = sqltypes.LargeBinary() inherit_cache = True name = "compactmolecule" def __init__( self, mol: AnyBingoMolLike | AnyBingoBinaryMolLike, - use_pos: sqltypes.Boolean | bool = False, + use_pos: BooleanOperand = False, **kwargs: Any, ) -> None: """Calculates the compact representation of a molecule. @@ -398,7 +410,7 @@ def __init__( ---------- mol : AnyBingoMolLike | AnyBingoBinaryMolLike Input molecule in any supported format - use_pos : sqltypes.Boolean | bool + use_pos : BooleanOperand If it is true, the positions of atoms are saved to the binary format. If it is false, the positions are skipped. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -412,14 +424,15 @@ def __init__( self.packagenames = ("bingo",) -class compactreaction(GenericFunction): +class compactreaction(GenericFunction[bytes]): + type = sqltypes.LargeBinary() inherit_cache = True name = "compactreaction" def __init__( self, rxn: AnyBingoReactionLike | AnyBingoBinaryReactionLike, - use_pos: sqltypes.Boolean | bool = False, + use_pos: BooleanOperand = False, **kwargs: Any, ) -> None: """Calls the bingo cartridge function `compactreaction`. @@ -428,7 +441,7 @@ def __init__( ---------- rxn : AnyBingoReactionLike | AnyBingoBinaryReactionLike Input reaction in any supported format - use_pos : sqltypes.Boolean | bool + use_pos : BooleanOperand If it is true, the positions of atoms are saved to the binary format. If it is false, the positions are skipped. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -442,29 +455,30 @@ def __init__( self.packagenames = ("bingo",) -class exportrdf(GenericFunction): +class exportrdf(GenericFunction[None]): + type = sqltypes.NullType() inherit_cache = True name = "exportrdf" def __init__( self, - arg_1: str | sqltypes.Text, - arg_2: str | sqltypes.Text, - arg_3: str | sqltypes.Text, - arg_4: str | sqltypes.Text, + arg_1: TextOperand, + arg_2: TextOperand, + arg_3: TextOperand, + arg_4: TextOperand, **kwargs: Any, ) -> None: """Exports reactions to an RDF format. Parameters ---------- - arg_1 : str | sqltypes.Text + arg_1 : TextOperand Undocumented cartridge parameter. - arg_2 : str | sqltypes.Text + arg_2 : TextOperand Undocumented cartridge parameter. - arg_3 : str | sqltypes.Text + arg_3 : TextOperand Undocumented cartridge parameter. - arg_4 : str | sqltypes.Text + arg_4 : TextOperand Undocumented cartridge parameter. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -478,29 +492,30 @@ def __init__( self.packagenames = ("bingo",) -class exportsdf(GenericFunction): +class exportsdf(GenericFunction[None]): + type = sqltypes.NullType() inherit_cache = True name = "exportsdf" def __init__( self, - table: str | sqltypes.Text, - column: str | sqltypes.Text, - other_columns: str | sqltypes.Text, - outfile: str | sqltypes.Text, + table: TextOperand, + column: TextOperand, + other_columns: TextOperand, + outfile: TextOperand, **kwargs: Any, ) -> None: """Exports molecules to an SDF format. Parameters ---------- - table : str | sqltypes.Text + table : TextOperand Name of the table containing the molecules to export - column : str | sqltypes.Text + column : TextOperand Name of the column containing the molecules to export - other_columns : str | sqltypes.Text + other_columns : TextOperand Space-separated list of other columns to include in the SDF file as SD data fields - outfile : str | sqltypes.Text + outfile : TextOperand Path to the output SDF file kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -514,16 +529,17 @@ def __init__( self.packagenames = ("bingo",) -class filetoblob(GenericFunction): +class filetoblob(GenericFunction[bytes]): + type = sqltypes.LargeBinary() inherit_cache = True name = "filetoblob" - def __init__(self, arg_1: str | sqltypes.Text, **kwargs: Any) -> None: + def __init__(self, arg_1: TextOperand, **kwargs: Any) -> None: """Calls the bingo cartridge function `filetoblob`. Parameters ---------- - arg_1 : str | sqltypes.Text + arg_1 : TextOperand Undocumented cartridge parameter. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -537,16 +553,17 @@ def __init__(self, arg_1: str | sqltypes.Text, **kwargs: Any) -> None: self.packagenames = ("bingo",) -class filetotext(GenericFunction): +class filetotext(GenericFunction[str]): + type = sqltypes.Text() inherit_cache = True name = "filetotext" - def __init__(self, arg_1: str | sqltypes.Text, **kwargs: Any) -> None: + def __init__(self, arg_1: TextOperand, **kwargs: Any) -> None: """Calls the bingo cartridge function `filetotext`. Parameters ---------- - arg_1 : str | sqltypes.Text + arg_1 : TextOperand Undocumented cartridge parameter. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -560,23 +577,21 @@ def __init__(self, arg_1: str | sqltypes.Text, **kwargs: Any) -> None: self.packagenames = ("bingo",) -class fingerprint(GenericFunction): +class fingerprint(GenericFunction[bytes]): + type = sqltypes.LargeBinary() inherit_cache = True name = "fingerprint" def __init__( - self, - arg_1: str | sqltypes.Text | bytes | sqltypes.LargeBinary, - arg_2: str | sqltypes.Text, - **kwargs: Any, + self, arg_1: TextOrBinaryOperand, arg_2: TextOperand, **kwargs: Any ) -> None: """Calls the bingo cartridge function `fingerprint`. Parameters ---------- - arg_1 : str | sqltypes.Text | bytes | sqltypes.LargeBinary + arg_1 : TextOrBinaryOperand Undocumented cartridge parameter. - arg_2 : str | sqltypes.Text + arg_2 : TextOperand Undocumented cartridge parameter. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -590,16 +605,17 @@ def __init__( self.packagenames = ("bingo",) -class getblockcount(GenericFunction): +class getblockcount(GenericFunction[int]): + type = sqltypes.Integer() inherit_cache = True name = "getblockcount" - def __init__(self, arg_1: str | sqltypes.Text, **kwargs: Any) -> None: + def __init__(self, arg_1: TextOperand, **kwargs: Any) -> None: """Calls the bingo cartridge function `getblockcount`. Parameters ---------- - arg_1 : str | sqltypes.Text + arg_1 : TextOperand Undocumented cartridge parameter. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -613,7 +629,8 @@ def __init__(self, arg_1: str | sqltypes.Text, **kwargs: Any) -> None: self.packagenames = ("bingo",) -class getindexstructurescount(GenericFunction): +class getindexstructurescount(GenericFunction[int]): + type = sqltypes.Integer() inherit_cache = True name = "getindexstructurescount" @@ -635,7 +652,8 @@ def __init__(self, **kwargs: Any) -> None: self.packagenames = ("bingo",) -class getmass(GenericFunction): +class getmass(GenericFunction[float]): + type = sqltypes.Float() inherit_cache = True name = "getmass" @@ -660,7 +678,8 @@ def __init__( self.packagenames = ("bingo",) -class getname(GenericFunction): +class getname(GenericFunction[str]): + type = sqltypes.Text() inherit_cache = True name = "getname" @@ -683,7 +702,7 @@ def __init__(self, arg_1: AnyBingoMolLike, **kwargs: Any) -> None: self.packagenames = ("bingo",) -class getsimilarity(GenericFunction): +class getsimilarity(GenericFunction[float]): type = sqltypes.Float() inherit_cache = True name = "getsimilarity" @@ -717,16 +736,17 @@ def __init__( self.packagenames = ("bingo",) -class getstructurescount(GenericFunction): +class getstructurescount(GenericFunction[int]): + type = sqltypes.Integer() inherit_cache = True name = "getstructurescount" - def __init__(self, arg_1: str | sqltypes.Text, **kwargs: Any) -> None: + def __init__(self, arg_1: TextOperand, **kwargs: Any) -> None: """Calls the bingo cartridge function `getstructurescount`. Parameters ---------- - arg_1 : str | sqltypes.Text + arg_1 : TextOperand Undocumented cartridge parameter. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -740,7 +760,8 @@ def __init__(self, arg_1: str | sqltypes.Text, **kwargs: Any) -> None: self.packagenames = ("bingo",) -class getversion(GenericFunction): +class getversion(GenericFunction[str]): + type = sqltypes.Text() inherit_cache = True name = "getversion" @@ -762,14 +783,15 @@ def __init__(self, **kwargs: Any) -> None: self.packagenames = ("bingo",) -class getweight(GenericFunction): +class getweight(GenericFunction[float]): + type = sqltypes.Float() inherit_cache = True name = "getweight" def __init__( self, mol: AnyBingoMolLike | AnyBingoBinaryMolLike, - arg_2: str | sqltypes.Text, + arg_2: TextOperand, **kwargs: Any, ) -> None: """Calls the bingo cartridge function `getweight`. @@ -778,7 +800,7 @@ def __init__( ---------- mol : AnyBingoMolLike | AnyBingoBinaryMolLike Undocumented cartridge parameter. - arg_2 : str | sqltypes.Text + arg_2 : TextOperand Undocumented cartridge parameter. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -792,7 +814,8 @@ def __init__( self.packagenames = ("bingo",) -class gross(GenericFunction): +class gross(GenericFunction[str]): + type = sqltypes.Text() inherit_cache = True name = "gross" @@ -817,7 +840,8 @@ def __init__( self.packagenames = ("bingo",) -class importrdf(GenericFunction): +class importrdf(GenericFunction[None]): + type = sqltypes.NullType() inherit_cache = True name = "importrdf" @@ -853,29 +877,30 @@ def __init__( self.packagenames = ("bingo",) -class importsdf(GenericFunction): +class importsdf(GenericFunction[None]): + type = sqltypes.NullType() inherit_cache = True name = "importsdf" def __init__( self, - arg_1: str | sqltypes.Text, - arg_2: str | sqltypes.Text, - arg_3: str | sqltypes.Text, - arg_4: str | sqltypes.Text, + arg_1: TextOperand, + arg_2: TextOperand, + arg_3: TextOperand, + arg_4: TextOperand, **kwargs: Any, ) -> None: """Calls the bingo cartridge function `importsdf`. Parameters ---------- - arg_1 : str | sqltypes.Text + arg_1 : TextOperand Undocumented cartridge parameter. - arg_2 : str | sqltypes.Text + arg_2 : TextOperand Undocumented cartridge parameter. - arg_3 : str | sqltypes.Text + arg_3 : TextOperand Undocumented cartridge parameter. - arg_4 : str | sqltypes.Text + arg_4 : TextOperand Undocumented cartridge parameter. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -889,29 +914,30 @@ def __init__( self.packagenames = ("bingo",) -class importsmiles(GenericFunction): +class importsmiles(GenericFunction[None]): + type = sqltypes.NullType() inherit_cache = True name = "importsmiles" def __init__( self, - arg_1: str | sqltypes.Text, - arg_2: str | sqltypes.Text, - arg_3: str | sqltypes.Text, - arg_4: str | sqltypes.Text, + arg_1: TextOperand, + arg_2: TextOperand, + arg_3: TextOperand, + arg_4: TextOperand, **kwargs: Any, ) -> None: """Calls the bingo cartridge function `importsmiles`. Parameters ---------- - arg_1 : str | sqltypes.Text + arg_1 : TextOperand Undocumented cartridge parameter. - arg_2 : str | sqltypes.Text + arg_2 : TextOperand Undocumented cartridge parameter. - arg_3 : str | sqltypes.Text + arg_3 : TextOperand Undocumented cartridge parameter. - arg_4 : str | sqltypes.Text + arg_4 : TextOperand Undocumented cartridge parameter. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -925,14 +951,15 @@ def __init__( self.packagenames = ("bingo",) -class inchi(GenericFunction): +class inchi(GenericFunction[str]): + type = sqltypes.Text() inherit_cache = True name = "inchi" def __init__( self, mol: AnyBingoMolLike | AnyBingoBinaryMolLike, - arg_2: str | sqltypes.Text, + arg_2: TextOperand, **kwargs: Any, ) -> None: """Calls the bingo cartridge function `inchi`. @@ -941,7 +968,7 @@ def __init__( ---------- mol : AnyBingoMolLike | AnyBingoBinaryMolLike Undocumented cartridge parameter. - arg_2 : str | sqltypes.Text + arg_2 : TextOperand Undocumented cartridge parameter. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -955,7 +982,8 @@ def __init__( self.packagenames = ("bingo",) -class inchikey(GenericFunction): +class inchikey(GenericFunction[str]): + type = sqltypes.Text() inherit_cache = True name = "inchikey" @@ -978,7 +1006,7 @@ def __init__(self, mol: AnyBingoMolLike, **kwargs: Any) -> None: self.packagenames = ("bingo",) -class matchexact(GenericFunction): +class matchexact(GenericFunction[bool]): type = sqltypes.Boolean() inherit_cache = True name = "matchexact" @@ -1001,7 +1029,7 @@ def __init__(self, **kwargs: Any) -> None: self.packagenames = ("bingo",) -class matchgross(GenericFunction): +class matchgross(GenericFunction[bool]): type = sqltypes.Boolean() inherit_cache = True name = "matchgross" @@ -1024,7 +1052,7 @@ def __init__(self, **kwargs: Any) -> None: self.packagenames = ("bingo",) -class matchrexact(GenericFunction): +class matchrexact(GenericFunction[bool]): type = sqltypes.Boolean() inherit_cache = True name = "matchrexact" @@ -1047,7 +1075,7 @@ def __init__(self, **kwargs: Any) -> None: self.packagenames = ("bingo",) -class matchrsmarts(GenericFunction): +class matchrsmarts(GenericFunction[bool]): type = sqltypes.Boolean() inherit_cache = True name = "matchrsmarts" @@ -1070,7 +1098,7 @@ def __init__(self, **kwargs: Any) -> None: self.packagenames = ("bingo",) -class matchrsub(GenericFunction): +class matchrsub(GenericFunction[bool]): type = sqltypes.Boolean() inherit_cache = True name = "matchrsub" @@ -1093,7 +1121,7 @@ def __init__(self, **kwargs: Any) -> None: self.packagenames = ("bingo",) -class matchsim(GenericFunction): +class matchsim(GenericFunction[bool]): type = sqltypes.Boolean() inherit_cache = True name = "matchsim" @@ -1116,7 +1144,7 @@ def __init__(self, **kwargs: Any) -> None: self.packagenames = ("bingo",) -class matchsmarts(GenericFunction): +class matchsmarts(GenericFunction[bool]): type = sqltypes.Boolean() inherit_cache = True name = "matchsmarts" @@ -1139,7 +1167,7 @@ def __init__(self, **kwargs: Any) -> None: self.packagenames = ("bingo",) -class matchsub(GenericFunction): +class matchsub(GenericFunction[bool]): type = sqltypes.Boolean() inherit_cache = True name = "matchsub" @@ -1162,7 +1190,8 @@ def __init__(self, **kwargs: Any) -> None: self.packagenames = ("bingo",) -class molfile(GenericFunction): +class molfile(GenericFunction[str]): + type = sqltypes.Text() inherit_cache = True name = "molfile" @@ -1187,20 +1216,19 @@ def __init__( self.packagenames = ("bingo",) -class precachedatabase(GenericFunction): +class precachedatabase(GenericFunction[str]): + type = sqltypes.Text() inherit_cache = True name = "precachedatabase" - def __init__( - self, arg_1: str | sqltypes.Text, arg_2: str | sqltypes.Text, **kwargs: Any - ) -> None: + def __init__(self, arg_1: TextOperand, arg_2: TextOperand, **kwargs: Any) -> None: """Calls the bingo cartridge function `precachedatabase`. Parameters ---------- - arg_1 : str | sqltypes.Text + arg_1 : TextOperand Undocumented cartridge parameter. - arg_2 : str | sqltypes.Text + arg_2 : TextOperand Undocumented cartridge parameter. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -1214,7 +1242,8 @@ def __init__( self.packagenames = ("bingo",) -class rcml(GenericFunction): +class rcml(GenericFunction[str]): + type = sqltypes.Text() inherit_cache = True name = "rcml" @@ -1239,14 +1268,15 @@ def __init__( self.packagenames = ("bingo",) -class rfingerprint(GenericFunction): +class rfingerprint(GenericFunction[bytes]): + type = sqltypes.LargeBinary() inherit_cache = True name = "rfingerprint" def __init__( self, rxn: AnyBingoReactionLike | AnyBingoBinaryReactionLike, - arg_2: str | sqltypes.Text, + arg_2: TextOperand, **kwargs: Any, ) -> None: """Calls the bingo cartridge function `rfingerprint`. @@ -1255,7 +1285,7 @@ def __init__( ---------- rxn : AnyBingoReactionLike | AnyBingoBinaryReactionLike Undocumented cartridge parameter. - arg_2 : str | sqltypes.Text + arg_2 : TextOperand Undocumented cartridge parameter. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -1269,7 +1299,8 @@ def __init__( self.packagenames = ("bingo",) -class rsmiles(GenericFunction): +class rsmiles(GenericFunction[str]): + type = sqltypes.Text() inherit_cache = True name = "rsmiles" @@ -1294,7 +1325,8 @@ def __init__( self.packagenames = ("bingo",) -class rxnfile(GenericFunction): +class rxnfile(GenericFunction[str]): + type = sqltypes.Text() inherit_cache = True name = "rxnfile" @@ -1319,7 +1351,8 @@ def __init__( self.packagenames = ("bingo",) -class smiles(GenericFunction): +class smiles(GenericFunction[str]): + type = sqltypes.Text() inherit_cache = True name = "smiles" @@ -1344,14 +1377,15 @@ def __init__( self.packagenames = ("bingo",) -class standardize(GenericFunction): +class standardize(GenericFunction[str]): + type = sqltypes.Text() inherit_cache = True name = "standardize" def __init__( self, mol: AnyBingoMolLike | AnyBingoBinaryMolLike, - arg_2: str | sqltypes.Text, + arg_2: TextOperand, **kwargs: Any, ) -> None: """Calls the bingo cartridge function `standardize`. @@ -1360,7 +1394,7 @@ def __init__( ---------- mol : AnyBingoMolLike | AnyBingoBinaryMolLike Undocumented cartridge parameter. - arg_2 : str | sqltypes.Text + arg_2 : TextOperand Undocumented cartridge parameter. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. diff --git a/src/molalchemy/bingo/functions/internal.py b/src/molalchemy/bingo/functions/internal.py index 28ce703..d4058a2 100644 --- a/src/molalchemy/bingo/functions/internal.py +++ b/src/molalchemy/bingo/functions/internal.py @@ -7,30 +7,36 @@ from sqlalchemy import types as sqltypes from sqlalchemy.sql.functions import GenericFunction +from molalchemy.protocols import ( + FloatOperand, + IntegerOperand, + TextOperand, + TextOrBinaryOperand, +) from molalchemy.types import CString -class _exact_internal(GenericFunction): +class _exact_internal(GenericFunction[bool]): type = sqltypes.Boolean() inherit_cache = True name = "_exact_internal" def __init__( self, - arg_1: str | sqltypes.Text, - arg_2: str | sqltypes.Text | bytes | sqltypes.LargeBinary, - arg_3: str | sqltypes.Text, + arg_1: TextOperand, + arg_2: TextOrBinaryOperand, + arg_3: TextOperand, **kwargs: Any, ) -> None: """Calls the bingo cartridge function `_exact_internal`. Parameters ---------- - arg_1 : str | sqltypes.Text + arg_1 : TextOperand Undocumented cartridge parameter. - arg_2 : str | sqltypes.Text | bytes | sqltypes.LargeBinary + arg_2 : TextOrBinaryOperand Undocumented cartridge parameter. - arg_3 : str | sqltypes.Text + arg_3 : TextOperand Undocumented cartridge parameter. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -44,7 +50,8 @@ def __init__( self.packagenames = ("bingo",) -class _get_block_count(GenericFunction): +class _get_block_count(GenericFunction[int]): + type = sqltypes.Integer() inherit_cache = True name = "_get_block_count" @@ -66,7 +73,7 @@ def __init__(self, **kwargs: Any) -> None: self.packagenames = ("bingo",) -class _get_profiling_info(GenericFunction): +class _get_profiling_info(GenericFunction[str]): type = CString() inherit_cache = True name = "_get_profiling_info" @@ -89,7 +96,8 @@ def __init__(self, **kwargs: Any) -> None: self.packagenames = ("bingo",) -class _get_structures_count(GenericFunction): +class _get_structures_count(GenericFunction[int]): + type = sqltypes.Integer() inherit_cache = True name = "_get_structures_count" @@ -111,27 +119,27 @@ def __init__(self, **kwargs: Any) -> None: self.packagenames = ("bingo",) -class _gross_internal(GenericFunction): +class _gross_internal(GenericFunction[bool]): type = sqltypes.Boolean() inherit_cache = True name = "_gross_internal" def __init__( self, - arg_1: str | sqltypes.Text, - arg_2: str | sqltypes.Text, - arg_3: str | sqltypes.Text | bytes | sqltypes.LargeBinary, + arg_1: TextOperand, + arg_2: TextOperand, + arg_3: TextOrBinaryOperand, **kwargs: Any, ) -> None: """Calls the bingo cartridge function `_gross_internal`. Parameters ---------- - arg_1 : str | sqltypes.Text + arg_1 : TextOperand Undocumented cartridge parameter. - arg_2 : str | sqltypes.Text + arg_2 : TextOperand Undocumented cartridge parameter. - arg_3 : str | sqltypes.Text | bytes | sqltypes.LargeBinary + arg_3 : TextOrBinaryOperand Undocumented cartridge parameter. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -145,26 +153,27 @@ def __init__( self.packagenames = ("bingo",) -class _internal_func_011(GenericFunction): +class _internal_func_011(GenericFunction[None]): + type = sqltypes.NullType() inherit_cache = True name = "_internal_func_011" def __init__( self, - arg_1: int | sqltypes.Integer, - arg_2: str | sqltypes.Text, - arg_3: str | sqltypes.Text, + arg_1: IntegerOperand, + arg_2: TextOperand, + arg_3: TextOperand, **kwargs: Any, ) -> None: """Calls the bingo cartridge function `_internal_func_011`. Parameters ---------- - arg_1 : int | sqltypes.Integer + arg_1 : IntegerOperand Undocumented cartridge parameter. - arg_2 : str | sqltypes.Text + arg_2 : TextOperand Undocumented cartridge parameter. - arg_3 : str | sqltypes.Text + arg_3 : TextOperand Undocumented cartridge parameter. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -178,20 +187,21 @@ def __init__( self.packagenames = ("bingo",) -class _internal_func_012(GenericFunction): +class _internal_func_012(GenericFunction[None]): + type = sqltypes.NullType() inherit_cache = True name = "_internal_func_012" def __init__( - self, arg_1: int | sqltypes.Integer, arg_2: str | sqltypes.Text, **kwargs: Any + self, arg_1: IntegerOperand, arg_2: TextOperand, **kwargs: Any ) -> None: """Calls the bingo cartridge function `_internal_func_012`. Parameters ---------- - arg_1 : int | sqltypes.Integer + arg_1 : IntegerOperand Undocumented cartridge parameter. - arg_2 : str | sqltypes.Text + arg_2 : TextOperand Undocumented cartridge parameter. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -205,17 +215,17 @@ def __init__( self.packagenames = ("bingo",) -class _internal_func_check(GenericFunction): +class _internal_func_check(GenericFunction[bool]): type = sqltypes.Boolean() inherit_cache = True name = "_internal_func_check" - def __init__(self, arg_1: int | sqltypes.Integer, **kwargs: Any) -> None: + def __init__(self, arg_1: IntegerOperand, **kwargs: Any) -> None: """Calls the bingo cartridge function `_internal_func_check`. Parameters ---------- - arg_1 : int | sqltypes.Integer + arg_1 : IntegerOperand Undocumented cartridge parameter. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -229,7 +239,7 @@ def __init__(self, arg_1: int | sqltypes.Integer, **kwargs: Any) -> None: self.packagenames = ("bingo",) -class _match_mass_great(GenericFunction): +class _match_mass_great(GenericFunction[bool]): type = sqltypes.Boolean() inherit_cache = True name = "_match_mass_great" @@ -252,7 +262,7 @@ def __init__(self, **kwargs: Any) -> None: self.packagenames = ("bingo",) -class _match_mass_less(GenericFunction): +class _match_mass_less(GenericFunction[bool]): type = sqltypes.Boolean() inherit_cache = True name = "_match_mass_less" @@ -275,7 +285,8 @@ def __init__(self, **kwargs: Any) -> None: self.packagenames = ("bingo",) -class _precache_database(GenericFunction): +class _precache_database(GenericFunction[str]): + type = sqltypes.Text() inherit_cache = True name = "_precache_database" @@ -297,7 +308,8 @@ def __init__(self, **kwargs: Any) -> None: self.packagenames = ("bingo",) -class _print_profiling_info(GenericFunction): +class _print_profiling_info(GenericFunction[None]): + type = sqltypes.NullType() inherit_cache = True name = "_print_profiling_info" @@ -319,7 +331,8 @@ def __init__(self, **kwargs: Any) -> None: self.packagenames = ("bingo",) -class _reset_profiling_info(GenericFunction): +class _reset_profiling_info(GenericFunction[None]): + type = sqltypes.NullType() inherit_cache = True name = "_reset_profiling_info" @@ -341,27 +354,27 @@ def __init__(self, **kwargs: Any) -> None: self.packagenames = ("bingo",) -class _rexact_internal(GenericFunction): +class _rexact_internal(GenericFunction[bool]): type = sqltypes.Boolean() inherit_cache = True name = "_rexact_internal" def __init__( self, - arg_1: str | sqltypes.Text, - arg_2: str | sqltypes.Text | bytes | sqltypes.LargeBinary, - arg_3: str | sqltypes.Text, + arg_1: TextOperand, + arg_2: TextOrBinaryOperand, + arg_3: TextOperand, **kwargs: Any, ) -> None: """Calls the bingo cartridge function `_rexact_internal`. Parameters ---------- - arg_1 : str | sqltypes.Text + arg_1 : TextOperand Undocumented cartridge parameter. - arg_2 : str | sqltypes.Text | bytes | sqltypes.LargeBinary + arg_2 : TextOrBinaryOperand Undocumented cartridge parameter. - arg_3 : str | sqltypes.Text + arg_3 : TextOperand Undocumented cartridge parameter. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -375,27 +388,27 @@ def __init__( self.packagenames = ("bingo",) -class _rsmarts_internal(GenericFunction): +class _rsmarts_internal(GenericFunction[bool]): type = sqltypes.Boolean() inherit_cache = True name = "_rsmarts_internal" def __init__( self, - arg_1: str | sqltypes.Text, - arg_2: str | sqltypes.Text | bytes | sqltypes.LargeBinary, - arg_3: str | sqltypes.Text, + arg_1: TextOperand, + arg_2: TextOrBinaryOperand, + arg_3: TextOperand, **kwargs: Any, ) -> None: """Calls the bingo cartridge function `_rsmarts_internal`. Parameters ---------- - arg_1 : str | sqltypes.Text + arg_1 : TextOperand Undocumented cartridge parameter. - arg_2 : str | sqltypes.Text | bytes | sqltypes.LargeBinary + arg_2 : TextOrBinaryOperand Undocumented cartridge parameter. - arg_3 : str | sqltypes.Text + arg_3 : TextOperand Undocumented cartridge parameter. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -409,27 +422,27 @@ def __init__( self.packagenames = ("bingo",) -class _rsub_internal(GenericFunction): +class _rsub_internal(GenericFunction[bool]): type = sqltypes.Boolean() inherit_cache = True name = "_rsub_internal" def __init__( self, - arg_1: str | sqltypes.Text, - arg_2: str | sqltypes.Text | bytes | sqltypes.LargeBinary, - arg_3: str | sqltypes.Text, + arg_1: TextOperand, + arg_2: TextOrBinaryOperand, + arg_3: TextOperand, **kwargs: Any, ) -> None: """Calls the bingo cartridge function `_rsub_internal`. Parameters ---------- - arg_1 : str | sqltypes.Text + arg_1 : TextOperand Undocumented cartridge parameter. - arg_2 : str | sqltypes.Text | bytes | sqltypes.LargeBinary + arg_2 : TextOrBinaryOperand Undocumented cartridge parameter. - arg_3 : str | sqltypes.Text + arg_3 : TextOperand Undocumented cartridge parameter. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -443,33 +456,33 @@ def __init__( self.packagenames = ("bingo",) -class _sim_internal(GenericFunction): +class _sim_internal(GenericFunction[bool]): type = sqltypes.Boolean() inherit_cache = True name = "_sim_internal" def __init__( self, - arg_1: float | sqltypes.Float, - arg_2: float | sqltypes.Float, - arg_3: str | sqltypes.Text, - arg_4: str | sqltypes.Text | bytes | sqltypes.LargeBinary, - arg_5: str | sqltypes.Text, + arg_1: FloatOperand, + arg_2: FloatOperand, + arg_3: TextOperand, + arg_4: TextOrBinaryOperand, + arg_5: TextOperand, **kwargs: Any, ) -> None: """Calls the bingo cartridge function `_sim_internal`. Parameters ---------- - arg_1 : float | sqltypes.Float + arg_1 : FloatOperand Undocumented cartridge parameter. - arg_2 : float | sqltypes.Float + arg_2 : FloatOperand Undocumented cartridge parameter. - arg_3 : str | sqltypes.Text + arg_3 : TextOperand Undocumented cartridge parameter. - arg_4 : str | sqltypes.Text | bytes | sqltypes.LargeBinary + arg_4 : TextOrBinaryOperand Undocumented cartridge parameter. - arg_5 : str | sqltypes.Text + arg_5 : TextOperand Undocumented cartridge parameter. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -483,27 +496,27 @@ def __init__( self.packagenames = ("bingo",) -class _smarts_internal(GenericFunction): +class _smarts_internal(GenericFunction[bool]): type = sqltypes.Boolean() inherit_cache = True name = "_smarts_internal" def __init__( self, - arg_1: str | sqltypes.Text, - arg_2: str | sqltypes.Text | bytes | sqltypes.LargeBinary, - arg_3: str | sqltypes.Text, + arg_1: TextOperand, + arg_2: TextOrBinaryOperand, + arg_3: TextOperand, **kwargs: Any, ) -> None: """Calls the bingo cartridge function `_smarts_internal`. Parameters ---------- - arg_1 : str | sqltypes.Text + arg_1 : TextOperand Undocumented cartridge parameter. - arg_2 : str | sqltypes.Text | bytes | sqltypes.LargeBinary + arg_2 : TextOrBinaryOperand Undocumented cartridge parameter. - arg_3 : str | sqltypes.Text + arg_3 : TextOperand Undocumented cartridge parameter. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -517,27 +530,27 @@ def __init__( self.packagenames = ("bingo",) -class _sub_internal(GenericFunction): +class _sub_internal(GenericFunction[bool]): type = sqltypes.Boolean() inherit_cache = True name = "_sub_internal" def __init__( self, - arg_1: str | sqltypes.Text, - arg_2: str | sqltypes.Text | bytes | sqltypes.LargeBinary, - arg_3: str | sqltypes.Text, + arg_1: TextOperand, + arg_2: TextOrBinaryOperand, + arg_3: TextOperand, **kwargs: Any, ) -> None: """Calls the bingo cartridge function `_sub_internal`. Parameters ---------- - arg_1 : str | sqltypes.Text + arg_1 : TextOperand Undocumented cartridge parameter. - arg_2 : str | sqltypes.Text | bytes | sqltypes.LargeBinary + arg_2 : TextOrBinaryOperand Undocumented cartridge parameter. - arg_3 : str | sqltypes.Text + arg_3 : TextOperand Undocumented cartridge parameter. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. diff --git a/src/molalchemy/bingo/search.py b/src/molalchemy/bingo/search.py index 2e3c67e..dc40dd2 100644 --- a/src/molalchemy/bingo/search.py +++ b/src/molalchemy/bingo/search.py @@ -36,7 +36,7 @@ def get_col_spec(self, **kw: Any) -> str: def _bingo_search( - column: SqlOperand, + column: SqlOperand[Any], query_tuple: Any, search_type: str, ) -> ColumnElement[bool]: @@ -50,7 +50,7 @@ def _bingo_search( def _bingo_search_values( - column: SqlOperand, values: tuple[object, ...], search_type: str + column: SqlOperand[Any], values: tuple[object, ...], search_type: str ) -> ColumnElement[bool]: """Build a Bingo predicate using SQLAlchemy's expression coercion. diff --git a/src/molalchemy/bingo/types.py b/src/molalchemy/bingo/types.py index b8ac51d..db2ffd5 100644 --- a/src/molalchemy/bingo/types.py +++ b/src/molalchemy/bingo/types.py @@ -4,7 +4,7 @@ chemical molecules and reactions in PostgreSQL using the Bingo cartridge. """ -from typing import Any, Literal +from typing import Any, Generic, Literal, TypeVar, overload from sqlalchemy import func from sqlalchemy.types import UserDefinedType @@ -12,6 +12,7 @@ from molalchemy.bingo.comparators import BingoMolComparator, BingoRxnComparator _BINGO_BINARY_MOL_RETURN_TYPES = ("smiles", "molfile", "cml", "bytes") +_T = TypeVar("_T") def _validate_return_type(value: object) -> None: @@ -27,7 +28,7 @@ def _validate_preserve_pos(value: object) -> None: raise TypeError(f"preserve_pos must be a bool, got {type(value).__name__}") -class BingoBaseType(UserDefinedType): +class BingoBaseType(UserDefinedType[_T], Generic[_T]): """Base class for Bingo types.""" _immutable_options: frozenset[str] = frozenset() @@ -40,7 +41,7 @@ def __setattr__(self, name: str, value: Any) -> None: super().__setattr__(name, value) -class BingoMol(BingoBaseType): +class BingoMol(BingoBaseType[str]): """SQLAlchemy type for molecule data stored as text (varchar). This type represents molecules stored as text in PostgreSQL, typically @@ -96,7 +97,7 @@ def get_col_spec(self, **kwargs: Any) -> str: return "varchar" -class BingoBinaryMol(BingoBaseType): +class BingoBinaryMol(BingoBaseType[_T], Generic[_T]): """SQLAlchemy type for binary molecule data with format conversion. This type represents molecules stored in Bingo's internal binary format @@ -148,7 +149,7 @@ class BingoBinaryMol(BingoBaseType): ... __tablename__ = 'molecules' ... ... id: Mapped[int] = mapped_column(Integer, primary_key=True) - ... structure: Mapped[bytes] = mapped_column( + ... structure: Mapped[str] = mapped_column( ... BingoBinaryMol(preserve_pos=True, return_type="smiles") ... ) ... name: Mapped[str] = mapped_column(String(100)) @@ -158,7 +159,7 @@ class BingoBinaryMol(BingoBaseType): ... __tablename__ = 'molecules_molfile' ... ... id: Mapped[int] = mapped_column(Integer, primary_key=True) - ... structure: Mapped[bytes] = mapped_column( + ... structure: Mapped[str] = mapped_column( ... BingoBinaryMol(preserve_pos=True, return_type="molfile") ... ) >>> @@ -173,11 +174,25 @@ class BingoBinaryMol(BingoBaseType): comparator_factory = BingoMolComparator _immutable_options = frozenset(("preserve_pos", "return_type")) + @overload + def __init__( + self: "BingoBinaryMol[str]", + preserve_pos: bool = False, + return_type: Literal["smiles", "molfile", "cml"] = "smiles", + ) -> None: ... + + @overload + def __init__( + self: "BingoBinaryMol[bytes]", + preserve_pos: bool = False, + return_type: Literal["bytes"] = "bytes", + ) -> None: ... + def __init__( self, preserve_pos: bool = False, return_type: Literal["smiles", "molfile", "cml", "bytes"] = "smiles", - ): + ) -> None: _validate_preserve_pos(preserve_pos) _validate_return_type(return_type) self.preserve_pos = preserve_pos @@ -205,7 +220,7 @@ def column_expression(self, colexpr): raise AssertionError("validated return_type was not handled") -class BingoReaction(BingoBaseType): +class BingoReaction(BingoBaseType[str]): """SQLAlchemy type for chemical reaction data stored as text (varchar). This type represents chemical reactions stored as text in PostgreSQL, @@ -259,7 +274,7 @@ def get_col_spec(self, **kwargs: Any) -> str: return "varchar" -class BingoBinaryReaction(BingoBaseType): +class BingoBinaryReaction(BingoBaseType[bytes]): """SQLAlchemy type for binary chemical reaction data. This type represents chemical reactions stored in Bingo's internal binary diff --git a/src/molalchemy/protocols.py b/src/molalchemy/protocols.py index 2fb82a0..a80dc96 100644 --- a/src/molalchemy/protocols.py +++ b/src/molalchemy/protocols.py @@ -5,22 +5,39 @@ ``molalchemy.helpers``. """ -from typing import Any, Literal, Protocol, TypeAlias +from typing import Any, Literal, Protocol, TypeAlias, TypeVar from rdkit import Chem from rdkit.Chem.rdChemReactions import ChemicalReaction from sqlalchemy.orm import InstrumentedAttribute from sqlalchemy.sql.elements import ColumnElement -SqlOperand: TypeAlias = ColumnElement[Any] | InstrumentedAttribute[Any] -RdkitMolOperand: TypeAlias = str | Chem.Mol | SqlOperand -RdkitReactionOperand: TypeAlias = str | ChemicalReaction | SqlOperand -RdkitFingerprintOperand: TypeAlias = bytes | SqlOperand +_T = TypeVar("_T") + +SqlOperand: TypeAlias = ColumnElement[_T] | InstrumentedAttribute[_T] +BooleanOperand: TypeAlias = bool | SqlOperand[bool] +IntegerOperand: TypeAlias = int | SqlOperand[int] +FloatOperand: TypeAlias = float | SqlOperand[float] +TextOperand: TypeAlias = str | SqlOperand[str] +BinaryOperand: TypeAlias = bytes | SqlOperand[bytes] +TextOrBinaryOperand: TypeAlias = TextOperand | BinaryOperand +BingoMolSqlOperand: TypeAlias = SqlOperand[str] | SqlOperand[bytes] +BingoReactionSqlOperand: TypeAlias = SqlOperand[str] | SqlOperand[bytes] +RdkitMolSqlOperand: TypeAlias = ( + SqlOperand[str] | SqlOperand[bytes] | SqlOperand[Chem.Mol] +) +RdkitReactionSqlOperand: TypeAlias = ( + SqlOperand[str] | SqlOperand[bytes] | SqlOperand[ChemicalReaction] +) +RdkitFingerprintSqlOperand: TypeAlias = SqlOperand[bytes] +RdkitMolOperand: TypeAlias = str | Chem.Mol | RdkitMolSqlOperand +RdkitReactionOperand: TypeAlias = str | ChemicalReaction | RdkitReactionSqlOperand +RdkitFingerprintOperand: TypeAlias = bytes | RdkitFingerprintSqlOperand RdkitSimilarityMetric: TypeAlias = Literal["Tanimoto", "Dice"] -RdkitSimilarityBound: TypeAlias = float | None | SqlOperand -BingoOperand: TypeAlias = str | bytes | SqlOperand -BingoParameters: TypeAlias = str | SqlOperand -BingoSimilarityBound: TypeAlias = float | None | SqlOperand +RdkitSimilarityBound: TypeAlias = float | None | SqlOperand[Any] +BingoOperand: TypeAlias = str | bytes | BingoMolSqlOperand +BingoParameters: TypeAlias = str | SqlOperand[Any] +BingoSimilarityBound: TypeAlias = float | None | SqlOperand[Any] class BingoMolColumn(Protocol): @@ -75,12 +92,14 @@ def not_equals( class RdkitMolColumn(Protocol): def has_substructure(self, query: RdkitMolOperand) -> ColumnElement[bool]: ... - def has_smarts(self, query: str | SqlOperand) -> ColumnElement[bool]: ... + def has_smarts(self, query: str | SqlOperand[Any]) -> ColumnElement[bool]: ... def is_substructure_of(self, query: RdkitMolOperand) -> ColumnElement[bool]: ... def equals(self, query: RdkitMolOperand) -> ColumnElement[bool]: ... def not_equals(self, query: RdkitMolOperand) -> ColumnElement[bool]: ... - def has_query_substructure(self, query: SqlOperand) -> ColumnElement[bool]: ... - def is_query_substructure_of(self, query: SqlOperand) -> ColumnElement[bool]: ... + def has_query_substructure(self, query: SqlOperand[Any]) -> ColumnElement[bool]: ... + def is_query_substructure_of( + self, query: SqlOperand[Any] + ) -> ColumnElement[bool]: ... class RdkitReactionColumn(Protocol): @@ -92,7 +111,7 @@ def is_substructure_of( def equals(self, query: RdkitReactionOperand) -> ColumnElement[bool]: ... def not_equals(self, query: RdkitReactionOperand) -> ColumnElement[bool]: ... - def has_smarts(self, query: str | SqlOperand) -> ColumnElement[bool]: ... + def has_smarts(self, query: str | SqlOperand[Any]) -> ColumnElement[bool]: ... def has_substructure_fp( self, query: RdkitReactionOperand ) -> ColumnElement[bool]: ... @@ -130,18 +149,29 @@ def dice_distance(self, query: RdkitFingerprintOperand) -> ColumnElement[float]: __all__ = [ + "BinaryOperand", "BingoMolColumn", + "BingoMolSqlOperand", "BingoOperand", "BingoParameters", "BingoReactionColumn", + "BingoReactionSqlOperand", "BingoSimilarityBound", + "BooleanOperand", + "FloatOperand", + "IntegerOperand", "RdkitFingerprintColumn", "RdkitFingerprintOperand", + "RdkitFingerprintSqlOperand", "RdkitMolColumn", "RdkitMolOperand", + "RdkitMolSqlOperand", "RdkitReactionColumn", "RdkitReactionOperand", + "RdkitReactionSqlOperand", "RdkitSimilarityBound", "RdkitSimilarityMetric", "SqlOperand", + "TextOperand", + "TextOrBinaryOperand", ] diff --git a/src/molalchemy/rdkit/functions/_types.py b/src/molalchemy/rdkit/functions/_types.py index 0d8c213..a143125 100644 --- a/src/molalchemy/rdkit/functions/_types.py +++ b/src/molalchemy/rdkit/functions/_types.py @@ -4,28 +4,33 @@ from rdkit import Chem from rdkit.Chem.rdChemReactions import ChemicalReaction -from sqlalchemy.orm import InstrumentedAttribute -from sqlalchemy.sql.elements import ColumnElement + +from molalchemy.protocols import ( + RdkitFingerprintSqlOperand, + RdkitMolSqlOperand, + RdkitReactionSqlOperand, + SqlOperand, +) T = TypeVar("T") -SQLAlchemyCoercible: TypeAlias = ColumnElement[T] | InstrumentedAttribute[T] -SqlExpression: TypeAlias = ColumnElement[Any] | InstrumentedAttribute[Any] +SQLAlchemyCoercible: TypeAlias = SqlOperand[T] +SqlExpression: TypeAlias = SqlOperand[Any] LiteralStrBytes: TypeAlias = str | bytes TextLike: TypeAlias = str | bytes | SqlExpression RdkitMolCoercible: TypeAlias = str | Chem.Mol -AnyRdkitMolLike: TypeAlias = RdkitMolCoercible | SqlExpression +AnyRdkitMolLike: TypeAlias = RdkitMolCoercible | RdkitMolSqlOperand RdkitQMolCoercible: TypeAlias = str -AnyRdkitQMolLike: TypeAlias = str | SqlExpression +AnyRdkitQMolLike: TypeAlias = str | SqlOperand[str] RdkitXQMolCoercible: TypeAlias = str -AnyRdkitXQMolLike: TypeAlias = str | SqlExpression +AnyRdkitXQMolLike: TypeAlias = str | SqlOperand[str] RdkitBitFingerprintCoercible: TypeAlias = bytes -AnyRdkitBitFingerprintLike: TypeAlias = bytes | SqlExpression +AnyRdkitBitFingerprintLike: TypeAlias = bytes | RdkitFingerprintSqlOperand RdkitSparseFingerprintCoercible: TypeAlias = bytes -AnyRdkitSparseFingerprintLike: TypeAlias = bytes | SqlExpression +AnyRdkitSparseFingerprintLike: TypeAlias = bytes | RdkitFingerprintSqlOperand RdkitReactionCoercible: TypeAlias = str | ChemicalReaction -AnyRdkitReactionLike: TypeAlias = RdkitReactionCoercible | SqlExpression -AnyRdkitFingerprintLike: TypeAlias = bytes | SqlExpression +AnyRdkitReactionLike: TypeAlias = RdkitReactionCoercible | RdkitReactionSqlOperand +AnyRdkitFingerprintLike: TypeAlias = bytes | RdkitFingerprintSqlOperand __all__ = [ "AnyRdkitBitFingerprintLike", diff --git a/src/molalchemy/rdkit/functions/general.py b/src/molalchemy/rdkit/functions/general.py index b6f1cf0..001d8f3 100644 --- a/src/molalchemy/rdkit/functions/general.py +++ b/src/molalchemy/rdkit/functions/general.py @@ -7,14 +7,21 @@ from sqlalchemy import types as sqltypes from sqlalchemy.sql import cast from sqlalchemy.sql.elements import ColumnElement -from sqlalchemy.sql.expression import Cast from sqlalchemy.sql.functions import GenericFunction from molalchemy.protocols import ( + BinaryOperand, + BooleanOperand, + FloatOperand, + IntegerOperand, RdkitFingerprintOperand, + RdkitFingerprintSqlOperand, + RdkitMolSqlOperand, + RdkitReactionSqlOperand, RdkitSimilarityBound, RdkitSimilarityMetric, SqlOperand, + TextOperand, ) from molalchemy.rdkit.search import ( _rdkit_mol_smarts, @@ -45,7 +52,7 @@ def fp_similar_to( - fp_column: SqlOperand, + fp_column: RdkitFingerprintSqlOperand, query: RdkitFingerprintOperand, minimum: RdkitSimilarityBound = 0.0, maximum: RdkitSimilarityBound = 1.0, @@ -61,7 +68,7 @@ def fp_similar_to( def fp_similarity_score( - fp_column: SqlOperand, + fp_column: RdkitFingerprintSqlOperand, query: RdkitFingerprintOperand, metric: RdkitSimilarityMetric = "Tanimoto", ) -> ColumnElement[float]: @@ -70,7 +77,7 @@ def fp_similarity_score( def mol_has_substructure( - mol_column: ColumnElement[RdkitMol], query: AnyRdkitMolLike + mol_column: RdkitMolSqlOperand, query: AnyRdkitMolLike ) -> ColumnElement[bool]: """ Perform substructure search. @@ -80,7 +87,7 @@ def mol_has_substructure( Parameters ---------- - mol_column : ColumnElement[molalchemy.rdkit.types.RdkitMol] + mol_column : RdkitMolSqlOperand The database column containing the molecular structure to search. query : AnyRdkitMolLike The query structure. Plain Python strings are treated as SMILES-like @@ -103,7 +110,7 @@ def mol_has_substructure( return _rdkit_predicate(mol_column, "@>", query) -def mol_has_smarts(mol_column: ColumnElement, pattern: str) -> ColumnElement[bool]: +def mol_has_smarts(mol_column: RdkitMolSqlOperand, pattern: str) -> ColumnElement[bool]: """ Perform molecule SMARTS search. @@ -133,7 +140,7 @@ def mol_has_smarts(mol_column: ColumnElement, pattern: str) -> ColumnElement[boo def mol_is_substructure_of( - mol_column: ColumnElement[RdkitMol], query: AnyRdkitMolLike + mol_column: RdkitMolSqlOperand, query: AnyRdkitMolLike ) -> ColumnElement[bool]: """ Perform reverse substructure search. @@ -143,7 +150,7 @@ def mol_is_substructure_of( Parameters ---------- - mol_column : ColumnElement[molalchemy.rdkit.types.RdkitMol] + mol_column : RdkitMolSqlOperand The database column containing the molecular structure to search. query : AnyRdkitMolLike The query structure. Plain Python strings are treated as SMILES-like @@ -159,7 +166,7 @@ def mol_is_substructure_of( def mol_equals( - mol_column: ColumnElement[RdkitMol], query: AnyRdkitMolLike + mol_column: RdkitMolSqlOperand, query: AnyRdkitMolLike ) -> ColumnElement[bool]: """ Perform exact structure matching. @@ -171,7 +178,7 @@ def mol_equals( Parameters ---------- - mol_column : ColumnElement[molalchemy.rdkit.types.RdkitMol] + mol_column : RdkitMolSqlOperand The database column containing the molecular structure to compare. query : AnyRdkitMolLike The query structure. Plain Python strings are treated as SMILES-like @@ -186,7 +193,7 @@ def mol_equals( def mol_not_equals( - mol_column: ColumnElement[RdkitMol], query: AnyRdkitMolLike + mol_column: RdkitMolSqlOperand, query: AnyRdkitMolLike ) -> ColumnElement[bool]: """ Perform negative exact structure matching. @@ -199,7 +206,7 @@ def mol_not_equals( def mol_has_query_substructure( - mol_column: ColumnElement[RdkitMol], + mol_column: RdkitMolSqlOperand, query: AnyRdkitMolLike | AnyRdkitQMolLike | AnyRdkitXQMolLike, ) -> ColumnElement[bool]: """ @@ -213,7 +220,7 @@ def mol_has_query_substructure( def mol_is_query_substructure_of( - mol_column: ColumnElement[RdkitMol], + mol_column: RdkitMolSqlOperand, query: AnyRdkitMolLike | AnyRdkitQMolLike | AnyRdkitXQMolLike, ) -> ColumnElement[bool]: """ @@ -227,7 +234,7 @@ def mol_is_query_substructure_of( def rxn_has_substructure( - rxn_column: ColumnElement[RdkitReaction], query: AnyRdkitReactionLike + rxn_column: RdkitReactionSqlOperand, query: AnyRdkitReactionLike ) -> ColumnElement[bool]: """ Perform reaction substructure search. @@ -239,7 +246,7 @@ def rxn_has_substructure( def rxn_is_substructure_of( - rxn_column: ColumnElement[RdkitReaction], query: AnyRdkitReactionLike + rxn_column: RdkitReactionSqlOperand, query: AnyRdkitReactionLike ) -> ColumnElement[bool]: """ Perform reverse reaction substructure search. @@ -251,7 +258,7 @@ def rxn_is_substructure_of( def rxn_equals( - rxn_column: ColumnElement[RdkitReaction], query: AnyRdkitReactionLike + rxn_column: RdkitReactionSqlOperand, query: AnyRdkitReactionLike ) -> ColumnElement[bool]: """ Perform exact reaction matching. @@ -263,7 +270,7 @@ def rxn_equals( def rxn_not_equals( - rxn_column: ColumnElement[RdkitReaction], query: AnyRdkitReactionLike + rxn_column: RdkitReactionSqlOperand, query: AnyRdkitReactionLike ) -> ColumnElement[bool]: """ Perform negative exact reaction matching. @@ -275,7 +282,7 @@ def rxn_not_equals( def rxn_has_substructure_fp( - rxn_column: ColumnElement[RdkitReaction], query: AnyRdkitReactionLike + rxn_column: RdkitReactionSqlOperand, query: AnyRdkitReactionLike ) -> ColumnElement[bool]: """ Perform fingerprint-backed reaction substructure search. @@ -287,7 +294,7 @@ def rxn_has_substructure_fp( def rxn_is_substructure_fp_of( - rxn_column: ColumnElement[RdkitReaction], query: AnyRdkitReactionLike + rxn_column: RdkitReactionSqlOperand, query: AnyRdkitReactionLike ) -> ColumnElement[bool]: """ Perform reverse fingerprint-backed reaction substructure search. @@ -298,7 +305,9 @@ def rxn_is_substructure_fp_of( return _rdkit_predicate(rxn_column, "?<", query) -def rxn_has_smarts(rxn_column: ColumnElement, pattern: str) -> ColumnElement[bool]: +def rxn_has_smarts( + rxn_column: RdkitReactionSqlOperand, pattern: str +) -> ColumnElement[bool]: """ Perform reaction substructure search. @@ -329,7 +338,7 @@ def rxn_has_smarts(rxn_column: ColumnElement, pattern: str) -> ColumnElement[boo return _rdkit_rxn_smarts(rxn_column, pattern) -class add(GenericFunction): +class add(GenericFunction[bytes]): type = RdkitSparseFingerprint() inherit_cache = True @@ -358,15 +367,12 @@ def __init__( super().__init__(fp_1, fp_2, **kwargs) -class all_values_gt(GenericFunction): +class all_values_gt(GenericFunction[bool]): type = sqltypes.Boolean() inherit_cache = True def __init__( - self, - fp: AnyRdkitSparseFingerprintLike, - value: int | sqltypes.Integer, - **kwargs: Any, + self, fp: AnyRdkitSparseFingerprintLike, value: IntegerOperand, **kwargs: Any ) -> None: """Returns a boolean indicating whether or not all elements of the sfp argument are greater than the int argument. @@ -374,7 +380,7 @@ def __init__( ---------- fp : AnyRdkitSparseFingerprintLike The sparse fingerprint to check. - value : int | sqltypes.Integer + value : IntegerOperand The integer value to compare against. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -387,15 +393,12 @@ def __init__( super().__init__(fp, value, **kwargs) -class all_values_lt(GenericFunction): +class all_values_lt(GenericFunction[bool]): type = sqltypes.Boolean() inherit_cache = True def __init__( - self, - fp: AnyRdkitSparseFingerprintLike, - value: int | sqltypes.Integer, - **kwargs: Any, + self, fp: AnyRdkitSparseFingerprintLike, value: IntegerOperand, **kwargs: Any ) -> None: """Returns a boolean indicating whether or not all elements of the sfp argument are less than the int argument. @@ -403,7 +406,7 @@ def __init__( ---------- fp : AnyRdkitSparseFingerprintLike The sparse fingerprint (sfp) to check. - value : int | sqltypes.Integer + value : IntegerOperand The integer value to compare against the sfp elements. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -416,7 +419,7 @@ def __init__( super().__init__(fp, value, **kwargs) -class atompair_fp(GenericFunction): +class atompair_fp(GenericFunction[bytes]): type = RdkitSparseFingerprint() inherit_cache = True @@ -438,7 +441,7 @@ def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: super().__init__(mol, **kwargs) -class atompairbv_fp(GenericFunction): +class atompairbv_fp(GenericFunction[bytes]): type = RdkitBitFingerprint() inherit_cache = True @@ -460,15 +463,15 @@ def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: super().__init__(mol, **kwargs) -class avalon_fp(GenericFunction): +class avalon_fp(GenericFunction[bytes]): type = RdkitBitFingerprint() inherit_cache = True def __init__( self, mol: AnyRdkitMolLike, - arg_2: sqltypes.Boolean, - arg_3: int | sqltypes.Integer, + arg_2: BooleanOperand, + arg_3: IntegerOperand, **kwargs: Any, ) -> None: """Generates Avalon fingerprints for a molecule. @@ -477,9 +480,9 @@ def __init__( ---------- mol : AnyRdkitMolLike The RDKit molecule for which to generate the fingerprint. - arg_2 : sqltypes.Boolean + arg_2 : BooleanOperand TODO - arg_3 : int | sqltypes.Integer + arg_3 : IntegerOperand TODO kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -492,16 +495,16 @@ def __init__( super().__init__(mol, arg_2, arg_3, **kwargs) -class bfp_from_binary_text(GenericFunction): +class bfp_from_binary_text(GenericFunction[bytes]): type = RdkitBitFingerprint() inherit_cache = True - def __init__(self, input: sqltypes.LargeBinary, **kwargs: Any) -> None: + def __init__(self, input: BinaryOperand, **kwargs: Any) -> None: """Constructs a bit vector fingerprint (bfp) from a binary string representation of the fingerprint. Parameters ---------- - input : sqltypes.LargeBinary + input : BinaryOperand The binary string representation of the fingerprint. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -514,7 +517,7 @@ def __init__(self, input: sqltypes.LargeBinary, **kwargs: Any) -> None: super().__init__(input, **kwargs) -class bfp_le(GenericFunction): +class bfp_le(GenericFunction[bool]): type = sqltypes.Boolean() inherit_cache = True @@ -543,7 +546,7 @@ def __init__( super().__init__(fp_1, fp_2, **kwargs) -class bfp_to_binary_text(GenericFunction): +class bfp_to_binary_text(GenericFunction[bytes]): type = sqltypes.LargeBinary() inherit_cache = True @@ -565,7 +568,7 @@ def __init__(self, fp: AnyRdkitBitFingerprintLike, **kwargs: Any) -> None: super().__init__(fp, **kwargs) -class dice_dist(GenericFunction): +class dice_dist(GenericFunction[float]): type = sqltypes.Float() inherit_cache = True @@ -594,7 +597,7 @@ def __init__( super().__init__(fp_1, fp_2, **kwargs) -class dice_sml(GenericFunction): +class dice_sml(GenericFunction[float]): type = sqltypes.Float() inherit_cache = True @@ -623,7 +626,7 @@ def __init__( super().__init__(fp_1, fp_2, **kwargs) -class dice_sml_op(GenericFunction): +class dice_sml_op(GenericFunction[bool]): type = sqltypes.Boolean() inherit_cache = True @@ -652,12 +655,12 @@ def __init__( super().__init__(arg_1, arg_2, **kwargs) -class featmorgan_fp(GenericFunction): +class featmorgan_fp(GenericFunction[bytes]): type = RdkitSparseFingerprint() inherit_cache = True def __init__( - self, mol: AnyRdkitMolLike, radius: int | sqltypes.Integer = 2, **kwargs: Any + self, mol: AnyRdkitMolLike, radius: IntegerOperand = 2, **kwargs: Any ) -> None: """Returns a count-based Morgan fingerprint for a molecule using chemical-feature invariants. This is an FCFP-like fingerprint. @@ -665,7 +668,7 @@ def __init__( ---------- mol : AnyRdkitMolLike The molecule for which to generate the fingerprint. - radius : int | sqltypes.Integer + radius : IntegerOperand The radius for the fingerprint generation. This argument is optional and defaults to 2. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -678,12 +681,12 @@ def __init__( super().__init__(mol, radius, **kwargs) -class featmorganbv_fp(GenericFunction): +class featmorganbv_fp(GenericFunction[bytes]): type = RdkitBitFingerprint() inherit_cache = True def __init__( - self, mol: AnyRdkitMolLike, radius: int | sqltypes.Integer = 2, **kwargs: Any + self, mol: AnyRdkitMolLike, radius: IntegerOperand = 2, **kwargs: Any ) -> None: """Returns a bit vector Morgan fingerprint for a molecule using chemical-feature invariants. The second argument provides the radius. This is an FCFP-like fingerprint. @@ -691,7 +694,7 @@ def __init__( ---------- mol : AnyRdkitMolLike The molecule for which to generate the fingerprint. - radius : int | sqltypes.Integer + radius : IntegerOperand The radius for the fingerprint generation. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -704,7 +707,7 @@ def __init__( super().__init__(mol, radius, **kwargs) -class fmcs(GenericFunction): +class fmcs(GenericFunction[str]): type = sqltypes.Text() inherit_cache = True @@ -726,23 +729,23 @@ def __init__(self, mols: AnyRdkitMolLike, **kwargs: Any) -> None: super().__init__(mols, **kwargs) -class fmcs_smiles(GenericFunction): +class fmcs_smiles(GenericFunction[str]): type = CString() inherit_cache = True def __init__( self, - molecules: sqltypes.Text | CString | Cast[Any], - json: sqltypes.Text | CString | Cast[Any] | str = "", + molecules: str | SqlOperand[Any], + json: str | SqlOperand[Any] = "", **kwargs: Any, ) -> None: """Calculates the Maximum Common Substructure (MCS) for a space-separated set of SMILES. Parameters ---------- - molecules : sqltypes.Text | CString | Cast[Any] + molecules : str | SqlOperand[Any] A space-separated string of SMILES representations of molecules for which to calculate the MCS. - json : sqltypes.Text | CString | Cast[Any] | str + json : str | SqlOperand[Any] An optional JSON string used to provide parameters to the MCS code. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -755,16 +758,16 @@ def __init__( super().__init__(molecules, json, **kwargs) -class is_valid_ctab(GenericFunction): +class is_valid_ctab(GenericFunction[bool]): type = sqltypes.Boolean() inherit_cache = True - def __init__(self, input: CString, **kwargs: Any) -> None: + def __init__(self, input: TextOperand, **kwargs: Any) -> None: """Returns whether or not a CTAB (mol block) string produces a valid RDKit molecule. Parameters ---------- - input : CString + input : TextOperand The CTAB (mol block) string to validate. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -777,16 +780,16 @@ def __init__(self, input: CString, **kwargs: Any) -> None: super().__init__(input, **kwargs) -class is_valid_mol_pkl(GenericFunction): +class is_valid_mol_pkl(GenericFunction[bool]): type = sqltypes.Boolean() inherit_cache = True - def __init__(self, input: sqltypes.LargeBinary, **kwargs: Any) -> None: + def __init__(self, input: BinaryOperand, **kwargs: Any) -> None: """Returns whether or not a binary string (bytea) can be converted into a valid RDKit molecule. Parameters ---------- - input : sqltypes.LargeBinary + input : BinaryOperand A binary string (bytea) representing a molecule. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -799,16 +802,16 @@ def __init__(self, input: sqltypes.LargeBinary, **kwargs: Any) -> None: super().__init__(input, **kwargs) -class is_valid_smarts(GenericFunction): +class is_valid_smarts(GenericFunction[bool]): type = sqltypes.Boolean() inherit_cache = True - def __init__(self, input: CString, **kwargs: Any) -> None: + def __init__(self, input: TextOperand, **kwargs: Any) -> None: """Returns whether or not a SMARTS string produces a valid RDKit molecule. Parameters ---------- - input : CString + input : TextOperand The SMARTS string to validate. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -821,16 +824,16 @@ def __init__(self, input: CString, **kwargs: Any) -> None: super().__init__(input, **kwargs) -class is_valid_smiles(GenericFunction): +class is_valid_smiles(GenericFunction[bool]): type = sqltypes.Boolean() inherit_cache = True - def __init__(self, input: CString, **kwargs: Any) -> None: + def __init__(self, input: TextOperand, **kwargs: Any) -> None: """Returns whether or not a SMILES string produces a valid RDKit molecule. Parameters ---------- - input : CString + input : TextOperand The SMILES string to validate. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -843,7 +846,7 @@ def __init__(self, input: CString, **kwargs: Any) -> None: super().__init__(input, **kwargs) -class layered_fp(GenericFunction): +class layered_fp(GenericFunction[bytes]): type = RdkitBitFingerprint() inherit_cache = True @@ -865,7 +868,7 @@ def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: super().__init__(mol, **kwargs) -class maccs_fp(GenericFunction): +class maccs_fp(GenericFunction[bytes]): type = RdkitBitFingerprint() inherit_cache = True @@ -887,14 +890,14 @@ def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: super().__init__(mol, **kwargs) -class mol_adjust_query_properties(GenericFunction): +class mol_adjust_query_properties(GenericFunction[str]): type = RdkitMol() inherit_cache = True def __init__( self, mol: AnyRdkitMolLike | AnyRdkitQMolLike, - query_parameters: CString | Cast[Any] = cast("", CString), + query_parameters: str | SqlOperand[Any] = cast("", CString), **kwargs: Any, ) -> None: """Returns a new molecule with additional query information attached. @@ -903,7 +906,7 @@ def __init__( ---------- mol : AnyRdkitMolLike | AnyRdkitQMolLike The molecule to which additional query information will be attached. - query_parameters : CString | Cast[Any] + query_parameters : str | SqlOperand[Any] A string with additional query parameters (optional) kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -916,7 +919,7 @@ def __init__( super().__init__(mol, query_parameters, **kwargs) -class mol_amw(GenericFunction): +class mol_amw(GenericFunction[float]): type = sqltypes.Float() inherit_cache = True @@ -938,7 +941,7 @@ def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: super().__init__(mol, **kwargs) -class mol_chi0n(GenericFunction): +class mol_chi0n(GenericFunction[float]): type = sqltypes.Float() inherit_cache = True @@ -960,7 +963,7 @@ def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: super().__init__(mol, **kwargs) -class mol_chi0v(GenericFunction): +class mol_chi0v(GenericFunction[float]): type = sqltypes.Float() inherit_cache = True @@ -982,7 +985,7 @@ def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: super().__init__(mol, **kwargs) -class mol_chi1n(GenericFunction): +class mol_chi1n(GenericFunction[float]): type = sqltypes.Float() inherit_cache = True @@ -1004,7 +1007,7 @@ def __init__(self, arg_1: AnyRdkitMolLike, **kwargs: Any) -> None: super().__init__(arg_1, **kwargs) -class mol_chi1v(GenericFunction): +class mol_chi1v(GenericFunction[float]): type = sqltypes.Float() inherit_cache = True @@ -1026,7 +1029,7 @@ def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: super().__init__(mol, **kwargs) -class mol_chi2n(GenericFunction): +class mol_chi2n(GenericFunction[float]): type = sqltypes.Float() inherit_cache = True @@ -1048,7 +1051,7 @@ def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: super().__init__(mol, **kwargs) -class mol_chi2v(GenericFunction): +class mol_chi2v(GenericFunction[float]): type = sqltypes.Float() inherit_cache = True @@ -1070,7 +1073,7 @@ def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: super().__init__(mol, **kwargs) -class mol_chi3n(GenericFunction): +class mol_chi3n(GenericFunction[float]): type = sqltypes.Float() inherit_cache = True @@ -1092,7 +1095,7 @@ def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: super().__init__(mol, **kwargs) -class mol_chi3v(GenericFunction): +class mol_chi3v(GenericFunction[float]): type = sqltypes.Float() inherit_cache = True @@ -1114,7 +1117,7 @@ def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: super().__init__(mol, **kwargs) -class mol_chi4n(GenericFunction): +class mol_chi4n(GenericFunction[float]): type = sqltypes.Float() inherit_cache = True @@ -1136,7 +1139,7 @@ def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: super().__init__(mol, **kwargs) -class mol_chi4v(GenericFunction): +class mol_chi4v(GenericFunction[float]): type = sqltypes.Float() inherit_cache = True @@ -1158,7 +1161,7 @@ def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: super().__init__(mol, **kwargs) -class mol_exactmw(GenericFunction): +class mol_exactmw(GenericFunction[float]): type = sqltypes.Float() inherit_cache = True @@ -1180,15 +1183,15 @@ def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: super().__init__(mol, **kwargs) -class mol_formula(GenericFunction): +class mol_formula(GenericFunction[str]): type = CString() inherit_cache = True def __init__( self, mol: AnyRdkitMolLike, - include_isotopes: bool | sqltypes.Boolean = False, - use_deuterium_tritium_symbols: bool | sqltypes.Boolean = True, + include_isotopes: BooleanOperand = False, + use_deuterium_tritium_symbols: BooleanOperand = True, **kwargs: Any, ) -> None: """Returns a string with the molecular formula for a molecule. The second argument controls whether isotope information is included in the formula; the third argument controls whether "D" and "T" are used instead of [2H] and [3H]. @@ -1197,9 +1200,9 @@ def __init__( ---------- mol : AnyRdkitMolLike The molecule for which to get the molecular formula. - include_isotopes : bool | sqltypes.Boolean + include_isotopes : BooleanOperand Controls whether isotope information is included in the formula. - use_deuterium_tritium_symbols : bool | sqltypes.Boolean + use_deuterium_tritium_symbols : BooleanOperand Controls whether "D" and "T" are used instead of [2H] and [3H]. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -1212,7 +1215,7 @@ def __init__( super().__init__(mol, include_isotopes, use_deuterium_tritium_symbols, **kwargs) -class mol_fractioncsp3(GenericFunction): +class mol_fractioncsp3(GenericFunction[float]): type = sqltypes.Float() inherit_cache = True @@ -1234,18 +1237,18 @@ def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: super().__init__(mol, **kwargs) -class mol_from_ctab(GenericFunction): +class mol_from_ctab(GenericFunction[str]): type = RdkitMol() inherit_cache = True - def __init__(self, ctab: CString, arg_2: sqltypes.Boolean, **kwargs: Any) -> None: + def __init__(self, ctab: TextOperand, arg_2: BooleanOperand, **kwargs: Any) -> None: """Returns a molecule object from a CTAB (mol block) string, returning NULL if the molecule construction fails. Parameters ---------- - ctab : CString + ctab : TextOperand The CTAB (mol block) string from which to create the molecule. - arg_2 : sqltypes.Boolean + arg_2 : BooleanOperand A boolean indicating whether the molecule's coordinates should be saved. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -1258,16 +1261,16 @@ def __init__(self, ctab: CString, arg_2: sqltypes.Boolean, **kwargs: Any) -> Non super().__init__(ctab, arg_2, **kwargs) -class mol_from_json(GenericFunction): +class mol_from_json(GenericFunction[str]): type = RdkitMol() inherit_cache = True - def __init__(self, json_str: CString, **kwargs: Any) -> None: + def __init__(self, json_str: TextOperand, **kwargs: Any) -> None: """Returns a molecule for a commonchem JSON string, NULL if the molecule construction fails. Parameters ---------- - json_str : CString + json_str : TextOperand A commonchem JSON string representing a molecule. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -1280,16 +1283,16 @@ def __init__(self, json_str: CString, **kwargs: Any) -> None: super().__init__(json_str, **kwargs) -class mol_from_pkl(GenericFunction): +class mol_from_pkl(GenericFunction[str]): type = RdkitMol() inherit_cache = True - def __init__(self, bytea: sqltypes.LargeBinary, **kwargs: Any) -> None: + def __init__(self, bytea: BinaryOperand, **kwargs: Any) -> None: """Returns a molecule for a binary string (bytea), NULL if the molecule construction fails. Parameters ---------- - bytea : sqltypes.LargeBinary + bytea : BinaryOperand A binary string representation of the molecule. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -1302,16 +1305,16 @@ def __init__(self, bytea: sqltypes.LargeBinary, **kwargs: Any) -> None: super().__init__(bytea, **kwargs) -class mol_from_smiles(GenericFunction): +class mol_from_smiles(GenericFunction[str]): type = RdkitMol() inherit_cache = True - def __init__(self, smiles: sqltypes.Text | CString, **kwargs: Any) -> None: + def __init__(self, smiles: TextOperand, **kwargs: Any) -> None: """Returns a molecule for a SMILES string, NULL if the molecule construction fails. Parameters ---------- - smiles : sqltypes.Text | CString + smiles : TextOperand The SMILES string to convert to a molecule. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -1324,7 +1327,7 @@ def __init__(self, smiles: sqltypes.Text | CString, **kwargs: Any) -> None: super().__init__(smiles, **kwargs) -class mol_hallkieralpha(GenericFunction): +class mol_hallkieralpha(GenericFunction[float]): type = sqltypes.Float() inherit_cache = True @@ -1346,7 +1349,8 @@ def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: super().__init__(mol, **kwargs) -class mol_hba(GenericFunction): +class mol_hba(GenericFunction[int]): + type = sqltypes.Integer() inherit_cache = True def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: @@ -1367,7 +1371,8 @@ def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: super().__init__(mol, **kwargs) -class mol_hbd(GenericFunction): +class mol_hbd(GenericFunction[int]): + type = sqltypes.Integer() inherit_cache = True def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: @@ -1388,18 +1393,18 @@ def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: super().__init__(mol, **kwargs) -class mol_inchi(GenericFunction): +class mol_inchi(GenericFunction[str]): type = CString() inherit_cache = True - def __init__(self, mol: AnyRdkitMolLike, arg_2: CString, **kwargs: Any) -> None: + def __init__(self, mol: AnyRdkitMolLike, arg_2: TextOperand, **kwargs: Any) -> None: """Returns an InChI (International Chemical Identifier) for the given molecule. This function requires that the RDKit be built with InChI support. Parameters ---------- mol : AnyRdkitMolLike The RDKit molecule for which to generate the InChI. - arg_2 : CString + arg_2 : TextOperand Additional parameters to pass to the generator (TODO) kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -1412,18 +1417,18 @@ def __init__(self, mol: AnyRdkitMolLike, arg_2: CString, **kwargs: Any) -> None: super().__init__(mol, arg_2, **kwargs) -class mol_inchikey(GenericFunction): +class mol_inchikey(GenericFunction[str]): type = CString() inherit_cache = True - def __init__(self, mol: AnyRdkitMolLike, arg_2: CString, **kwargs: Any) -> None: + def __init__(self, mol: AnyRdkitMolLike, arg_2: TextOperand, **kwargs: Any) -> None: """Returns an InChI key for the molecule. Requires RDKit to be built with InChI support. Parameters ---------- mol : AnyRdkitMolLike The RDKit molecule for which to generate the InChI key. - arg_2 : CString + arg_2 : TextOperand Additional parameters to pass to the generator (TODO) kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -1436,7 +1441,7 @@ def __init__(self, mol: AnyRdkitMolLike, arg_2: CString, **kwargs: Any) -> None: super().__init__(mol, arg_2, **kwargs) -class mol_kappa1(GenericFunction): +class mol_kappa1(GenericFunction[float]): type = sqltypes.Float() inherit_cache = True @@ -1458,7 +1463,7 @@ def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: super().__init__(mol, **kwargs) -class mol_kappa2(GenericFunction): +class mol_kappa2(GenericFunction[float]): type = sqltypes.Float() inherit_cache = True @@ -1480,7 +1485,7 @@ def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: super().__init__(mol, **kwargs) -class mol_kappa3(GenericFunction): +class mol_kappa3(GenericFunction[float]): type = sqltypes.Float() inherit_cache = True @@ -1502,7 +1507,7 @@ def __init__(self, mol_1: AnyRdkitMolLike, **kwargs: Any) -> None: super().__init__(mol_1, **kwargs) -class mol_labuteasa(GenericFunction): +class mol_labuteasa(GenericFunction[float]): type = sqltypes.Float() inherit_cache = True @@ -1524,7 +1529,7 @@ def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: super().__init__(mol, **kwargs) -class mol_logp(GenericFunction): +class mol_logp(GenericFunction[float]): type = sqltypes.Float() inherit_cache = True @@ -1546,7 +1551,7 @@ def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: super().__init__(mol, **kwargs) -class mol_murckoscaffold(GenericFunction): +class mol_murckoscaffold(GenericFunction[str]): type = RdkitMol() inherit_cache = True @@ -1568,14 +1573,14 @@ def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: super().__init__(mol, **kwargs) -class mol_nm_hash(GenericFunction): +class mol_nm_hash(GenericFunction[str]): type = CString() inherit_cache = True def __init__( self, mol: AnyRdkitMolLike, - hash_type: CString | Cast[Any] = cast("AnonymousGraph", CString), + hash_type: str | SqlOperand[Any] = cast("AnonymousGraph", CString), **kwargs: Any, ) -> None: """Returns a string with a hash for the molecule. @@ -1584,7 +1589,7 @@ def __init__( ---------- mol : AnyRdkitMolLike The molecule for which to generate the hash. - hash_type : CString | Cast[Any] + hash_type : str | SqlOperand[Any] The type of hash to generate. Legal values are 'AnonymousGraph', 'ElementGraph', 'CanonicalSmiles', 'MurckoScaffold', 'ExtendedMurcko', 'MolFormula', 'AtomBondCounts', 'DegreeVector', 'Mesomer', 'HetAtomTautomer', 'HetAtomProtomer', 'RedoxPair', 'Regioisomer', 'NetCharge', 'SmallWorldIndexBR', 'SmallWorldIndexBRL', 'ArthorSubstructureOrder'. The default is 'AnonymousGraph'. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -1597,7 +1602,8 @@ def __init__( super().__init__(mol, hash_type, **kwargs) -class mol_numaliphaticcarbocycles(GenericFunction): +class mol_numaliphaticcarbocycles(GenericFunction[int]): + type = sqltypes.Integer() inherit_cache = True def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: @@ -1618,7 +1624,8 @@ def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: super().__init__(mol, **kwargs) -class mol_numaliphaticheterocycles(GenericFunction): +class mol_numaliphaticheterocycles(GenericFunction[int]): + type = sqltypes.Integer() inherit_cache = True def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: @@ -1639,7 +1646,8 @@ def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: super().__init__(mol, **kwargs) -class mol_numaliphaticrings(GenericFunction): +class mol_numaliphaticrings(GenericFunction[int]): + type = sqltypes.Integer() inherit_cache = True def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: @@ -1660,7 +1668,8 @@ def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: super().__init__(mol, **kwargs) -class mol_numamidebonds(GenericFunction): +class mol_numamidebonds(GenericFunction[int]): + type = sqltypes.Integer() inherit_cache = True def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: @@ -1681,7 +1690,8 @@ def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: super().__init__(mol, **kwargs) -class mol_numaromaticcarbocycles(GenericFunction): +class mol_numaromaticcarbocycles(GenericFunction[int]): + type = sqltypes.Integer() inherit_cache = True def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: @@ -1702,7 +1712,8 @@ def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: super().__init__(mol, **kwargs) -class mol_numaromaticheterocycles(GenericFunction): +class mol_numaromaticheterocycles(GenericFunction[int]): + type = sqltypes.Integer() inherit_cache = True def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: @@ -1723,7 +1734,8 @@ def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: super().__init__(mol, **kwargs) -class mol_numaromaticrings(GenericFunction): +class mol_numaromaticrings(GenericFunction[int]): + type = sqltypes.Integer() inherit_cache = True def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: @@ -1744,7 +1756,8 @@ def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: super().__init__(mol, **kwargs) -class mol_numatoms(GenericFunction): +class mol_numatoms(GenericFunction[int]): + type = sqltypes.Integer() inherit_cache = True def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: @@ -1765,7 +1778,8 @@ def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: super().__init__(mol, **kwargs) -class mol_numbridgeheadatoms(GenericFunction): +class mol_numbridgeheadatoms(GenericFunction[int]): + type = sqltypes.Integer() inherit_cache = True def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: @@ -1786,7 +1800,8 @@ def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: super().__init__(mol, **kwargs) -class mol_numheavyatoms(GenericFunction): +class mol_numheavyatoms(GenericFunction[int]): + type = sqltypes.Integer() inherit_cache = True def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: @@ -1807,7 +1822,8 @@ def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: super().__init__(mol, **kwargs) -class mol_numheteroatoms(GenericFunction): +class mol_numheteroatoms(GenericFunction[int]): + type = sqltypes.Integer() inherit_cache = True def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: @@ -1828,7 +1844,8 @@ def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: super().__init__(mol, **kwargs) -class mol_numheterocycles(GenericFunction): +class mol_numheterocycles(GenericFunction[int]): + type = sqltypes.Integer() inherit_cache = True def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: @@ -1849,7 +1866,8 @@ def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: super().__init__(mol, **kwargs) -class mol_numrings(GenericFunction): +class mol_numrings(GenericFunction[int]): + type = sqltypes.Integer() inherit_cache = True def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: @@ -1870,7 +1888,8 @@ def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: super().__init__(mol, **kwargs) -class mol_numrotatablebonds(GenericFunction): +class mol_numrotatablebonds(GenericFunction[int]): + type = sqltypes.Integer() inherit_cache = True def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: @@ -1891,7 +1910,8 @@ def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: super().__init__(mol, **kwargs) -class mol_numsaturatedcarbocycles(GenericFunction): +class mol_numsaturatedcarbocycles(GenericFunction[int]): + type = sqltypes.Integer() inherit_cache = True def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: @@ -1912,7 +1932,8 @@ def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: super().__init__(mol, **kwargs) -class mol_numsaturatedheterocycles(GenericFunction): +class mol_numsaturatedheterocycles(GenericFunction[int]): + type = sqltypes.Integer() inherit_cache = True def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: @@ -1933,7 +1954,8 @@ def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: super().__init__(mol, **kwargs) -class mol_numsaturatedrings(GenericFunction): +class mol_numsaturatedrings(GenericFunction[int]): + type = sqltypes.Integer() inherit_cache = True def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: @@ -1954,7 +1976,8 @@ def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: super().__init__(mol, **kwargs) -class mol_numspiroatoms(GenericFunction): +class mol_numspiroatoms(GenericFunction[int]): + type = sqltypes.Integer() inherit_cache = True def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: @@ -1975,7 +1998,7 @@ def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: super().__init__(mol, **kwargs) -class mol_phi(GenericFunction): +class mol_phi(GenericFunction[float]): type = sqltypes.Float() inherit_cache = True @@ -1997,7 +2020,7 @@ def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: super().__init__(mol, **kwargs) -class mol_send(GenericFunction): +class mol_send(GenericFunction[bytes]): type = sqltypes.LargeBinary() inherit_cache = True @@ -2019,15 +2042,15 @@ def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: super().__init__(mol, **kwargs) -class mol_to_ctab(GenericFunction): +class mol_to_ctab(GenericFunction[str]): type = CString() inherit_cache = True def __init__( self, mol: AnyRdkitMolLike, - arg_2: sqltypes.Boolean | bool = True, - arg_3: sqltypes.Boolean | bool = False, + arg_2: BooleanOperand = True, + arg_3: BooleanOperand = False, **kwargs: Any, ) -> None: """Returns a CTAB (mol block) string for a molecule. @@ -2036,9 +2059,9 @@ def __init__( ---------- mol : AnyRdkitMolLike The molecule for which to generate the CTAB string. - arg_2 : sqltypes.Boolean | bool + arg_2 : BooleanOperand Undocumented cartridge parameter. - arg_3 : sqltypes.Boolean | bool + arg_3 : BooleanOperand Undocumented cartridge parameter. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -2051,7 +2074,7 @@ def __init__( super().__init__(mol, arg_2, arg_3, **kwargs) -class mol_to_cxsmarts(GenericFunction): +class mol_to_cxsmarts(GenericFunction[str]): type = CString() inherit_cache = True @@ -2073,7 +2096,7 @@ def __init__(self, mol: AnyRdkitMolLike | AnyRdkitQMolLike, **kwargs: Any) -> No super().__init__(mol, **kwargs) -class mol_to_cxsmiles(GenericFunction): +class mol_to_cxsmiles(GenericFunction[str]): type = CString() inherit_cache = True @@ -2095,7 +2118,7 @@ def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: super().__init__(mol, **kwargs) -class mol_to_json(GenericFunction): +class mol_to_json(GenericFunction[str]): type = CString() inherit_cache = True @@ -2117,7 +2140,7 @@ def __init__(self, mol: AnyRdkitMolLike | AnyRdkitQMolLike, **kwargs: Any) -> No super().__init__(mol, **kwargs) -class mol_to_pkl(GenericFunction): +class mol_to_pkl(GenericFunction[bytes]): type = sqltypes.LargeBinary() inherit_cache = True @@ -2139,7 +2162,7 @@ def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: super().__init__(mol, **kwargs) -class mol_to_smarts(GenericFunction): +class mol_to_smarts(GenericFunction[str]): type = CString() inherit_cache = True @@ -2161,7 +2184,7 @@ def __init__(self, mol: AnyRdkitMolLike | AnyRdkitQMolLike, **kwargs: Any) -> No super().__init__(mol, **kwargs) -class mol_to_smiles(GenericFunction): +class mol_to_smiles(GenericFunction[str]): type = CString() inherit_cache = True @@ -2183,17 +2206,17 @@ def __init__(self, mol: AnyRdkitMolLike | AnyRdkitQMolLike, **kwargs: Any) -> No super().__init__(mol, **kwargs) -class mol_to_svg(GenericFunction): +class mol_to_svg(GenericFunction[str]): type = CString() inherit_cache = True def __init__( self, mol: AnyRdkitMolLike | AnyRdkitQMolLike, - arg_2: CString | Cast[Any] = cast("", CString), - width: int | sqltypes.Integer = 250, - height: int | sqltypes.Integer = 200, - arg_5: CString | Cast[Any] = cast("", CString), + arg_2: str | SqlOperand[Any] = cast("", CString), + width: IntegerOperand = 250, + height: IntegerOperand = 200, + arg_5: str | SqlOperand[Any] = cast("", CString), **kwargs: Any, ) -> None: """Returns an SVG with a drawing of the molecule. This function is available from the 2016_09 release. @@ -2202,13 +2225,13 @@ def __init__( ---------- mol : AnyRdkitMolLike | AnyRdkitQMolLike The molecule to be drawn. - arg_2 : CString | Cast[Any] + arg_2 : str | SqlOperand[Any] An optional string to use as the legend for the drawing. - width : int | sqltypes.Integer + width : IntegerOperand The optional width of the generated SVG image. - height : int | sqltypes.Integer + height : IntegerOperand The optional height of the generated SVG image. - arg_5 : CString | Cast[Any] + arg_5 : str | SqlOperand[Any] Undocumented cartridge parameter. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -2221,14 +2244,14 @@ def __init__( super().__init__(mol, arg_2, width, height, arg_5, **kwargs) -class mol_to_v3kctab(GenericFunction): +class mol_to_v3kctab(GenericFunction[str]): type = CString() inherit_cache = True def __init__( self, mol: AnyRdkitMolLike, - create_depiction: sqltypes.Boolean | bool = True, + create_depiction: BooleanOperand = True, **kwargs: Any, ) -> None: """Returns a CTAB (mol block) string for a molecule. The optional second argument controls whether or not 2D coordinates will be generated for molecules that don’t have coordinates. @@ -2237,7 +2260,7 @@ def __init__( ---------- mol : AnyRdkitMolLike The molecule to convert to a V3000 CTAB string. - create_depiction : sqltypes.Boolean | bool + create_depiction : BooleanOperand Controls whether or not 2D coordinates will be generated for molecules that don't have coordinates. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -2250,17 +2273,17 @@ def __init__( super().__init__(mol, create_depiction, **kwargs) -class mol_to_xqmol(GenericFunction): +class mol_to_xqmol(GenericFunction[str]): type = RdkitXQMol() inherit_cache = True def __init__( self, arg_1: AnyRdkitMolLike, - arg_2: sqltypes.Boolean, - arg_3: sqltypes.Boolean, - arg_4: sqltypes.Boolean, - arg_5: CString, + arg_2: BooleanOperand, + arg_3: BooleanOperand, + arg_4: BooleanOperand, + arg_5: TextOperand, **kwargs: Any, ) -> None: """Converts an RDKit molecule to an RDKit XQuery molecule. TODO: add docs @@ -2269,13 +2292,13 @@ def __init__( ---------- arg_1 : AnyRdkitMolLike The RDKit molecule to be converted. - arg_2 : sqltypes.Boolean + arg_2 : BooleanOperand A boolean parameter for the conversion process. - arg_3 : sqltypes.Boolean + arg_3 : BooleanOperand Another boolean parameter for the conversion process. - arg_4 : sqltypes.Boolean + arg_4 : BooleanOperand A third boolean parameter for the conversion process. - arg_5 : CString + arg_5 : TextOperand A string parameter for the conversion process. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -2288,7 +2311,7 @@ def __init__( super().__init__(arg_1, arg_2, arg_3, arg_4, arg_5, **kwargs) -class mol_tpsa(GenericFunction): +class mol_tpsa(GenericFunction[float]): type = sqltypes.Float() inherit_cache = True @@ -2310,12 +2333,12 @@ def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: super().__init__(mol, **kwargs) -class morgan_fp(GenericFunction): +class morgan_fp(GenericFunction[bytes]): type = RdkitSparseFingerprint() inherit_cache = True def __init__( - self, mol: AnyRdkitMolLike, radius: int | sqltypes.Integer = 2, **kwargs: Any + self, mol: AnyRdkitMolLike, radius: IntegerOperand = 2, **kwargs: Any ) -> None: """Returns a count-based Morgan fingerprint (sfp) for a molecule using connectivity invariants. This is an ECFP-like fingerprint. @@ -2323,7 +2346,7 @@ def __init__( ---------- mol : AnyRdkitMolLike The molecule for which to generate the fingerprint. - radius : int | sqltypes.Integer + radius : IntegerOperand The radius for the Morgan fingerprint generation. Defaults to 2. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -2336,12 +2359,12 @@ def __init__( super().__init__(mol, radius, **kwargs) -class morganbv_fp(GenericFunction): +class morganbv_fp(GenericFunction[bytes]): type = RdkitBitFingerprint() inherit_cache = True def __init__( - self, mol: AnyRdkitMolLike, radius: int | sqltypes.Integer = 2, **kwargs: Any + self, mol: AnyRdkitMolLike, radius: IntegerOperand = 2, **kwargs: Any ) -> None: """Returns a bit vector Morgan fingerprint (bfp) for a molecule using connectivity invariants. The second argument provides the radius. This is an ECFP-like fingerprint. @@ -2349,7 +2372,7 @@ def __init__( ---------- mol : AnyRdkitMolLike The molecule for which to generate the fingerprint. - radius : int | sqltypes.Integer + radius : IntegerOperand The radius for the Morgan fingerprint calculation. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -2362,20 +2385,20 @@ def __init__( super().__init__(mol, radius, **kwargs) -class qmol_from_ctab(GenericFunction): +class qmol_from_ctab(GenericFunction[str]): type = RdkitQMol() inherit_cache = True def __init__( - self, ctab: CString, keep_conformer: sqltypes.Boolean, **kwargs: Any + self, ctab: TextOperand, keep_conformer: BooleanOperand, **kwargs: Any ) -> None: """Returns a query molecule for a CTAB (mol block) string. TODO: This functions changed between the versions - adding new arg. Parameters ---------- - ctab : CString + ctab : TextOperand A CTAB (mol block) string. - keep_conformer : sqltypes.Boolean + keep_conformer : BooleanOperand Controls whether or not the coordinates are saved. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -2388,16 +2411,16 @@ def __init__( super().__init__(ctab, keep_conformer, **kwargs) -class qmol_from_json(GenericFunction): +class qmol_from_json(GenericFunction[str]): type = RdkitQMol() inherit_cache = True - def __init__(self, json: CString, **kwargs: Any) -> None: + def __init__(self, json: TextOperand, **kwargs: Any) -> None: """Returns a query molecule for a commonchem JSON string. Parameters ---------- - json : CString + json : TextOperand The commonchem JSON string representing the query molecule. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -2410,16 +2433,16 @@ def __init__(self, json: CString, **kwargs: Any) -> None: super().__init__(json, **kwargs) -class qmol_from_smarts(GenericFunction): +class qmol_from_smarts(GenericFunction[str]): type = RdkitQMol() inherit_cache = True - def __init__(self, smarts: CString, **kwargs: Any) -> None: + def __init__(self, smarts: TextOperand, **kwargs: Any) -> None: """Returns a query molecule for a SMARTS string. Explicit Hs in the SMARTS are converted into query features on the attached atom. Parameters ---------- - smarts : CString + smarts : TextOperand The SMARTS string representing the query molecule. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -2432,16 +2455,16 @@ def __init__(self, smarts: CString, **kwargs: Any) -> None: super().__init__(smarts, **kwargs) -class qmol_from_smiles(GenericFunction): +class qmol_from_smiles(GenericFunction[str]): type = RdkitQMol() inherit_cache = True - def __init__(self, smiles: CString, **kwargs: Any) -> None: + def __init__(self, smiles: TextOperand, **kwargs: Any) -> None: """Returns a query molecule for a SMILES string. Explicit Hs in the SMILES are converted into query features on the attached atom. Parameters ---------- - smiles : CString + smiles : TextOperand The SMILES string to convert into a query molecule. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -2454,7 +2477,7 @@ def __init__(self, smiles: CString, **kwargs: Any) -> None: super().__init__(smiles, **kwargs) -class qmol_send(GenericFunction): +class qmol_send(GenericFunction[bytes]): type = sqltypes.LargeBinary() inherit_cache = True @@ -2476,7 +2499,7 @@ def __init__(self, mol: AnyRdkitQMolLike, **kwargs: Any) -> None: super().__init__(mol, **kwargs) -class rdkit_fp(GenericFunction): +class rdkit_fp(GenericFunction[bytes]): type = RdkitBitFingerprint() inherit_cache = True @@ -2498,7 +2521,7 @@ def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: super().__init__(mol, **kwargs) -class rdkit_toolkit_version(GenericFunction): +class rdkit_toolkit_version(GenericFunction[str]): type = sqltypes.Text() inherit_cache = True @@ -2519,7 +2542,7 @@ def __init__(self, **kwargs: Any) -> None: super().__init__(**kwargs) -class rdkit_version(GenericFunction): +class rdkit_version(GenericFunction[str]): type = sqltypes.Text() inherit_cache = True @@ -2540,15 +2563,12 @@ def __init__(self, **kwargs: Any) -> None: super().__init__(**kwargs) -class reaction_difference_fp(GenericFunction): +class reaction_difference_fp(GenericFunction[bytes]): type = RdkitSparseFingerprint() inherit_cache = True def __init__( - self, - rxn_1: AnyRdkitReactionLike, - fp_type: int | sqltypes.Integer, - **kwargs: Any, + self, rxn_1: AnyRdkitReactionLike, fp_type: IntegerOperand, **kwargs: Any ) -> None: """Calculates a sparse fingerprint representing the difference between reactants and products in an RDKit reaction. @@ -2556,7 +2576,7 @@ def __init__( ---------- rxn_1 : AnyRdkitReactionLike The RDKit reaction object. - fp_type : int | sqltypes.Integer + fp_type : IntegerOperand Integer denoting the fingerprint type. Likely 1 (AtomPairFP), 2 (TopologicalTorsionFP), or 3 (MorganFP). kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -2569,16 +2589,16 @@ def __init__( super().__init__(rxn_1, fp_type, **kwargs) -class reaction_from_ctab(GenericFunction): +class reaction_from_ctab(GenericFunction[str]): type = RdkitReaction() inherit_cache = True - def __init__(self, rxn_str: CString, **kwargs: Any) -> None: + def __init__(self, rxn_str: TextOperand, **kwargs: Any) -> None: """Returns a reaction for a CTAB (reaction block) string. Parameters ---------- - rxn_str : CString + rxn_str : TextOperand The CTAB (reaction block) string representing the reaction. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -2591,16 +2611,16 @@ def __init__(self, rxn_str: CString, **kwargs: Any) -> None: super().__init__(rxn_str, **kwargs) -class reaction_from_smarts(GenericFunction): +class reaction_from_smarts(GenericFunction[str]): type = RdkitReaction() inherit_cache = True - def __init__(self, rxn_str: CString | Cast[Any], **kwargs: Any) -> None: + def __init__(self, rxn_str: str | SqlOperand[Any], **kwargs: Any) -> None: """Returns a reaction object for a SMARTS string. Parameters ---------- - rxn_str : CString | Cast[Any] + rxn_str : str | SqlOperand[Any] The SMARTS string representing the reaction. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -2613,16 +2633,16 @@ def __init__(self, rxn_str: CString | Cast[Any], **kwargs: Any) -> None: super().__init__(rxn_str, **kwargs) -class reaction_from_smiles(GenericFunction): +class reaction_from_smiles(GenericFunction[str]): type = RdkitReaction() inherit_cache = True - def __init__(self, rxn_str: CString, **kwargs: Any) -> None: + def __init__(self, rxn_str: TextOperand, **kwargs: Any) -> None: """Returns a reaction object for a reaction SMILES string. Returns NULL if the reaction construction fails. Parameters ---------- - rxn_str : CString + rxn_str : TextOperand The reaction SMILES string to convert into an RDKit reaction object. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -2635,7 +2655,8 @@ def __init__(self, rxn_str: CString, **kwargs: Any) -> None: super().__init__(rxn_str, **kwargs) -class reaction_numagents(GenericFunction): +class reaction_numagents(GenericFunction[int]): + type = sqltypes.Integer() inherit_cache = True def __init__(self, rxn: AnyRdkitReactionLike, **kwargs: Any) -> None: @@ -2656,7 +2677,8 @@ def __init__(self, rxn: AnyRdkitReactionLike, **kwargs: Any) -> None: super().__init__(rxn, **kwargs) -class reaction_numproducts(GenericFunction): +class reaction_numproducts(GenericFunction[int]): + type = sqltypes.Integer() inherit_cache = True def __init__(self, rxn: AnyRdkitReactionLike, **kwargs: Any) -> None: @@ -2677,7 +2699,8 @@ def __init__(self, rxn: AnyRdkitReactionLike, **kwargs: Any) -> None: super().__init__(rxn, **kwargs) -class reaction_numreactants(GenericFunction): +class reaction_numreactants(GenericFunction[int]): + type = sqltypes.Integer() inherit_cache = True def __init__(self, rxn: AnyRdkitReactionLike, **kwargs: Any) -> None: @@ -2698,7 +2721,7 @@ def __init__(self, rxn: AnyRdkitReactionLike, **kwargs: Any) -> None: super().__init__(rxn, **kwargs) -class reaction_send(GenericFunction): +class reaction_send(GenericFunction[bytes]): type = sqltypes.LargeBinary() inherit_cache = True @@ -2720,12 +2743,12 @@ def __init__(self, rxn: AnyRdkitReactionLike, **kwargs: Any) -> None: super().__init__(rxn, **kwargs) -class reaction_structural_bfp(GenericFunction): +class reaction_structural_bfp(GenericFunction[bytes]): type = RdkitBitFingerprint() inherit_cache = True def __init__( - self, rxn: AnyRdkitReactionLike, radius: int | sqltypes.Integer, **kwargs: Any + self, rxn: AnyRdkitReactionLike, radius: IntegerOperand, **kwargs: Any ) -> None: """Returns a bit vector fingerprint (bfp) representing the structural features of a chemical reaction. The second argument provides the radius for the fingerprint generation. @@ -2733,7 +2756,7 @@ def __init__( ---------- rxn : AnyRdkitReactionLike The RDKit reaction object. - radius : int | sqltypes.Integer + radius : IntegerOperand The radius to use for the fingerprint generation. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -2746,7 +2769,7 @@ def __init__( super().__init__(rxn, radius, **kwargs) -class reaction_to_ctab(GenericFunction): +class reaction_to_ctab(GenericFunction[str]): type = CString() inherit_cache = True @@ -2768,7 +2791,7 @@ def __init__(self, reaction: AnyRdkitReactionLike, **kwargs: Any) -> None: super().__init__(reaction, **kwargs) -class reaction_to_smarts(GenericFunction): +class reaction_to_smarts(GenericFunction[str]): type = CString() inherit_cache = True @@ -2790,7 +2813,7 @@ def __init__(self, rxn: AnyRdkitReactionLike, **kwargs: Any) -> None: super().__init__(rxn, **kwargs) -class reaction_to_smiles(GenericFunction): +class reaction_to_smiles(GenericFunction[str]): type = CString() inherit_cache = True @@ -2812,17 +2835,17 @@ def __init__(self, rxn: AnyRdkitReactionLike, **kwargs: Any) -> None: super().__init__(rxn, **kwargs) -class reaction_to_svg(GenericFunction): +class reaction_to_svg(GenericFunction[str]): type = CString() inherit_cache = True def __init__( self, rxn: AnyRdkitReactionLike, - highlight_reactants: sqltypes.Boolean, - width: int | sqltypes.Integer, - height: int | sqltypes.Integer, - params: CString, + highlight_reactants: BooleanOperand, + width: IntegerOperand, + height: IntegerOperand, + params: TextOperand, **kwargs: Any, ) -> None: """Returns an SVG (Scalable Vector Graphics) drawing of the provided RDKit reaction. This function is quite slow @@ -2831,13 +2854,13 @@ def __init__( ---------- rxn : AnyRdkitReactionLike The RDKit reaction object to be drawn. - highlight_reactants : sqltypes.Boolean + highlight_reactants : BooleanOperand If true, highlights the reactants in the SVG drawing. - width : int | sqltypes.Integer + width : IntegerOperand The desired width of the SVG image. - height : int | sqltypes.Integer + height : IntegerOperand The desired height of the SVG image. - params : CString + params : TextOperand An optional string for other drawing parameters? [TODO] kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -2850,7 +2873,7 @@ def __init__( super().__init__(rxn, highlight_reactants, width, height, params, **kwargs) -class rsubstruct(GenericFunction): +class rsubstruct(GenericFunction[bool]): type = sqltypes.Boolean() inherit_cache = True @@ -2882,7 +2905,7 @@ def __init__( super().__init__(mol, query, **kwargs) -class rsubstruct_chiral(GenericFunction): +class rsubstruct_chiral(GenericFunction[bool]): type = sqltypes.Boolean() inherit_cache = True @@ -2908,7 +2931,7 @@ def __init__( super().__init__(mol, query_mol, **kwargs) -class rsubstruct_query(GenericFunction): +class rsubstruct_query(GenericFunction[bool]): type = sqltypes.Boolean() inherit_cache = True @@ -2937,7 +2960,7 @@ def __init__( super().__init__(mol_1, mol_2, **kwargs) -class rsubstructfp(GenericFunction): +class rsubstructfp(GenericFunction[bool]): type = sqltypes.Boolean() inherit_cache = True @@ -2963,7 +2986,8 @@ def __init__( super().__init__(rxn_1, rxn_2, **kwargs) -class size(GenericFunction): +class size(GenericFunction[int]): + type = sqltypes.Integer() inherit_cache = True def __init__(self, bfp: AnyRdkitBitFingerprintLike, **kwargs: Any) -> None: @@ -2984,7 +3008,7 @@ def __init__(self, bfp: AnyRdkitBitFingerprintLike, **kwargs: Any) -> None: super().__init__(bfp, **kwargs) -class substruct(GenericFunction): +class substruct(GenericFunction[bool]): type = sqltypes.Boolean() inherit_cache = True @@ -3016,7 +3040,7 @@ def __init__( super().__init__(mol, query, **kwargs) -class substruct_chiral(GenericFunction): +class substruct_chiral(GenericFunction[bool]): type = sqltypes.Boolean() inherit_cache = True @@ -3042,14 +3066,15 @@ def __init__( super().__init__(mol, query, **kwargs) -class substruct_count(GenericFunction): +class substruct_count(GenericFunction[int]): + type = sqltypes.Integer() inherit_cache = True def __init__( self, mol: AnyRdkitMolLike, query: AnyRdkitMolLike | AnyRdkitQMolLike, - unique: sqltypes.Boolean | bool = True, + unique: BooleanOperand = True, **kwargs: Any, ) -> None: """Returns the number of substructure matches between the second molecule and the first. Optionally, the matches can be uniquified. @@ -3060,7 +3085,7 @@ def __init__( The molecule to search within. query : AnyRdkitMolLike | AnyRdkitQMolLike The substructure to search for. - unique : sqltypes.Boolean | bool + unique : BooleanOperand Toggles whether or not the matches are uniquified. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -3073,14 +3098,15 @@ def __init__( super().__init__(mol, query, unique, **kwargs) -class substruct_count_chiral(GenericFunction): +class substruct_count_chiral(GenericFunction[int]): + type = sqltypes.Integer() inherit_cache = True def __init__( self, mol: AnyRdkitMolLike, query: AnyRdkitMolLike | AnyRdkitQMolLike, - unique: sqltypes.Boolean, + unique: BooleanOperand, **kwargs: Any, ) -> None: """Returns the number of chiral substructure matches found between a query molecule and a target molecule. This function considers chirality during the matching process. @@ -3091,7 +3117,7 @@ def __init__( The target RDKit molecule to search within. query : AnyRdkitMolLike | AnyRdkitQMolLike The RDKit molecule or query molecule to search for as a chiral substructure. - unique : sqltypes.Boolean + unique : BooleanOperand A boolean flag indicating whether to count only unique chiral substructure matches (true) or all matches (false). kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -3104,7 +3130,7 @@ def __init__( super().__init__(mol, query, unique, **kwargs) -class substruct_query(GenericFunction): +class substruct_query(GenericFunction[bool]): type = sqltypes.Boolean() inherit_cache = True @@ -3133,7 +3159,7 @@ def __init__( super().__init__(mol_1, mol_2, **kwargs) -class substructfp(GenericFunction): +class substructfp(GenericFunction[bool]): type = sqltypes.Boolean() inherit_cache = True @@ -3159,7 +3185,7 @@ def __init__( super().__init__(rxn_1, rxn_2, **kwargs) -class subtract(GenericFunction): +class subtract(GenericFunction[bytes]): type = RdkitSparseFingerprint() inherit_cache = True @@ -3188,7 +3214,7 @@ def __init__( super().__init__(fp_1, fp_2, **kwargs) -class tanimoto_dist(GenericFunction): +class tanimoto_dist(GenericFunction[float]): type = sqltypes.Float() inherit_cache = True @@ -3217,7 +3243,7 @@ def __init__( super().__init__(fp_1, fp_2, **kwargs) -class tanimoto_sml(GenericFunction): +class tanimoto_sml(GenericFunction[float]): type = sqltypes.Float() inherit_cache = True @@ -3246,7 +3272,7 @@ def __init__( super().__init__(fp_1, fp_2, **kwargs) -class torsion_fp(GenericFunction): +class torsion_fp(GenericFunction[bytes]): type = RdkitSparseFingerprint() inherit_cache = True @@ -3268,7 +3294,7 @@ def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: super().__init__(mol, **kwargs) -class torsionbv_fp(GenericFunction): +class torsionbv_fp(GenericFunction[bytes]): type = RdkitBitFingerprint() inherit_cache = True @@ -3290,7 +3316,7 @@ def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: super().__init__(mol, **kwargs) -class tversky_sml(GenericFunction): +class tversky_sml(GenericFunction[float]): type = sqltypes.Float() inherit_cache = True @@ -3298,8 +3324,8 @@ def __init__( self, fp_1: AnyRdkitBitFingerprintLike, fp_2: AnyRdkitBitFingerprintLike, - alpha: float, - beta: float, + alpha: FloatOperand, + beta: FloatOperand, **kwargs: Any, ) -> None: """Returns the Tversky similarity between two bit fingerprints. The third and fourth arguments are the alpha and beta parameters for the Tversky similarity. @@ -3310,9 +3336,9 @@ def __init__( The first fingerprint. fp_2 : AnyRdkitBitFingerprintLike The second fingerprint. - alpha : float + alpha : FloatOperand The alpha parameter for the Tversky similarity. - beta : float + beta : FloatOperand The beta parameter for the Tversky similarity. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -3325,7 +3351,7 @@ def __init__( super().__init__(fp_1, fp_2, alpha, beta, **kwargs) -class xqmol_send(GenericFunction): +class xqmol_send(GenericFunction[bytes]): type = sqltypes.LargeBinary() inherit_cache = True diff --git a/src/molalchemy/rdkit/functions/internal.py b/src/molalchemy/rdkit/functions/internal.py index 365a464..73d031f 100644 --- a/src/molalchemy/rdkit/functions/internal.py +++ b/src/molalchemy/rdkit/functions/internal.py @@ -8,6 +8,9 @@ from sqlalchemy import types as sqltypes from sqlalchemy.sql.functions import GenericFunction +from molalchemy.protocols import ( + TextOperand, +) from molalchemy.rdkit.types import ( RdkitBitFingerprint, RdkitMol, @@ -29,7 +32,8 @@ ) -class bfp_cmp(GenericFunction): +class bfp_cmp(GenericFunction[int]): + type = sqltypes.Integer() inherit_cache = True def __init__( @@ -57,7 +61,7 @@ def __init__( super().__init__(fp_1, fp_2, **kwargs) -class bfp_eq(GenericFunction): +class bfp_eq(GenericFunction[bool]): type = sqltypes.Boolean() inherit_cache = True @@ -86,7 +90,7 @@ def __init__( super().__init__(fp_1, fp_2, **kwargs) -class bfp_ge(GenericFunction): +class bfp_ge(GenericFunction[bool]): type = sqltypes.Boolean() inherit_cache = True @@ -115,7 +119,7 @@ def __init__( super().__init__(fp_1, fp_2, **kwargs) -class bfp_gt(GenericFunction): +class bfp_gt(GenericFunction[bool]): type = sqltypes.Boolean() inherit_cache = True @@ -144,16 +148,16 @@ def __init__( super().__init__(fp_1, fp_2, **kwargs) -class bfp_in(GenericFunction): +class bfp_in(GenericFunction[bytes]): type = RdkitBitFingerprint() inherit_cache = True - def __init__(self, input: CString, **kwargs: Any) -> None: + def __init__(self, input: TextOperand, **kwargs: Any) -> None: """Converts a string representation into an RDKit bit fingerprint. Used for input conversion from the client. Parameters ---------- - input : CString + input : TextOperand The string representation of the bit fingerprint. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -166,7 +170,7 @@ def __init__(self, input: CString, **kwargs: Any) -> None: super().__init__(input, **kwargs) -class bfp_lt(GenericFunction): +class bfp_lt(GenericFunction[bool]): type = sqltypes.Boolean() inherit_cache = True @@ -195,7 +199,7 @@ def __init__( super().__init__(fp_1, fp_2, **kwargs) -class bfp_ne(GenericFunction): +class bfp_ne(GenericFunction[bool]): type = sqltypes.Boolean() inherit_cache = True @@ -224,7 +228,7 @@ def __init__( super().__init__(bfp1, bfp2, **kwargs) -class bfp_out(GenericFunction): +class bfp_out(GenericFunction[str]): type = CString() inherit_cache = True @@ -246,20 +250,18 @@ def __init__(self, fp: AnyRdkitBitFingerprintLike, **kwargs: Any) -> None: super().__init__(fp, **kwargs) -class fmcs_smiles_transition(GenericFunction): +class fmcs_smiles_transition(GenericFunction[str]): type = sqltypes.Text() inherit_cache = True - def __init__( - self, arg_1: sqltypes.Text, arg_2: sqltypes.Text, **kwargs: Any - ) -> None: + def __init__(self, arg_1: TextOperand, arg_2: TextOperand, **kwargs: Any) -> None: """TODO Parameters ---------- - arg_1 : sqltypes.Text + arg_1 : TextOperand TODO. - arg_2 : sqltypes.Text + arg_2 : TextOperand TODO. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -272,7 +274,8 @@ def __init__( super().__init__(arg_1, arg_2, **kwargs) -class mol_cmp(GenericFunction): +class mol_cmp(GenericFunction[int]): + type = sqltypes.Integer() inherit_cache = True def __init__( @@ -297,7 +300,7 @@ def __init__( super().__init__(mol_1, mol_2, **kwargs) -class mol_eq(GenericFunction): +class mol_eq(GenericFunction[bool]): type = sqltypes.Boolean() inherit_cache = True @@ -323,7 +326,7 @@ def __init__( super().__init__(mol_1, mol_2, **kwargs) -class mol_ge(GenericFunction): +class mol_ge(GenericFunction[bool]): type = sqltypes.Boolean() inherit_cache = True @@ -349,7 +352,7 @@ def __init__( super().__init__(arg_1, arg_2, **kwargs) -class mol_gt(GenericFunction): +class mol_gt(GenericFunction[bool]): type = sqltypes.Boolean() inherit_cache = True @@ -375,16 +378,16 @@ def __init__( super().__init__(mol_1, mol_2, **kwargs) -class mol_in(GenericFunction): +class mol_in(GenericFunction[str]): type = RdkitMol() inherit_cache = True - def __init__(self, mol_str: CString, **kwargs: Any) -> None: + def __init__(self, mol_str: TextOperand, **kwargs: Any) -> None: """Internal function used to load the molecule from the client input. Parameters ---------- - mol_str : CString + mol_str : TextOperand The string representation of the molecule. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -397,7 +400,7 @@ def __init__(self, mol_str: CString, **kwargs: Any) -> None: super().__init__(mol_str, **kwargs) -class mol_le(GenericFunction): +class mol_le(GenericFunction[bool]): type = sqltypes.Boolean() inherit_cache = True @@ -423,7 +426,7 @@ def __init__( super().__init__(mol_1, mol_2, **kwargs) -class mol_lt(GenericFunction): +class mol_lt(GenericFunction[bool]): type = sqltypes.Boolean() inherit_cache = True @@ -449,7 +452,7 @@ def __init__( super().__init__(mol_1, mol_2, **kwargs) -class mol_ne(GenericFunction): +class mol_ne(GenericFunction[bool]): type = sqltypes.Boolean() inherit_cache = True @@ -475,7 +478,7 @@ def __init__( super().__init__(mol_1, mol_2, **kwargs) -class mol_out(GenericFunction): +class mol_out(GenericFunction[str]): type = CString() inherit_cache = True @@ -497,16 +500,16 @@ def __init__(self, mol: AnyRdkitMolLike, **kwargs: Any) -> None: super().__init__(mol, **kwargs) -class qmol_in(GenericFunction): +class qmol_in(GenericFunction[str]): type = RdkitQMol() inherit_cache = True - def __init__(self, mol_str: CString, **kwargs: Any) -> None: + def __init__(self, mol_str: TextOperand, **kwargs: Any) -> None: """Constructs an RDKit query molecule from a string representation. This function is used internally for receiving a query molecule from the client. Parameters ---------- - mol_str : CString + mol_str : TextOperand The string representation of the query molecule kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -519,7 +522,7 @@ def __init__(self, mol_str: CString, **kwargs: Any) -> None: super().__init__(mol_str, **kwargs) -class qmol_out(GenericFunction): +class qmol_out(GenericFunction[str]): type = CString() inherit_cache = True @@ -541,7 +544,7 @@ def __init__(self, mol: AnyRdkitQMolLike, **kwargs: Any) -> None: super().__init__(mol, **kwargs) -class reaction_eq(GenericFunction): +class reaction_eq(GenericFunction[bool]): type = sqltypes.Boolean() inherit_cache = True @@ -567,16 +570,16 @@ def __init__( super().__init__(rxn_1, rxn_2, **kwargs) -class reaction_in(GenericFunction): +class reaction_in(GenericFunction[str]): type = RdkitReaction() inherit_cache = True - def __init__(self, rxn_str: CString, **kwargs: Any) -> None: + def __init__(self, rxn_str: TextOperand, **kwargs: Any) -> None: """Converts a string representation of a chemical reaction into an RDKit reaction object. Parameters ---------- - rxn_str : CString + rxn_str : TextOperand The string representation of the chemical reaction, typically in reaction SMILES format. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -589,7 +592,7 @@ def __init__(self, rxn_str: CString, **kwargs: Any) -> None: super().__init__(rxn_str, **kwargs) -class reaction_ne(GenericFunction): +class reaction_ne(GenericFunction[bool]): type = sqltypes.Boolean() inherit_cache = True @@ -615,7 +618,7 @@ def __init__( super().__init__(rxn_1, rxn_2, **kwargs) -class reaction_out(GenericFunction): +class reaction_out(GenericFunction[str]): type = CString() inherit_cache = True @@ -637,7 +640,8 @@ def __init__(self, rxn: AnyRdkitReactionLike, **kwargs: Any) -> None: super().__init__(rxn, **kwargs) -class sfp_cmp(GenericFunction): +class sfp_cmp(GenericFunction[int]): + type = sqltypes.Integer() inherit_cache = True def __init__( @@ -665,7 +669,7 @@ def __init__( super().__init__(arg_1, arg_2, **kwargs) -class sfp_eq(GenericFunction): +class sfp_eq(GenericFunction[bool]): type = sqltypes.Boolean() inherit_cache = True @@ -694,7 +698,7 @@ def __init__( super().__init__(fp_1, fp_2, **kwargs) -class sfp_ge(GenericFunction): +class sfp_ge(GenericFunction[bool]): type = sqltypes.Boolean() inherit_cache = True @@ -723,7 +727,7 @@ def __init__( super().__init__(fp_1, fp_2, **kwargs) -class sfp_gt(GenericFunction): +class sfp_gt(GenericFunction[bool]): type = sqltypes.Boolean() inherit_cache = True @@ -752,16 +756,16 @@ def __init__( super().__init__(fp_1, fp_2, **kwargs) -class sfp_in(GenericFunction): +class sfp_in(GenericFunction[bytes]): type = RdkitSparseFingerprint() inherit_cache = True - def __init__(self, fp_string: CString, **kwargs: Any) -> None: + def __init__(self, fp_string: TextOperand, **kwargs: Any) -> None: """Internal function, that constructs an RDKit sparse fingerprint (sfp) from a string representation. Parameters ---------- - fp_string : CString + fp_string : TextOperand The string representation of the sparse fingerprint. kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -774,7 +778,7 @@ def __init__(self, fp_string: CString, **kwargs: Any) -> None: super().__init__(fp_string, **kwargs) -class sfp_le(GenericFunction): +class sfp_le(GenericFunction[bool]): type = sqltypes.Boolean() inherit_cache = True @@ -803,7 +807,7 @@ def __init__( super().__init__(fp_1, fp_2, **kwargs) -class sfp_lt(GenericFunction): +class sfp_lt(GenericFunction[bool]): type = sqltypes.Boolean() inherit_cache = True @@ -832,7 +836,7 @@ def __init__( super().__init__(fp_1, fp_2, **kwargs) -class sfp_ne(GenericFunction): +class sfp_ne(GenericFunction[bool]): type = sqltypes.Boolean() inherit_cache = True @@ -861,7 +865,7 @@ def __init__( super().__init__(fp_1, fp_2, **kwargs) -class sfp_out(GenericFunction): +class sfp_out(GenericFunction[str]): type = CString() inherit_cache = True @@ -883,7 +887,7 @@ def __init__(self, fp: AnyRdkitSparseFingerprintLike, **kwargs: Any) -> None: super().__init__(fp, **kwargs) -class tanimoto_sml_op(GenericFunction): +class tanimoto_sml_op(GenericFunction[bool]): type = sqltypes.Boolean() inherit_cache = True @@ -912,16 +916,16 @@ def __init__( super().__init__(fp_1, fp_2, **kwargs) -class xqmol_in(GenericFunction): +class xqmol_in(GenericFunction[str]): type = RdkitXQMol() inherit_cache = True - def __init__(self, arg_1: CString, **kwargs: Any) -> None: + def __init__(self, arg_1: TextOperand, **kwargs: Any) -> None: """Internal function: Constructs a query molecule from an input string. Parameters ---------- - arg_1 : CString + arg_1 : TextOperand The string representation of the query molecule (e.g., SMILES, SMARTS, or CTAB). kwargs : Any Additional keyword arguments passed to the `GenericFunction`. @@ -934,7 +938,7 @@ def __init__(self, arg_1: CString, **kwargs: Any) -> None: super().__init__(arg_1, **kwargs) -class xqmol_out(GenericFunction): +class xqmol_out(GenericFunction[str]): type = CString() inherit_cache = True diff --git a/src/molalchemy/rdkit/search.py b/src/molalchemy/rdkit/search.py index ddf477c..521176f 100644 --- a/src/molalchemy/rdkit/search.py +++ b/src/molalchemy/rdkit/search.py @@ -18,21 +18,21 @@ def _rdkit_predicate( - column: ColumnElement[Any], operator: str, query: object + column: SqlOperand[Any], operator: str, query: object ) -> ColumnElement[bool]: """Build a Boolean RDKit cartridge operator expression.""" return cast(ColumnElement[bool], column.bool_op(operator)(query)) def _rdkit_distance( - column: ColumnElement[Any], operator: str, query: object + column: SqlOperand[Any], operator: str, query: object ) -> ColumnElement[float]: """Build a floating-point RDKit KNN distance expression.""" return cast(ColumnElement[float], column.op(operator, return_type=Float())(query)) def _rdkit_similarity_score( - column: SqlOperand, + column: SqlOperand[Any], query: RdkitFingerprintOperand, metric: RdkitSimilarityMetric, ) -> ColumnElement[float]: @@ -47,7 +47,7 @@ def _rdkit_similarity_score( def _rdkit_similar_to( - column: SqlOperand, + column: SqlOperand[Any], query: RdkitFingerprintOperand, minimum: RdkitSimilarityBound, maximum: RdkitSimilarityBound, @@ -64,16 +64,12 @@ def _rdkit_similar_to( return cast(ColumnElement[bool], score.is_not(None)) -def _rdkit_mol_smarts( - column: ColumnElement[Any], pattern: object -) -> ColumnElement[bool]: +def _rdkit_mol_smarts(column: SqlOperand[Any], pattern: object) -> ColumnElement[bool]: query = func.qmol_from_smarts(sql_cast(pattern, CString)) return _rdkit_predicate(column, "@>", query) -def _rdkit_rxn_smarts( - column: ColumnElement[Any], pattern: object -) -> ColumnElement[bool]: +def _rdkit_rxn_smarts(column: SqlOperand[Any], pattern: object) -> ColumnElement[bool]: return cast( ColumnElement[bool], func.substruct( diff --git a/src/molalchemy/rdkit/types.py b/src/molalchemy/rdkit/types.py index c2122ad..6d4b3d1 100644 --- a/src/molalchemy/rdkit/types.py +++ b/src/molalchemy/rdkit/types.py @@ -5,7 +5,7 @@ """ import functools -from typing import Any, Literal +from typing import Any, Generic, Literal, TypeVar, overload from rdkit import Chem from rdkit.Chem import AllChem, rdChemReactions @@ -20,6 +20,7 @@ ) _RDKIT_RETURN_TYPES = ("smiles", "bytes", "mol") +_T = TypeVar("_T") def _validate_return_type(value: object) -> None: @@ -30,7 +31,7 @@ def _validate_return_type(value: object) -> None: raise ValueError(f"return_type must be one of {choices}, got {value!r}") -class RdkitBaseType(UserDefinedType): +class RdkitBaseType(UserDefinedType[_T], Generic[_T]): """Base class for RDKit types.""" _immutable_options: frozenset[str] = frozenset() @@ -43,7 +44,7 @@ def __setattr__(self, name: str, value: Any) -> None: super().__setattr__(name, value) -class RdkitMol(RdkitBaseType): +class RdkitMol(RdkitBaseType[_T], Generic[_T]): """SQLAlchemy type for RDKit molecule data stored in PostgreSQL. This type maps to the PostgreSQL `mol` type provided by the RDKit cartridge. @@ -78,7 +79,20 @@ def get_col_spec(self, **kwargs: Any) -> str: comparator_factory = RdkitMolComparator - def __init__(self, return_type: Literal["smiles", "bytes", "mol"] = "smiles"): + @overload + def __init__( + self: "RdkitMol[str]", return_type: Literal["smiles"] = "smiles" + ) -> None: ... + + @overload + def __init__(self: "RdkitMol[bytes]", return_type: Literal["bytes"]) -> None: ... + + @overload + def __init__(self: "RdkitMol[Chem.Mol]", return_type: Literal["mol"]) -> None: ... + + def __init__( + self, return_type: Literal["smiles", "bytes", "mol"] = "smiles" + ) -> None: _validate_return_type(return_type) super().__init__() self.return_type = return_type @@ -136,7 +150,7 @@ def process(value, return_type): return functools.partial(process, return_type=self.return_type) -class RdkitBitFingerprint(RdkitBaseType): +class RdkitBitFingerprint(RdkitBaseType[bytes]): """SQLAlchemy type for RDKit bit fingerprint data stored in PostgreSQL. This type maps to the PostgreSQL `bfp` type provided by the RDKit cartridge, @@ -154,7 +168,7 @@ def get_col_spec(self, **kwargs: Any) -> str: return "bfp" -class RdkitSparseFingerprint(RdkitBaseType): +class RdkitSparseFingerprint(RdkitBaseType[bytes]): """SQLAlchemy type for RDKit sparse fingerprint data stored in PostgreSQL. This type maps to the PostgreSQL `sfp` type provided by the RDKit cartridge, @@ -172,7 +186,7 @@ def get_col_spec(self, **kwargs: Any) -> str: return "sfp" -class RdkitReaction(RdkitBaseType): +class RdkitReaction(RdkitBaseType[_T], Generic[_T]): """SQLAlchemy type for RDKit chemical reaction data stored in PostgreSQL. This type maps to the PostgreSQL `reaction` type provided by the RDKit cartridge. @@ -207,7 +221,25 @@ def get_col_spec(self, **kwargs: Any) -> str: comparator_factory = RdkitReactionComparator - def __init__(self, return_type: Literal["smiles", "bytes", "mol"] = "smiles"): + @overload + def __init__( + self: "RdkitReaction[str]", return_type: Literal["smiles"] = "smiles" + ) -> None: ... + + @overload + def __init__( + self: "RdkitReaction[bytes]", return_type: Literal["bytes"] + ) -> None: ... + + @overload + def __init__( + self: "RdkitReaction[rdChemReactions.ChemicalReaction]", + return_type: Literal["mol"], + ) -> None: ... + + def __init__( + self, return_type: Literal["smiles", "bytes", "mol"] = "smiles" + ) -> None: """Initialize the RdkitReaction type. Parameters @@ -275,7 +307,7 @@ def process(value, return_type): return functools.partial(process, return_type=self.return_type) -class RdkitQMol(RdkitBaseType): +class RdkitQMol(RdkitBaseType[str]): cache_ok = True def __repr__(self): @@ -285,7 +317,7 @@ def get_col_spec(self, **kwargs: Any) -> str: return "qmol" -class RdkitXQMol(RdkitBaseType): +class RdkitXQMol(RdkitBaseType[str]): cache_ok = True def __repr__(self): diff --git a/src/molalchemy/types.py b/src/molalchemy/types.py index 43d39a0..4a5bef6 100644 --- a/src/molalchemy/types.py +++ b/src/molalchemy/types.py @@ -1,7 +1,7 @@ from sqlalchemy.types import UserDefinedType -class CString(UserDefinedType): +class CString(UserDefinedType[str]): """Custom type for C-style strings (null-terminated).""" impl = str diff --git a/tests/bingo/test_integration.py b/tests/bingo/test_integration.py index 01e0905..11a1f58 100644 --- a/tests/bingo/test_integration.py +++ b/tests/bingo/test_integration.py @@ -172,7 +172,7 @@ class BinaryCompound(Base): id: Mapped[int] = mapped_column(Integer, primary_key=True) name: Mapped[str] = mapped_column(String(100)) - structure: Mapped[bytes] = mapped_column(BingoBinaryMol()) + structure: Mapped[str] = mapped_column(BingoBinaryMol()) __table_args__ = ( BingoBinaryMolIndex("idx_binary_compounds_structure", "structure"), diff --git a/tests/bingo/test_types.py b/tests/bingo/test_types.py index 671d20e..123758f 100644 --- a/tests/bingo/test_types.py +++ b/tests/bingo/test_types.py @@ -107,11 +107,12 @@ def test_configuration_is_immutable_and_cacheable(self): assert bingo_binary_mol.return_type == "smiles" assert bingo_binary_mol.preserve_pos is False - assert bingo_binary_mol._static_cache_key == ( - BingoBinaryMol, + cache_key = bingo_binary_mol._static_cache_key + assert cache_key[0] is BingoBinaryMol + assert frozenset(cache_key[1:]) == { ("preserve_pos", False), ("return_type", "smiles"), - ) + } @pytest.mark.parametrize( "return_type, expected_sql", diff --git a/tests/rdkit/test_functions.py b/tests/rdkit/test_functions.py index b9e3805..556d08c 100644 --- a/tests/rdkit/test_functions.py +++ b/tests/rdkit/test_functions.py @@ -1,5 +1,7 @@ """Tests for RDKit functions.""" +from typing import get_type_hints + import pytest from sqlalchemy import ( Column, @@ -13,6 +15,11 @@ from sqlalchemy.dialects import postgresql from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column +from molalchemy.protocols import ( + RdkitFingerprintSqlOperand, + RdkitMolSqlOperand, + RdkitReactionSqlOperand, +) from molalchemy.rdkit import functions as rdkit_func from molalchemy.rdkit.types import RdkitMol, RdkitQMol, RdkitReaction @@ -37,6 +44,19 @@ class Reaction(Base): query_reaction: Mapped[str] = mapped_column(RdkitReaction()) +def test_manual_helpers_expose_domain_specific_column_operands(): + """Hand-written helpers must not regress to untyped SQL operands.""" + assert get_type_hints(rdkit_func.mol_has_substructure)["mol_column"] == ( + RdkitMolSqlOperand + ) + assert get_type_hints(rdkit_func.rxn_has_substructure)["rxn_column"] == ( + RdkitReactionSqlOperand + ) + assert get_type_hints(rdkit_func.fp_similarity_score)["fp_column"] == ( + RdkitFingerprintSqlOperand + ) + + @pytest.mark.parametrize( ("helper_name", "query", "operator"), [ diff --git a/tests/test_helpers.py b/tests/test_helpers.py index 7095e9f..ae73710 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -33,7 +33,7 @@ class BingoCompound(Base): id: Mapped[int] = mapped_column(Integer, primary_key=True) structure: Mapped[str] = mapped_column(BingoMol()) - binary_structure: Mapped[bytes] = mapped_column(BingoBinaryMol()) + binary_structure: Mapped[str] = mapped_column(BingoBinaryMol()) reaction: Mapped[str] = mapped_column(BingoReaction()) diff --git a/tests/typing/consumer.py b/tests/typing/consumer.py new file mode 100644 index 0000000..7dcf84c --- /dev/null +++ b/tests/typing/consumer.py @@ -0,0 +1,88 @@ +"""Static consumer contract for MolAlchemy's shipped typing surface.""" + +from rdkit import Chem +from rdkit.Chem.rdChemReactions import ChemicalReaction +from sqlalchemy import Column, select +from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column +from sqlalchemy.sql import Select +from sqlalchemy.sql.elements import ColumnElement +from typing_extensions import assert_type + +from molalchemy.bingo.functions import ( + getsimilarity, + mol_has_substructure as bingo_has_substructure, +) +from molalchemy.bingo.types import ( + BingoBinaryMol, + BingoBinaryReaction, + BingoMol, + BingoReaction, +) +from molalchemy.rdkit.functions import ( + mol_from_smiles, + mol_has_substructure as rdkit_has_substructure, + morganbv_fp, + reaction_from_smarts, +) +from molalchemy.rdkit.types import ( + RdkitBitFingerprint, + RdkitMol, + RdkitQMol, + RdkitReaction, + RdkitSparseFingerprint, + RdkitXQMol, +) +from molalchemy.types import CString + + +assert_type(RdkitMol(), RdkitMol[str]) +assert_type(RdkitMol(return_type="smiles"), RdkitMol[str]) +assert_type(RdkitMol(return_type="bytes"), RdkitMol[bytes]) +assert_type(RdkitMol(return_type="mol"), RdkitMol[Chem.Mol]) +assert_type(RdkitReaction(), RdkitReaction[str]) +assert_type(RdkitReaction(return_type="bytes"), RdkitReaction[bytes]) +assert_type( + RdkitReaction(return_type="mol"), RdkitReaction[ChemicalReaction] +) +assert_type(BingoBinaryMol(), BingoBinaryMol[str]) +assert_type(BingoBinaryMol(return_type="molfile"), BingoBinaryMol[str]) +assert_type(BingoBinaryMol(return_type="bytes"), BingoBinaryMol[bytes]) + +assert_type(Column(CString()), Column[str]) +assert_type(Column(RdkitBitFingerprint()), Column[bytes]) +assert_type(Column(RdkitSparseFingerprint()), Column[bytes]) +assert_type(Column(RdkitQMol()), Column[str]) +assert_type(Column(RdkitXQMol()), Column[str]) +assert_type(Column(BingoMol()), Column[str]) +assert_type(Column(BingoReaction()), Column[str]) +assert_type(Column(BingoBinaryReaction()), Column[bytes]) +assert_type(select(Column(RdkitMol())), Select[tuple[str]]) +assert_type( + select(Column(RdkitMol(return_type="mol"))), Select[tuple[Chem.Mol]] +) + + +class Base(DeclarativeBase): + pass + + +class Molecule(Base): + __tablename__ = "typing_molecule" + + id: Mapped[int] = mapped_column(primary_key=True) + rdkit_mol: Mapped[str] = mapped_column(RdkitMol()) + bingo_mol: Mapped[str] = mapped_column(BingoMol()) + + +assert_type( + rdkit_has_substructure(Molecule.rdkit_mol, "c1ccccc1"), ColumnElement[bool] +) +assert_type( + bingo_has_substructure(Molecule.bingo_mol, "c1ccccc1"), ColumnElement[bool] +) +assert_type(select(mol_from_smiles("CCO")), Select[tuple[str]]) +assert_type(select(morganbv_fp(Molecule.rdkit_mol)), Select[tuple[bytes]]) +assert_type(select(reaction_from_smarts("CCO>>CC=O")), Select[tuple[str]]) +assert_type( + select(getsimilarity(Molecule.bingo_mol, "CCO")), Select[tuple[float]] +) From b01cd4d8e10754551a2acd4622685d61d516c274 Mon Sep 17 00:00:00 2001 From: Anton Siomchen <41703271+asiomchen@users.noreply.github.com.> Date: Sun, 9 Aug 2026 15:02:45 +0200 Subject: [PATCH 3/8] update import guide --- README.md | 71 +++-- docs/index.md | 71 +++-- .../01_Getting_Started_bingo_ORM.ipynb | 178 ++++++------ .../01_Getting_Started_rdkit_ORM.ipynb | 259 +++++++++--------- .../02_Getting_Started_rdkit_Core.ipynb | 143 +++++----- docs/tutorials/03_alembic_migrations.md | 8 +- .../04_Similarity_Threshold_Settings.ipynb | 103 +++---- docs/tutorials/05_Reactions_rdkit_ORM.ipynb | 178 ++++++------ .../tutorials/06_bingo_reactions_binary.ipynb | 54 ++-- .../07_rdkit_descriptors_advanced.ipynb | 63 +++-- docs/tutorials/08_proxy_helpers.md | 6 +- src/molalchemy/bingo/__init__.py | 2 + src/molalchemy/rdkit/__init__.py | 2 + 13 files changed, 582 insertions(+), 556 deletions(-) diff --git a/README.md b/README.md index 4af4eb8..9b0f016 100644 --- a/README.md +++ b/README.md @@ -132,24 +132,26 @@ To learn how to use molalchemy, check out the tutorials in the [documentation](h ## 🏗️ Supported Cartridges +Application code should import public cartridge APIs from `molalchemy.rdkit` +or `molalchemy.bingo`. These package facades are the canonical import paths and +keep cartridge ownership explicit without coupling applications to the +internal module layout. Existing root-package and leaf-module imports remain +supported for compatibility; Alembic-generated migrations intentionally use +leaf-module imports. + ### Bingo Cartridge ```python -from molalchemy.bingo.types import ( +from molalchemy.bingo import ( BingoMol, # Text-based molecule storage (SMILES/Molfile) BingoBinaryMol, # Binary molecule storage with format conversion BingoReaction, # Reaction storage (reaction SMILES/Rxnfile) - BingoBinaryReaction # Binary reaction storage -) -from molalchemy.bingo.index import ( + BingoBinaryReaction, # Binary reaction storage BingoMolIndex, # Molecule indexing BingoBinaryMolIndex, # Binary molecule indexing BingoRxnIndex, # Reaction indexing - BingoBinaryRxnIndex # Binary reaction indexing -) -from molalchemy.bingo.functions import ( - # Individual function imports available, see documentation - # for complete list of chemical analysis functions + BingoBinaryRxnIndex, # Binary reaction indexing + functions as bingo_func, ) from molalchemy.helpers import ( bingo_col, # Typed molecule-column helper for IDE autocomplete @@ -160,25 +162,18 @@ from molalchemy.helpers import ( ### RDKit Cartridge ```python -from molalchemy.rdkit.types import ( +from molalchemy.rdkit import ( RdkitMol, # RDKit molecule type with configurable return formats RdkitBitFingerprint, # Binary fingerprints (bfp) RdkitSparseFingerprint,# Sparse fingerprints (sfp) RdkitReaction, # Chemical reactions with input validation RdkitQMol, # Query molecules RdkitXQMol, # Extended query molecules -) -from molalchemy.rdkit.index import ( RdkitIndex, # RDKit molecule indexing (GIST index) -) -from molalchemy.rdkit.settings import ( get_tanimoto_threshold, set_tanimoto_threshold, # Tanimoto threshold management get_dice_threshold, set_dice_threshold, # Dice threshold management similarity_threshold, # Context manager for temporary thresholds -) -from molalchemy.rdkit.functions import ( - # Individual function imports available, see documentation - # for complete list of 150+ RDKit functions + functions as rdkit_func, ) from molalchemy.helpers import ( rdkit_col, # Typed molecule-column helper for IDE autocomplete @@ -191,8 +186,7 @@ from molalchemy.helpers import ( ### Chemical Indexing ```python -from molalchemy.bingo.index import BingoMolIndex -from molalchemy.bingo.types import BingoMol +from molalchemy.bingo import BingoMol, BingoMolIndex class Molecule(Base): __tablename__ = 'molecules' @@ -245,7 +239,7 @@ Use the matching helper for the cartridge and data kind: ```python from rdkit import Chem -from molalchemy.rdkit.types import RdkitMol +from molalchemy.rdkit import RdkitMol class MoleculeWithFormats(Base): __tablename__ = 'molecules_formatted' @@ -283,7 +277,7 @@ RDKit PostgreSQL uses GUC variables to control similarity, substructure matching ```python from sqlalchemy import create_engine -from molalchemy.rdkit.settings import ( +from molalchemy.rdkit import ( RdkitSettings, configure_engine, get_tanimoto_threshold, @@ -319,8 +313,7 @@ with similarity_threshold(session, tanimoto=0.1, dice=0.2): Store and query chemical reactions using `RdkitReaction`: ```python -from molalchemy.rdkit.types import RdkitReaction -from molalchemy.rdkit.functions import rxn_has_smarts, reaction_numreactants +from molalchemy.rdkit import RdkitReaction, functions as rdkit_func class Reaction(Base): __tablename__ = 'reactions' @@ -333,50 +326,52 @@ session.add(Reaction(name="Amide formation", rxn="[C:1](=O)[OH].[N:2]>>[C:1](=O) # Reaction substructure search results = session.execute( - select(Reaction).where(rxn_has_smarts(Reaction.rxn, ">>[C:1][N:2]")) + select(Reaction).where( + rdkit_func.rxn_has_smarts(Reaction.rxn, ">>[C:1][N:2]") + ) ).all() ``` ### Using Chemical Functions -The chemical functions are available as individual imports from the functions modules. Under the hood they use SQLAlchemy's `func` to call the corresponding database functions, and provide type hints and syntax highlighting in IDEs. +Chemical functions are available through each cartridge's `functions` +namespace. Under the hood they use SQLAlchemy's `func` to call the corresponding +database functions and provide type hints and syntax highlighting in IDEs. ```python -from molalchemy.bingo.functions import smiles, getweight, gross, inchikey +from molalchemy.bingo import functions as bingo_func # Calculate molecular properties using Bingo functions results = session.query( Molecule.name, - getweight(Molecule.structure).label('molecular_weight'), - gross(Molecule.structure).label('formula'), - smiles(Molecule.structure).label('canonical_smiles') + bingo_func.getweight(Molecule.structure).label('molecular_weight'), + bingo_func.gross(Molecule.structure).label('formula'), + bingo_func.smiles(Molecule.structure).label('canonical_smiles') ).all() # Validate molecular structures -from molalchemy.bingo.functions import checkmolecule - invalid_molecules = session.query(Molecule).filter( - checkmolecule(Molecule.structure).isnot(None) + bingo_func.checkmolecule(Molecule.structure).isnot(None) ).all() # Format conversions inchi_keys = session.query( Molecule.id, - inchikey(Molecule.structure).label('inchikey') + bingo_func.inchikey(Molecule.structure).label('inchikey') ).all() ``` For RDKit functions: ```python -from molalchemy.rdkit.functions import mol_amw, mol_formula, mol_inchikey +from molalchemy.rdkit import functions as rdkit_func # Calculate molecular properties using RDKit functions results = session.query( Molecule.name, - mol_amw(Molecule.structure).label('molecular_weight'), - mol_formula(Molecule.structure).label('formula'), - mol_inchikey(Molecule.structure).label('inchikey') + rdkit_func.mol_amw(Molecule.structure).label('molecular_weight'), + rdkit_func.mol_formula(Molecule.structure).label('formula'), + rdkit_func.mol_inchikey(Molecule.structure).label('inchikey') ).all() ``` diff --git a/docs/index.md b/docs/index.md index 4af4eb8..9b0f016 100644 --- a/docs/index.md +++ b/docs/index.md @@ -132,24 +132,26 @@ To learn how to use molalchemy, check out the tutorials in the [documentation](h ## 🏗️ Supported Cartridges +Application code should import public cartridge APIs from `molalchemy.rdkit` +or `molalchemy.bingo`. These package facades are the canonical import paths and +keep cartridge ownership explicit without coupling applications to the +internal module layout. Existing root-package and leaf-module imports remain +supported for compatibility; Alembic-generated migrations intentionally use +leaf-module imports. + ### Bingo Cartridge ```python -from molalchemy.bingo.types import ( +from molalchemy.bingo import ( BingoMol, # Text-based molecule storage (SMILES/Molfile) BingoBinaryMol, # Binary molecule storage with format conversion BingoReaction, # Reaction storage (reaction SMILES/Rxnfile) - BingoBinaryReaction # Binary reaction storage -) -from molalchemy.bingo.index import ( + BingoBinaryReaction, # Binary reaction storage BingoMolIndex, # Molecule indexing BingoBinaryMolIndex, # Binary molecule indexing BingoRxnIndex, # Reaction indexing - BingoBinaryRxnIndex # Binary reaction indexing -) -from molalchemy.bingo.functions import ( - # Individual function imports available, see documentation - # for complete list of chemical analysis functions + BingoBinaryRxnIndex, # Binary reaction indexing + functions as bingo_func, ) from molalchemy.helpers import ( bingo_col, # Typed molecule-column helper for IDE autocomplete @@ -160,25 +162,18 @@ from molalchemy.helpers import ( ### RDKit Cartridge ```python -from molalchemy.rdkit.types import ( +from molalchemy.rdkit import ( RdkitMol, # RDKit molecule type with configurable return formats RdkitBitFingerprint, # Binary fingerprints (bfp) RdkitSparseFingerprint,# Sparse fingerprints (sfp) RdkitReaction, # Chemical reactions with input validation RdkitQMol, # Query molecules RdkitXQMol, # Extended query molecules -) -from molalchemy.rdkit.index import ( RdkitIndex, # RDKit molecule indexing (GIST index) -) -from molalchemy.rdkit.settings import ( get_tanimoto_threshold, set_tanimoto_threshold, # Tanimoto threshold management get_dice_threshold, set_dice_threshold, # Dice threshold management similarity_threshold, # Context manager for temporary thresholds -) -from molalchemy.rdkit.functions import ( - # Individual function imports available, see documentation - # for complete list of 150+ RDKit functions + functions as rdkit_func, ) from molalchemy.helpers import ( rdkit_col, # Typed molecule-column helper for IDE autocomplete @@ -191,8 +186,7 @@ from molalchemy.helpers import ( ### Chemical Indexing ```python -from molalchemy.bingo.index import BingoMolIndex -from molalchemy.bingo.types import BingoMol +from molalchemy.bingo import BingoMol, BingoMolIndex class Molecule(Base): __tablename__ = 'molecules' @@ -245,7 +239,7 @@ Use the matching helper for the cartridge and data kind: ```python from rdkit import Chem -from molalchemy.rdkit.types import RdkitMol +from molalchemy.rdkit import RdkitMol class MoleculeWithFormats(Base): __tablename__ = 'molecules_formatted' @@ -283,7 +277,7 @@ RDKit PostgreSQL uses GUC variables to control similarity, substructure matching ```python from sqlalchemy import create_engine -from molalchemy.rdkit.settings import ( +from molalchemy.rdkit import ( RdkitSettings, configure_engine, get_tanimoto_threshold, @@ -319,8 +313,7 @@ with similarity_threshold(session, tanimoto=0.1, dice=0.2): Store and query chemical reactions using `RdkitReaction`: ```python -from molalchemy.rdkit.types import RdkitReaction -from molalchemy.rdkit.functions import rxn_has_smarts, reaction_numreactants +from molalchemy.rdkit import RdkitReaction, functions as rdkit_func class Reaction(Base): __tablename__ = 'reactions' @@ -333,50 +326,52 @@ session.add(Reaction(name="Amide formation", rxn="[C:1](=O)[OH].[N:2]>>[C:1](=O) # Reaction substructure search results = session.execute( - select(Reaction).where(rxn_has_smarts(Reaction.rxn, ">>[C:1][N:2]")) + select(Reaction).where( + rdkit_func.rxn_has_smarts(Reaction.rxn, ">>[C:1][N:2]") + ) ).all() ``` ### Using Chemical Functions -The chemical functions are available as individual imports from the functions modules. Under the hood they use SQLAlchemy's `func` to call the corresponding database functions, and provide type hints and syntax highlighting in IDEs. +Chemical functions are available through each cartridge's `functions` +namespace. Under the hood they use SQLAlchemy's `func` to call the corresponding +database functions and provide type hints and syntax highlighting in IDEs. ```python -from molalchemy.bingo.functions import smiles, getweight, gross, inchikey +from molalchemy.bingo import functions as bingo_func # Calculate molecular properties using Bingo functions results = session.query( Molecule.name, - getweight(Molecule.structure).label('molecular_weight'), - gross(Molecule.structure).label('formula'), - smiles(Molecule.structure).label('canonical_smiles') + bingo_func.getweight(Molecule.structure).label('molecular_weight'), + bingo_func.gross(Molecule.structure).label('formula'), + bingo_func.smiles(Molecule.structure).label('canonical_smiles') ).all() # Validate molecular structures -from molalchemy.bingo.functions import checkmolecule - invalid_molecules = session.query(Molecule).filter( - checkmolecule(Molecule.structure).isnot(None) + bingo_func.checkmolecule(Molecule.structure).isnot(None) ).all() # Format conversions inchi_keys = session.query( Molecule.id, - inchikey(Molecule.structure).label('inchikey') + bingo_func.inchikey(Molecule.structure).label('inchikey') ).all() ``` For RDKit functions: ```python -from molalchemy.rdkit.functions import mol_amw, mol_formula, mol_inchikey +from molalchemy.rdkit import functions as rdkit_func # Calculate molecular properties using RDKit functions results = session.query( Molecule.name, - mol_amw(Molecule.structure).label('molecular_weight'), - mol_formula(Molecule.structure).label('formula'), - mol_inchikey(Molecule.structure).label('inchikey') + rdkit_func.mol_amw(Molecule.structure).label('molecular_weight'), + rdkit_func.mol_formula(Molecule.structure).label('formula'), + rdkit_func.mol_inchikey(Molecule.structure).label('inchikey') ).all() ``` diff --git a/docs/tutorials/01_Getting_Started_bingo_ORM.ipynb b/docs/tutorials/01_Getting_Started_bingo_ORM.ipynb index cefd0b5..736eb57 100644 --- a/docs/tutorials/01_Getting_Started_bingo_ORM.ipynb +++ b/docs/tutorials/01_Getting_Started_bingo_ORM.ipynb @@ -61,10 +61,10 @@ "id": "8965b961", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:34:16.893722Z", - "iopub.status.busy": "2026-08-08T20:34:16.893470Z", - "iopub.status.idle": "2026-08-08T20:34:17.981767Z", - "shell.execute_reply": "2026-08-08T20:34:17.981549Z" + "iopub.execute_input": "2026-08-09T13:01:11.036140Z", + "iopub.status.busy": "2026-08-09T13:01:11.035925Z", + "iopub.status.idle": "2026-08-09T13:01:11.592492Z", + "shell.execute_reply": "2026-08-09T13:01:11.592240Z" } }, "outputs": [ @@ -95,7 +95,13 @@ " sessionmaker,\n", ")\n", "\n", - "from molalchemy.bingo import functions, index, types\n", + "from molalchemy.bingo import (\n", + " BingoMol,\n", + " BingoMolIndex,\n", + " BingoReaction,\n", + " BingoRxnIndex,\n", + " functions,\n", + ")\n", "\n", "eng = engine.create_engine(\n", " os.environ.get(\n", @@ -117,8 +123,8 @@ "\n", "Now let's create a SQLAlchemy model to store molecular data. The model uses:\n", "\n", - "- `molalchemy.bingo.types.BingoMol` for storing molecular structures\n", - "- `molalchemy.bingo.index.BingoMolIndex` to create a Bingo index for efficient chemical searches\n", + "- `molalchemy.bingo.BingoMol` for storing molecular structures\n", + "- `molalchemy.bingo.BingoMolIndex` to create a Bingo index for efficient chemical searches\n", "- Standard SQLAlchemy columns for metadata like name and properties\n", "\n", "The `bingo_idx` index on the `mol` column enables fast substructure and similarity searches using Bingo's optimized algorithms." @@ -130,10 +136,10 @@ "id": "5d6ff669", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:34:17.982981Z", - "iopub.status.busy": "2026-08-08T20:34:17.982896Z", - "iopub.status.idle": "2026-08-08T20:34:18.060766Z", - "shell.execute_reply": "2026-08-08T20:34:18.060474Z" + "iopub.execute_input": "2026-08-09T13:01:11.593590Z", + "iopub.status.busy": "2026-08-09T13:01:11.593493Z", + "iopub.status.idle": "2026-08-09T13:01:11.654403Z", + "shell.execute_reply": "2026-08-09T13:01:11.654137Z" } }, "outputs": [], @@ -145,13 +151,13 @@ "class Molecule(Base):\n", " __tablename__ = \"molalchemy_tutorial_molecules\"\n", " __table_args__ = (\n", - " index.BingoMolIndex(\"molalchemy_tutorial_bingo_orm_mol_gist_idx\", \"mol\"),\n", + " BingoMolIndex(\"molalchemy_tutorial_bingo_orm_mol_gist_idx\", \"mol\"),\n", " )\n", " id: Mapped[int] = mapped_column(\n", " Integer, primary_key=True, autoincrement=True, init=False\n", " )\n", " name: Mapped[str] = mapped_column(String(100), unique=True)\n", - " mol: Mapped[bytes] = mapped_column(types.BingoMol)\n", + " mol: Mapped[bytes] = mapped_column(BingoMol)\n", " is_nsaid: Mapped[bool] = mapped_column(Boolean, default=False)\n", "\n", "\n", @@ -177,7 +183,7 @@ "For example, this illustrative index covers only NSAID molecules, is built concurrently, and is stored in an existing tablespace named `fast_indexes`:\n", "\n", "```python\n", - "index.BingoMolIndex(\n", + "BingoMolIndex(\n", " \"ix_molecules_nsaid_mol\",\n", " \"mol\",\n", " postgresql_where=text(\"is_nsaid IS TRUE\"),\n", @@ -224,10 +230,10 @@ "id": "0f6f8b1f", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:34:18.062528Z", - "iopub.status.busy": "2026-08-08T20:34:18.062434Z", - "iopub.status.idle": "2026-08-08T20:34:18.088251Z", - "shell.execute_reply": "2026-08-08T20:34:18.087947Z" + "iopub.execute_input": "2026-08-09T13:01:11.655491Z", + "iopub.status.busy": "2026-08-09T13:01:11.655410Z", + "iopub.status.idle": "2026-08-09T13:01:11.674481Z", + "shell.execute_reply": "2026-08-09T13:01:11.674245Z" } }, "outputs": [], @@ -265,10 +271,10 @@ "id": "650f4aa8", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:34:18.089577Z", - "iopub.status.busy": "2026-08-08T20:34:18.089498Z", - "iopub.status.idle": "2026-08-08T20:34:18.092131Z", - "shell.execute_reply": "2026-08-08T20:34:18.091880Z" + "iopub.execute_input": "2026-08-09T13:01:11.675604Z", + "iopub.status.busy": "2026-08-09T13:01:11.675486Z", + "iopub.status.idle": "2026-08-09T13:01:11.677899Z", + "shell.execute_reply": "2026-08-09T13:01:11.677653Z" } }, "outputs": [], @@ -297,10 +303,10 @@ "id": "ff9cc6d6", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:34:18.093277Z", - "iopub.status.busy": "2026-08-08T20:34:18.093185Z", - "iopub.status.idle": "2026-08-08T20:34:18.097150Z", - "shell.execute_reply": "2026-08-08T20:34:18.096933Z" + "iopub.execute_input": "2026-08-09T13:01:11.678858Z", + "iopub.status.busy": "2026-08-09T13:01:11.678785Z", + "iopub.status.idle": "2026-08-09T13:01:11.682282Z", + "shell.execute_reply": "2026-08-09T13:01:11.682091Z" } }, "outputs": [ @@ -337,10 +343,10 @@ "id": "32f8a426", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:34:18.098307Z", - "iopub.status.busy": "2026-08-08T20:34:18.098237Z", - "iopub.status.idle": "2026-08-08T20:34:18.102430Z", - "shell.execute_reply": "2026-08-08T20:34:18.102204Z" + "iopub.execute_input": "2026-08-09T13:01:11.683173Z", + "iopub.status.busy": "2026-08-09T13:01:11.683108Z", + "iopub.status.idle": "2026-08-09T13:01:11.686643Z", + "shell.execute_reply": "2026-08-09T13:01:11.686462Z" } }, "outputs": [ @@ -377,10 +383,10 @@ "id": "c1e188a1", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:34:18.103443Z", - "iopub.status.busy": "2026-08-08T20:34:18.103373Z", - "iopub.status.idle": "2026-08-08T20:34:18.106547Z", - "shell.execute_reply": "2026-08-08T20:34:18.106352Z" + "iopub.execute_input": "2026-08-09T13:01:11.687559Z", + "iopub.status.busy": "2026-08-09T13:01:11.687481Z", + "iopub.status.idle": "2026-08-09T13:01:11.690445Z", + "shell.execute_reply": "2026-08-09T13:01:11.690242Z" } }, "outputs": [ @@ -416,10 +422,10 @@ "id": "5bccdfa6", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:34:18.107615Z", - "iopub.status.busy": "2026-08-08T20:34:18.107545Z", - "iopub.status.idle": "2026-08-08T20:34:18.111040Z", - "shell.execute_reply": "2026-08-08T20:34:18.110808Z" + "iopub.execute_input": "2026-08-09T13:01:11.691291Z", + "iopub.status.busy": "2026-08-09T13:01:11.691225Z", + "iopub.status.idle": "2026-08-09T13:01:11.694253Z", + "shell.execute_reply": "2026-08-09T13:01:11.694044Z" } }, "outputs": [ @@ -455,10 +461,10 @@ "id": "240f140b", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:34:18.112087Z", - "iopub.status.busy": "2026-08-08T20:34:18.112015Z", - "iopub.status.idle": "2026-08-08T20:34:18.114968Z", - "shell.execute_reply": "2026-08-08T20:34:18.114775Z" + "iopub.execute_input": "2026-08-09T13:01:11.695142Z", + "iopub.status.busy": "2026-08-09T13:01:11.695076Z", + "iopub.status.idle": "2026-08-09T13:01:11.697850Z", + "shell.execute_reply": "2026-08-09T13:01:11.697652Z" } }, "outputs": [ @@ -492,10 +498,10 @@ "id": "bingo-mol-smarts-query", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:34:18.115945Z", - "iopub.status.busy": "2026-08-08T20:34:18.115881Z", - "iopub.status.idle": "2026-08-08T20:34:18.119059Z", - "shell.execute_reply": "2026-08-08T20:34:18.118855Z" + "iopub.execute_input": "2026-08-09T13:01:11.698676Z", + "iopub.status.busy": "2026-08-09T13:01:11.698612Z", + "iopub.status.idle": "2026-08-09T13:01:11.701680Z", + "shell.execute_reply": "2026-08-09T13:01:11.701495Z" } }, "outputs": [ @@ -523,10 +529,10 @@ "id": "af67ac59", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:34:18.120007Z", - "iopub.status.busy": "2026-08-08T20:34:18.119940Z", - "iopub.status.idle": "2026-08-08T20:34:18.122926Z", - "shell.execute_reply": "2026-08-08T20:34:18.122706Z" + "iopub.execute_input": "2026-08-09T13:01:11.702526Z", + "iopub.status.busy": "2026-08-09T13:01:11.702462Z", + "iopub.status.idle": "2026-08-09T13:01:11.705082Z", + "shell.execute_reply": "2026-08-09T13:01:11.704879Z" } }, "outputs": [ @@ -554,10 +560,10 @@ "id": "8eb1f4b8", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:34:18.123872Z", - "iopub.status.busy": "2026-08-08T20:34:18.123810Z", - "iopub.status.idle": "2026-08-08T20:34:18.125937Z", - "shell.execute_reply": "2026-08-08T20:34:18.125736Z" + "iopub.execute_input": "2026-08-09T13:01:11.705920Z", + "iopub.status.busy": "2026-08-09T13:01:11.705855Z", + "iopub.status.idle": "2026-08-09T13:01:11.707892Z", + "shell.execute_reply": "2026-08-09T13:01:11.707688Z" } }, "outputs": [ @@ -601,10 +607,10 @@ "id": "bingo-rxn-model", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:34:18.126981Z", - "iopub.status.busy": "2026-08-08T20:34:18.126920Z", - "iopub.status.idle": "2026-08-08T20:34:18.195076Z", - "shell.execute_reply": "2026-08-08T20:34:18.194809Z" + "iopub.execute_input": "2026-08-09T13:01:11.708706Z", + "iopub.status.busy": "2026-08-09T13:01:11.708642Z", + "iopub.status.idle": "2026-08-09T13:01:11.772690Z", + "shell.execute_reply": "2026-08-09T13:01:11.772416Z" } }, "outputs": [], @@ -612,13 +618,13 @@ "class Reaction(Base):\n", " __tablename__ = \"molalchemy_tutorial_reactions\"\n", " __table_args__ = (\n", - " index.BingoRxnIndex(\"molalchemy_tutorial_bingo_orm_rxn_idx\", \"rxn\"),\n", + " BingoRxnIndex(\"molalchemy_tutorial_bingo_orm_rxn_idx\", \"rxn\"),\n", " )\n", " id: Mapped[int] = mapped_column(\n", " Integer, primary_key=True, autoincrement=True, init=False\n", " )\n", " name: Mapped[str] = mapped_column(String(100), unique=True)\n", - " rxn: Mapped[str] = mapped_column(types.BingoReaction)\n", + " rxn: Mapped[str] = mapped_column(BingoReaction)\n", "\n", "\n", "Reaction.__table__.drop(eng, checkfirst=True)\n", @@ -638,10 +644,10 @@ "id": "bingo-rxn-functions", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:34:18.196269Z", - "iopub.status.busy": "2026-08-08T20:34:18.196195Z", - "iopub.status.idle": "2026-08-08T20:34:18.201532Z", - "shell.execute_reply": "2026-08-08T20:34:18.201261Z" + "iopub.execute_input": "2026-08-09T13:01:11.773801Z", + "iopub.status.busy": "2026-08-09T13:01:11.773726Z", + "iopub.status.idle": "2026-08-09T13:01:11.779096Z", + "shell.execute_reply": "2026-08-09T13:01:11.778872Z" } }, "outputs": [ @@ -686,10 +692,10 @@ "id": "893a6d86", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:34:18.202854Z", - "iopub.status.busy": "2026-08-08T20:34:18.202764Z", - "iopub.status.idle": "2026-08-08T20:34:18.246366Z", - "shell.execute_reply": "2026-08-08T20:34:18.246146Z" + "iopub.execute_input": "2026-08-09T13:01:11.780026Z", + "iopub.status.busy": "2026-08-09T13:01:11.779956Z", + "iopub.status.idle": "2026-08-09T13:01:11.822730Z", + "shell.execute_reply": "2026-08-09T13:01:11.822455Z" } }, "outputs": [], @@ -701,13 +707,13 @@ "class MoleculeFP(Base):\n", " __tablename__ = \"molalchemy_tutorial_molecules_fp\"\n", " __table_args__ = (\n", - " index.BingoMolIndex(\"molalchemy_tutorial_bingo_orm_mol_gist_idx_2\", \"mol\"),\n", + " BingoMolIndex(\"molalchemy_tutorial_bingo_orm_mol_gist_idx_2\", \"mol\"),\n", " )\n", " id: Mapped[int] = mapped_column(\n", " Integer, primary_key=True, autoincrement=True, init=False\n", " )\n", " name: Mapped[str] = mapped_column(String(100), unique=True)\n", - " mol: Mapped[bytes] = mapped_column(types.BingoMol)\n", + " mol: Mapped[bytes] = mapped_column(BingoMol)\n", " is_nsaid: Mapped[bool] = mapped_column(Boolean, default=False)\n", "\n", "\n", @@ -731,10 +737,10 @@ "id": "1338370b", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:34:18.247582Z", - "iopub.status.busy": "2026-08-08T20:34:18.247516Z", - "iopub.status.idle": "2026-08-08T20:34:18.262005Z", - "shell.execute_reply": "2026-08-08T20:34:18.261691Z" + "iopub.execute_input": "2026-08-09T13:01:11.823930Z", + "iopub.status.busy": "2026-08-09T13:01:11.823852Z", + "iopub.status.idle": "2026-08-09T13:01:11.838119Z", + "shell.execute_reply": "2026-08-09T13:01:11.837887Z" } }, "outputs": [], @@ -765,10 +771,10 @@ "id": "eeb2db50", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:34:18.263556Z", - "iopub.status.busy": "2026-08-08T20:34:18.263438Z", - "iopub.status.idle": "2026-08-08T20:34:18.268742Z", - "shell.execute_reply": "2026-08-08T20:34:18.268552Z" + "iopub.execute_input": "2026-08-09T13:01:11.839202Z", + "iopub.status.busy": "2026-08-09T13:01:11.839126Z", + "iopub.status.idle": "2026-08-09T13:01:11.843691Z", + "shell.execute_reply": "2026-08-09T13:01:11.843471Z" } }, "outputs": [ @@ -817,10 +823,10 @@ "id": "bingo-similarity-examples", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:34:18.269968Z", - "iopub.status.busy": "2026-08-08T20:34:18.269845Z", - "iopub.status.idle": "2026-08-08T20:34:18.274048Z", - "shell.execute_reply": "2026-08-08T20:34:18.273867Z" + "iopub.execute_input": "2026-08-09T13:01:11.844626Z", + "iopub.status.busy": "2026-08-09T13:01:11.844558Z", + "iopub.status.idle": "2026-08-09T13:01:11.848086Z", + "shell.execute_reply": "2026-08-09T13:01:11.847878Z" } }, "outputs": [ @@ -867,10 +873,10 @@ "id": "d83fb983", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:34:18.274975Z", - "iopub.status.busy": "2026-08-08T20:34:18.274916Z", - "iopub.status.idle": "2026-08-08T20:34:18.276710Z", - "shell.execute_reply": "2026-08-08T20:34:18.276409Z" + "iopub.execute_input": "2026-08-09T13:01:11.848974Z", + "iopub.status.busy": "2026-08-09T13:01:11.848908Z", + "iopub.status.idle": "2026-08-09T13:01:11.850576Z", + "shell.execute_reply": "2026-08-09T13:01:11.850381Z" } }, "outputs": [ diff --git a/docs/tutorials/01_Getting_Started_rdkit_ORM.ipynb b/docs/tutorials/01_Getting_Started_rdkit_ORM.ipynb index 90fa35a..54c2f9c 100644 --- a/docs/tutorials/01_Getting_Started_rdkit_ORM.ipynb +++ b/docs/tutorials/01_Getting_Started_rdkit_ORM.ipynb @@ -55,10 +55,10 @@ "id": "ddcb2b72", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:34:35.477734Z", - "iopub.status.busy": "2026-08-08T20:34:35.477471Z", - "iopub.status.idle": "2026-08-08T20:34:36.031521Z", - "shell.execute_reply": "2026-08-08T20:34:36.031291Z" + "iopub.execute_input": "2026-08-09T13:01:12.487074Z", + "iopub.status.busy": "2026-08-09T13:01:12.486856Z", + "iopub.status.idle": "2026-08-09T13:01:12.802157Z", + "shell.execute_reply": "2026-08-09T13:01:12.801873Z" } }, "outputs": [ @@ -89,7 +89,12 @@ " sessionmaker,\n", ")\n", "\n", - "from molalchemy.rdkit import functions, index, types\n", + "from molalchemy.rdkit import (\n", + " RdkitIndex,\n", + " RdkitMol,\n", + " RdkitSparseFingerprint,\n", + " functions,\n", + ")\n", "\n", "eng = engine.create_engine(\n", " os.environ.get(\n", @@ -117,8 +122,8 @@ "\n", "Now let's create a SQLAlchemy model to store molecular data. The model uses:\n", "\n", - "- `molalchemy.rdkit.types.RdkitMol` for storing molecular structures\n", - "- `molalchemy.rdkit.index.RdkitIndex` to create a GiST index for efficient chemical searches\n", + "- `molalchemy.rdkit.RdkitMol` for storing molecular structures\n", + "- `molalchemy.rdkit.RdkitIndex` to create a GiST index for efficient chemical searches\n", "- Standard SQLAlchemy columns for metadata like name and properties\n", "\n", "The GiST index on the `mol` column enables fast substructure and similarity searches." @@ -130,10 +135,10 @@ "id": "7c1d4286", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:34:36.032634Z", - "iopub.status.busy": "2026-08-08T20:34:36.032537Z", - "iopub.status.idle": "2026-08-08T20:34:36.055595Z", - "shell.execute_reply": "2026-08-08T20:34:36.055341Z" + "iopub.execute_input": "2026-08-09T13:01:12.803228Z", + "iopub.status.busy": "2026-08-09T13:01:12.803134Z", + "iopub.status.idle": "2026-08-09T13:01:12.822586Z", + "shell.execute_reply": "2026-08-09T13:01:12.822329Z" } }, "outputs": [], @@ -145,13 +150,13 @@ "class Molecule(Base):\n", " __tablename__ = \"molalchemy_tutorial_molecules\"\n", " __table_args__ = (\n", - " index.RdkitIndex(\"molalchemy_tutorial_rdkit_orm_mol_gist_idx\", \"mol\"),\n", + " RdkitIndex(\"molalchemy_tutorial_rdkit_orm_mol_gist_idx\", \"mol\"),\n", " )\n", " id: Mapped[int] = mapped_column(\n", " Integer, primary_key=True, autoincrement=True, init=False\n", " )\n", " name: Mapped[str] = mapped_column(String(100), unique=True)\n", - " mol: Mapped[bytes] = mapped_column(types.RdkitMol)\n", + " mol: Mapped[bytes] = mapped_column(RdkitMol)\n", " is_nsaid: Mapped[bool] = mapped_column(Boolean, default=False)\n", "\n", "\n", @@ -183,10 +188,10 @@ "id": "9b32959c", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:34:36.056768Z", - "iopub.status.busy": "2026-08-08T20:34:36.056688Z", - "iopub.status.idle": "2026-08-08T20:34:36.075403Z", - "shell.execute_reply": "2026-08-08T20:34:36.075169Z" + "iopub.execute_input": "2026-08-09T13:01:12.823808Z", + "iopub.status.busy": "2026-08-09T13:01:12.823721Z", + "iopub.status.idle": "2026-08-09T13:01:12.838018Z", + "shell.execute_reply": "2026-08-09T13:01:12.837809Z" } }, "outputs": [], @@ -229,10 +234,10 @@ "id": "fe2028ab", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:34:36.076464Z", - "iopub.status.busy": "2026-08-08T20:34:36.076398Z", - "iopub.status.idle": "2026-08-08T20:34:36.080903Z", - "shell.execute_reply": "2026-08-08T20:34:36.080654Z" + "iopub.execute_input": "2026-08-09T13:01:12.838965Z", + "iopub.status.busy": "2026-08-09T13:01:12.838896Z", + "iopub.status.idle": "2026-08-09T13:01:12.842501Z", + "shell.execute_reply": "2026-08-09T13:01:12.842327Z" } }, "outputs": [], @@ -252,10 +257,10 @@ "id": "b6e65469", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:34:36.081904Z", - "iopub.status.busy": "2026-08-08T20:34:36.081838Z", - "iopub.status.idle": "2026-08-08T20:34:36.089978Z", - "shell.execute_reply": "2026-08-08T20:34:36.089805Z" + "iopub.execute_input": "2026-08-09T13:01:12.843346Z", + "iopub.status.busy": "2026-08-09T13:01:12.843277Z", + "iopub.status.idle": "2026-08-09T13:01:12.847703Z", + "shell.execute_reply": "2026-08-09T13:01:12.847506Z" } }, "outputs": [ @@ -293,10 +298,10 @@ "id": "a5b2666e", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:34:36.090959Z", - "iopub.status.busy": "2026-08-08T20:34:36.090893Z", - "iopub.status.idle": "2026-08-08T20:34:36.094588Z", - "shell.execute_reply": "2026-08-08T20:34:36.094386Z" + "iopub.execute_input": "2026-08-09T13:01:12.848606Z", + "iopub.status.busy": "2026-08-09T13:01:12.848533Z", + "iopub.status.idle": "2026-08-09T13:01:12.851892Z", + "shell.execute_reply": "2026-08-09T13:01:12.851682Z" } }, "outputs": [ @@ -334,10 +339,10 @@ "id": "8f356747", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:34:36.095544Z", - "iopub.status.busy": "2026-08-08T20:34:36.095483Z", - "iopub.status.idle": "2026-08-08T20:34:36.098644Z", - "shell.execute_reply": "2026-08-08T20:34:36.098433Z" + "iopub.execute_input": "2026-08-09T13:01:12.852716Z", + "iopub.status.busy": "2026-08-09T13:01:12.852650Z", + "iopub.status.idle": "2026-08-09T13:01:12.855212Z", + "shell.execute_reply": "2026-08-09T13:01:12.855021Z" } }, "outputs": [ @@ -373,10 +378,10 @@ "id": "024ffa61", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:34:36.099600Z", - "iopub.status.busy": "2026-08-08T20:34:36.099535Z", - "iopub.status.idle": "2026-08-08T20:34:36.103152Z", - "shell.execute_reply": "2026-08-08T20:34:36.102960Z" + "iopub.execute_input": "2026-08-09T13:01:12.856100Z", + "iopub.status.busy": "2026-08-09T13:01:12.856033Z", + "iopub.status.idle": "2026-08-09T13:01:12.858939Z", + "shell.execute_reply": "2026-08-09T13:01:12.858736Z" } }, "outputs": [ @@ -412,10 +417,10 @@ "id": "033e8261", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:34:36.104083Z", - "iopub.status.busy": "2026-08-08T20:34:36.104019Z", - "iopub.status.idle": "2026-08-08T20:34:36.106691Z", - "shell.execute_reply": "2026-08-08T20:34:36.106516Z" + "iopub.execute_input": "2026-08-09T13:01:12.859724Z", + "iopub.status.busy": "2026-08-09T13:01:12.859660Z", + "iopub.status.idle": "2026-08-09T13:01:12.862109Z", + "shell.execute_reply": "2026-08-09T13:01:12.861930Z" } }, "outputs": [ @@ -449,10 +454,10 @@ "id": "ab2d92fd", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:34:36.107601Z", - "iopub.status.busy": "2026-08-08T20:34:36.107530Z", - "iopub.status.idle": "2026-08-08T20:34:36.111023Z", - "shell.execute_reply": "2026-08-08T20:34:36.110838Z" + "iopub.execute_input": "2026-08-09T13:01:12.862909Z", + "iopub.status.busy": "2026-08-09T13:01:12.862845Z", + "iopub.status.idle": "2026-08-09T13:01:12.865987Z", + "shell.execute_reply": "2026-08-09T13:01:12.865793Z" } }, "outputs": [ @@ -495,10 +500,10 @@ "id": "0dd1caf0", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:34:36.111969Z", - "iopub.status.busy": "2026-08-08T20:34:36.111902Z", - "iopub.status.idle": "2026-08-08T20:34:36.114671Z", - "shell.execute_reply": "2026-08-08T20:34:36.114492Z" + "iopub.execute_input": "2026-08-09T13:01:12.866825Z", + "iopub.status.busy": "2026-08-09T13:01:12.866762Z", + "iopub.status.idle": "2026-08-09T13:01:12.869042Z", + "shell.execute_reply": "2026-08-09T13:01:12.868852Z" } }, "outputs": [ @@ -535,10 +540,10 @@ "id": "109711ef", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:34:36.115623Z", - "iopub.status.busy": "2026-08-08T20:34:36.115562Z", - "iopub.status.idle": "2026-08-08T20:34:36.119257Z", - "shell.execute_reply": "2026-08-08T20:34:36.119071Z" + "iopub.execute_input": "2026-08-09T13:01:12.869859Z", + "iopub.status.busy": "2026-08-09T13:01:12.869796Z", + "iopub.status.idle": "2026-08-09T13:01:12.872522Z", + "shell.execute_reply": "2026-08-09T13:01:12.872325Z" } }, "outputs": [ @@ -575,10 +580,10 @@ "id": "484b41d2", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:34:36.120185Z", - "iopub.status.busy": "2026-08-08T20:34:36.120127Z", - "iopub.status.idle": "2026-08-08T20:34:36.123460Z", - "shell.execute_reply": "2026-08-08T20:34:36.123216Z" + "iopub.execute_input": "2026-08-09T13:01:12.873318Z", + "iopub.status.busy": "2026-08-09T13:01:12.873258Z", + "iopub.status.idle": "2026-08-09T13:01:12.875632Z", + "shell.execute_reply": "2026-08-09T13:01:12.875436Z" } }, "outputs": [ @@ -613,7 +618,7 @@ "### Enhanced Model with Fingerprints\n", "\n", "This model adds:\n", - "- A `molalchemy.rdkit.types.RdkitSparseFingerprint` column for storing Morgan fingerprints\n", + "- A `molalchemy.rdkit.RdkitSparseFingerprint` column for storing Morgan fingerprints\n", "- A computed column that automatically generates fingerprints using `molalchemy.rdkit.functions.mol.morgan_fp()`\n", "- Additional GiST indexes for efficient fingerprint operations\n", "\n", @@ -626,10 +631,10 @@ "id": "f5617b86", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:34:36.124388Z", - "iopub.status.busy": "2026-08-08T20:34:36.124328Z", - "iopub.status.idle": "2026-08-08T20:34:36.147861Z", - "shell.execute_reply": "2026-08-08T20:34:36.147617Z" + "iopub.execute_input": "2026-08-09T13:01:12.876484Z", + "iopub.status.busy": "2026-08-09T13:01:12.876426Z", + "iopub.status.idle": "2026-08-09T13:01:12.892169Z", + "shell.execute_reply": "2026-08-09T13:01:12.891964Z" } }, "outputs": [], @@ -644,16 +649,16 @@ "class MoleculeFP(Base):\n", " __tablename__ = \"molalchemy_tutorial_molecules_fp\"\n", " __table_args__ = (\n", - " index.RdkitIndex(\"molalchemy_tutorial_rdkit_orm_mol_gist_idx_2\", \"mol\"),\n", - " index.RdkitIndex(\"molalchemy_tutorial_rdkit_orm_fp_gist_idx_2\", \"fp\"),\n", + " RdkitIndex(\"molalchemy_tutorial_rdkit_orm_mol_gist_idx_2\", \"mol\"),\n", + " RdkitIndex(\"molalchemy_tutorial_rdkit_orm_fp_gist_idx_2\", \"fp\"),\n", " )\n", " id: Mapped[int] = mapped_column(\n", " Integer, primary_key=True, autoincrement=True, init=False\n", " )\n", " name: Mapped[str] = mapped_column(String(100), unique=True)\n", - " mol: Mapped[bytes] = mapped_column(types.RdkitMol)\n", + " mol: Mapped[bytes] = mapped_column(RdkitMol)\n", " fp: Mapped[bytes] = mapped_column(\n", - " types.RdkitSparseFingerprint,\n", + " RdkitSparseFingerprint,\n", " Computed(functions.morgan_fp(mol, 2), persisted=True),\n", " init=False,\n", " )\n", @@ -670,10 +675,10 @@ "id": "5e2c36e8", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:34:36.148777Z", - "iopub.status.busy": "2026-08-08T20:34:36.148718Z", - "iopub.status.idle": "2026-08-08T20:34:36.162120Z", - "shell.execute_reply": "2026-08-08T20:34:36.161932Z" + "iopub.execute_input": "2026-08-09T13:01:12.893015Z", + "iopub.status.busy": "2026-08-09T13:01:12.892950Z", + "iopub.status.idle": "2026-08-09T13:01:12.902948Z", + "shell.execute_reply": "2026-08-09T13:01:12.902745Z" } }, "outputs": [], @@ -699,10 +704,10 @@ "id": "45e6718a", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:34:36.163134Z", - "iopub.status.busy": "2026-08-08T20:34:36.163073Z", - "iopub.status.idle": "2026-08-08T20:34:36.166400Z", - "shell.execute_reply": "2026-08-08T20:34:36.166206Z" + "iopub.execute_input": "2026-08-09T13:01:12.903875Z", + "iopub.status.busy": "2026-08-09T13:01:12.903807Z", + "iopub.status.idle": "2026-08-09T13:01:12.906874Z", + "shell.execute_reply": "2026-08-09T13:01:12.906691Z" } }, "outputs": [ @@ -752,10 +757,10 @@ "id": "9447c97a", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:34:36.167316Z", - "iopub.status.busy": "2026-08-08T20:34:36.167259Z", - "iopub.status.idle": "2026-08-08T20:34:36.173049Z", - "shell.execute_reply": "2026-08-08T20:34:36.172866Z" + "iopub.execute_input": "2026-08-09T13:01:12.907806Z", + "iopub.status.busy": "2026-08-09T13:01:12.907740Z", + "iopub.status.idle": "2026-08-09T13:01:12.912030Z", + "shell.execute_reply": "2026-08-09T13:01:12.911829Z" } }, "outputs": [ @@ -797,10 +802,10 @@ "id": "rdkit-score-examples", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:34:36.173983Z", - "iopub.status.busy": "2026-08-08T20:34:36.173926Z", - "iopub.status.idle": "2026-08-08T20:34:36.175365Z", - "shell.execute_reply": "2026-08-08T20:34:36.175161Z" + "iopub.execute_input": "2026-08-09T13:01:12.912875Z", + "iopub.status.busy": "2026-08-09T13:01:12.912809Z", + "iopub.status.idle": "2026-08-09T13:01:12.914275Z", + "shell.execute_reply": "2026-08-09T13:01:12.914077Z" } }, "outputs": [], @@ -838,10 +843,10 @@ "id": "164cb11b", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:34:36.176296Z", - "iopub.status.busy": "2026-08-08T20:34:36.176233Z", - "iopub.status.idle": "2026-08-08T20:34:36.181428Z", - "shell.execute_reply": "2026-08-08T20:34:36.181255Z" + "iopub.execute_input": "2026-08-09T13:01:12.915089Z", + "iopub.status.busy": "2026-08-09T13:01:12.915028Z", + "iopub.status.idle": "2026-08-09T13:01:12.919462Z", + "shell.execute_reply": "2026-08-09T13:01:12.919274Z" } }, "outputs": [ @@ -889,10 +894,10 @@ "id": "rdkit-bounded-knn-examples", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:34:36.182351Z", - "iopub.status.busy": "2026-08-08T20:34:36.182278Z", - "iopub.status.idle": "2026-08-08T20:34:36.184096Z", - "shell.execute_reply": "2026-08-08T20:34:36.183925Z" + "iopub.execute_input": "2026-08-09T13:01:12.920299Z", + "iopub.status.busy": "2026-08-09T13:01:12.920222Z", + "iopub.status.idle": "2026-08-09T13:01:12.922064Z", + "shell.execute_reply": "2026-08-09T13:01:12.921879Z" } }, "outputs": [], @@ -930,10 +935,10 @@ "id": "32703967", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:34:36.184913Z", - "iopub.status.busy": "2026-08-08T20:34:36.184859Z", - "iopub.status.idle": "2026-08-08T20:34:36.186561Z", - "shell.execute_reply": "2026-08-08T20:34:36.186387Z" + "iopub.execute_input": "2026-08-09T13:01:12.922877Z", + "iopub.status.busy": "2026-08-09T13:01:12.922817Z", + "iopub.status.idle": "2026-08-09T13:01:12.924501Z", + "shell.execute_reply": "2026-08-09T13:01:12.924319Z" } }, "outputs": [ @@ -977,10 +982,10 @@ "id": "68a51b79", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:34:36.187443Z", - "iopub.status.busy": "2026-08-08T20:34:36.187391Z", - "iopub.status.idle": "2026-08-08T20:34:36.197594Z", - "shell.execute_reply": "2026-08-08T20:34:36.197370Z" + "iopub.execute_input": "2026-08-09T13:01:12.925336Z", + "iopub.status.busy": "2026-08-09T13:01:12.925277Z", + "iopub.status.idle": "2026-08-09T13:01:12.933616Z", + "shell.execute_reply": "2026-08-09T13:01:12.933417Z" } }, "outputs": [], @@ -992,16 +997,16 @@ "class RawMoleculeFP(Base):\n", " __tablename__ = \"molalchemy_tutorial_raw_molecules_fp\"\n", " __table_args__ = (\n", - " index.RdkitIndex(\"molalchemy_tutorial_rdkit_orm_mol_gist_idx_3\", \"mol\"),\n", - " index.RdkitIndex(\"molalchemy_tutorial_rdkit_orm_fp_gist_idx_3\", \"fp\"),\n", + " RdkitIndex(\"molalchemy_tutorial_rdkit_orm_mol_gist_idx_3\", \"mol\"),\n", + " RdkitIndex(\"molalchemy_tutorial_rdkit_orm_fp_gist_idx_3\", \"fp\"),\n", " )\n", " id: Mapped[int] = mapped_column(\n", " Integer, primary_key=True, autoincrement=True, init=False\n", " )\n", " name: Mapped[str] = mapped_column(String(100), unique=True)\n", - " mol: Mapped[bytes] = mapped_column(types.RdkitMol(return_type=\"bytes\"))\n", + " mol: Mapped[bytes] = mapped_column(RdkitMol(return_type=\"bytes\"))\n", " fp: Mapped[bytes] = mapped_column(\n", - " types.RdkitSparseFingerprint,\n", + " RdkitSparseFingerprint,\n", " Computed(functions.morgan_fp(mol, 2), persisted=True),\n", " init=False,\n", " )\n", @@ -1028,10 +1033,10 @@ "id": "be9e0616", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:34:36.198519Z", - "iopub.status.busy": "2026-08-08T20:34:36.198458Z", - "iopub.status.idle": "2026-08-08T20:34:36.206597Z", - "shell.execute_reply": "2026-08-08T20:34:36.206406Z" + "iopub.execute_input": "2026-08-09T13:01:12.934444Z", + "iopub.status.busy": "2026-08-09T13:01:12.934385Z", + "iopub.status.idle": "2026-08-09T13:01:12.940805Z", + "shell.execute_reply": "2026-08-09T13:01:12.940630Z" } }, "outputs": [], @@ -1047,10 +1052,10 @@ "id": "e5ce3158", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:34:36.207468Z", - "iopub.status.busy": "2026-08-08T20:34:36.207412Z", - "iopub.status.idle": "2026-08-08T20:34:36.210254Z", - "shell.execute_reply": "2026-08-08T20:34:36.210064Z" + "iopub.execute_input": "2026-08-09T13:01:12.941667Z", + "iopub.status.busy": "2026-08-09T13:01:12.941607Z", + "iopub.status.idle": "2026-08-09T13:01:12.944301Z", + "shell.execute_reply": "2026-08-09T13:01:12.944107Z" } }, "outputs": [ @@ -1084,10 +1089,10 @@ "id": "f6b41d01", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:34:36.211161Z", - "iopub.status.busy": "2026-08-08T20:34:36.211105Z", - "iopub.status.idle": "2026-08-08T20:34:36.230553Z", - "shell.execute_reply": "2026-08-08T20:34:36.230357Z" + "iopub.execute_input": "2026-08-09T13:01:12.945194Z", + "iopub.status.busy": "2026-08-09T13:01:12.945115Z", + "iopub.status.idle": "2026-08-09T13:01:12.958947Z", + "shell.execute_reply": "2026-08-09T13:01:12.958742Z" } }, "outputs": [], @@ -1099,16 +1104,16 @@ "class ConvertedMoleculeFP(Base):\n", " __tablename__ = \"molalchemy_tutorial_converted_molecules_fp\"\n", " __table_args__ = (\n", - " index.RdkitIndex(\"molalchemy_tutorial_rdkit_orm_mol_gist_idx_4\", \"mol\"),\n", - " index.RdkitIndex(\"molalchemy_tutorial_rdkit_orm_fp_gist_idx_4\", \"fp\"),\n", + " RdkitIndex(\"molalchemy_tutorial_rdkit_orm_mol_gist_idx_4\", \"mol\"),\n", + " RdkitIndex(\"molalchemy_tutorial_rdkit_orm_fp_gist_idx_4\", \"fp\"),\n", " )\n", " id: Mapped[int] = mapped_column(\n", " Integer, primary_key=True, autoincrement=True, init=False\n", " )\n", " name: Mapped[str] = mapped_column(String(100), unique=True)\n", - " mol: Mapped[bytes] = mapped_column(types.RdkitMol(return_type=\"mol\"))\n", + " mol: Mapped[bytes] = mapped_column(RdkitMol(return_type=\"mol\"))\n", " fp: Mapped[bytes] = mapped_column(\n", - " types.RdkitSparseFingerprint,\n", + " RdkitSparseFingerprint,\n", " Computed(functions.morgan_fp(mol, 2), persisted=True),\n", " init=False,\n", " )\n", @@ -1125,10 +1130,10 @@ "id": "5877f080", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:34:36.231548Z", - "iopub.status.busy": "2026-08-08T20:34:36.231473Z", - "iopub.status.idle": "2026-08-08T20:34:36.258097Z", - "shell.execute_reply": "2026-08-08T20:34:36.257871Z" + "iopub.execute_input": "2026-08-09T13:01:12.959826Z", + "iopub.status.busy": "2026-08-09T13:01:12.959763Z", + "iopub.status.idle": "2026-08-09T13:01:12.983311Z", + "shell.execute_reply": "2026-08-09T13:01:12.983108Z" } }, "outputs": [ @@ -1136,17 +1141,17 @@ "name": "stderr", "output_type": "stream", "text": [ - "[22:34:36] Depickling from a version number (16.3)that is higher than our version (16.2).\n", + "[15:01:12] Depickling from a version number (16.3)that is higher than our version (16.2).\n", "This probably won't work.\n", - "[22:34:36] Depickling from a version number (16.3)that is higher than our version (16.2).\n", + "[15:01:12] Depickling from a version number (16.3)that is higher than our version (16.2).\n", "This probably won't work.\n" ] }, { "data": { "text/plain": [ - "[(ConvertedMoleculeFP(id=1, name='Aspirin', mol=, fp='\\\\x0100000004000000ffffffff190000004034df050200000017 ... (249 characters truncated) ... 00000c76fa289010000000b9cd89e01000000c831f8a501000000a7d50bb2010000006455c5bf02000000515fd9bf04000000f9fb51d301000000afbc69ee02000000', is_nsaid=True),),\n", - " (ConvertedMoleculeFP(id=2, name='Loratadine', mol=, fp='\\\\x0100000004000000ffffffff3400000043892d020100000 ... (685 characters truncated) ... 0000ac3e61ce01000000269925d3010000004aff1ee10100000030fb63e50100000056c98fe6010000003abe53ed0100000060a959ed01000000d6f410ee01000000', is_nsaid=False),)]" + "[(ConvertedMoleculeFP(id=1, name='Aspirin', mol=, fp='\\\\x0100000004000000ffffffff190000004034df050200000017 ... (249 characters truncated) ... 00000c76fa289010000000b9cd89e01000000c831f8a501000000a7d50bb2010000006455c5bf02000000515fd9bf04000000f9fb51d301000000afbc69ee02000000', is_nsaid=True),),\n", + " (ConvertedMoleculeFP(id=2, name='Loratadine', mol=, fp='\\\\x0100000004000000ffffffff3400000043892d020100000 ... (685 characters truncated) ... 0000ac3e61ce01000000269925d3010000004aff1ee10100000030fb63e50100000056c98fe6010000003abe53ed0100000060a959ed01000000d6f410ee01000000', is_nsaid=False),)]" ] }, "metadata": {}, @@ -1156,7 +1161,7 @@ "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAcIAAACWCAIAAADCEh9HAAAABmJLR0QA/wD/AP+gvaeTAAAeZklEQVR4nO3deVgT97oH8G/CEkGQRRR3Fhcsyq2ggAuIYrWAUFlMtVV7atXaPqfF2tNTe459tN7alm6PcOu91mOlalcbCYIigohWUKig0iK4ICAgsiiL7Fsy94+hESkqAslkJu/nr+bNJPPmefDbmd/85jcihmFACCGkr8RcN0AIIfxGMUoIIf1CMUoIIf1CMUoIIf1CMUoIIf2iz3UDhKhXXV1dWFiYRCLZuHHjkCFDuG6HCJCIJjwRAbt9+7aTk1N1dTUAfX19Hx8fqVQaHBxsYmLCdWtEOChGiWCVlZX5+Pj88ccfYrHY0NCwpaWFrRsbG/v5+QUHBy9evJiOT0n/UYwSYSooKHj22Wdv3Lhha2u7b98+Ly+vmzdvxsTEyGSyc+fOsX/2EonE09PT399/+fLl1tbWXLdM+IpilAhQZmbm4sWLKysrXV1d4+Lihg0b1vXdkpKS+Pj4I0eOHD9+vKOjA4Cent7MmTOlUqlUKh01ahRHXRO+ohglQnPy5MmgoKD6+vpnnnlGLpebmpo+bMuqqqq4uDiZTJaYmNjW1gZALBbPmjUrICAgJCRkwoQJGuya8BjFKBGU77///pVXXmlvb1+1atXevXsNDAxUb126dMnR0VEikfz1UzU1NUeOHDl69OixY8caGxvZoqOjo1QqXb58+eTJkzXUPeEnilEiHBEREW+//bZSqQwNDd2xY4dYfH9adGtr6/Dhwzs6Ory9vaVSaVBQUI9HqU1NTSdPnpTJZIcPH66vr2eLbJ4GBARMnz5dQ7+E8AtDCP8plcp3330XgEgk+uyzz/66wY0bN5ydnVV/9sbGxsHBwT/88MO9e/d6/MLm5ubY2NhVq1aZm5urPmVnZxcaGpqSkqJUKtX8gwif0NEo4b2Ojo7169dHRkYaGhru27fvhRdeeNiWRUVFhw8f7nqxXnVx6WEX6xUKRVpamkwm++WXX8rLy9niuHHjAgMDpVLp7Nmzux7zEt1EMUr4rbGxUSqVxsfHm5iYyGQyHx+f3nzqzp078fHxMpms9xfrVXkaFRVVWlrKFq2srHx9faVSqY+PT9dxWKJTKEYJj1VVVQUEBKSlpVlbWx87dszFxaUP3/DXi/XOzs7+/v4rVqyYOHHiXz+iVCrT0tLkcrlcLr958yZbNDIyGjduXFhYWGBgYP9+E+EfilHCV4WFhT4+PtevX7ezs0tISOgx8nqvpqYmKSnpyJEjcrm89xfrc3JyZDLZwYMHr169CmDQoEGNjY10mq9rKEYJL2VnZ/v6+paWlk6fPj0uLm4A70Fqbm5OSkqSyWQxMTF1dXVs0dHRMSAgwN/f38PDo8dPHT58OCQkRKlUJiYmLly4cKCaIbxAMUr459SpU0FBQffu3fP29o6OjlbTffEtLS0nTpw4evRodHT0nTt32KKdnV1AQIBUKp0zZ45IJOq6vaura2Zm5jfffLNmzRp19EO0F4ezBAjpA7lcPmjQIAAhISHNzc0a2GNra2t8fPzatWu73lRqY2OzcePG7Oxs1WZhYWEA3njjDQ20RLQKxSjhk6+++oodeQwNDVUoFBreu0KhSElJCQ0NHT16NBume/fuVb2bnJwMwM3NTcNdEc7RST3hB4Zhtm3btm3bNpFItGXLlg8++IDDZpRKZXp6ulwuf++996ysrNhifX29hYWFnp5eXV1dj7ecEqGiGCU8oFAoXn/99T179ujr6+/atWvt2rVcd9QzJyeny5cvp6enu7u7c90L0RyamUG0XVNT05IlS/bs2TN48OCYmBitzVAAbHr+9ttvXDdCNIpilGi16urqRYsWxcXFWVpaJiYm+vn5cd3Ro7i5uQE4f/48140QjaJH2hHtVVRU5OPjc/XqVVtb2+PHjzs4OHDd0WPQ0ahuorFRoqVycnJ8fX1LSkqmTp0aHx8/ZswYrjt6PIVCYW5u3tjYWFlZqbr0RASPTuqJNoqJifHy8iopKfHy8kpNTeVFhgLQ09NzcXFhGCYjI4PrXojmUIwSrfP+++8HBgZWVVUtXbo0ISHBzMyM646eAA2P6iAaGyXapamp6ZNPPgHg5OR08OBB3i3zQcOjOohnf6NE8IyNjfX09ABs3ryZdxmKLjFKVx10B//+TIngsefFZWVl7EuFQvHtt9++9dZbnDbVW2PHjh01alR1dXV+fj7XvRANoRglWmfZsmUAsrOz2Zd6enqbN2+OiIgoKCjgtK/ecnV1BQ2P6hKKUaJ12PPirjHEBhNfBhxpeFTXUIwSrTNt2jSJRJKbm6taNZlfl7/ZbilGdQfFKNE6hoaG06ZNUyqVFy5cYCv8Or5zc3MTi8VZWVmtra1c90I0gWKUaKNuB3Surq5isfjSpUvsU+e0nKmp6eTJk1tbW//44w+ueyGaQDEqUG1tiInBxx/jo48QHY2WFq4bejLdhkfNzMwcHBxaWlr4Ekz8Onwm/UQxKkS5uXjqKbz8Mk6fxpkzWLsWDg7IyuK6rSfAHo2mp6d3q/BreJQv3ZJ+ohgVnNZWLFmCsWNRVITERCQk4OZN2NtjyRI0NXHdXG9NmDBh6NChZWVlt27dYiv8Or7jV7eknyhGBScmBvn52LMHqudlmpriq69w6xZkMk47ewIikajbJCd+BZOTk9PgwYPz8vKqqqq47oWoHcWo4Jw7h2HDMHHiA8WpUzF6NM6d46invug2POrk5GRkZHT9+vWamhpO++oVfX19Z2dnhmEyMzO57oWoHcWo4Ny9i5Eje6iPGYO7dzXeTd91u1hvYGDAr2Di1+Ez6Q+KUcExNsa9ez3Ua2pgbKzxbvrO3d1dJBJlZmZ2dHSoKuBPMNFVJt1BMSo4jo4oLUVj4wPF+noUFWHqVI566ouhQ4fa29s3NjZeuXKFrfArmNjQT09Pp6WeBI9iVHBCQgBg584Hil99hfZ2PP88Jx31Wbfzen4djdrY2FhbW1dVVRUWFnLdC1EvilHBGTsWYWHYvBmhoTh6FHFx2LgRW7Zg+3bY2XHd3JPplpt2dnbW1taVlZU3b97ksq1eo5vrdQTFqBC9/Taio3H1Ktatw9q1yM7GoUPYtInrtp6YMJZ64ssoBOkzilGBCghAYiLKylBWhqQkBAYiPh6bN/d89UlbOTs7SySSnJychoYGtsLH4VG+hD7pM4pRgWprQ0oKfv75fuXDD/Hxx+DVEyslEomTk5NCoeDFUk9KpfKdd95JTU1VVdgVVS5evNjEn/vHSB9QjArUvXuYOxfr1kGh6Ky4uQGAVgbQI3TLTXYNugsXLrS3t3PaV3etra0vvvjil19+KZVKVaFpZmZmZGTU2toaFRXFbXtErShGBWrYMNjZoaEBubmdFXd3AODJ6bBKt7N4c3PziRMntrS0qB4xog0aGhqWLFly8OBBExOT/fv3G/85P7empoad9Pr7779z2iBRL4pR4eqWm+zLLmsm8cJfz+K1bXi0oqLCy8srISFhxIgRZ86cWbRoEVuvrq728PBobW3V09NbunQpt00StaIYFS42N1UBZG+P4cNRWYmiIg6belKTJk2ysLC4devW7du32YpWDY8WFBR4enpevHjR3t4+JSXF2dmZrd++fXv+/Pm5ublWVlaxsbEzZ87ktk+iVhSjwsUOhnY9apsxA+DZ8KhqqSfV4af2TMbMzMycNWtWXl7ejBkz0tLSJkyYwNZzc3Nnzpz5xx9/TJky5dKlS35+ftz2SdSNYlS4XFxgaIjLl/HnbCFeD4+qcnPatGlGRkZXr16tra3lsKvk5OQFCxZUVlYuWLAgOTl5+PDhbD09Pd3Ly6ukpGTmzJm//vrrmDFjOGySaAbFqHANGgQnJygUuHixs9LtNJ8nuk1iNzAwePrppxmGUc2C0rwffvjB19e3rq5u5cqV8fHxpqambD02Ntbb2/vu3btLlixJTk4eOnQoVx0STaIYFbRuuenqCpEIFy5Ay2YLPRoboxkZGYo/J29xOzwaERHx0ksvtbW1hYaG7t+/38DAgK3v27cvJCSkubl59erVhw4dMjIy4qQ9onkUo4LWbXjU0hITJqC5GTk5HDb1pIYNG2Zra1tfX3/16lW2wtXFeoZhPvjgg7feeothmE8//TQiIkIs7vwX9Omnn65evbqjo2PTpk2RkZH6+voa7o1wiSECduUKAzBjx96vrFzJAMzXX3PXU18sW7YMwN69e9mXN27cADBixAhN9tDe3r5mzRoAhoaGP/zwg6re0dHx+uuvA9DT09u1a5cmWyJago5GBc3BARYWKCnBn7OFhDE8am9v7+fnt2LFCo09tr6xsfG5557bu3fv4MGDY2JiXnzxRbbO3ry0a9cuiUTy888/v/baa5rph2gXrnOcqNnChQzAREd3vvztNwZgpkzhtKcnxt6oPm3aNE72XlVVNWvWLABDhw5NS0tT1WtqaubOnQvA3Nz8zJkznPRGtAEdjQpdt0lO06ZBIsGVK6ir47CpJ+Xi4mJgYJCdnd3YbVV/9bt58+bs2bPT0tLs7OzOnTunmkhfVlY2f/78M2fOjBw58vTp056enhpujGgPilGh67YiiaFh46JFBbNm3cjK4rCpJ2VkZMQu9aTh59ldvnzZw8Pj2rVrTk5OKSkpkyZNYuv5+fmenp5ZWVlPPfVUenr6008/rcmuiLahGBU6Nzfl0KG3FQqlUskW/m1nN/7sWdnZs9z29UTa29tbWlqGDx/+3HPPvfTSS0eOHNHAqOjp06c9PDxKS0vnz5+fmpo6evRotp6RkTFr1qz8/Hw3N7czZ86MGzdO3Z0Qbcf1qAJRO1tbWwCXL19mX37//fcAAgMDue2q9+rr6318fAAYd3myqYWFxd/+9reYmJjm5mZ17FQulw8aNAhAcHBw110kJiayk+39/f0bGxvVsWvCOxSjwsfOFoqMjGRf5uXlARg5ciS3XfVSVVXV7NmzAVhbW2dmZl6+fHnr1q3Tp09X5amRkZG/v//+/fvv3bs3UDvduXMnOyH0zTffVCgUqvqBAwfYyfbs9PuB2h3hO4pR4fvyyy8BrF+/nn2pVCqtrKwAFBcXc9vYYxUWFjo4OACws7O7fv1617cKCgrCw8PnzJkjEonYPB00aJC/v//u3bsrKyv7vEelUrl161YAIpFo69atXd8KDw9n9xUaGqpUKvu8CyI8FKPCx84WcnZ2VlV8fX0ByGQyDrt6rOzsbHY40snJqbS09GGbFRUVsXmquqFIT09vzpw54eHhZWVlT7THjo6OdevWsd/wn//8R1Vnnw7CZusXX3zR959EBIpiVPiampoMDAz09fUbGhrYCnvA9c9//pPbxh7h1KlTZmZmALy9vXt5tn7nzp39+/f7+/urbnIXi8Vsnt66das339DQ0ODu7j548OC4uDhVsbW1dfny5QAMDQ1/+umnPv4eImgUozqBXU44JSWFfXns2DEAc+fO5barh1Fd3mFX+njSj1dVVbF5KpFIVEOojo6OW7duvXbt2qM/e+fOnfPnz6te1tfXP/vsswBMTEwSEhKe+JcQ3UAxqhPYmxRVJ6RVVVUikcjY2Li9vZ3bxv5KdXknNDS06+WdPmhsbIyNjV21apWJiUm3PM3JyXnsx8vLy11cXACMGDHi4sWL/emECBvFqE6IjIwE8Pzzz6sq7FLtWVlZHHbVzSMu7/RTU1MTm6dDhgxR5am9vX1oaGhKSkqP14sKCgomTpzIbpaXlzeAzRDhoRjVCTk5OQBsbGxUFXZxja4XUjjW3v7jv/8NwMDAYP/+/WraSXNz84kTJ0JDQ1WL1QOwtbXtlqeZmZnsBjNmzKioqFBTM0QwKEZ1glKpNDc3B1BeXs5WIiIiAKxZs4bbxjo1NjL+/gqxePW8eceOHdPADtva2hISEl599dWueTp27NgNGzbs2LGDPWhdsGBBXV2dBpohfEcxqisWLFgAIDY2ln2Znp4OYOrUqdx2xTAMU13NzJnDAIylJXP2rIZ3rlAoUlJSNm3aNH78eDZM2QxdtWoVTbAnvUT31OuKrg+Gy8rKmjp1qkQiyc3NreN2qafbt+HlhbNnYWODs2cxe7aG9y8Wiz08PMLCwvLy8tLT09etW1dfX29padn16SCEPBrFqK5gVz5OT093dnZ2dnYeMWKEiYmJUqnU/KM47svJwcyZyM7GlClITcXkyZx1AohEInd39927d5ubm1dXV5eVlXHYDOEXilFdwcbor7/+mpWVBaChoaGqqgpASEjImjVr4uLiWltbNdpQejq8vFBS0nk0qh0PIhaJRDNmzAAXD3oi/EUxqitMTEwGDRrU0dEhkUg+//xzdo0PR0fHurq6yMhIf39/S0vLgICAAwcO1NfXq72bmBh4e6OqCoGBiI+HmZna99hr3D52lPAS14OzRBPKysrYG5lGjBhx6dKlrm/l5+d3W+NDtWZSbW2tWrqJjGT09RmAeeUVRvvm/8fGxgLw9vbmuhHCGxSjwpefn89Oth8/fvwjZpLfuHHj008/dXd3V+WpRCJZHhTEREYyd+8OWDdhYQzAAMymTQP2nQOqoqICgKmpaUdHB9e9EH6gGBW4jIwMdmqkq6trL1eQKykp2b17t7+/v76+/odubgzA6Okxc+Yw4eHMw1da6pXXXuv8tj17+vU9atZtoWtCHo1iVMiSkpLYWZDPPPNMH2aSV1RUFB84wCxaxBgYdB5CisWMpyezYwdTVPSYD5eXM+fPM7//zrS23i+GhTESCaPdC/Qxfy50vXfvXq4bIfxAMSpY3333HTvzcQBmkldXM/v3M1IpM3hwZ54CjKMjs3Urc+VK943z85n58xmAMTJiRCJmyBBm+3ZGdd96fn6/OtGIbgtdE/JoFKPCFB4ePlDrJD2gsZGJjWVWrWJMTR/I002bGHYVvupqZtw4xsODyc5mFAqmro7Zu5eRSJgtWwasB/VjF7qeNm0a140QfqAYFRqlUrlp0yYAIpHos88+U9dumpoYuZxZuZIxN+8MUz09pqKC2b6dkUiYkpIHNv7nPxkjI6aqSl3NDDR2oWs9PT3VQteEPIKIYRhNzq8iatXR0bF+/frIyEhDQ8N9+/a98MILat9lWxtOnkRUFGpqEBWFuXNhYoJjxx7YJjcXU6YgOhqBgWrvZ4BMnz794sWLZ86c8fT05LoXou1o+r1wNDY2Pvfcc5GRkSYmJjExMZrIUACGhvD1xTffICoKAG7dwl+f225nB5EIJSWa6GeAsEsQ0L1MpDcoRgWiqqpq4cKF8fHx1tbWp0+fZh/szgGRCApF96JCAYaBnh4XDfUR3ctEek+f6wbIACgsLPTx8bl+/bqdnV1CQgK7bDs3bG1RVNS9WFjY+RZ/UIyS3qOjUd7Lzs729PS8fv26k5NTamoqlxkKwNcXp0515qbKwYMYMgS8GmScPHmyubl5cXExLfVEHotilN9OnTrl6elZWlrq7e2dmpo6atQojhtavx62tli2DBcuoKMDtbX4v//D559jyxaYmnLc25MQiUTTp08HkJGRwXUvRNtRjPJYdHS0n5/fvXv3QkJC4uLiuj6vjTOmpjh1CsOGwc0NJiawsMCWLfj8c/zjH1x39sTovJ70Eo2N8tXOnTs3bNigVCpDQ0N37NjBTrbXCmPGIC4O1dW4eRNGRpg0iV8Xl1QoRkkv0bxR/mEYZtu2bdu2bROJRFu2bPnggw+47kiYKisrra2tTU1Na2trtej/UkT7UIzyjEKheP311/fs2aOvr79r1661a9dy3ZGQ2djYFBcX5+bmPvXUU1z3QrQX/T+WT5qampYsWbJnz57BgwfHxMRQhqobndeT3qAY5Y3q6upFixbFxcVZWlomJib6+flx3ZHwdX2cKiEPQ5eY+KGoqMjHx+fq1au2trbHjx93cHDguiOdwB6N0i2h5NFobJQHcnJyfH19S0pKpk6dGh8fP0Y7HqKpC5qamszMzEQiUW1trbGxMdftEC1FJ/U8cODAgZKSknnz5qWmplKGapKxsfHUqVPb29svXbrEdS9Ee1GM8sAnn3wSHh5+/PhxM216ELGOoKtM5LEoRnlALBZv2LBBIpFw3YguohXzyGNRjBLyKHQ0Sh6LLjER8ihKpdLCwqKurq68vNza2prrdog2oqNRQh5FLBbPmDEDdF5PHo5ilJDHYIdHN2zY8PXXX5eXl3PdDtE6dFJPyGMcPnw4KCiI/W+xWDxr1qyAgICQkJAJEyZw2xjREhSjhDxGcXGxjY2NWCwODg6Oj49vbGxk646OjlKpdPny5ZMnT+a2Q8ItilFCHkOpVBoYGCiVyhMnTsyePfvkyZMymezw4cP19fXsBo6OjgEBAf7+/h4eHty2SjhBMUrIo7S2tq5cufLQoUP6+vrnz593dnZm683NzcePH5fL5UePHq2trWWLDg4OwcHBy5YufdrFhbuWiaZRjBLyUA0NDcHBwSdOnDA2Nt69e/fKlSv/uo1CoUhLS5PJZL/88gt7Aeqr2bPfuHULgYEICMC8edCnBYAEjmKUkJ6Vl5f7+fmp7qbX09ObOXOmVCqVSqU9PjpQoVD8+uuvcrn8vby8MYmJndWRIxEUhOBgzJvH04epkMeiGCWkB/n5+T4+Pjdu3HBwcFi9evWpU6eSk5Pb29vx58X6kJCQ4OBgGxubnj+fkwOZDD/9hOvXOyuWlli8GFIpFi0C3dcrLBSjhHSXkZGxePHiO3fuuLm5xcXFWVlZAaitrT1x4sSRI0fkcnm3i/XLli176FNG2DyVyZCb21kxNoa3N6RSBAfDxEQTv4eoGcUoIQ9ISkoKDg6ur6/39/c/ePDgX5cZbW5uTkpKkslkMTExdXV1bPHxF+tzchAVBbkcv//eWTE2hp8fXnkFvr7q+jFEMxhCyJ++++47AwMDAC+99FJbW9ujN25qajp8+PCqVavMzc3Zf01DJJKOadOY995jMjIYpbLnjxUWMuHhzJw5jEjEAMzmzZ3Fl19mRo1iDA2Z0aOZV15hiooG+scRdaGjUUI6RUREvP3220qlMjQ0NDw8XCQS9fKDbW1tycnJcrncoaDgHydPdlZtbBAcjOBgzJ6NHp/PXFICuRyLFsHYGO7usLfHhg0YPx43buCLL1BaivPnMXbsAP04okYUo4QASmXY5s3/CgsTi8URERFvvPFGn78H585BJkNUFEpLO4tWVvD1hVQKHx8YGPTwqWXLkJWFrCwYGXVW6usxcSK8vfHjj33shGgQxSjReW1tePnlpqwsx4qKsP/93+XLlw/M1/byYn1bG8zMsGUL/vWvBz6+ZQu+/BK1tT0nL9EmFKNEt9XXIzgYSUkYMqQpNtbYy2vgd3HxIuRyREXh6tXOipkZFi9GSAiWLEFBASZNwi+/QCp94FM//ogVK1BQADu7gW+JDChaKI/osIoKzJuHpCSMGIHTp9WSoQBcXLB9O65cQX4+wsMxZw7q6vDjj/j73yESoaMDwP3TeRV2LlRbm1paIgOKblMjuqqwEM8+i7w82Nvj+HFMnKj2PbIXkTZsQH4+oqJgYACxGNbWEInuD6SqFBdDJMKIEWrvivQbndQTnXThAhYvRkUFZsxAXByGD+eyGScnODri4MEHikFBKCrCxYsc9USeAJ3UE92TnAxvb1RUYMECnDzJcYYCeO89HDqE77+/X/n2W8TEdL/oRLQVHY0SHRMVhZUr0dKCFSvw7bfach38o4/w3/+N0aMxcSKuX8ft2/jwQ7z7LtdtkV6hGCW65H/+Bxs3QqlEaCh27Oh5VjxXbt3CqVMoK8OoUfD2Rk+LSBHtRDFKdAPDYNs2bNsGkQiffIJNm7huiAgHxSjRDTU1cHVFcTG+/RYrVnDdDREUbTqpIeTRLl/GpEm4du2B4vvvo+t9RxUVePNNTJgAS0vY2mLdOhQXA4CFBRISEBdHGUoGHM0bJfzR0oK8PLS2PlAsL+8MSgAVFXB3x5Ah2LwZkyahsBAREXB1RVoa7O0xfjzGj9d810TwKEaJgLz/PurrcekSLCwAYM4cBAXBwQHvvAO5nOvmiGDRST0RCqUShw5hzZrODGUNHoy//x1Hj6K5mbvOiMDR0Sjhm507H5gwf+FC5w3plZWorYWDQ/ftHR3R3o6CAkyZorkmiS6hGCV8U16Olpb7LxsaOmOUXcXD1LT79myl24gqIQOHYpTwzfbt+K//uv9y7drOp8VZWUFPD7dudd+evQBFa3wQtaGxUSIUxsZwcUFcXPf60aOYMIFuCiLqQzFKBOTdd5GcjH377leioxEdTTenE7Wik3oiIEuX4qOP8Oqr+PhjODigoADXruHdd7F2LdedESGjm0EJf9TUIDERPj4wM7tfzMhAXR0WLLhfKS7GiRO4exfm5li4EPb2mu+U6BSKUUII6RcaGyWEkH6hGCWEkH6hGCWEkH6hGCWEkH6hGCWEkH6hGCWEkH75f0XDISGcnXRAAAABGnpUWHRyZGtpdFBLTCByZGtpdCAyMDI1LjAzLjYAAHice79v7T0GIBAAYiYGCOCF4gZGNoYEIM3IzMagAaSZWTggNBOMZnOAiLM5ZIBoZka8DKhaDLPAChgZuRkYGRiZNJgYmRWYWRRYWDOYWNkS2NgzmNg5Ejg4M5g4uRS4uDWYuHgUOFkSnBiBmthYODnY2VjFl4EcyQBzfd6f4gMPti7ZD+K0b9c5cMR3wj4QO+GEw4H766bbg9gTDi/avzjNDqxG5JzivrI9rXYg9vncj/tyDe+C1WyOUbF/91LPAcR+k8Pi8C9SEMw+UivhEPHYF6xmT+Eie8k2X7D5uZNP2QsXXwWbWTbfwaHKk+MAiN2g9sHuIJc2mC0GAK25Q1Mf5VwoAAABdHpUWHRNT0wgcmRraXQgMjAyNS4wMy42AAB4nH2TUW7DIAyG33MKX6DINgabx7appmlqIm3d7rD33V+zU3WkEhrEEZAPG347E0R7n9++f+Cv8TxNAPjP01qDr4yI0xViAKfLy+sC59vx9Fg5r5/L7QMox4PRn9njbb0+VgjOcMjJiNkYDpTYqqFvSbi1vpeD5FSbKTqJTpJJHpAZ1vCJ7jMiJLKCLANQAvSQSqXlcKmStYzIEsExUTGMOyWuxDiKXe+guEshj61sqDQA1UFMVdxNA06aM7INOHOOE9ZGYj7wsxKNuLZx2bhq9c+GwmUkI3l+/FxcG7a6yYioqCOSNrK4S1fPdapVi47UIXYhXXBsfo1IEnETKyMycuPyeHSRLZ3KJY/0uSzzU6HcS+e0LnMvnejc6yN67kXg30B6qsmt9Hz6BGrPmrhpz424WU+BuLWutLjRXlHaXrRTjuNFvFOItpW8U0JiV9lfeH+9mD/+Kh9PvzErr8LHNVvZAAAAvXpUWHRTTUlMRVMgcmRraXQgMjAyNS4wMy42AAB4nCWOyw0CUQhFW3GpCUP4w8vE1RRgEbZh8d6n7Dgc4F7X/fl6vN763qX/7va5H86jZkOHsk0NnYdxrWk6BEAnHMhZIDkp66QYCOzWXNvq8M4AE9YcUSdslpr4jwW8UKy2jTSdwhWYLTJu9y0ZSy1NANxU28DHkEV4JCzpxDcYv0giva8oJxTbsas6QZBRVjshv9qK2Z+ilkRsVG3p9Ph8AaOXNexrmcq5AAAAAElFTkSuQmCC", "text/plain": [ - "" + "" ] }, "metadata": {}, diff --git a/docs/tutorials/02_Getting_Started_rdkit_Core.ipynb b/docs/tutorials/02_Getting_Started_rdkit_Core.ipynb index 69acc82..9c030a8 100644 --- a/docs/tutorials/02_Getting_Started_rdkit_Core.ipynb +++ b/docs/tutorials/02_Getting_Started_rdkit_Core.ipynb @@ -59,10 +59,10 @@ "id": "ddcb2b72", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:34:48.089561Z", - "iopub.status.busy": "2026-08-08T20:34:48.089318Z", - "iopub.status.idle": "2026-08-08T20:34:48.407087Z", - "shell.execute_reply": "2026-08-08T20:34:48.406856Z" + "iopub.execute_input": "2026-08-09T13:01:13.695769Z", + "iopub.status.busy": "2026-08-09T13:01:13.695497Z", + "iopub.status.idle": "2026-08-09T13:01:14.000115Z", + "shell.execute_reply": "2026-08-09T13:01:13.999875Z" } }, "outputs": [ @@ -86,7 +86,12 @@ " text,\n", ")\n", "from sqlalchemy import Column, Table, MetaData\n", - "from molalchemy.rdkit import functions, index, types\n", + "from molalchemy.rdkit import (\n", + " RdkitIndex,\n", + " RdkitMol,\n", + " RdkitSparseFingerprint,\n", + " functions,\n", + ")\n", "from sqlalchemy.orm import sessionmaker\n", "\n", "eng = engine.create_engine(\n", @@ -115,8 +120,8 @@ "\n", "Now let's create a SQLAlchemy model to store molecular data. The model uses:\n", "\n", - "- `molalchemy.rdkit.types.RdkitMol` for storing molecular structures\n", - "- `molalchemy.rdkit.index.RdkitIndex` to create a GiST index for efficient chemical searches\n", + "- `molalchemy.rdkit.RdkitMol` for storing molecular structures\n", + "- `molalchemy.rdkit.RdkitIndex` to create a GiST index for efficient chemical searches\n", "- Standard SQLAlchemy columns for metadata like name and properties\n", "\n", "The GiST index on the `mol` column enables fast substructure and similarity searches." @@ -128,10 +133,10 @@ "id": "7c1d4286", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:34:48.408276Z", - "iopub.status.busy": "2026-08-08T20:34:48.408194Z", - "iopub.status.idle": "2026-08-08T20:34:48.427741Z", - "shell.execute_reply": "2026-08-08T20:34:48.427509Z" + "iopub.execute_input": "2026-08-09T13:01:14.001226Z", + "iopub.status.busy": "2026-08-09T13:01:14.001137Z", + "iopub.status.idle": "2026-08-09T13:01:14.020595Z", + "shell.execute_reply": "2026-08-09T13:01:14.020386Z" } }, "outputs": [], @@ -142,9 +147,9 @@ " metadata,\n", " Column(\"id\", Integer, primary_key=True, autoincrement=True),\n", " Column(\"name\", String(100), unique=True),\n", - " Column(\"mol\", types.RdkitMol),\n", + " Column(\"mol\", RdkitMol),\n", " Column(\"is_nsaid\", Boolean, default=False),\n", - " index.RdkitIndex(\"molalchemy_tutorial_rdkit_core_mol_gist_idx\", \"mol\"),\n", + " RdkitIndex(\"molalchemy_tutorial_rdkit_core_mol_gist_idx\", \"mol\"),\n", ")\n", "\n", "molecule_table.drop(eng, checkfirst=True)\n", @@ -175,10 +180,10 @@ "id": "9b32959c", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:34:48.428861Z", - "iopub.status.busy": "2026-08-08T20:34:48.428798Z", - "iopub.status.idle": "2026-08-08T20:34:48.446672Z", - "shell.execute_reply": "2026-08-08T20:34:48.446455Z" + "iopub.execute_input": "2026-08-09T13:01:14.021489Z", + "iopub.status.busy": "2026-08-09T13:01:14.021422Z", + "iopub.status.idle": "2026-08-09T13:01:14.032615Z", + "shell.execute_reply": "2026-08-09T13:01:14.032425Z" } }, "outputs": [], @@ -227,10 +232,10 @@ "id": "a5b2666e", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:34:48.447666Z", - "iopub.status.busy": "2026-08-08T20:34:48.447593Z", - "iopub.status.idle": "2026-08-08T20:34:48.455256Z", - "shell.execute_reply": "2026-08-08T20:34:48.455049Z" + "iopub.execute_input": "2026-08-09T13:01:14.033523Z", + "iopub.status.busy": "2026-08-09T13:01:14.033460Z", + "iopub.status.idle": "2026-08-09T13:01:14.042251Z", + "shell.execute_reply": "2026-08-09T13:01:14.042037Z" } }, "outputs": [ @@ -268,10 +273,10 @@ "id": "8f356747", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:34:48.456241Z", - "iopub.status.busy": "2026-08-08T20:34:48.456177Z", - "iopub.status.idle": "2026-08-08T20:34:48.459042Z", - "shell.execute_reply": "2026-08-08T20:34:48.458850Z" + "iopub.execute_input": "2026-08-09T13:01:14.043145Z", + "iopub.status.busy": "2026-08-09T13:01:14.043084Z", + "iopub.status.idle": "2026-08-09T13:01:14.045924Z", + "shell.execute_reply": "2026-08-09T13:01:14.045721Z" } }, "outputs": [ @@ -308,10 +313,10 @@ "id": "024ffa61", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:34:48.459989Z", - "iopub.status.busy": "2026-08-08T20:34:48.459929Z", - "iopub.status.idle": "2026-08-08T20:34:48.462729Z", - "shell.execute_reply": "2026-08-08T20:34:48.462538Z" + "iopub.execute_input": "2026-08-09T13:01:14.046749Z", + "iopub.status.busy": "2026-08-09T13:01:14.046690Z", + "iopub.status.idle": "2026-08-09T13:01:14.049423Z", + "shell.execute_reply": "2026-08-09T13:01:14.049222Z" } }, "outputs": [ @@ -346,7 +351,7 @@ "### Enhanced Model with Fingerprints\n", "\n", "This model adds:\n", - "- A `molalchemy.rdkit.types.RdkitSparseFingerprint` column for storing Morgan fingerprints\n", + "- A `molalchemy.rdkit.RdkitSparseFingerprint` column for storing Morgan fingerprints\n", "- A computed column that automatically generates fingerprints using `molalchemy.rdkit.functions.mol.morgan_fp()`\n", "- Additional GiST indexes for efficient fingerprint operations\n", "\n", @@ -359,10 +364,10 @@ "id": "f5617b86", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:34:48.463700Z", - "iopub.status.busy": "2026-08-08T20:34:48.463638Z", - "iopub.status.idle": "2026-08-08T20:34:48.475511Z", - "shell.execute_reply": "2026-08-08T20:34:48.475265Z" + "iopub.execute_input": "2026-08-09T13:01:14.050271Z", + "iopub.status.busy": "2026-08-09T13:01:14.050208Z", + "iopub.status.idle": "2026-08-09T13:01:14.060073Z", + "shell.execute_reply": "2026-08-09T13:01:14.059879Z" } }, "outputs": [], @@ -376,20 +381,20 @@ " metadata,\n", " Column(\"id\", Integer, primary_key=True, autoincrement=True),\n", " Column(\"name\", String(100), unique=True),\n", - " Column(\"mol\", types.RdkitMol),\n", + " Column(\"mol\", RdkitMol),\n", " Column(\"is_nsaid\", Boolean, default=False),\n", - " index.RdkitIndex(\"molalchemy_tutorial_rdkit_core_mol_gist_idx_2\", \"mol\"),\n", + " RdkitIndex(\"molalchemy_tutorial_rdkit_core_mol_gist_idx_2\", \"mol\"),\n", ")\n", "molecules_fp.append_column(\n", " Column(\n", " \"fp\",\n", - " types.RdkitSparseFingerprint,\n", + " RdkitSparseFingerprint,\n", " Computed(functions.morgan_fp(molecules_fp.c.mol, 2), persisted=True),\n", " )\n", ")\n", "\n", "molecules_fp.append_constraint(\n", - " index.RdkitIndex(\"molalchemy_tutorial_rdkit_core_fp_idx_2\", \"fp\")\n", + " RdkitIndex(\"molalchemy_tutorial_rdkit_core_fp_idx_2\", \"fp\")\n", ")\n", "\n", "molecules_fp.drop(eng, checkfirst=True)\n", @@ -412,10 +417,10 @@ "id": "5e2c36e8", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:34:48.476420Z", - "iopub.status.busy": "2026-08-08T20:34:48.476361Z", - "iopub.status.idle": "2026-08-08T20:34:48.482483Z", - "shell.execute_reply": "2026-08-08T20:34:48.482284Z" + "iopub.execute_input": "2026-08-09T13:01:14.060910Z", + "iopub.status.busy": "2026-08-09T13:01:14.060845Z", + "iopub.status.idle": "2026-08-09T13:01:14.066441Z", + "shell.execute_reply": "2026-08-09T13:01:14.066250Z" } }, "outputs": [], @@ -431,10 +436,10 @@ "id": "45e6718a", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:34:48.483387Z", - "iopub.status.busy": "2026-08-08T20:34:48.483320Z", - "iopub.status.idle": "2026-08-08T20:34:48.486743Z", - "shell.execute_reply": "2026-08-08T20:34:48.486550Z" + "iopub.execute_input": "2026-08-09T13:01:14.067335Z", + "iopub.status.busy": "2026-08-09T13:01:14.067276Z", + "iopub.status.idle": "2026-08-09T13:01:14.070721Z", + "shell.execute_reply": "2026-08-09T13:01:14.070526Z" } }, "outputs": [ @@ -484,10 +489,10 @@ "id": "9447c97a", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:34:48.487843Z", - "iopub.status.busy": "2026-08-08T20:34:48.487776Z", - "iopub.status.idle": "2026-08-08T20:34:48.492028Z", - "shell.execute_reply": "2026-08-08T20:34:48.491838Z" + "iopub.execute_input": "2026-08-09T13:01:14.071645Z", + "iopub.status.busy": "2026-08-09T13:01:14.071571Z", + "iopub.status.idle": "2026-08-09T13:01:14.075303Z", + "shell.execute_reply": "2026-08-09T13:01:14.075102Z" } }, "outputs": [ @@ -529,10 +534,10 @@ "id": "32703967", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:34:48.492963Z", - "iopub.status.busy": "2026-08-08T20:34:48.492905Z", - "iopub.status.idle": "2026-08-08T20:34:48.494454Z", - "shell.execute_reply": "2026-08-08T20:34:48.494257Z" + "iopub.execute_input": "2026-08-09T13:01:14.076239Z", + "iopub.status.busy": "2026-08-09T13:01:14.076170Z", + "iopub.status.idle": "2026-08-09T13:01:14.077920Z", + "shell.execute_reply": "2026-08-09T13:01:14.077647Z" } }, "outputs": [ @@ -576,10 +581,10 @@ "id": "68a51b79", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:34:48.495329Z", - "iopub.status.busy": "2026-08-08T20:34:48.495272Z", - "iopub.status.idle": "2026-08-08T20:34:48.509448Z", - "shell.execute_reply": "2026-08-08T20:34:48.509188Z" + "iopub.execute_input": "2026-08-09T13:01:14.078816Z", + "iopub.status.busy": "2026-08-09T13:01:14.078747Z", + "iopub.status.idle": "2026-08-09T13:01:14.089089Z", + "shell.execute_reply": "2026-08-09T13:01:14.088857Z" } }, "outputs": [], @@ -590,14 +595,14 @@ " metadata,\n", " Column(\"id\", Integer, primary_key=True, autoincrement=True),\n", " Column(\"name\", String(100), unique=True),\n", - " Column(\"mol\", types.RdkitMol(return_type=\"bytes\")),\n", + " Column(\"mol\", RdkitMol(return_type=\"bytes\")),\n", " Column(\"is_nsaid\", Boolean, default=False),\n", - " index.RdkitIndex(\"molalchemy_tutorial_rdkit_core_mol_gist_idx_3\", \"mol\"),\n", + " RdkitIndex(\"molalchemy_tutorial_rdkit_core_mol_gist_idx_3\", \"mol\"),\n", ")\n", "molecules_fp_raw.append_column(\n", " Column(\n", " \"fp\",\n", - " types.RdkitSparseFingerprint,\n", + " RdkitSparseFingerprint,\n", " Computed(functions.morgan_fp(molecules_fp_raw.c.mol, 2), persisted=True),\n", " )\n", ")\n", @@ -622,10 +627,10 @@ "id": "be9e0616", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:34:48.510799Z", - "iopub.status.busy": "2026-08-08T20:34:48.510727Z", - "iopub.status.idle": "2026-08-08T20:34:48.521464Z", - "shell.execute_reply": "2026-08-08T20:34:48.521210Z" + "iopub.execute_input": "2026-08-09T13:01:14.090039Z", + "iopub.status.busy": "2026-08-09T13:01:14.089969Z", + "iopub.status.idle": "2026-08-09T13:01:14.096471Z", + "shell.execute_reply": "2026-08-09T13:01:14.096236Z" } }, "outputs": [], @@ -641,10 +646,10 @@ "id": "e5ce3158", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:34:48.522626Z", - "iopub.status.busy": "2026-08-08T20:34:48.522553Z", - "iopub.status.idle": "2026-08-08T20:34:48.525334Z", - "shell.execute_reply": "2026-08-08T20:34:48.525137Z" + "iopub.execute_input": "2026-08-09T13:01:14.097433Z", + "iopub.status.busy": "2026-08-09T13:01:14.097365Z", + "iopub.status.idle": "2026-08-09T13:01:14.100022Z", + "shell.execute_reply": "2026-08-09T13:01:14.099809Z" } }, "outputs": [ diff --git a/docs/tutorials/03_alembic_migrations.md b/docs/tutorials/03_alembic_migrations.md index f67b1ad..3ca1882 100644 --- a/docs/tutorials/03_alembic_migrations.md +++ b/docs/tutorials/03_alembic_migrations.md @@ -5,7 +5,7 @@ The [Alembic](https://alembic.sqlalchemy.org/en/latest/) library is a lightweigh Having model defined like this: ```python -from molalchemy.rdkit import index, types +from molalchemy.rdkit import RdkitIndex, RdkitMol import sqlalchemy as sa from sqlalchemy.orm import ( DeclarativeBase, @@ -19,10 +19,10 @@ class Base(MappedAsDataclass, DeclarativeBase): class Molecule(Base): __tablename__ = "molecules" __table_args__ = ( - index.RdkitIndex("idx_molecules_mol", "mol"), + RdkitIndex("idx_molecules_mol", "mol"), ) id: Mapped[int] = mapped_column(sa.Integer, primary_key=True) - mol: Mapped[bytes] = mapped_column(types.RdkitMol(return_type="bytes")) + mol: Mapped[bytes] = mapped_column(RdkitMol(return_type="bytes")) ``` @@ -95,4 +95,4 @@ def run_migrations_online(): # ... ``` -This will ensure that when Alembic generates migration scripts, it will include the necessary import statements for `molalchemy` types, allowing the migrations to run without import errors. \ No newline at end of file +This will ensure that when Alembic generates migration scripts, it will include the necessary import statements for `molalchemy` types, allowing the migrations to run without import errors. diff --git a/docs/tutorials/04_Similarity_Threshold_Settings.ipynb b/docs/tutorials/04_Similarity_Threshold_Settings.ipynb index 321550e..6c14049 100644 --- a/docs/tutorials/04_Similarity_Threshold_Settings.ipynb +++ b/docs/tutorials/04_Similarity_Threshold_Settings.ipynb @@ -47,10 +47,10 @@ "execution_count": 1, "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:35:03.783671Z", - "iopub.status.busy": "2026-08-08T20:35:03.783429Z", - "iopub.status.idle": "2026-08-08T20:35:04.215152Z", - "shell.execute_reply": "2026-08-08T20:35:04.214850Z" + "iopub.execute_input": "2026-08-09T13:01:14.616101Z", + "iopub.status.busy": "2026-08-09T13:01:14.615891Z", + "iopub.status.idle": "2026-08-09T13:01:14.921386Z", + "shell.execute_reply": "2026-08-09T13:01:14.921137Z" } }, "outputs": [], @@ -74,10 +74,13 @@ " sessionmaker,\n", ")\n", "\n", - "from molalchemy.rdkit import functions, index, types\n", - "from molalchemy.rdkit.settings import (\n", + "from molalchemy.rdkit import (\n", + " RdkitIndex,\n", + " RdkitMol,\n", " RdkitSettings,\n", + " RdkitSparseFingerprint,\n", " configure_engine,\n", + " functions,\n", " get_dice_threshold,\n", " get_tanimoto_threshold,\n", " set_dice_threshold,\n", @@ -114,10 +117,10 @@ "execution_count": 2, "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:35:04.216408Z", - "iopub.status.busy": "2026-08-08T20:35:04.216303Z", - "iopub.status.idle": "2026-08-08T20:35:04.241065Z", - "shell.execute_reply": "2026-08-08T20:35:04.240760Z" + "iopub.execute_input": "2026-08-09T13:01:14.922538Z", + "iopub.status.busy": "2026-08-09T13:01:14.922440Z", + "iopub.status.idle": "2026-08-09T13:01:14.943221Z", + "shell.execute_reply": "2026-08-09T13:01:14.943013Z" } }, "outputs": [], @@ -129,16 +132,16 @@ "class MoleculeFP(Base):\n", " __tablename__ = \"molalchemy_tutorial_molecules_fp\"\n", " __table_args__ = (\n", - " index.RdkitIndex(\"molalchemy_tutorial_rdkit_settings_mol_gist_idx_2\", \"mol\"),\n", - " index.RdkitIndex(\"molalchemy_tutorial_rdkit_settings_fp_gist_idx_2\", \"fp\"),\n", + " RdkitIndex(\"molalchemy_tutorial_rdkit_settings_mol_gist_idx_2\", \"mol\"),\n", + " RdkitIndex(\"molalchemy_tutorial_rdkit_settings_fp_gist_idx_2\", \"fp\"),\n", " )\n", " id: Mapped[int] = mapped_column(\n", " Integer, primary_key=True, autoincrement=True, init=False\n", " )\n", " name: Mapped[str] = mapped_column(String(100), unique=True)\n", - " mol: Mapped[bytes] = mapped_column(types.RdkitMol)\n", + " mol: Mapped[bytes] = mapped_column(RdkitMol)\n", " fp: Mapped[bytes] = mapped_column(\n", - " types.RdkitSparseFingerprint,\n", + " RdkitSparseFingerprint,\n", " Computed(functions.morgan_fp(mol, 2), persisted=True),\n", " init=False,\n", " )\n", @@ -154,10 +157,10 @@ "execution_count": 3, "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:35:04.242116Z", - "iopub.status.busy": "2026-08-08T20:35:04.242047Z", - "iopub.status.idle": "2026-08-08T20:35:04.260658Z", - "shell.execute_reply": "2026-08-08T20:35:04.260456Z" + "iopub.execute_input": "2026-08-09T13:01:14.944184Z", + "iopub.status.busy": "2026-08-09T13:01:14.944112Z", + "iopub.status.idle": "2026-08-09T13:01:14.961729Z", + "shell.execute_reply": "2026-08-09T13:01:14.961505Z" } }, "outputs": [], @@ -208,10 +211,10 @@ "execution_count": 4, "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:35:04.261660Z", - "iopub.status.busy": "2026-08-08T20:35:04.261595Z", - "iopub.status.idle": "2026-08-08T20:35:04.264002Z", - "shell.execute_reply": "2026-08-08T20:35:04.263835Z" + "iopub.execute_input": "2026-08-09T13:01:14.962625Z", + "iopub.status.busy": "2026-08-09T13:01:14.962558Z", + "iopub.status.idle": "2026-08-09T13:01:14.964929Z", + "shell.execute_reply": "2026-08-09T13:01:14.964742Z" } }, "outputs": [ @@ -245,10 +248,10 @@ "execution_count": 5, "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:35:04.277409Z", - "iopub.status.busy": "2026-08-08T20:35:04.277313Z", - "iopub.status.idle": "2026-08-08T20:35:04.284304Z", - "shell.execute_reply": "2026-08-08T20:35:04.284084Z" + "iopub.execute_input": "2026-08-09T13:01:14.965789Z", + "iopub.status.busy": "2026-08-09T13:01:14.965718Z", + "iopub.status.idle": "2026-08-09T13:01:14.969890Z", + "shell.execute_reply": "2026-08-09T13:01:14.969707Z" } }, "outputs": [ @@ -296,10 +299,10 @@ "execution_count": 6, "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:35:04.285293Z", - "iopub.status.busy": "2026-08-08T20:35:04.285230Z", - "iopub.status.idle": "2026-08-08T20:35:04.289548Z", - "shell.execute_reply": "2026-08-08T20:35:04.289354Z" + "iopub.execute_input": "2026-08-09T13:01:14.970726Z", + "iopub.status.busy": "2026-08-09T13:01:14.970664Z", + "iopub.status.idle": "2026-08-09T13:01:14.974020Z", + "shell.execute_reply": "2026-08-09T13:01:14.973836Z" } }, "outputs": [ @@ -344,10 +347,10 @@ "execution_count": 7, "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:35:04.290501Z", - "iopub.status.busy": "2026-08-08T20:35:04.290439Z", - "iopub.status.idle": "2026-08-08T20:35:04.293857Z", - "shell.execute_reply": "2026-08-08T20:35:04.293662Z" + "iopub.execute_input": "2026-08-09T13:01:14.974853Z", + "iopub.status.busy": "2026-08-09T13:01:14.974785Z", + "iopub.status.idle": "2026-08-09T13:01:14.977947Z", + "shell.execute_reply": "2026-08-09T13:01:14.977758Z" } }, "outputs": [ @@ -392,10 +395,10 @@ "execution_count": 8, "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:35:04.294812Z", - "iopub.status.busy": "2026-08-08T20:35:04.294746Z", - "iopub.status.idle": "2026-08-08T20:35:04.300303Z", - "shell.execute_reply": "2026-08-08T20:35:04.300112Z" + "iopub.execute_input": "2026-08-09T13:01:14.978775Z", + "iopub.status.busy": "2026-08-09T13:01:14.978711Z", + "iopub.status.idle": "2026-08-09T13:01:14.982715Z", + "shell.execute_reply": "2026-08-09T13:01:14.982522Z" } }, "outputs": [ @@ -438,10 +441,10 @@ "execution_count": 9, "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:35:04.301216Z", - "iopub.status.busy": "2026-08-08T20:35:04.301153Z", - "iopub.status.idle": "2026-08-08T20:35:04.304901Z", - "shell.execute_reply": "2026-08-08T20:35:04.304689Z" + "iopub.execute_input": "2026-08-09T13:01:14.983519Z", + "iopub.status.busy": "2026-08-09T13:01:14.983452Z", + "iopub.status.idle": "2026-08-09T13:01:14.987289Z", + "shell.execute_reply": "2026-08-09T13:01:14.987096Z" } }, "outputs": [ @@ -479,10 +482,10 @@ "execution_count": 10, "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:35:04.305847Z", - "iopub.status.busy": "2026-08-08T20:35:04.305768Z", - "iopub.status.idle": "2026-08-08T20:35:04.310687Z", - "shell.execute_reply": "2026-08-08T20:35:04.310492Z" + "iopub.execute_input": "2026-08-09T13:01:14.988093Z", + "iopub.status.busy": "2026-08-09T13:01:14.988033Z", + "iopub.status.idle": "2026-08-09T13:01:14.992745Z", + "shell.execute_reply": "2026-08-09T13:01:14.992552Z" } }, "outputs": [ @@ -532,10 +535,10 @@ "execution_count": 11, "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:35:04.311630Z", - "iopub.status.busy": "2026-08-08T20:35:04.311568Z", - "iopub.status.idle": "2026-08-08T20:35:04.313060Z", - "shell.execute_reply": "2026-08-08T20:35:04.312868Z" + "iopub.execute_input": "2026-08-09T13:01:14.993532Z", + "iopub.status.busy": "2026-08-09T13:01:14.993470Z", + "iopub.status.idle": "2026-08-09T13:01:14.995011Z", + "shell.execute_reply": "2026-08-09T13:01:14.994803Z" } }, "outputs": [ diff --git a/docs/tutorials/05_Reactions_rdkit_ORM.ipynb b/docs/tutorials/05_Reactions_rdkit_ORM.ipynb index d148c79..0342226 100644 --- a/docs/tutorials/05_Reactions_rdkit_ORM.ipynb +++ b/docs/tutorials/05_Reactions_rdkit_ORM.ipynb @@ -51,10 +51,10 @@ "id": "cell-2", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:35:17.990179Z", - "iopub.status.busy": "2026-08-08T20:35:17.989972Z", - "iopub.status.idle": "2026-08-08T20:35:18.300447Z", - "shell.execute_reply": "2026-08-08T20:35:18.300200Z" + "iopub.execute_input": "2026-08-09T13:01:15.528444Z", + "iopub.status.busy": "2026-08-09T13:01:15.528230Z", + "iopub.status.idle": "2026-08-09T13:01:15.835365Z", + "shell.execute_reply": "2026-08-09T13:01:15.835107Z" } }, "outputs": [ @@ -84,7 +84,7 @@ " sessionmaker,\n", ")\n", "\n", - "from molalchemy.rdkit import functions, types\n", + "from molalchemy.rdkit import RdkitReaction, functions\n", "\n", "eng = engine.create_engine(\n", " os.environ.get(\n", @@ -112,7 +112,7 @@ "\n", "Let's create a SQLAlchemy model to store chemical reactions. The model uses:\n", "\n", - "- `molalchemy.rdkit.types.RdkitReaction` for storing reaction data\n", + "- `molalchemy.rdkit.RdkitReaction` for storing reaction data\n", "- Standard SQLAlchemy columns for metadata like name and reaction class\n", "\n", "The `RdkitReaction` type maps to the PostgreSQL `reaction` type provided by the RDKit cartridge. It accepts reaction SMILES/SMARTS strings and `ChemicalReaction` objects as input, validating them before sending to the database." @@ -124,10 +124,10 @@ "id": "cell-4", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:35:18.301599Z", - "iopub.status.busy": "2026-08-08T20:35:18.301520Z", - "iopub.status.idle": "2026-08-08T20:35:18.321547Z", - "shell.execute_reply": "2026-08-08T20:35:18.321292Z" + "iopub.execute_input": "2026-08-09T13:01:15.836422Z", + "iopub.status.busy": "2026-08-09T13:01:15.836331Z", + "iopub.status.idle": "2026-08-09T13:01:15.850637Z", + "shell.execute_reply": "2026-08-09T13:01:15.850419Z" } }, "outputs": [], @@ -143,7 +143,7 @@ " )\n", " name: Mapped[str] = mapped_column(String(100), unique=True)\n", " rxn_class: Mapped[str] = mapped_column(String(100))\n", - " rxn: Mapped[str] = mapped_column(types.RdkitReaction())\n", + " rxn: Mapped[str] = mapped_column(RdkitReaction())\n", "\n", "\n", "Reaction.__table__.drop(eng, checkfirst=True)\n", @@ -177,10 +177,10 @@ "id": "cell-6", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:35:18.322620Z", - "iopub.status.busy": "2026-08-08T20:35:18.322555Z", - "iopub.status.idle": "2026-08-08T20:35:18.331319Z", - "shell.execute_reply": "2026-08-08T20:35:18.331094Z" + "iopub.execute_input": "2026-08-09T13:01:15.851573Z", + "iopub.status.busy": "2026-08-09T13:01:15.851505Z", + "iopub.status.idle": "2026-08-09T13:01:15.859516Z", + "shell.execute_reply": "2026-08-09T13:01:15.859320Z" } }, "outputs": [], @@ -234,10 +234,10 @@ "id": "cell-8", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:35:18.332302Z", - "iopub.status.busy": "2026-08-08T20:35:18.332242Z", - "iopub.status.idle": "2026-08-08T20:35:18.342670Z", - "shell.execute_reply": "2026-08-08T20:35:18.342463Z" + "iopub.execute_input": "2026-08-09T13:01:15.860411Z", + "iopub.status.busy": "2026-08-09T13:01:15.860335Z", + "iopub.status.idle": "2026-08-09T13:01:15.869308Z", + "shell.execute_reply": "2026-08-09T13:01:15.869106Z" } }, "outputs": [], @@ -256,10 +256,10 @@ "id": "cell-9", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:35:18.343584Z", - "iopub.status.busy": "2026-08-08T20:35:18.343515Z", - "iopub.status.idle": "2026-08-08T20:35:18.353139Z", - "shell.execute_reply": "2026-08-08T20:35:18.352958Z" + "iopub.execute_input": "2026-08-09T13:01:15.870159Z", + "iopub.status.busy": "2026-08-09T13:01:15.870097Z", + "iopub.status.idle": "2026-08-09T13:01:15.879581Z", + "shell.execute_reply": "2026-08-09T13:01:15.879396Z" } }, "outputs": [ @@ -299,10 +299,10 @@ "id": "cell-11", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:35:18.354102Z", - "iopub.status.busy": "2026-08-08T20:35:18.354026Z", - "iopub.status.idle": "2026-08-08T20:35:18.357302Z", - "shell.execute_reply": "2026-08-08T20:35:18.357097Z" + "iopub.execute_input": "2026-08-09T13:01:15.880468Z", + "iopub.status.busy": "2026-08-09T13:01:15.880403Z", + "iopub.status.idle": "2026-08-09T13:01:15.883012Z", + "shell.execute_reply": "2026-08-09T13:01:15.882799Z" } }, "outputs": [ @@ -312,18 +312,18 @@ "text": [ "Error adding invalid reaction: (molalchemy.exceptions.InvalidReactionError) Invalid reaction SMARTS string: 'not_a_>>reaction'\n", "[SQL: INSERT INTO molalchemy_tutorial_reactions (name, rxn_class, rxn) VALUES (%(name)s::VARCHAR, %(rxn_class)s::VARCHAR, reaction_from_smarts(%(rxn)s)) RETURNING molalchemy_tutorial_reactions.id]\n", - "[parameters: [{'name': 'Bad', 'rxn': 'not_a_>>reaction', 'rxn_class': 'Invalid>>BAD'}]]\n" + "[parameters: [{'rxn_class': 'Invalid>>BAD', 'name': 'Bad', 'rxn': 'not_a_>>reaction'}]]\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ - "[22:35:18] SMARTS Parse Error: syntax error while parsing: not_a_\n", - "[22:35:18] SMARTS Parse Error: check for mistakes around position 3:\n", - "[22:35:18] not_a_\n", - "[22:35:18] ~~^\n", - "[22:35:18] SMARTS Parse Error: Failed parsing SMARTS 'not_a_' for input: 'not_a_'\n" + "[15:01:15] SMARTS Parse Error: syntax error while parsing: not_a_\n", + "[15:01:15] SMARTS Parse Error: check for mistakes around position 3:\n", + "[15:01:15] not_a_\n", + "[15:01:15] ~~^\n", + "[15:01:15] SMARTS Parse Error: Failed parsing SMARTS 'not_a_' for input: 'not_a_'\n" ] } ], @@ -355,10 +355,10 @@ "id": "cell-13", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:35:18.358247Z", - "iopub.status.busy": "2026-08-08T20:35:18.358184Z", - "iopub.status.idle": "2026-08-08T20:35:18.361277Z", - "shell.execute_reply": "2026-08-08T20:35:18.361100Z" + "iopub.execute_input": "2026-08-09T13:01:15.883836Z", + "iopub.status.busy": "2026-08-09T13:01:15.883773Z", + "iopub.status.idle": "2026-08-09T13:01:15.886730Z", + "shell.execute_reply": "2026-08-09T13:01:15.886541Z" } }, "outputs": [ @@ -396,10 +396,10 @@ "id": "cell-15", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:35:18.362198Z", - "iopub.status.busy": "2026-08-08T20:35:18.362139Z", - "iopub.status.idle": "2026-08-08T20:35:18.365675Z", - "shell.execute_reply": "2026-08-08T20:35:18.365492Z" + "iopub.execute_input": "2026-08-09T13:01:15.887588Z", + "iopub.status.busy": "2026-08-09T13:01:15.887520Z", + "iopub.status.idle": "2026-08-09T13:01:15.890785Z", + "shell.execute_reply": "2026-08-09T13:01:15.890584Z" } }, "outputs": [ @@ -435,10 +435,10 @@ "id": "cell-17", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:35:18.366604Z", - "iopub.status.busy": "2026-08-08T20:35:18.366547Z", - "iopub.status.idle": "2026-08-08T20:35:18.370461Z", - "shell.execute_reply": "2026-08-08T20:35:18.370277Z" + "iopub.execute_input": "2026-08-09T13:01:15.891632Z", + "iopub.status.busy": "2026-08-09T13:01:15.891570Z", + "iopub.status.idle": "2026-08-09T13:01:15.894411Z", + "shell.execute_reply": "2026-08-09T13:01:15.894207Z" } }, "outputs": [ @@ -474,10 +474,10 @@ "id": "0d7cc4b1", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:35:18.371332Z", - "iopub.status.busy": "2026-08-08T20:35:18.371274Z", - "iopub.status.idle": "2026-08-08T20:35:18.374515Z", - "shell.execute_reply": "2026-08-08T20:35:18.374318Z" + "iopub.execute_input": "2026-08-09T13:01:15.895294Z", + "iopub.status.busy": "2026-08-09T13:01:15.895230Z", + "iopub.status.idle": "2026-08-09T13:01:15.898119Z", + "shell.execute_reply": "2026-08-09T13:01:15.897925Z" } }, "outputs": [ @@ -504,10 +504,10 @@ "id": "92b27581", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:35:18.375381Z", - "iopub.status.busy": "2026-08-08T20:35:18.375319Z", - "iopub.status.idle": "2026-08-08T20:35:18.378245Z", - "shell.execute_reply": "2026-08-08T20:35:18.378052Z" + "iopub.execute_input": "2026-08-09T13:01:15.898943Z", + "iopub.status.busy": "2026-08-09T13:01:15.898879Z", + "iopub.status.idle": "2026-08-09T13:01:15.901908Z", + "shell.execute_reply": "2026-08-09T13:01:15.901717Z" } }, "outputs": [ @@ -542,10 +542,10 @@ "id": "ef470eef", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:35:18.379185Z", - "iopub.status.busy": "2026-08-08T20:35:18.379126Z", - "iopub.status.idle": "2026-08-08T20:35:18.382678Z", - "shell.execute_reply": "2026-08-08T20:35:18.382518Z" + "iopub.execute_input": "2026-08-09T13:01:15.902795Z", + "iopub.status.busy": "2026-08-09T13:01:15.902715Z", + "iopub.status.idle": "2026-08-09T13:01:15.906379Z", + "shell.execute_reply": "2026-08-09T13:01:15.906203Z" } }, "outputs": [ @@ -580,10 +580,10 @@ "id": "926e778d", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:35:18.383566Z", - "iopub.status.busy": "2026-08-08T20:35:18.383509Z", - "iopub.status.idle": "2026-08-08T20:35:18.386188Z", - "shell.execute_reply": "2026-08-08T20:35:18.386018Z" + "iopub.execute_input": "2026-08-09T13:01:15.907300Z", + "iopub.status.busy": "2026-08-09T13:01:15.907232Z", + "iopub.status.idle": "2026-08-09T13:01:15.911245Z", + "shell.execute_reply": "2026-08-09T13:01:15.911059Z" } }, "outputs": [ @@ -623,10 +623,10 @@ "id": "6ab91663", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:35:18.387179Z", - "iopub.status.busy": "2026-08-08T20:35:18.387118Z", - "iopub.status.idle": "2026-08-08T20:35:18.389950Z", - "shell.execute_reply": "2026-08-08T20:35:18.389779Z" + "iopub.execute_input": "2026-08-09T13:01:15.912104Z", + "iopub.status.busy": "2026-08-09T13:01:15.912043Z", + "iopub.status.idle": "2026-08-09T13:01:15.914821Z", + "shell.execute_reply": "2026-08-09T13:01:15.914627Z" } }, "outputs": [ @@ -666,10 +666,10 @@ "id": "cell-19", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:35:18.390937Z", - "iopub.status.busy": "2026-08-08T20:35:18.390881Z", - "iopub.status.idle": "2026-08-08T20:35:18.394688Z", - "shell.execute_reply": "2026-08-08T20:35:18.394540Z" + "iopub.execute_input": "2026-08-09T13:01:15.915599Z", + "iopub.status.busy": "2026-08-09T13:01:15.915539Z", + "iopub.status.idle": "2026-08-09T13:01:15.919261Z", + "shell.execute_reply": "2026-08-09T13:01:15.919063Z" } }, "outputs": [ @@ -716,10 +716,10 @@ "id": "cell-21", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:35:18.395650Z", - "iopub.status.busy": "2026-08-08T20:35:18.395595Z", - "iopub.status.idle": "2026-08-08T20:35:18.399650Z", - "shell.execute_reply": "2026-08-08T20:35:18.399405Z" + "iopub.execute_input": "2026-08-09T13:01:15.920071Z", + "iopub.status.busy": "2026-08-09T13:01:15.920009Z", + "iopub.status.idle": "2026-08-09T13:01:15.923130Z", + "shell.execute_reply": "2026-08-09T13:01:15.922931Z" } }, "outputs": [ @@ -770,10 +770,10 @@ "id": "cell-23", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:35:18.400530Z", - "iopub.status.busy": "2026-08-08T20:35:18.400475Z", - "iopub.status.idle": "2026-08-08T20:35:18.419582Z", - "shell.execute_reply": "2026-08-08T20:35:18.419372Z" + "iopub.execute_input": "2026-08-09T13:01:15.923954Z", + "iopub.status.busy": "2026-08-09T13:01:15.923881Z", + "iopub.status.idle": "2026-08-09T13:01:15.939757Z", + "shell.execute_reply": "2026-08-09T13:01:15.939568Z" } }, "outputs": [], @@ -789,7 +789,7 @@ " )\n", " name: Mapped[str] = mapped_column(String(100), unique=True)\n", " rxn: Mapped[AllChem.ChemicalReaction] = mapped_column(\n", - " types.RdkitReaction(return_type=\"mol\")\n", + " RdkitReaction(return_type=\"mol\")\n", " )\n", "\n", "\n", @@ -803,10 +803,10 @@ "id": "cell-24", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:35:18.420579Z", - "iopub.status.busy": "2026-08-08T20:35:18.420518Z", - "iopub.status.idle": "2026-08-08T20:35:18.432503Z", - "shell.execute_reply": "2026-08-08T20:35:18.432306Z" + "iopub.execute_input": "2026-08-09T13:01:15.940588Z", + "iopub.status.busy": "2026-08-09T13:01:15.940527Z", + "iopub.status.idle": "2026-08-09T13:01:15.951033Z", + "shell.execute_reply": "2026-08-09T13:01:15.950843Z" } }, "outputs": [ @@ -823,11 +823,11 @@ "name": "stderr", "output_type": "stream", "text": [ - "[22:35:18] Depickling from a version number (16.3)that is higher than our version (16.2).\n", + "[15:01:15] Depickling from a version number (16.3)that is higher than our version (16.2).\n", "This probably won't work.\n", - "[22:35:18] Depickling from a version number (16.3)that is higher than our version (16.2).\n", + "[15:01:15] Depickling from a version number (16.3)that is higher than our version (16.2).\n", "This probably won't work.\n", - "[22:35:18] Depickling from a version number (16.3)that is higher than our version (16.2).\n", + "[15:01:15] Depickling from a version number (16.3)that is higher than our version (16.2).\n", "This probably won't work.\n" ] } @@ -868,10 +868,10 @@ "id": "cell-26", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:35:18.433513Z", - "iopub.status.busy": "2026-08-08T20:35:18.433434Z", - "iopub.status.idle": "2026-08-08T20:35:18.436043Z", - "shell.execute_reply": "2026-08-08T20:35:18.435839Z" + "iopub.execute_input": "2026-08-09T13:01:15.951879Z", + "iopub.status.busy": "2026-08-09T13:01:15.951810Z", + "iopub.status.idle": "2026-08-09T13:01:15.953437Z", + "shell.execute_reply": "2026-08-09T13:01:15.953260Z" } }, "outputs": [ diff --git a/docs/tutorials/06_bingo_reactions_binary.ipynb b/docs/tutorials/06_bingo_reactions_binary.ipynb index be585f4..15d93f6 100644 --- a/docs/tutorials/06_bingo_reactions_binary.ipynb +++ b/docs/tutorials/06_bingo_reactions_binary.ipynb @@ -18,10 +18,10 @@ "id": "bb495784", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:35:30.246819Z", - "iopub.status.busy": "2026-08-08T20:35:30.246505Z", - "iopub.status.idle": "2026-08-08T20:35:30.810613Z", - "shell.execute_reply": "2026-08-08T20:35:30.810348Z" + "iopub.execute_input": "2026-08-09T13:01:16.690019Z", + "iopub.status.busy": "2026-08-09T13:01:16.689764Z", + "iopub.status.idle": "2026-08-09T13:01:17.000838Z", + "shell.execute_reply": "2026-08-09T13:01:17.000574Z" } }, "outputs": [ @@ -54,7 +54,15 @@ " sessionmaker,\n", ")\n", "\n", - "from molalchemy.bingo import functions, index, types\n", + "from molalchemy.bingo import (\n", + " BingoBinaryMol,\n", + " BingoBinaryMolIndex,\n", + " BingoBinaryReaction,\n", + " BingoBinaryRxnIndex,\n", + " BingoReaction,\n", + " BingoRxnIndex,\n", + " functions,\n", + ")\n", "\n", "engine = create_engine(\n", " os.environ.get(\n", @@ -84,10 +92,10 @@ "id": "5187d3a4", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:35:30.811778Z", - "iopub.status.busy": "2026-08-08T20:35:30.811685Z", - "iopub.status.idle": "2026-08-08T20:35:30.865546Z", - "shell.execute_reply": "2026-08-08T20:35:30.865292Z" + "iopub.execute_input": "2026-08-09T13:01:17.001919Z", + "iopub.status.busy": "2026-08-09T13:01:17.001825Z", + "iopub.status.idle": "2026-08-09T13:01:17.062872Z", + "shell.execute_reply": "2026-08-09T13:01:17.062538Z" } }, "outputs": [ @@ -107,14 +115,14 @@ "class BinaryMolecule(Base):\n", " __tablename__ = \"molalchemy_tutorial_bingo_binary_molecules\"\n", " __table_args__ = (\n", - " index.BingoBinaryMolIndex(\"molalchemy_tutorial_bingo_binary_mol_idx\", \"mol\"),\n", + " BingoBinaryMolIndex(\"molalchemy_tutorial_bingo_binary_mol_idx\", \"mol\"),\n", " )\n", "\n", " id: Mapped[int] = mapped_column(\n", " Integer, primary_key=True, autoincrement=True, init=False\n", " )\n", " name: Mapped[str] = mapped_column(String(100), unique=True)\n", - " mol: Mapped[str] = mapped_column(types.BingoBinaryMol(return_type=\"smiles\"))\n", + " mol: Mapped[str] = mapped_column(BingoBinaryMol(return_type=\"smiles\"))\n", "\n", "\n", "BinaryMolecule.__table__.drop(engine, checkfirst=True)\n", @@ -165,10 +173,10 @@ "id": "cb1be3b3", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:35:30.866630Z", - "iopub.status.busy": "2026-08-08T20:35:30.866554Z", - "iopub.status.idle": "2026-08-08T20:35:30.940495Z", - "shell.execute_reply": "2026-08-08T20:35:30.940251Z" + "iopub.execute_input": "2026-08-09T13:01:17.063881Z", + "iopub.status.busy": "2026-08-09T13:01:17.063798Z", + "iopub.status.idle": "2026-08-09T13:01:17.144017Z", + "shell.execute_reply": "2026-08-09T13:01:17.143769Z" } }, "outputs": [ @@ -184,14 +192,14 @@ "class BingoReactionExample(Base):\n", " __tablename__ = \"molalchemy_tutorial_bingo_reactions\"\n", " __table_args__ = (\n", - " index.BingoRxnIndex(\"molalchemy_tutorial_bingo_rxn_idx\", \"reaction\"),\n", + " BingoRxnIndex(\"molalchemy_tutorial_bingo_rxn_idx\", \"reaction\"),\n", " )\n", "\n", " id: Mapped[int] = mapped_column(\n", " Integer, primary_key=True, autoincrement=True, init=False\n", " )\n", " name: Mapped[str] = mapped_column(String(100), unique=True)\n", - " reaction: Mapped[str] = mapped_column(types.BingoReaction())\n", + " reaction: Mapped[str] = mapped_column(BingoReaction())\n", " similarity_fp: Mapped[bytes] = mapped_column(\n", " LargeBinary,\n", " Computed(functions.rfingerprint(reaction, \"sim\"), persisted=True),\n", @@ -207,7 +215,7 @@ "class BinaryReactionExample(Base):\n", " __tablename__ = \"molalchemy_tutorial_bingo_binary_reactions\"\n", " __table_args__ = (\n", - " index.BingoBinaryRxnIndex(\n", + " BingoBinaryRxnIndex(\n", " \"molalchemy_tutorial_bingo_binary_rxn_idx\", \"reaction\"\n", " ),\n", " )\n", @@ -216,7 +224,7 @@ " Integer, primary_key=True, autoincrement=True, init=False\n", " )\n", " name: Mapped[str] = mapped_column(String(100), unique=True)\n", - " reaction: Mapped[bytes] = mapped_column(types.BingoBinaryReaction())\n", + " reaction: Mapped[bytes] = mapped_column(BingoBinaryReaction())\n", "\n", "\n", "BingoReactionExample.__table__.drop(engine, checkfirst=True)\n", @@ -264,10 +272,10 @@ "id": "4b3934aa", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:35:30.941556Z", - "iopub.status.busy": "2026-08-08T20:35:30.941486Z", - "iopub.status.idle": "2026-08-08T20:35:30.945165Z", - "shell.execute_reply": "2026-08-08T20:35:30.944963Z" + "iopub.execute_input": "2026-08-09T13:01:17.145034Z", + "iopub.status.busy": "2026-08-09T13:01:17.144961Z", + "iopub.status.idle": "2026-08-09T13:01:17.148856Z", + "shell.execute_reply": "2026-08-09T13:01:17.148652Z" } }, "outputs": [ diff --git a/docs/tutorials/07_rdkit_descriptors_advanced.ipynb b/docs/tutorials/07_rdkit_descriptors_advanced.ipynb index 29d9e05..87afa75 100644 --- a/docs/tutorials/07_rdkit_descriptors_advanced.ipynb +++ b/docs/tutorials/07_rdkit_descriptors_advanced.ipynb @@ -18,10 +18,10 @@ "id": "c059ac5c", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:35:44.854881Z", - "iopub.status.busy": "2026-08-08T20:35:44.854684Z", - "iopub.status.idle": "2026-08-08T20:35:45.354047Z", - "shell.execute_reply": "2026-08-08T20:35:45.353797Z" + "iopub.execute_input": "2026-08-09T13:01:17.672867Z", + "iopub.status.busy": "2026-08-09T13:01:17.672602Z", + "iopub.status.idle": "2026-08-09T13:01:17.983740Z", + "shell.execute_reply": "2026-08-09T13:01:17.983479Z" } }, "outputs": [ @@ -56,7 +56,12 @@ ")\n", "\n", "from molalchemy.types import CString\n", - "from molalchemy.rdkit import functions, index, types\n", + "from molalchemy.rdkit import (\n", + " RdkitIndex,\n", + " RdkitMol,\n", + " RdkitSparseFingerprint,\n", + " functions,\n", + ")\n", "\n", "engine = create_engine(\n", " os.environ.get(\n", @@ -86,10 +91,10 @@ "id": "53b4a779", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:35:45.355239Z", - "iopub.status.busy": "2026-08-08T20:35:45.355148Z", - "iopub.status.idle": "2026-08-08T20:35:45.400551Z", - "shell.execute_reply": "2026-08-08T20:35:45.400269Z" + "iopub.execute_input": "2026-08-09T13:01:17.984864Z", + "iopub.status.busy": "2026-08-09T13:01:17.984766Z", + "iopub.status.idle": "2026-08-09T13:01:18.023869Z", + "shell.execute_reply": "2026-08-09T13:01:18.023631Z" } }, "outputs": [], @@ -101,17 +106,17 @@ "class Molecule(Base):\n", " __tablename__ = \"molalchemy_tutorial_rdkit_advanced_molecules\"\n", " __table_args__ = (\n", - " index.RdkitIndex(\"molalchemy_tutorial_rdkit_advanced_mol_idx\", \"mol\"),\n", - " index.RdkitIndex(\"molalchemy_tutorial_rdkit_advanced_fp_idx\", \"fp\"),\n", + " RdkitIndex(\"molalchemy_tutorial_rdkit_advanced_mol_idx\", \"mol\"),\n", + " RdkitIndex(\"molalchemy_tutorial_rdkit_advanced_fp_idx\", \"fp\"),\n", " )\n", "\n", " id: Mapped[int] = mapped_column(\n", " Integer, primary_key=True, autoincrement=True, init=False\n", " )\n", " name: Mapped[str] = mapped_column(String(100), unique=True)\n", - " mol: Mapped[str] = mapped_column(types.RdkitMol())\n", + " mol: Mapped[str] = mapped_column(RdkitMol())\n", " fp: Mapped[bytes] = mapped_column(\n", - " types.RdkitSparseFingerprint(),\n", + " RdkitSparseFingerprint(),\n", " Computed(functions.morgan_fp(mol, 2), persisted=True),\n", " init=False,\n", " )\n", @@ -151,10 +156,10 @@ "id": "6ab7dd5b", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:35:45.401673Z", - "iopub.status.busy": "2026-08-08T20:35:45.401593Z", - "iopub.status.idle": "2026-08-08T20:35:45.407927Z", - "shell.execute_reply": "2026-08-08T20:35:45.407733Z" + "iopub.execute_input": "2026-08-09T13:01:18.024893Z", + "iopub.status.busy": "2026-08-09T13:01:18.024823Z", + "iopub.status.idle": "2026-08-09T13:01:18.030448Z", + "shell.execute_reply": "2026-08-09T13:01:18.030246Z" } }, "outputs": [ @@ -207,10 +212,10 @@ "id": "71c91a0b", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:35:45.408996Z", - "iopub.status.busy": "2026-08-08T20:35:45.408923Z", - "iopub.status.idle": "2026-08-08T20:35:45.414051Z", - "shell.execute_reply": "2026-08-08T20:35:45.413859Z" + "iopub.execute_input": "2026-08-09T13:01:18.031347Z", + "iopub.status.busy": "2026-08-09T13:01:18.031285Z", + "iopub.status.idle": "2026-08-09T13:01:18.035728Z", + "shell.execute_reply": "2026-08-09T13:01:18.035535Z" } }, "outputs": [ @@ -261,10 +266,10 @@ "id": "b46b6e37", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:35:45.415034Z", - "iopub.status.busy": "2026-08-08T20:35:45.414968Z", - "iopub.status.idle": "2026-08-08T20:35:45.418788Z", - "shell.execute_reply": "2026-08-08T20:35:45.418617Z" + "iopub.execute_input": "2026-08-09T13:01:18.036595Z", + "iopub.status.busy": "2026-08-09T13:01:18.036534Z", + "iopub.status.idle": "2026-08-09T13:01:18.039792Z", + "shell.execute_reply": "2026-08-09T13:01:18.039586Z" } }, "outputs": [ @@ -312,10 +317,10 @@ "id": "b53112dc", "metadata": { "execution": { - "iopub.execute_input": "2026-08-08T20:35:45.419733Z", - "iopub.status.busy": "2026-08-08T20:35:45.419668Z", - "iopub.status.idle": "2026-08-08T20:35:45.423021Z", - "shell.execute_reply": "2026-08-08T20:35:45.422851Z" + "iopub.execute_input": "2026-08-09T13:01:18.040700Z", + "iopub.status.busy": "2026-08-09T13:01:18.040630Z", + "iopub.status.idle": "2026-08-09T13:01:18.044217Z", + "shell.execute_reply": "2026-08-09T13:01:18.044028Z" } }, "outputs": [ diff --git a/docs/tutorials/08_proxy_helpers.md b/docs/tutorials/08_proxy_helpers.md index e156950..1386eca 100644 --- a/docs/tutorials/08_proxy_helpers.md +++ b/docs/tutorials/08_proxy_helpers.md @@ -27,7 +27,7 @@ and static analysis can see the comparator API and its precise result types. from sqlalchemy import Integer, String, select from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column -from molalchemy.bingo.types import BingoMol, BingoReaction +from molalchemy.bingo import BingoMol, BingoReaction from molalchemy.helpers import bingo_col, bingo_rxn_col @@ -80,7 +80,7 @@ from sqlalchemy import Integer, String, select from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column from molalchemy.helpers import rdkit_col, rdkit_fp_col, rdkit_rxn_col -from molalchemy.rdkit.types import RdkitBitFingerprint, RdkitMol, RdkitReaction +from molalchemy.rdkit import RdkitBitFingerprint, RdkitMol, RdkitReaction class Base(DeclarativeBase): @@ -140,7 +140,7 @@ The helpers also accept Core table columns. ```python from sqlalchemy import Column, Integer, MetaData, String, Table, select -from molalchemy.bingo.types import BingoMol +from molalchemy.bingo import BingoMol from molalchemy.helpers import bingo_col diff --git a/src/molalchemy/bingo/__init__.py b/src/molalchemy/bingo/__init__.py index 769fbd5..0a1844b 100644 --- a/src/molalchemy/bingo/__init__.py +++ b/src/molalchemy/bingo/__init__.py @@ -1,3 +1,4 @@ +from . import functions from .comparators import BingoMolComparator, BingoRxnComparator from .index import ( BingoBinaryMolIndex, @@ -18,4 +19,5 @@ "BingoReaction", "BingoRxnComparator", "BingoRxnIndex", + "functions", ] diff --git a/src/molalchemy/rdkit/__init__.py b/src/molalchemy/rdkit/__init__.py index 57a27a8..5d1aa6e 100644 --- a/src/molalchemy/rdkit/__init__.py +++ b/src/molalchemy/rdkit/__init__.py @@ -1,3 +1,4 @@ +from . import functions from .comparators import RdkitFPComparator, RdkitMolComparator, RdkitReactionComparator from .index import RdkitIndex from .settings import ( @@ -31,6 +32,7 @@ "RdkitSparseFingerprint", "RdkitXQMol", "configure_engine", + "functions", "get_dice_threshold", "get_tanimoto_threshold", "set_dice_threshold", From 896cfec209718d13e56b920a34a8bed44fc51bc7 Mon Sep 17 00:00:00 2001 From: Anton Siomchen <41703271+asiomchen@users.noreply.github.com.> Date: Sun, 9 Aug 2026 21:18:08 +0200 Subject: [PATCH 4/8] Enhance Alembic integration with improved type rendering and migration stability --- README.md | 6 +++- docs/index.md | 6 +++- docs/tutorials/03_alembic_migrations.md | 21 +++++++++++- src/molalchemy/bingo/index.py | 6 ++-- src/molalchemy/bingo/types.py | 27 +++++++-------- src/molalchemy/rdkit/types.py | 12 +++---- tests/test_alembic_helpers.py | 44 ++++++++++++++++++++++--- 7 files changed, 92 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 9b0f016..51c1ee4 100644 --- a/README.md +++ b/README.md @@ -377,7 +377,11 @@ results = session.query( ### Alembic Database Migrations -Molalchemy provides utilities for Alembic integration.For automatic import handling in migrations, the library provides type rendering utilities that ensure proper import statements are generated for molalchemy types. +MolAlchemy provides utilities for Alembic integration. For automatic import +handling in migrations, the library provides type rendering utilities that +ensure proper import statements are generated for MolAlchemy types. Generated +type constructors explicitly include configurable defaults so migrations do +not inherit different behavior if a future release changes those defaults. ```python # ... diff --git a/docs/index.md b/docs/index.md index 9b0f016..51c1ee4 100644 --- a/docs/index.md +++ b/docs/index.md @@ -377,7 +377,11 @@ results = session.query( ### Alembic Database Migrations -Molalchemy provides utilities for Alembic integration.For automatic import handling in migrations, the library provides type rendering utilities that ensure proper import statements are generated for molalchemy types. +MolAlchemy provides utilities for Alembic integration. For automatic import +handling in migrations, the library provides type rendering utilities that +ensure proper import statements are generated for MolAlchemy types. Generated +type constructors explicitly include configurable defaults so migrations do +not inherit different behavior if a future release changes those defaults. ```python # ... diff --git a/docs/tutorials/03_alembic_migrations.md b/docs/tutorials/03_alembic_migrations.md index 3ca1882..8aa0a50 100644 --- a/docs/tutorials/03_alembic_migrations.md +++ b/docs/tutorials/03_alembic_migrations.md @@ -95,4 +95,23 @@ def run_migrations_online(): # ... ``` -This will ensure that when Alembic generates migration scripts, it will include the necessary import statements for `molalchemy` types, allowing the migrations to run without import errors. +This ensures that Alembic includes the necessary type imports. For the model +above, the generated migration contains: + +```python +from molalchemy.rdkit.types import RdkitMol + + +def upgrade() -> None: + op.create_table( + "molecules", + sa.Column("id", sa.Integer(), nullable=False), + sa.Column("mol", RdkitMol(return_type="bytes"), nullable=False), + sa.PrimaryKeyConstraint("id"), + ) +``` + +MolAlchemy renders every configurable constructor option, including defaults. +For example, a default binary Bingo reaction type is rendered as +`BingoBinaryReaction(preserve_pos=False)`. This keeps an existing migration's +meaning stable if a constructor default changes in a later MolAlchemy release. diff --git a/src/molalchemy/bingo/index.py b/src/molalchemy/bingo/index.py index 9d4a9a6..dc5508e 100644 --- a/src/molalchemy/bingo/index.py +++ b/src/molalchemy/bingo/index.py @@ -72,7 +72,7 @@ class BingoMolIndex(_BingoIndexBase): ... __tablename__ = 'molecules' ... ... id: Mapped[int] = mapped_column(Integer, primary_key=True) - ... structure: Mapped[BingoMol] = mapped_column(BingoMol) + ... structure: Mapped[str] = mapped_column(BingoMol()) ... ... __table_args__ = ( ... BingoMolIndex('idx_mol_structure', 'structure'), @@ -121,7 +121,7 @@ class BingoBinaryMolIndex(_BingoIndexBase): ... __tablename__ = 'molecules' ... ... id: Mapped[int] = mapped_column(Integer, primary_key=True) - ... structure_bin: Mapped[BingoBinaryMol] = mapped_column(BingoBinaryMol) + ... structure_bin: Mapped[str] = mapped_column(BingoBinaryMol()) ... ... __table_args__ = ( ... BingoBinaryMolIndex('idx_mol_structure_bin', 'structure_bin'), @@ -171,7 +171,7 @@ class BingoRxnIndex(_BingoIndexBase): ... __tablename__ = 'reactions' ... ... id: Mapped[int] = mapped_column(Integer, primary_key=True) - ... reaction: Mapped[BingoReaction] = mapped_column(BingoReaction) + ... reaction: Mapped[str] = mapped_column(BingoReaction()) ... ... __table_args__ = ( ... BingoRxnIndex('idx_reaction_structure', 'reaction'), diff --git a/src/molalchemy/bingo/types.py b/src/molalchemy/bingo/types.py index db2ffd5..caa8c6a 100644 --- a/src/molalchemy/bingo/types.py +++ b/src/molalchemy/bingo/types.py @@ -68,7 +68,7 @@ class BingoMol(BingoBaseType[str]): ... __tablename__ = 'molecules' ... ... id: Mapped[int] = mapped_column(Integer, primary_key=True) - ... smiles: Mapped[str] = mapped_column(BingoMol) + ... smiles: Mapped[str] = mapped_column(BingoMol()) ... name: Mapped[str] = mapped_column(String(100)) >>> >>> # Usage in queries @@ -83,7 +83,7 @@ class BingoMol(BingoBaseType[str]): cache_ok = True comparator_factory = BingoMolComparator - def __repr__(self): + def __repr__(self) -> str: return "BingoMol()" def get_col_spec(self, **kwargs: Any) -> str: @@ -106,7 +106,7 @@ class BingoBinaryMol(BingoBaseType[_T], Generic[_T]): atomic coordinates and specifying the return format for queries. Parameters - ---------- + ---------- preserve_pos : bool, default False Whether to preserve atomic coordinates when converting to binary format. If `True`, coordinates are stored; if `False`, they are discarded. @@ -199,8 +199,11 @@ def __init__( self.return_type = return_type super().__init__() - def __repr__(self): - return f"BingoBinaryMol(preserve_pos={self.preserve_pos!r}, return_type={self.return_type!r})" + def __repr__(self) -> str: + return ( + f"BingoBinaryMol(preserve_pos={self.preserve_pos!r}, " + f"return_type={self.return_type!r})" + ) def get_col_spec(self, **kwargs: Any) -> str: return "bytea" @@ -242,7 +245,7 @@ class BingoReaction(BingoBaseType[str]): ... __tablename__ = 'reactions' ... ... id: Mapped[int] = mapped_column(Integer, primary_key=True) - ... reaction_smiles: Mapped[str] = mapped_column(BingoReaction) + ... reaction_smiles: Mapped[str] = mapped_column(BingoReaction()) ... name: Mapped[str] = mapped_column(String(200)) >>> >>> # Usage in queries @@ -267,7 +270,7 @@ class BingoReaction(BingoBaseType[str]): cache_ok = True comparator_factory = BingoRxnComparator - def __repr__(self): + def __repr__(self) -> str: return "BingoReaction()" def get_col_spec(self, **kwargs: Any) -> str: @@ -313,7 +316,7 @@ class BingoBinaryReaction(BingoBaseType[bytes]): ... __tablename__ = 'reactions_binary' ... ... id: Mapped[int] = mapped_column(Integer, primary_key=True) - ... reaction_data: Mapped[bytes] = mapped_column(BingoBinaryReaction) + ... reaction_data: Mapped[bytes] = mapped_column(BingoBinaryReaction()) ... name: Mapped[str] = mapped_column(String(200)) >>> >>> # Usage: Binary storage provides faster searching and less storage space @@ -338,15 +341,13 @@ class BingoBinaryReaction(BingoBaseType[bytes]): comparator_factory = BingoRxnComparator _immutable_options = frozenset(("preserve_pos",)) - def __init__(self, preserve_pos: bool = False): + def __init__(self, preserve_pos: bool = False) -> None: _validate_preserve_pos(preserve_pos) self.preserve_pos = preserve_pos super().__init__() - def __repr__(self): - if self.preserve_pos: - return "BingoBinaryReaction(preserve_pos=True)" - return "BingoBinaryReaction()" + def __repr__(self) -> str: + return f"BingoBinaryReaction(preserve_pos={self.preserve_pos!r})" def get_col_spec(self, **kwargs: Any) -> str: return "bytea" diff --git a/src/molalchemy/rdkit/types.py b/src/molalchemy/rdkit/types.py index 6d4b3d1..9950513 100644 --- a/src/molalchemy/rdkit/types.py +++ b/src/molalchemy/rdkit/types.py @@ -97,7 +97,7 @@ def __init__( super().__init__() self.return_type = return_type - def __repr__(self): + def __repr__(self) -> str: return f"RdkitMol(return_type={self.return_type!r})" def column_expression(self, colexpr): @@ -161,7 +161,7 @@ class RdkitBitFingerprint(RdkitBaseType[bytes]): cache_ok = True comparator_factory = RdkitFPComparator - def __repr__(self): + def __repr__(self) -> str: return "RdkitBitFingerprint()" def get_col_spec(self, **kwargs: Any) -> str: @@ -179,7 +179,7 @@ class RdkitSparseFingerprint(RdkitBaseType[bytes]): cache_ok = True comparator_factory = RdkitFPComparator - def __repr__(self): + def __repr__(self) -> str: return "RdkitSparseFingerprint()" def get_col_spec(self, **kwargs: Any) -> str: @@ -251,7 +251,7 @@ def __init__( super().__init__() self.return_type = return_type - def __repr__(self): + def __repr__(self) -> str: return f"RdkitReaction(return_type={self.return_type!r})" def bind_processor(self, dialect): @@ -310,7 +310,7 @@ def process(value, return_type): class RdkitQMol(RdkitBaseType[str]): cache_ok = True - def __repr__(self): + def __repr__(self) -> str: return "RdkitQMol()" def get_col_spec(self, **kwargs: Any) -> str: @@ -320,7 +320,7 @@ def get_col_spec(self, **kwargs: Any) -> str: class RdkitXQMol(RdkitBaseType[str]): cache_ok = True - def __repr__(self): + def __repr__(self) -> str: return "RdkitXQMol()" def get_col_spec(self, **kwargs: Any) -> str: diff --git a/tests/test_alembic_helpers.py b/tests/test_alembic_helpers.py index 861d0ab..5e55949 100644 --- a/tests/test_alembic_helpers.py +++ b/tests/test_alembic_helpers.py @@ -5,7 +5,7 @@ import pytest from alembic.autogenerate.api import render_python_code from alembic.migration import MigrationContext -from alembic.operations.ops import CreateIndexOp, UpgradeOps +from alembic.operations.ops import CreateIndexOp, CreateTableOp, UpgradeOps from sqlalchemy import Column, MetaData, Table, text from molalchemy.alembic_helpers import ( @@ -101,7 +101,13 @@ BingoBinaryReaction(), "molalchemy.bingo.types", "BingoBinaryReaction", - "BingoBinaryReaction()", + "BingoBinaryReaction(preserve_pos=False)", + ), + ( + BingoBinaryReaction(preserve_pos=True), + "molalchemy.bingo.types", + "BingoBinaryReaction", + "BingoBinaryReaction(preserve_pos=True)", ), ] @@ -135,12 +141,41 @@ def test_render_all_types( def test_rendered_type_is_valid_constructor( self, instance, expected_module, class_name, expected_repr ): - """Test that the rendered string is exactly the constructor call.""" + """The rendered constructor recreates the type's complete configuration.""" autogen_context = Mock() autogen_context.imports = set() result = render_item("type", instance, autogen_context) + assert result == expected_repr + recreated = eval(result, {class_name: type(instance)}) + assert recreated._static_cache_key == instance._static_cache_key + + +def render_table_operation(table): + """Render an Alembic table operation with the offline PostgreSQL dialect.""" + migration_context = MigrationContext.configure(dialect_name="postgresql") + upgrade_ops = UpgradeOps(ops=[CreateTableOp.from_table(table)]) + return render_python_code( + upgrade_ops, + render_item=render_item, + migration_context=migration_context, + ) + + +def test_alembic_table_rendering_preserves_explicit_default_options(): + """A generated table migration does not rely on future constructor defaults.""" + metadata = MetaData() + table = Table( + "reactions", + metadata, + Column("reaction", BingoBinaryReaction()), + ) + + rendered = render_table_operation(table) + + assert "BingoBinaryReaction(preserve_pos=False)" in rendered + compile(f"def upgrade():\n{rendered}", "", "exec") class TestRenderNonTypes: @@ -265,8 +300,7 @@ def test_alembic_renders_generic_index_operation( rendered = render_index_operation(index) assert ( - "op.create_index('ix_items_structure', 'items', ['structure'], " - "unique=False" + "op.create_index('ix_items_structure', 'items', ['structure'], unique=False" ) in rendered for expected_option in expected_options: assert expected_option in rendered From 0a6a20f4aa54d51afcab5cbd2d7844da27ce8e53 Mon Sep 17 00:00:00 2001 From: Anton Siomchen <41703271+asiomchen@users.noreply.github.com.> Date: Sun, 9 Aug 2026 21:34:25 +0200 Subject: [PATCH 5/8] Implement lazy loading for functions in bingo and rdkit modules --- src/molalchemy/bingo/__init__.py | 14 +++++++- src/molalchemy/bingo/comparators.py | 17 ++++++++-- src/molalchemy/rdkit/__init__.py | 14 +++++++- tests/test_import_side_effects.py | 51 +++++++++++++++++++++++++++++ 4 files changed, 92 insertions(+), 4 deletions(-) create mode 100644 tests/test_import_side_effects.py diff --git a/src/molalchemy/bingo/__init__.py b/src/molalchemy/bingo/__init__.py index 0a1844b..b2a95e7 100644 --- a/src/molalchemy/bingo/__init__.py +++ b/src/molalchemy/bingo/__init__.py @@ -1,4 +1,7 @@ -from . import functions +from importlib import import_module +from types import ModuleType +from typing import TYPE_CHECKING + from .comparators import BingoMolComparator, BingoRxnComparator from .index import ( BingoBinaryMolIndex, @@ -8,6 +11,15 @@ ) from .types import BingoBinaryMol, BingoBinaryReaction, BingoMol, BingoReaction +if TYPE_CHECKING: + from . import functions + + +def __getattr__(name: str) -> ModuleType: + if name == "functions": + return import_module(f"{__name__}.functions") + raise AttributeError(f"module {__name__!r} has no attribute {name!r}") + __all__ = [ "BingoBinaryMol", "BingoBinaryMolIndex", diff --git a/src/molalchemy/bingo/comparators.py b/src/molalchemy/bingo/comparators.py index e1122e0..91cb00c 100644 --- a/src/molalchemy/bingo/comparators.py +++ b/src/molalchemy/bingo/comparators.py @@ -1,9 +1,12 @@ """Bingo SQLAlchemy comparators for chemical structure searching.""" +from typing import cast + from sqlalchemy import ColumnElement +from sqlalchemy import types as sqltypes +from sqlalchemy.sql.functions import Function from sqlalchemy.types import UserDefinedType -from molalchemy.bingo.functions.general import mol_similarity_score from molalchemy.bingo.search import _bingo_search_values from molalchemy.protocols import ( BingoOperand, @@ -139,7 +142,17 @@ def similarity_score( metric: BingoParameters = "Tanimoto", ) -> ColumnElement[float]: """Return the numeric similarity score for `query`.""" - return mol_similarity_score(self.expr, query, metric) + return cast( + ColumnElement[float], + Function( + "getsimilarity", + self.expr, + query, + metric, + packagenames=("bingo",), + type_=sqltypes.Float(), + ), + ) class BingoRxnComparator(UserDefinedType.Comparator): diff --git a/src/molalchemy/rdkit/__init__.py b/src/molalchemy/rdkit/__init__.py index 5d1aa6e..c5c4b98 100644 --- a/src/molalchemy/rdkit/__init__.py +++ b/src/molalchemy/rdkit/__init__.py @@ -1,4 +1,7 @@ -from . import functions +from importlib import import_module +from types import ModuleType +from typing import TYPE_CHECKING + from .comparators import RdkitFPComparator, RdkitMolComparator, RdkitReactionComparator from .index import RdkitIndex from .settings import ( @@ -19,6 +22,15 @@ RdkitXQMol, ) +if TYPE_CHECKING: + from . import functions + + +def __getattr__(name: str) -> ModuleType: + if name == "functions": + return import_module(f"{__name__}.functions") + raise AttributeError(f"module {__name__!r} has no attribute {name!r}") + __all__ = [ "RdkitBitFingerprint", "RdkitFPComparator", diff --git a/tests/test_import_side_effects.py b/tests/test_import_side_effects.py new file mode 100644 index 0000000..8029255 --- /dev/null +++ b/tests/test_import_side_effects.py @@ -0,0 +1,51 @@ +"""Tests for package import behavior.""" + +import subprocess +import sys +import textwrap + + +def test_plain_import_does_not_register_cartridge_functions(): + script = textwrap.dedent( + """ + import sys + + from sqlalchemy import func + from sqlalchemy.sql.functions import Function, _registry + from sqlalchemy.sql.sqltypes import NullType + + registry_before = { + package: dict(functions) for package, functions in _registry.items() + } + + import molalchemy + import molalchemy.bingo as bingo + import molalchemy.rdkit as rdkit + + registry_after = { + package: dict(functions) for package, functions in _registry.items() + } + assert registry_after == registry_before + assert "molalchemy.bingo.functions" not in sys.modules + assert "molalchemy.rdkit.functions" not in sys.modules + + smiles = func.smiles("x") + add = func.add("x", "y") + assert type(smiles) is Function + assert type(add) is Function + assert smiles.packagenames == () + assert add.packagenames == () + assert isinstance(smiles.type, NullType) + assert isinstance(add.type, NullType) + + from molalchemy.bingo import functions as bingo_functions + from molalchemy.rdkit import functions as rdkit_functions + + assert bingo.functions is bingo_functions + assert rdkit.functions is rdkit_functions + assert bingo_functions.__name__ == "molalchemy.bingo.functions" + assert rdkit_functions.__name__ == "molalchemy.rdkit.functions" + """ + ) + + subprocess.run([sys.executable, "-c", script], check=True) From aadb038e60940073a4c848afed0e7f8731cce5dd Mon Sep 17 00:00:00 2001 From: Anton Siomchen <41703271+asiomchen@users.noreply.github.com.> Date: Sun, 9 Aug 2026 21:42:06 +0200 Subject: [PATCH 6/8] run ruff --- src/molalchemy/bingo/__init__.py | 1 + src/molalchemy/rdkit/__init__.py | 1 + 2 files changed, 2 insertions(+) diff --git a/src/molalchemy/bingo/__init__.py b/src/molalchemy/bingo/__init__.py index b2a95e7..d0b5ae3 100644 --- a/src/molalchemy/bingo/__init__.py +++ b/src/molalchemy/bingo/__init__.py @@ -20,6 +20,7 @@ def __getattr__(name: str) -> ModuleType: return import_module(f"{__name__}.functions") raise AttributeError(f"module {__name__!r} has no attribute {name!r}") + __all__ = [ "BingoBinaryMol", "BingoBinaryMolIndex", diff --git a/src/molalchemy/rdkit/__init__.py b/src/molalchemy/rdkit/__init__.py index c5c4b98..43cf930 100644 --- a/src/molalchemy/rdkit/__init__.py +++ b/src/molalchemy/rdkit/__init__.py @@ -31,6 +31,7 @@ def __getattr__(name: str) -> ModuleType: return import_module(f"{__name__}.functions") raise AttributeError(f"module {__name__!r} has no attribute {name!r}") + __all__ = [ "RdkitBitFingerprint", "RdkitFPComparator", From 42182685294f073e8ba0572ff157ee6126093de1 Mon Sep 17 00:00:00 2001 From: Anton Siomchen <41703271+asiomchen@users.noreply.github.com.> Date: Sun, 9 Aug 2026 21:43:49 +0200 Subject: [PATCH 7/8] add rdkit stubs --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index bb40374..768dd2d 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -48,7 +48,7 @@ jobs: run: | uv build --wheel --out-dir dist-typing uv venv /tmp/molalchemy-typing-venv --python 3.10 - uv pip install --python /tmp/molalchemy-typing-venv dist-typing/*.whl ty + uv pip install --python /tmp/molalchemy-typing-venv dist-typing/*.whl ty rdkit-stubs mkdir -p /tmp/molalchemy-typing-consumer cp tests/typing/consumer.py /tmp/molalchemy-typing-consumer/consumer.py From bfd0300a0e8c07e7e325248885d6f4a13288dc00 Mon Sep 17 00:00:00 2001 From: Anton Siomchen <41703271+asiomchen@users.noreply.github.com.> Date: Sun, 9 Aug 2026 21:56:07 +0200 Subject: [PATCH 8/8] fix typing check --- .github/workflows/ci.yaml | 48 ++++++++++++++++++++--------------- pyproject.toml | 1 - src/molalchemy/rdkit/types.py | 20 ++++++++++----- uv.lock | 11 -------- 4 files changed, 41 insertions(+), 39 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 768dd2d..128b75a 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -13,7 +13,7 @@ concurrency: jobs: typing: - name: Installed-wheel typing surface + name: Typing checks runs-on: ubuntu-latest steps: - name: Checkout @@ -33,28 +33,36 @@ jobs: python-version: "3.10" - name: Check source and consumer types - run: uv run ty check src tests/typing/consumer.py + run: uv run --frozen ty check src tests/typing/consumer.py - - name: Check generated functions are current - run: | - uv run python dev_scripts/gen_functions.py rdkit - uv run python dev_scripts/gen_functions.py bingo - uv run ruff format src/molalchemy/rdkit/functions src/molalchemy/bingo/functions - uv run ruff check --fix src/molalchemy/rdkit/functions src/molalchemy/bingo/functions - uv run ruff format src/molalchemy/rdkit/functions src/molalchemy/bingo/functions - git diff --exit-code -- src/molalchemy/rdkit/functions src/molalchemy/bingo/functions + generated-functions: + name: Generated functions are current + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v6 + with: + fetch-depth: 0 + + - name: Set up Python + uses: actions/setup-python@v6 + with: + python-version: "3.10" + + - name: Install UV + uses: astral-sh/setup-uv@v7 + with: + version: "0.9.9" + python-version: "3.10" - - name: Build and install wheel in an isolated environment + - name: Regenerate and compare functions run: | - uv build --wheel --out-dir dist-typing - uv venv /tmp/molalchemy-typing-venv --python 3.10 - uv pip install --python /tmp/molalchemy-typing-venv dist-typing/*.whl ty rdkit-stubs - mkdir -p /tmp/molalchemy-typing-consumer - cp tests/typing/consumer.py /tmp/molalchemy-typing-consumer/consumer.py - - - name: Check the installed consumer surface - working-directory: /tmp/molalchemy-typing-consumer - run: /tmp/molalchemy-typing-venv/bin/ty check consumer.py + uv run --frozen python dev_scripts/gen_functions.py rdkit + uv run --frozen python dev_scripts/gen_functions.py bingo + uv run --frozen ruff format src/molalchemy/rdkit/functions src/molalchemy/bingo/functions + uv run --frozen ruff check --fix src/molalchemy/rdkit/functions src/molalchemy/bingo/functions + uv run --frozen ruff format src/molalchemy/rdkit/functions src/molalchemy/bingo/functions + git diff --exit-code -- src/molalchemy/rdkit/functions src/molalchemy/bingo/functions test: name: Test on Python ${{ matrix.python-version }} - ${{ matrix.os }} diff --git a/pyproject.toml b/pyproject.toml index 35d925a..a459302 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -48,7 +48,6 @@ dev = [ "pytest>=8.4.2", "pytest-cov>=7.0.0", "pyyaml>=6.0.2", - "rdkit-stubs>=0.8", "ruff==0.14.5", "ty>=0.0.66", ] diff --git a/src/molalchemy/rdkit/types.py b/src/molalchemy/rdkit/types.py index 9950513..bdfb2f9 100644 --- a/src/molalchemy/rdkit/types.py +++ b/src/molalchemy/rdkit/types.py @@ -8,7 +8,7 @@ from typing import Any, Generic, Literal, TypeVar, overload from rdkit import Chem -from rdkit.Chem import AllChem, rdChemReactions +from rdkit.Chem import rdChemReactions from sqlalchemy import func from sqlalchemy.types import UserDefinedType @@ -122,7 +122,7 @@ def process(value): raise InvalidMoleculeError( "Value must be a SMILES string or an RDKit Mol object" ) - return value.ToBinary() # ty: ignore[no-matching-overload] + return value.ToBinary() return process @@ -138,7 +138,9 @@ def process(value, return_type): if return_type == "mol": # If we have bytes from mol_send, create molecule from binary if isinstance(value, bytes | memoryview): - return Chem.Mol(bytes(value)) + # RDKit accepts binary pickles here, although its generated + # stub currently annotates the argument as str. + return Chem.Mol(bytes(value)) # ty: ignore[no-matching-overload] # If we have a string (shouldn't happen with mol_send but just in case) else: return Chem.MolFromSmiles(str(value)) @@ -198,7 +200,7 @@ class RdkitReaction(RdkitBaseType[_T], Generic[_T]): The format in which to return reaction data from the database: - `"smiles"`: Return as reaction SMILES string - `"bytes"`: Return as raw bytes - - `"mol"`: Return as `AllChem.ChemicalReaction` object + - `"mol"`: Return as `rdChemReactions.ChemicalReaction` object Raises ------ @@ -264,7 +266,7 @@ def process(value): return rdChemReactions.ReactionToSmarts(value) if isinstance(value, str): try: - rxn = AllChem.ReactionFromSmarts(value) + rxn = rdChemReactions.ReactionFromSmarts(value) except ValueError: rxn = None if rxn is None: @@ -296,9 +298,13 @@ def process(value, return_type): return None if return_type == "mol": if isinstance(value, bytes | memoryview): - return AllChem.ChemicalReaction(bytes(value)) + # RDKit accepts binary pickles here, although its generated + # stub currently annotates the argument as str. + return rdChemReactions.ChemicalReaction( # ty: ignore[no-matching-overload] + bytes(value) + ) else: - return AllChem.ReactionFromSmarts(str(value)) + return rdChemReactions.ReactionFromSmarts(str(value)) elif return_type == "bytes": return bytes(value) if isinstance(value, memoryview) else value else: # smiles diff --git a/uv.lock b/uv.lock index a3fcb40..9d0cbc0 100644 --- a/uv.lock +++ b/uv.lock @@ -1136,7 +1136,6 @@ dev = [ { name = "pytest" }, { name = "pytest-cov" }, { name = "pyyaml" }, - { name = "rdkit-stubs" }, { name = "ruff" }, { name = "ty" }, ] @@ -1166,7 +1165,6 @@ dev = [ { name = "pytest", specifier = ">=8.4.2" }, { name = "pytest-cov", specifier = ">=7.0.0" }, { name = "pyyaml", specifier = ">=6.0.2" }, - { name = "rdkit-stubs", specifier = ">=0.8" }, { name = "ruff", specifier = "==0.14.5" }, { name = "ty", specifier = ">=0.0.66" }, ] @@ -1963,15 +1961,6 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/37/1d/415fcfdc96c0453d02d8265684083bfac45425c52aeee64aadc330aa6f66/rdkit-2025.3.6-cp314-cp314-win_amd64.whl", hash = "sha256:600d7fc3a2665baa9de7ec6870f33a53027f532f9a47e5df765ac91539c7e746", size = 24004467, upload-time = "2025-09-05T12:47:33.743Z" }, ] -[[package]] -name = "rdkit-stubs" -version = "0.8" -source = { registry = "https://pypi.org/simple" } -sdist = { url = "https://files.pythonhosted.org/packages/af/e0/67632bd3811b1d24b9eb912912321003ad7ab02b0ac93dd6c955840ec537/rdkit-stubs-0.8.tar.gz", hash = "sha256:2af5a1dcccdc85e598fda9b7f7ad3cc8bd6bc32fc55414a98d9fa69f85c12549", size = 101706, upload-time = "2024-09-19T18:43:50.549Z" } -wheels = [ - { url = "https://files.pythonhosted.org/packages/d9/0f/90088510d4758e0ee475ae1fc7f96e7bccd0e31f24107567075482b2fe9e/rdkit_stubs-0.8-py3-none-any.whl", hash = "sha256:1d58bcc604181b52713d62d5904386b1682c42b9694ddb20ceb81d3b896ccbd0", size = 186615, upload-time = "2024-09-19T18:43:49.101Z" }, -] - [[package]] name = "referencing" version = "0.36.2"