Can someone tell why Chem.MolFromSmiles is not converting list of SMILES into mol objects in RDKit?

Viewed 89

''' mol_object_list = []

for mol in str_smiles:

Chem.MolFromSmiles(mol)

mol_object_list.append(mol)

''' ''' TypeError: No registered converter was able to produce a C++ rvalue of type std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > from this Python object of type float '''

I have a list of 298 SMILES and I want to turn those 298 into mol objects however rdkit is giving me the above error.

Can someone tell what's wrong?

1 Answers

First of all, the code you presented won't work because you need to assign the object to something first. Something like this:

mol_object_list = []
for smi in str_smiles:
    mol = Chem.MolFromSmiles(smi)
    mol_object_list.append(mol)

Coming back to your error, the error occurs when the SMILES string input is invalid. It's possible some of the SMILES in str_smiles list are wrong. Try the following piece of code to figure out which ones:

mol_object_list = []
for smi in str_smiles:
    try:  # Try converting the SMILES to mol object
        mol = Chem.MolFromSmiles(smi)
        mol_object_list.append(mol)
    except:  # Print the SMILES if there was an error in converting
        print(smi)

The SMILES that are printed are invalid and you have to fix them.

P.S. I'm assuming that str_smiles is a python list.

Related