S SmartDocs
シリーズ: AI for Chemistry python 16 行 · 更新日 2026-02-11

rdkit_mol.py

AI for Chemistry/code/chemprop_VP-main (1)/chemprop_VP-main/chemprop/rdkit_mol.py

from rdkit import Chem

def make_mol(s: str, keep_h: bool):
    """
    Builds an RDKit molecule from a SMILES string.
    
    :param s: SMILES string.
    :param keep_h: Boolean whether to keep hydrogens in the input smiles. This does not add hydrogens, it only keeps them if they are specified.
    :return: RDKit molecule.
    """
    if keep_h:
        mol = Chem.MolFromSmiles(s, sanitize = False)
        Chem.SanitizeMol(mol, sanitizeOps = Chem.SanitizeFlags.SANITIZE_ALL^Chem.SanitizeFlags.SANITIZE_ADJUSTHS)
    else:
        mol = Chem.MolFromSmiles(s)
    return mol

関連記事