python-3.xrdkitcheminformatics

rdkit.Chem.rdForceFieldHelpers.UFFOptimizeMolecule(int) did not match C++ signature


Context

I need to convert SMILES to 3D SDF. If I only use Chem.MolFromSmiles, it outputs 2D SDF successfully.

My code is that:

df.loc[ind, 'ROMol'] = Chem.MolFromSmiles(row[args.smi_column])
df.loc[ind, 'Mol_H'] = Chem.AddHs(df.loc[ind, 'ROMol'])
df.loc[ind, 'Mol_H'] = AllChem.EmbedMolecule(df.loc[ind, 'Mol_H'])
df.loc[ind, 'Mol_H'] = AllChem.UFFOptimizeMolecule(df.loc[ind, 'Mol_H'])

My RDKit version:

rdkit                     2024.03.5        py39hc1ff0a3_1    conda-forge

Problem

With smiles CCCS, the error is:

 df.loc[ind, 'Mol_H'] = AllChem.UFFOptimizeMolecule(df.loc[ind, 'Mol_H'])
Boost.Python.ArgumentError: Python argument types in
    rdkit.Chem.rdForceFieldHelpers.UFFOptimizeMolecule(int)
did not match C++ signature:
    UFFOptimizeMolecule(RDKit::ROMol {lvalue} self, int maxIters=200, double vdwThresh=10.0, int confId=-1, bool ignoreInterfragInteractions=True)

Output of AllChem.EmbedMolecule(df.loc[ind, 'Mol_H']) for CCCS is 0, which means that we can skip this error.

Additional context

I tried some solutions in these refs: Change to OptimizeMoleculeConfs()


Solution

  • I found that I have not to re-assign AllChem.EmbedMolecule to the object, just call it:

    AllChem.EmbedMolecule(mol) 
    AllChem.UFFOptimizeMolecule(mol) 
    df.loc[ind, 'Mol_H'] = mol
    

    Besides, you should check whether AllChem.EmbedMolecule return a value > 0 or not. If not, it can cause a new error in AllChem.UFFOptimizeMolecule.

    The problem is solved.