API Reference
rdchiral
rdchiralReactants
Bases: object
Class to store everything that should be pre-computed for a reactant mol so that library application is faster
Attributes:
| Name | Type | Description |
|---|---|---|
reactant_smiles |
str
|
Reactant SMILES string |
reactants |
Mol
|
RDKit Molecule created from |
atoms_r |
dict
|
Dictionary mapping from atom map number to atom in |
reactants_achiral |
Mol
|
achiral version of |
bonds_by_mapnum |
list
|
List of reactant bonds as (int, int, rdkit.Chem.rdchem.Bond) tuples keyed by atom-map numbers |
bond_dirs_by_mapnum |
dict
|
Dictionary mapping from atom map number tuples to BondDir |
atoms_across_double_bonds |
list
|
List of cis/trans specifications from |
Methods:
| Name | Description |
|---|---|
idx_to_mapnum |
Return atom map number for given atom idx |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reactant_smiles
|
str
|
Reactant SMILES string |
required |
custom_reactant_mapping
|
bool
|
Whether to use custom reactant mapping |
False
|
lazy_init
|
bool
|
If True, delay initialization of reactants until accessed |
True
|
enumerate_tautomers
|
bool
|
Whether to enumerate tautomers (currently unused) |
False
|
Source code in rdchiral/initialization.py
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 | |
rdchiralReaction
Bases: object
Class to store everything that should be pre-computed for a reaction. This makes library application much faster, since we can pre-do a lot of work instead of doing it for every mol-template pair
Attributes:
| Name | Type | Description |
|---|---|---|
reaction_smarts |
str
|
Reaction SMARTS string |
rxn |
ChemicalReaction
|
RDKit reaction object.
Generated lazily from |
template_r |
Mol
|
Reaction reactant template fragments |
template_p |
Mol
|
Reaction product template fragments |
atoms_rt_map |
dict
|
Dictionary mapping from atom map number to RDKit Atom for reactants |
atoms_pt_map |
dict
|
Dictionary mapping from atom map number to RDKit Atom for products |
atoms_rt_idx_to_map |
dict
|
Dictionary mapping from atom idx to atom map number for reactants |
atoms_pt_idx_to_map |
dict
|
Dictionary mapping from atom idx to atom map number for products |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reaction_smarts
|
str
|
Reaction SMARTS string |
required |
lazy_init
|
bool
|
If True, delay initialization of the reaction object and template fragments until first accessed. Defaults to True. |
True
|
Source code in rdchiral/initialization.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 | |
reset()
Restore template fragment atom-map numbers to their original values.
Iterates over template_r and template_p atoms and resets each
atom's map number to the value recorded in atoms_rt_idx_to_map /
atoms_pt_idx_to_map during initialization. This is an in-place
operation — no molecular graph copy is made.
Note
This method must be called between reaction applications when
reusing the same rdchiralReaction object, because
assign_outcome_atom_mapnums and assign_pt_mapnums mutate
template atom map numbers in-place.
Source code in rdchiral/initialization.py
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 | |
extract_from_reaction(reaction, no_special_groups=False, radius=1, use_stereochemistry=True, canonicalize_template=True, maximum_number_unmapped_product_atoms=5, include_all_unmapped_reactant_atoms=True)
Extract a retrosynthetic reaction template from a mapped chemical reaction.
This function analyzes a chemical reaction with atom-mapped reactants and products to identify the reaction center and extract a template representing the transformation. The template captures the local environment around atoms that change during the reaction, including bonds formed, broken, or modified.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reaction
|
rdChiralTemplateExtractInput
|
Dictionary containing the reaction data with keys 'reactants' (SMILES string), 'products' (SMILES string), and '_id' (optional reaction identifier). |
required |
no_special_groups
|
bool
|
If True, disable special functional group handling during fragment extraction. Defaults to False. |
False
|
radius
|
int
|
Number of bonds to expand around changed atoms when extracting fragments. A larger radius captures more context. Defaults to 1. |
1
|
use_stereochemistry
|
bool
|
If True, include stereochemical information in the extracted template. Defaults to True. |
True
|
canonicalize_template
|
bool
|
If True, canonicalize the reaction SMARTS string for consistent representation. Defaults to True. |
True
|
maximum_number_unmapped_product_atoms
|
int
|
Maximum allowed number of unmapped atoms in the products. Reactions exceeding this limit are skipped. Defaults to 5. |
5
|
include_all_unmapped_reactant_atoms
|
bool
|
If True, include all unmapped reactant atoms in the template, not just those near the reaction center. Defaults to True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
ExtractedTemplate |
ExtractedTemplate
|
A dictionary containing the extracted template with the following keys: - 'products': Product fragment SMARTS string - 'reactants': Reactant fragment SMARTS string - 'spectators': SMILES string of spectator molecules (reactants not participating in the reaction) - 'reaction_smarts': Complete retrosynthetic reaction SMARTS (products>>reactants) - 'separated_reaction_smarts': List of individual reaction SMARTS components - 'intra_only': Boolean indicating if the reaction is intramolecular - 'dimer_only': Boolean indicating if the reaction involves dimerization - 'reaction_id': The reaction identifier from the input - 'necessary_reagent': SMILES fragment for unmapped product atoms that must be supplied as reagents |
Raises:
| Type | Description |
|---|---|
ValueError
|
Propagated from get_fragments_for_changed_atoms if fragment extraction fails (caught internally and returns default template). |
Note
This function returns a default empty template (with empty strings and False flags) if any of the following conditions occur: - RDKit fails to parse reactants or products - The number of unmapped product atoms exceeds the maximum threshold - No reactant atoms are mapped to product atoms - Molecule sanitization fails - No atoms change between reactants and products - The extracted reaction SMARTS fails RDKit validation The returned template uses retro-synthetic direction (products>>reactants).
Source code in rdchiral/template_extractor.py
1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 | |
extract_from_reaction_smiles(rxn_smiles, no_special_groups=False, radius=1, use_stereochemistry=True, canonicalize_template=True, maximum_number_unmapped_product_atoms=5, include_all_unmapped_reactant_atoms=True, reaction_id=None)
Extract a retrosynthetic reaction template from a reaction SMILES string.
This function parses a reaction SMILES string and extracts a template representing the chemical transformation. It is a convenience wrapper around extract_from_reaction that handles the SMILES parsing and delegates to the core extraction logic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rxn_smiles
|
str
|
Reaction SMILES string in the format "reactants>>products". The reactants and products should have atom mapping numbers for template extraction to work correctly. |
required |
no_special_groups
|
bool
|
If True, disable special functional group handling during fragment extraction. Defaults to False. |
False
|
radius
|
int
|
Number of bonds to expand around changed atoms when extracting fragments. A larger radius captures more context. Defaults to 1. |
1
|
use_stereochemistry
|
bool
|
If True, include stereochemical information in the extracted template. Defaults to True. |
True
|
canonicalize_template
|
bool
|
If True, canonicalize the reaction SMARTS string for consistent representation. Defaults to True. |
True
|
maximum_number_unmapped_product_atoms
|
int
|
Maximum allowed number of unmapped atoms in the products. Reactions exceeding this limit are skipped. Defaults to 5. |
5
|
include_all_unmapped_reactant_atoms
|
bool
|
If True, include all unmapped reactant atoms in the template, not just those near the reaction center. Defaults to True. |
True
|
reaction_id
|
Optional[str | int]
|
Optional identifier for the reaction. This will be included in the returned template. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
ExtractedTemplate |
ExtractedTemplate
|
A dictionary containing the extracted template with the following keys: - 'products': Product fragment SMARTS string - 'reactants': Reactant fragment SMARTS string - 'spectators': SMILES string of spectator molecules (reactants not participating in the reaction) - 'reaction_smarts': Complete retrosynthetic reaction SMARTS (products>>reactants) - 'separated_reaction_smarts': List of individual reaction SMARTS components - 'intra_only': Boolean indicating if the reaction is intramolecular - 'dimer_only': Boolean indicating if the reaction involves dimerization - 'reaction_id': The reaction identifier from the input - 'necessary_reagent': SMILES fragment for unmapped product atoms that must be supplied as reagents |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the reaction SMILES does not contain exactly one '>>' separator. |
Source code in rdchiral/template_extractor.py
1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 | |
rdchiralRun(rxn, reactants, keep_mapnums=False, combine_enantiomers=True, return_mapped=False, skip_reset=False, max_depth=1, max_products=100)
Iteratively apply an rdchiral reaction template to reactants across multiple depth levels.
At each depth level, the products from the previous iteration are used as reactants for the next iteration. This enables multi-step reaction prediction where products can undergo further transformations defined by the same reaction template.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rxn
|
rdchiralReaction
|
The reaction template to apply. |
required |
reactants
|
rdchiralReactants
|
The initial reactants to start the iteration. |
required |
keep_mapnums
|
bool
|
If True, preserve atom map numbers in the output SMILES. |
False
|
combine_enantiomers
|
bool
|
If True, combine enantiomeric outcomes into their achiral racemic equivalents, removing the individual enantiomers. If False, enantiomers are retained and their achiral racemic forms are also appended to the results. |
True
|
return_mapped
|
bool
|
If True, return a mapping between mapped and unmapped SMILES along with atom change information. |
False
|
skip_reset
|
bool
|
If True, skip resetting the reaction object state. Ignored if max_depth > 1, as reset is forced for multi-depth iterations. |
False
|
max_depth
|
int
|
Maximum number of iterative depth levels to explore (default: 1). |
1
|
max_products
|
int
|
Maximum number of products to return (default: 100). |
100
|
Returns:
| Type | Description |
|---|---|
Union[List[str], Tuple[List[str], Dict[str, Tuple[str, Tuple[int, ...]]]]]
|
Union[List[str], Tuple[List[str], Dict[str, Tuple[str, Tuple[int, ...]]]]]: - If return_mapped is False: A list of product SMILES strings. - If return_mapped is True: A tuple containing: - List of product SMILES strings - Dictionary mapping SMILES to a tuple of (mapped_smiles, flattened_changes) where flattened_changes contains all atom indices that changed across all depth levels. |
Note
When max_depth > 1, skip_reset is automatically set to False to ensure correct reaction state between iterations. Products already seen at any depth are skipped to avoid duplicate processing and infinite loops.
Source code in rdchiral/main.py
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 | |
rdchiralRunText(reaction_smarts, reactant_smiles, custom_reactant_mapping=False, keep_mapnums=False, combine_enantiomers=True, return_mapped=False, max_depth=1, max_products=100)
Run a reaction by constructing rdchiralReaction and rdchiralReactants from text inputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reaction_smarts
|
str
|
Reaction SMARTS string used to initialize |
required |
reactant_smiles
|
str
|
Reactant SMILES string used to initialize |
required |
custom_reactant_mapping
|
bool
|
If True, assume the input reactants already contain an atom-mapping that should be preserved/used. |
False
|
keep_mapnums
|
bool
|
If True, preserve atom map numbers in returned product SMILES. |
False
|
combine_enantiomers
|
bool
|
If True, combine enantiomeric outcomes into their achiral racemic equivalents, removing the individual enantiomers. If False, enantiomers are retained and their achiral racemic forms are also appended to the results. |
True
|
return_mapped
|
bool
|
If True, also return per-outcome atom-mapped information. |
False
|
max_depth
|
int
|
Maximum number of iterative depth levels to explore (default: 1). |
1
|
max_products
|
int
|
Maximum number of products to return (default: 100). |
100
|
Returns:
| Type | Description |
|---|---|
Union[List[str], Tuple[List[str], Dict[str, Tuple[str, Tuple[int, ...]]]]]
|
Union[List[str], Tuple[List[str], Dict[str, Tuple[str, Tuple[int, ...]]]]]:
- If |
Note
This helper is convenient for one-off use but is not recommended for batch/library
workflows because template/reactant initialization is relatively expensive. For
repeated application, construct rdchiralReaction and rdchiralReactants once and
call rdchiralRun directly.
Source code in rdchiral/main.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | |