FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pgvector-python/examples/rdkit/example.py at rtm-pgvector-python · razi-tm/pgvector-python · GitHub
razi-tm
/
pgvector-python
Public
forked from
pgvector/pgvector-python
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
pgvector-python
/
examples
/
rdkit
/
example.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
32 lines (23 loc) · 1.13 KB
Breadcrumbs
pgvector-python
/
examples
/
rdkit
/
example.py
Copy path
File metadata and controls
32 lines (23 loc) · 1.13 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# good resource
# https://www.rdkit.org/docs/GettingStartedInPython.html#morgan-fingerprints-circular-fingerprints
from
pgvector
.
psycopg
import
register_vector
,
Bit
import
psycopg
from
rdkit
import
Chem
from
rdkit
.
Chem
import
AllChem
def
generate_fingerprint
(
molecule
):
fpgen
=
AllChem
.
GetMorganGenerator
()
return
fpgen
.
GetFingerprintAsNumPy
(
Chem
.
MolFromSmiles
(
molecule
))
conn
=
psycopg
.
connect
(
dbname
=
'pgvector_example'
,
autocommit
=
True
)
conn
.
execute
(
'CREATE EXTENSION IF NOT EXISTS vector'
)
register_vector
(
conn
)
conn
.
execute
(
'DROP TABLE IF EXISTS molecules'
)
conn
.
execute
(
'CREATE TABLE molecules (id text PRIMARY KEY, fingerprint bit(2048))'
)
molecules
=
[
'Cc1ccccc1'
,
'Cc1ncccc1'
,
'c1ccccn1'
]
for
molecule
in
molecules
:
fingerprint
=
generate_fingerprint
(
molecule
)
conn
.
execute
(
'INSERT INTO molecules (id, fingerprint) VALUES (%s, %s)'
, (
molecule
,
Bit
(
fingerprint
)))
query_molecule
=
'c1ccco1'
query_fingerprint
=
generate_fingerprint
(
query_molecule
)
result
=
conn
.
execute
(
'SELECT id, fingerprint <%%> %s AS distance FROM molecules ORDER BY distance LIMIT 5'
, (
Bit
(
query_fingerprint
),)).
fetchall
()
for
row
in
result
:
print
(
row
)
Back
|
FazBrowse Home
|
New Git URL