chemschema 0.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
chemschema/__init__.py ADDED
File without changes
chemschema/base.py ADDED
File without changes
File without changes
@@ -0,0 +1,13 @@
1
+ from sqlalchemy import text
2
+ from sqlalchemy.types import UserDefinedType
3
+
4
+
5
+ class BingoMolComparator(UserDefinedType.Comparator):
6
+ def substructure(self, query, parameters=""):
7
+ return self.expr.op("@")(text(f"('{query}', '{parameters}')::bingo.sub"))
8
+
9
+ def smarts(self, query, parameters=""):
10
+ return self.expr.op("@")(text(f"('{query}', '{parameters}')::bingo.smarts"))
11
+
12
+ def equals(self, query, parameters=""):
13
+ return self.expr.op("@")(text(f"('{query}', '{parameters}')::bingo.exact"))
@@ -0,0 +1,27 @@
1
+ from chemschema.utils import get_column_name
2
+ from sqlalchemy import text
3
+
4
+
5
+ class bingo_func:
6
+ name = "bingo"
7
+ mol_type_name = "bingo.molecule"
8
+ fingerprint_type_name = "bingo.fingerprint"
9
+
10
+ @staticmethod
11
+ def substructure(mol_column, query, parameters=""):
12
+ return text(f"{mol_column} @ {query, parameters}::bingo.sub")
13
+
14
+ @staticmethod
15
+ def smarts(mol_column, query, parameters=""):
16
+ return text(f"{mol_column} @ {query, parameters}::bingo.smarts")
17
+
18
+ @staticmethod
19
+ def equals(mol_column, query, parameters=""):
20
+ mol_column = get_column_name(mol_column)
21
+ return text(f"{mol_column} @ {query, parameters}::bingo.exact")
22
+
23
+ @staticmethod
24
+ def similarity(mol_column, query, bottom=0.0, top=1.0, metric="Tanimoto"):
25
+ # get table name if the columnis mapped
26
+ mol_column = get_column_name(mol_column)
27
+ return text(f"{mol_column} @ {bottom, top, query, metric}::bingo.sim")
@@ -0,0 +1,30 @@
1
+ from sqlalchemy.schema import Index
2
+
3
+
4
+ # @compiles(BingoMolIndex, 'postgresql')
5
+ # def compile_bingo_rxn_index(element, compiler, **kw):
6
+ # expr = list(element.expressions)[0]
7
+ # print(expr)
8
+ # return "CREATE INDEX %s ON %s USING bingo_idx (%s bingo.reaction)" % (
9
+ # element.name,
10
+ # compiler.preparer.format_table(expr.table),
11
+ # compiler.process(expr, include_table=False)
12
+ # )
13
+ class BingoMolIndex(Index):
14
+ def __init__(self, name, mol_column):
15
+ super().__init__(
16
+ name,
17
+ mol_column,
18
+ postgresql_using="bingo_idx",
19
+ postgresql_ops={mol_column: "bingo.molecule"},
20
+ )
21
+
22
+
23
+ class BingoBinaryMolIndex(Index):
24
+ def __init__(self, name, mol_column):
25
+ super().__init__(
26
+ name,
27
+ mol_column,
28
+ postgresql_using="bingo_idx",
29
+ postgresql_ops={mol_column: "bingo.bmolecule"},
30
+ )
@@ -0,0 +1,18 @@
1
+ from sqlalchemy.types import UserDefinedType
2
+ from chemschema.bingo.comparators import BingoMolComparator
3
+
4
+
5
+ class BingoMol(UserDefinedType):
6
+ cache_ok = True
7
+ comparator_factory = BingoMolComparator
8
+
9
+ def get_col_spec(self):
10
+ return "varchar"
11
+
12
+
13
+ class BingoBinaryMol(UserDefinedType):
14
+ cache_ok = True
15
+ comparator_factory = BingoMolComparator
16
+
17
+ def get_col_spec(self):
18
+ return "bytea"
chemschema/py.typed ADDED
File without changes
File without changes
@@ -0,0 +1,6 @@
1
+ from sqlalchemy.types import UserDefinedType
2
+
3
+
4
+ class Mol(UserDefinedType):
5
+ def get_col_spec(self):
6
+ return "mol"
chemschema/utils.py ADDED
@@ -0,0 +1,19 @@
1
+ from sqlalchemy.sql import ColumnElement
2
+ from sqlalchemy.orm import InstrumentedAttribute
3
+ from sqlalchemy.schema import Column
4
+ from typing import Union
5
+
6
+
7
+ def get_column_name(
8
+ mol_column: Union[InstrumentedAttribute, Column, ColumnElement, str],
9
+ ) -> str:
10
+ """Helper to get column name regardless of input type"""
11
+ if hasattr(mol_column, "table"):
12
+ # Handle ORM attributes
13
+ table_name = mol_column.table.name
14
+ column_name = mol_column.name
15
+ return f"{table_name}.{column_name}"
16
+ elif hasattr(mol_column, "name"):
17
+ # Handle Table columns
18
+ return mol_column.name
19
+ return str(mol_column)
@@ -0,0 +1,31 @@
1
+ Metadata-Version: 2.3
2
+ Name: chemschema
3
+ Version: 0.0.1
4
+ Summary: Extensions for SQLAlchemy to work with chemical cartridges
5
+ Keywords: chemistry
6
+ Author: Anton Siomchen
7
+ Author-email: Anton Siomchen <41703271+asiomchen@users.noreply.github.com>
8
+ License: Apache-2.0
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Intended Audience :: Science/Research
11
+ Classifier: License :: OSI Approved :: Apache Software License
12
+ Classifier: Topic :: Scientific/Engineering
13
+ Classifier: Topic :: Utilities
14
+ Classifier: Topic :: Database
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3 :: Only
19
+ Requires-Dist: datamol>=0.12.5
20
+ Requires-Dist: geoalchemy2>=0.18.0
21
+ Requires-Dist: psycopg[binary]>=3.2.9
22
+ Requires-Dist: rdkit>=2025.3.6
23
+ Requires-Dist: sqlalchemy>=2.0.43
24
+ Requires-Python: >=3.10
25
+ Project-URL: homepage, https://github.com/asiomchen/chemschema
26
+ Project-URL: repository, https://github.com/asiomchen/chemschema
27
+ Description-Content-Type: text/markdown
28
+
29
+ # ChemSchema
30
+
31
+ [WIP]
@@ -0,0 +1,14 @@
1
+ chemschema/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ chemschema/base.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ chemschema/bingo/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ chemschema/bingo/comparators.py,sha256=l63YLOD5YyMfVt5AcpsfcJYJWuS70JiWMXqgP3ec26Q,520
5
+ chemschema/bingo/functions.py,sha256=h71bch7lSd_3cuMx5jDtr_pcHOxMoMF3EPOFBIzgCQA,948
6
+ chemschema/bingo/index.py,sha256=91F3mnKNRLL-pjTLvJ7DuywaarNjfcvOn5mNeICm3NQ,919
7
+ chemschema/bingo/types.py,sha256=iXOJ0L4RZjsYytuiG2Mt3tYKyreaVB-69kboNBmjaSQ,415
8
+ chemschema/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
+ chemschema/rdkit/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
+ chemschema/rdkit/types.py,sha256=xHmz5a-Fr5Ne3f-0a9K5hb4EGoIqNXMj8RifTFLPN2o,124
11
+ chemschema/utils.py,sha256=LXBMKv0ZlcOL7dBexW-n257bb8fS6eIaoBZ5latzVoI,642
12
+ chemschema-0.0.1.dist-info/WHEEL,sha256=Pi5uDq5Fdo_Rr-HD5h9BiPn9Et29Y9Sh8NhcJNnFU1c,79
13
+ chemschema-0.0.1.dist-info/METADATA,sha256=WwQI-UZkoqBu9IGKV8h8jhqHeoVjNxDYF4nQvQC376U,1112
14
+ chemschema-0.0.1.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: uv 0.8.17
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any