Install rdchiral via pip
masterInstall the standard version of rdchiral from PyPI using pip.
pip install rdchiralrepository·master·Indexed 41 days ago
https://github.com/connorcoley/rdchiralA wrapper for RDKit's RunReactants designed to improve stereochemistry handling during chemical reactions. It provides functions like rdchiralRun and rdchiralRunText for processing SMARTS and SMILES strings, and offers a fast C++ implementation called rdchiral_cpp for improved performance. Requires RDKit >= 2019 and Python >= 3.5.
Install the standard version of rdchiral from PyPI using pip.
pip install rdchiralThe extraction process requires the USPTO reaction database. Follow these steps to download and prepare the data:
data/ directory in your project root.1976_Sep2016_USPTOgrants_smiles.7z archive.1976_Sep2016_USPTOgrants_smiles.rsmi is located inside the data/ folder.Alternatively, you can skip the extraction process by downloading the pre-processed files data/uspto.reactions.json.gz and data/uspto.templates.json.gz directly from ChemRxiv.
$ mkdir data/ && cd data/
$ wget -O 1976_Sep2016_USPTOgrants_smiles.7z https://ndownloader.figshare.com/files/8664379
$ 7z e 1976_Sep2016_USPTOgrants_smiles.7z
$ cd ../To use the Template Extractor, ensure you have the following tools and Python libraries installed on your system:
System Tools:
7z (archive extraction tool)Python Libraries:
rdkitnumpypandasjoblibOnce the data is prepared, run the clean_and_extract_uspto.py script to clean and extract templates from the USPTO reaction database.
Performance Note: The script is designed to use all available CPU cores. On a 32-core machine, the process takes approximately 1 hour.
Outputs:
Running the script generates two compressed JSON files in the data/ directory:
data/uspto.reactions.json.gzdata/uspto.templates.json.gz$ python clean_and_extract_uspto.pyTo use rdchiral, ensure your environment meets the following requirements:
For a ~10x speedup, you can use rdchiral_cpp, which is a fast C++ implementation designed as a drop-in replacement for rdchiral. Install it via conda from the ljn917 channel:
conda install -c conda-forge -c ljn917 rdchiral_cppTo install the most recent version directly from the GitHub repository in editable mode, use the following command:
pip install -e "git://github.com/connorcoley/rdchiral.git#egg=rdchiral"Use rdchiralRun for efficient stereochemical reaction handling. This function is designed to be used with pre-initialized rdchiralReaction and rdchiralReactants objects.
Arguments:
rxn (rdchiralReaction): An object containing the RDKit reaction and auxiliary stereochemical information.reactants (rdchiralReactants): An object containing the RDKit molecule and auxiliary information.keep_mapnums (bool): Whether to keep atom map numbers in the output.combine_enantiomers (bool): Whether to combine enantiomers into a racemic mixture.return_mapped (bool): If True, returns both the list of outcome SMILES and a dictionary mapping SMILES to their atom-mapped versions and changed atoms.Returns:
return_mapped is False: A list of outcome SMILES strings.return_mapped is True: A tuple containing (list_of_outcomes, mapped_outcomes_dict).from rdchiral.initialization import rdchiralReaction, rdchiralReactants
from rdchiral.main import rdchiralRun
# Pre-initialize for efficiency
rxn = rdchiralReaction('[C:1][OH:2]>>[C:1][O:2][C]')
reactants = rdchiralReactants('OCC(=O)OCCCO')
# Run the reaction
outcomes = rdchiralRun(rxn, reactants)
# Run with detailed mapping information
outcomes, mapped_outcomes = rdchiralRun(rxn, reactants, return_mapped=True)Use rdchiralRunText for a quick way to run a reaction using SMARTS and SMILES strings.
Note: This method is not recommended for high-performance library applications because it performs slow initialization every time it is called. For repeated use, you should manually initialize rdchiralReaction and rdchiralReactants objects and use rdchiralRun instead.
Arguments:
reaction_smarts (str): The reaction SMARTS string.reactant_smiles (str): The reactant SMILES string.custom_reactant_mapping (bool): Whether to use a custom reactant mapping.**kwargs: Passed through to rdchiralRun.from rdchiral.main import rdchiralRunText
reaction_smarts = '[C:1][OH:2]>>[C:1][O:2][C]'
reactant_smiles = 'OCC(=O)OCCCO'
outcomes = rdchiralRunText(reaction_smarts, reactant_smiles)
print(outcomes)