Skip to content

Complete

API

rdworks.complete

Complete stereoisomers and tautomers as rdworks.MolLibr libraries.

These functions build rdworks.Mol and rdworks.MolLibr objects, so they live above rdworks.mol and rdworks.mollibr in the import hierarchy and import them at module level. The RDKit-level helpers they use stay in rdworks.stereoisomers and rdworks.tautomers, which rdworks.mol and rdworks.microstate import.

rdworks.stereoisomers.complete_stereoisomers and rdworks.tautomers.complete_tautomers remain available as aliases.

Classes

Functions:

complete_stereoisomers(molecular_input, name=None, std=False, override=False, **kwargs)

Completes stereoisomers and returns a rdworks.MolLibr.

Small rings (< 8 atoms): RDKit does NOT enumerate E/Z stereochemistry for double bonds because the ring constraints make one configuration impossible

Macrocycles (≥ 8 atoms): RDKit CAN enumerate E/Z stereochemistry for double bonds since both configurations are geometrically feasible

Parameters:

  • molecular_input (Union[Mol, str, Mol]) –

    input molecule.

  • name (Optional[str], default: None ) –

    name of the molecule. Defaults to None.

  • std (bool, default: False ) –

    whether to standardize the input. Only applies to SMILES or rdkit.Chem.Mol input. Defaults to False.

  • override (bool, default: False ) –

    whether to override input stereoisomers. Defaults to False.

  • **kwargs (Any, default: {} ) –

    additional keyword arguments passed to MolLibr.compute().

Raises:

  • TypeError –

    if molecular_input is not rdworks.Mol, SMILES, or rdkit.Chem.Mol object.

Returns:

  • MolLibr ( MolLibr ) –

    a library of complete stereoisomers.

complete_tautomers(mol, **kwargs)

Returns a library of enumerated tautomers.

Parameters:

  • mol (Mol) –

    input molecule.

Returns:

  • MolLibr ( MolLibr ) –

    a library of enumerated tautomers.

rdworks.stereoisomers

Functions:

can_have_stereo(bond)

Check if a double bond can have E/Z stereochemistry.

Uses RDKit's stereo perception, which correctly handles implicit H, lone pairs (e.g. imines C=N-R), identical substituents, and small-ring double bonds.

correct_wedged_bonds(rdmol)

Corrects wedged bonds for chiral centers. Args: rdmol (Chem.Mol): input molecule.

  1. Clear all stereochemistry information
  2. Identify chiral centers and non-chiral atoms/bonds
  3. Reassign stereochemistry only where appropriate
  4. Return the modified molecule

enumerate_ring_bond_stereoisomers(rdmol, ring_bond_stereo_info, override=False)

Enumerates unspecified double bond stereochemistry (cis/trans).

Small rings (< 8 atoms): RDKit does NOT enumerate E/Z stereochemistry for double bonds because the ring constraints make one configuration impossible

Macrocycles (≥ 8 atoms): RDKit CAN enumerate E/Z stereochemistry for double bonds since both configurations are geometrically feasible

Parameters:

  • rdmol (Mol) –

    input molecule.

  • ring_bond_stereo_info (List[Tuple]) –

    ring_bond_stereo_info will be set when .remove_stereo() is called. bond_stereo_info = [(bond_idx, bond_stereo_descriptor), ..] where bond_stereo_descriptor is Chem.StereoDescriptor.Bond_Cis or Chem.StereoDescriptor.Bond_Trans, or Chem.StereoDescriptor.NoValue.

  • override (bool, default: False ) –

    description. Defaults to False.

Returns:

  • list[Mol] –

    List[Chem.Mol]: list of enumerated stereoisomers.

enumerate_stereoisomers(rdmol)

Returns enumerated stereoisomers.

Parameters:

  • rdmol (Mol) –

    input molecule.

Returns:

  • list[Mol] –

    List[Chem.Mol]: a list of enumerated stereoisomers.

rdworks.tautomers

Reference:

D. K. Dhaked, W.-D. Ihlenfeldt, H. Patel, V. Delannée, M. C. Nicklaus, Toward a Comprehensive Treatment of Tautomerism in Chemoinformatics Including in InChI V2. J. Chem. Inf. Model. (2020). https://doi.org/10.1021/acs.jcim.9b01080.

https://github.com/xundrug/moltaut

Attributes

logger = logging.getLogger(__name__) module-attribute

Classes

ComprehensiveTautomers

Comprehensive tautomer enumeration based on MolTaut implementation D. K. Dhaked, W.-D. Ihlenfeldt, H. Patel, V. Delannée, M. C. Nicklaus, Toward a Comprehensive Treatment of Tautomerism in Chemoinformatics Including in InChI V2. J. Chem. Inf. Model. (2020). https://doi.org/10.1021/acs.jcim.9b01080.

Attributes
device = None instance-attribute
dict = {'self': [self.smiles]} instance-attribute
enumerated = [] instance-attribute
forbidden = ['O=[N+]([O-])'] class-attribute instance-attribute
forbidden_patterns = [Chem.MolFromSmarts(_) for _ in forbidden] class-attribute instance-attribute
imodel = None instance-attribute
microstates = [] instance-attribute
nmodel = None instance-attribute
num_confs = None instance-attribute
optimizer = None instance-attribute
ordered = [] instance-attribute
popular = [] instance-attribute
ps = Chem.SmilesParserParams() class-attribute instance-attribute
rdmol = Chem.MolFromSmiles(smiles) instance-attribute
revdict = defaultdict(list) instance-attribute
smiles = smiles instance-attribute
smirks = [line.strip().split('\t') for line in contents] instance-attribute
states = [] instance-attribute
uncharger = rdMolStandardize.Uncharger() class-attribute instance-attribute
Methods:
enumerate()

