Source code for boltz_data.rdkit._from_smiles
"""Convert SMILES strings to RDKit molecules."""
from rdkit import Chem
from rdkit.Chem import Mol
[docs]
def rdmol_from_smiles(smiles: str, /) -> Mol:
"""
Parse a SMILES string into an RDKit molecule.
Args:
smiles: A valid SMILES string representing the molecule.
Returns:
An RDKit Mol object.
Raises:
ValueError: If the SMILES string is invalid or cannot be parsed.
Example:
>>> mol = rdmol_from_smiles("CCO") # Ethanol
>>> mol.GetNumAtoms()
3 # Without hydrogens
"""
rdmol = Chem.MolFromSmiles(smiles)
if rdmol is None:
msg = f"Invalid SMILES string: {smiles}"
raise ValueError(msg)
return rdmol