rdtools.conversion.smiles#

Conversion functions for SMILES strings and RDKit molecules.

rdtools.conversion.smiles.get_smiles_parser_params(remove_hs: bool = True, sanitize: bool = True, allow_cxsmiles: bool = False) SmilesParserParams#

Get the parameters for the RDKit SMILES parser.

Parameters:
  • remove_hs (bool, optional) – Whether to remove hydrogen atoms from the molecule. Defaults to True.

  • sanitize (bool, optional) – Whether to sanitize the RDKit molecule. Defaults to True.

  • allow_cxsmiles (bool, optional) – Whether to recognize and parse CXSMILES. Defaults to False.

Returns:

Chem.SmilesParserParams – The parameters for the RDKit SMILES parser.

rdtools.conversion.smiles.mol_from_smiles(smiles: str, remove_hs: bool = False, add_hs: bool = True, sanitize: bool = True, allow_cxsmiles: bool = True, keep_atom_map: bool = True, assign_atom_map: bool = True, atom_order: str = 'atom_map') Mol#

Convert a SMILES string to an Chem.Mol molecule object.

Parameters:
  • smiles (str) – A SMILES representation of the molecule.

  • remove_hs (bool, optional) – Whether to remove hydrogen atoms from the molecule, True to remove.

  • add_hs (bool, optional) – Whether to add explicit hydrogen atoms to the molecule. True to add. Only functioning when removeHs is False.

  • sanitize (bool, optional) – Whether to sanitize the RDKit molecule, True to sanitize.

  • allow_cxsmiles (bool, optional) – Whether to recognize and parse CXSMILES. Defaults to True.

  • keep_atom_map (bool, optional) – Whether to keep the atom mapping contained in the SMILES. Defaults Defaults to True.

  • assign_atom_map (bool, optional) – Whether to assign the atom mapping according to the atom index if no atom mapping available in the SMILES. Defaults to True.

  • atom_order (str, optional) – Whether the atom order in the returned molecule (indexes) is according to atom map (“atom_map”) or FIFO (RDKit’s default, “fifo”). Defaults to “atom_map”.

Returns:

Chem.Mol – An RDKit molecule object corresponding to the SMILES.

rdtools.conversion.smiles.mol_to_smiles(mol: Mol, stereo: bool = True, kekule: bool = False, canonical: bool = True, remove_atom_map: bool = True, remove_hs: bool = True) str#

Convert an RDKit molecule object to a SMILES string.

Parameters:
  • mol (Chem.Mol) – An RDKit molecule object.

  • stereo (bool, optional) – Whether to include stereochemistry information in the SMILES. Defaults to True.

  • kekule (bool, optional) – Whether to use Kekule encoding. Defaults to False.

  • canonical (bool, optional) – Whether to use canonical SMILES. Defaults to True.

  • remove_atom_map (bool, optional) – Whether to keep the Atom mapping contained in the SMILES. Defaults Defaults to True.

  • remove_hs (bool, optional) – Whether to remove hydrogen atoms from the molecule. Defaults to True.

Returns:

str – A SMILES string corresponding to the RDKit molecule object.

rdtools.conversion.smiles.process_mol_from_smiles(mol: Mol, remove_hs: bool = True, add_hs: bool = True) Mol#

A helper function processing molecules generated from MolFromSmiles.

Parameters:
  • mol (Chem.Mol) – The RDKit Mol/RWMol object to be processed.

  • remove_hs (bool, optional) – Whether to remove hydrogen atoms from the molecule. Defaults to True.

  • add_hs (bool, optional) – Whether to add explicit hydrogen atoms to the molecule. Defaults to True. Only functioning when removeHs is False.

Returns:

Chem.Mol – The processed RDKit Mol/RWMol object.

Raises:

ValueError – If the provided SMILES is not valid or if there is an error in processing.