RdkTautomers

RDKit built-in tautomer enumeration

M. Sitzmann, W.-D. Ihlenfeldt, M. C. Nicklaus, Tautomerism in large databases. J. Comput. Aided Mol. Des. 24, 521-551 (2010).

Attributes
enumerator = rdMolStandardize.TautomerEnumerator() instance-attribute
rdmol = Chem.MolFromSmiles(smiles) instance-attribute
smiles = smiles instance-attribute
Methods:
canonicalize()
enumerate()

rdworks.std

Functions:

clean_2d(rdmol, reset_isotope=True, remove_H=True)

Clean molecule for 2D depiction.

Parameters:

  • rdmol (Mol) –

    molecule (not to be modified)

  • reset_isotope (bool, default: True ) –

    whether to reset isotope information. Defaults to True.

  • remove_H (bool, default: True ) –

    whether to remove explicit hydrogens. Defaults to True.

Returns:

  • Mol –

    (cleaned 2D copy of molecule, list of Chem.Mol each holding one 3D conformer

  • list[Mol] –

    of the input molecule with its original atoms, ready for Conf()).

  • tuple[Mol, list[Mol]] –

    3D conformers are returned only if all hydrogens are explicit, as Conf()

  • tuple[Mol, list[Mol]] –

    requires; 2D conformers and 3D input without hydrogens yield an empty list.

desalt_smiles(smiles)

Remove salt(s) from SMILES by keeping the largest fragment.

The whole SMILES is parsed first, so ring-closure bonds across . (e.g. C1.C1) are handled correctly, and the returned SMILES is canonical, i.e. identical to the SMILES of the same molecule given without salts.

Parameters:

  • smiles (str) –

    SMILES.

Raises:

  • ValueError –

    if smiles is invalid.

Returns:

  • tuple[str, Mol] –

    (desalted canonical SMILES, desalted Chem.Mol)

generate_inchi_key(rdmol)

Generate InChIKey.

Note
  • An InChIKey is a 27-character string consisting of three parts:
    • 14 characters: Derived from the connectivity layer of the InChI.
    • Hyphen (-): Separates the first two blocks.
    • 9 characters: Derived from the remaining InChI layers.
    • A hyphen (-): Separates the second and third blocks.
    • A final checksum character: Ensures the integrity of the key.

Parameters:

  • rdmol (Mol) –

    input molecule

Returns:

  • str ( str ) –

    27-character InChIKey, or an empty string if InChI cannot be generated (e.g. molecules with dummy atoms *).

neutralize_atoms(rdmol)

Neutralizes atoms.

It is adapted from Noel O'Boyle's nocharge code: rdkit cookbook, no charge. It is a neutralization by atom approach and neutralizes atoms with a +1 or -1 charge by removing or adding hydrogen where possible. The SMARTS pattern checks for a hydrogen in +1 charged atoms and checks for no neighbors with a negative charge (for +1 atoms) and no neighbors with a positive charge (for -1 atoms), this is to avoid altering molecules with charge separation (e.g., nitro groups).

The neutralize_atoms() function differs from the rdMolStandardize.Uncharger behavior. See the MolVS documentation for Uncharger.

This class uncharges molecules by adding and/or removing hydrogens. In cases where there is a positive charge that is not neutralizable, any corresponding negative charge is also preserved. As an example, rdMolStandardize.Uncharger will not change charges on CN+(C)CCC([O-])=O, as there is a positive charge that is not neutralizable. In contrast, the neutralize_atoms() function will attempt to neutralize any atoms it can (in this case to CN+(C)CCC(=O)O). That is, neutralize_atoms() ignores the overall charge on the molecule, and attempts to neutralize charges even if the neutralization introduces an overall formal charge on the molecule.

Parameters:

  • rdmol (Mol) –

    molecule (not to be modified).

Returns:

  • Mol –

    Chem.Mol: neutralized copy of molecule.

standardize(rdmol)

Returns standardized rdkit.Chem.Mol object.

Parameters:

  • rdmol (str | Mol) –

    input SMILES string or molecule (not modified).

Raises:

  • TypeError –

    if rdmol is neither a SMILES string nor a Chem.Mol.

  • ValueError –

    if rdmol is an invalid SMILES.

Returns:

  • Mol –

    Chem.Mol: standardized rdkit.Chem.Mol object.

standardize_smiles(smiles)

Returns standardized SMILES string.

The rdMolStandardize.StandardizeSmiles() function performs the following steps:

  1. mol = Chem.MolFromSmiles(sm)
  2. Chem.SanitizeMol(mol)
  3. mol = Chem.RemoveHs(mol)
  4. mol = rdMolStandardize.MetalDisconnector().Disconnect(mol)
  5. mol = rdMolStandardize.Normalize(mol)
  6. mol = rdMolStandardize.Reionize(mol)
  7. Chem.AssignStereochemistry(mol, force=True, cleanIt=True)
  8. Chem.MolToSmiles(mol)

See rdkit notebook and greg's notebook, and youtube video.

Parameters:

  • smiles (str) –

    input SMILES string.

Returns:

  • str ( str ) –

    standardized SMILES string.