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
- Create or activate a virtual environment.
- Clone the repository.
- 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.
Metadata
Release files for rdcanon 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| rdcanon-0.1.2.tar.gz | 7.7 MB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| rdcanon-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.9 MB
Release files / rdcanon-0.1.2.tar.gz
| Download URL | rdcanon-0.1.2.tar.gz |
|---|---|
| Size | 7.7 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3678387096c9e93db05446d894999ddf31208a8612bafd6bcf1ca1796aa03fdb
|
|
BLAKE2b-256 checksum How to use checksums |
65b31c66143c29523c5d7e700df8aeb7c4d55bd7ebcad69b1cde3730778b8e01
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.0
|
Release files / rdcanon-0.1.2-py3-none-any.whl
| Download URL | rdcanon-0.1.2-py3-none-any.whl |
|---|---|
| Size | 4.2 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
325df97acfa4d975347b0e9d154eca76efee3ded9703d97594a53056370d4543
|
|
BLAKE2b-256 checksum How to use checksums |
7b19b4a16baf0773d0ecb93bc4a0c74430532246d8524ae76316bc44db8810db
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.0
|
Security for rdcanon 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.