Skip to content

Commit

Permalink
no temp table for reactions
Browse files Browse the repository at this point in the history
  • Loading branch information
skearnes committed Jul 10, 2024
1 parent 3c79071 commit 681ed80
Showing 1 changed file with 12 additions and 23 deletions.
35 changes: 12 additions & 23 deletions ord_schema/orm/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,35 +117,23 @@ def _update_rdkit_reactions(dataset_id: str, session: Session) -> None:
"""Updates the RDKit reactions table."""
logger.debug("Updating RDKit reactions")
start = time.time()
session.execute(text("CREATE TEMPORARY TABLE temp_reactions (LIKE rdkit.reactions INCLUDING DEFAULTS)"))
result = session.execute(
text(
"""
INSERT INTO temp_reactions (reaction_smiles)
SELECT reaction_smiles
FROM ord.reaction
JOIN ord.dataset ON ord.reaction.dataset_id = ord.dataset.id
WHERE ord.dataset.dataset_id = :dataset_id
AND ord.reaction.rdkit_reaction_id IS NULL
EXCEPT
SELECT reaction_smiles
FROM rdkit.reactions
INSERT INTO rdkit.reactions (reaction_smiles, reaction)
SELECT reaction_smiles, reaction_from_smiles(reaction_smiles::cstring)
FROM (
SELECT reaction_smiles
FROM ord.reaction
JOIN ord.dataset ON ord.reaction.dataset_id = ord.dataset.id
WHERE ord.dataset.dataset_id = :dataset_id
AND ord.reaction.rdkit_reaction_id IS NULL
EXCEPT SELECT reaction_smiles FROM rdkit.reactions
) subquery
"""
),
{"dataset_id": dataset_id},
)
session.execute(text("UPDATE temp_reactions SET reaction = reaction_from_smiles(reaction_smiles::cstring)"))
session.execute(
text(
"""
INSERT INTO rdkit.reactions (reaction_smiles, reaction)
SELECT reaction_smiles, reaction
FROM temp_reactions
ON CONFLICT (reaction_smiles) DO NOTHING
"""
)
)
session.execute(text("DROP TABLE temp_reactions"))
logger.debug(f"Updating reactions took {time.time() - start:g}s ({result.rowcount} rows)")


Expand All @@ -158,7 +146,8 @@ def _update_rdkit_mols(dataset_id: str, session: Session) -> None:
text(
"""
INSERT INTO temp_mols (smiles)
SELECT smiles FROM (
SELECT smiles
FROM (
(
SELECT smiles
-- NOTE(skearnes): This join path does not include non-input compounds like workups,
Expand Down

0 comments on commit 681ed80

Please sign in to comment.