Skip to main content

SMARTS Sanitization/Canonicalization

Project description

rdcanon - SMARTS and Reaction SMARTS Canonicalization

Overview

rdcanon is a package designed for canonicalizing SMARTS and Reaction SMARTS templates. It reorders SMARTS to optimize querying speed. This optimization is invariant of atom mapping.

Installation

Prerequisites

  • Ensure you have rdkit installed (version > 2023.9.2).
  • The following packages will be installed: 'rdkit > 2023.09.1', 'matplotlib', 'lark', 'numpy', 'networkx', 'scikit-learn', (optional, for kde generation) 'ipykernel', 'pandas', 'openpyxl'

Steps

  1. Create or activate a virtual environment.
  2. Clone the repository.
  3. Install the package with the command:

pip install -e rdcanon

Usage

Sanitizing Individual SMARTS

To sanitize individual SMARTS:

from rdcanon import canon_smarts 

test_smarts = [
 "[$([NX3H,NX4H2+]),$([NX3](C)(C)(C))]1[CX4H]([CH2][CH2][CH2]1)[CX3](=[OX1])[OX2H,OX1-,N]",
 "[$([NX3H2,NX4H3+]),$([NX3H](C)(C))][CX4H]([*])[CX3](=[OX1])[OX2H,OX1-,N]",
 "[CX3](=O)[OX1H0-,OX2H1]",
 "[CX3](=[OX1])[OX2][CX3](=[OX1])",
 "[N&H2&+0:4]-[C&H1&+0:2](-[C&H2&+0:8])-[O&H1&+0:3]"
]

# The second parameter is optional and flags whether atom mapping should be returned (defaults to False)
for smarts in test_smarts:
 print(smarts, canon_smarts(smarts), canon_smarts(smarts, True))

Sanitizing Reaction SMARTS

For sanitizing reaction SMARTS:

from rdcanon import canon_reaction_smarts

Unit Testing

To run all unit tests:

python rdcanon_tests.py

note: currently, "TestRecursive.test_validate_recursive_against_database" is expected to fail at: "[#1]C&X3=[O&X1] [#1,#6][C&X3;H1,H2]=[O&X1]". This is due to a strange edge case with merging query Hs, explicit hydrogens, and explicit/implicit connections.

Current Limitations

No consolidation or expansion of atomic queries is performed automatically, but a mechanism is provided to allow the user to systematically replace canonicalized atomic queries with an input dictionary (e.g., {"[O;H1]": "[O;H1;+0]"} would replace the canonicalized variant of [O;H1] with the canonicalized variant of [O;H1;+0]).

Replacement dictionaries should be processed first using

canon_repl_dict = gen_canon_repl_dict(repl_dict)

before passing as an argument into canon_smarts.

Chirality or directionality beyond tetrahedral centers and cis/trans isomerism is not currently supported.

Manuscript Figures and Tests

All data can be found in the manuscripts/data directory.

To create the bar charts of Figure 1, use the notebook within the manuscript directory named "prim_frequencies.ipynb".

To run the subgraph isomorphism experiments of Figure 3, use the notebook within the manuscript directory named "generate_plots_substruct_match.ipynb".

To run the template application experiments of Figure 4, use the notebook within the manuscript directory named "gen_plots_run_reactants_20240104.ipynb".

To run the retrosynthetic analysis experiments of Figure 5, use the notebook within the manuscript directory named "gen_retrosim_plots_20240105.ipynb".

RDCanon Files

The main workflow consists of two files, main.py and token_parser.py. The main.py file calls token_parser.py to parse and score atomic queries.

The files askcos_prims.py, drugbank_prims_with_nots.py, np_prims.py, and pubchem_prims.py are 4 query primitive frequency dictonaries, which are used for embedding leaf nodes in query trees.

The rdcanon_tests.py file contains all of the test cases using the abseil interface.

Finally, utils.py contains some helper functions for testing and plotting.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rdcanon-0.1.2.tar.gz (7.7 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rdcanon-0.1.2-py3-none-any.whl (4.2 MB view details)

Uploaded Python 3

File details

Details for the file rdcanon-0.1.2.tar.gz.

File metadata

  • Download URL: rdcanon-0.1.2.tar.gz
  • Upload date:
  • Size: 7.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.0

File hashes

Hashes for rdcanon-0.1.2.tar.gz
Algorithm Hash digest
SHA256 3678387096c9e93db05446d894999ddf31208a8612bafd6bcf1ca1796aa03fdb
MD5 b17ee43d869f6b06844aa2fad791d257
BLAKE2b-256 65b31c66143c29523c5d7e700df8aeb7c4d55bd7ebcad69b1cde3730778b8e01

See more details on using hashes here.

File details

Details for the file rdcanon-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: rdcanon-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 4.2 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.0

File hashes

Hashes for rdcanon-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 325df97acfa4d975347b0e9d154eca76efee3ded9703d97594a53056370d4543
MD5 4624863300a763cb99522562d46b5ab6
BLAKE2b-256 7b19b4a16baf0773d0ecb93bc4a0c74430532246d8524ae76316bc44db8810db

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page