Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: No registered converter was able to produce a C++ rvalue of type class #2994

Closed
abuhaby opened this issue Mar 10, 2020 · 12 comments
Closed

Comments

@abuhaby
Copy link

abuhaby commented Mar 10, 2020

  • RDKit Version: '2019.03.4'
  • Operating system: windows 10, 64bits
  • Python version (if relevant): 3.7
  • Are you using conda? YES
  • If you are using conda, which channel did you install the rdkit from?
  • If you are not using conda: how did you install the RDKit?

Description:
When I try to below code in jupyter notebook:

smiles_list = ['C(C(=O)O)N' , 'NC@@HC(O)=O']
mol_list = []
for smiles in smiles_list:
mol = Chem.MolFromSmiles(smiles_list)
mol_list.append(mol)
img = Draw.MolsToGridImage(mol_list)
img

I get the following error message:

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

KINDLY HELP ME FIX THE ABOVE ERROR.

@bp-kelley
Copy link
Contributor

bp-kelley commented Mar 10, 2020 via email

@ptosco
Copy link
Contributor

ptosco commented Mar 11, 2020

@abuhaby Brian is right. You are looping on smiles_list but then pass smiles_list to Chem.MolFromSmiles rather than smiles. Your code should be:

smiles_list = ['C(C(=O)O)N' , 'NC@@HC(O)=O']
mol_list = []
for smiles in smiles_list:
    mol = Chem.MolFromSmiles(smiles)
    mol_list.append(mol)
img = Draw.MolsToGridImage(mol_list)

or, more concisely and efficiently:

mol_list = [Chem.MolFromSmiles(smiles) for smiles in smiles_list]
img = Draw.MolsToGridImage(mol_list)

@abuhaby
Copy link
Author

abuhaby commented Mar 11, 2020

@ptosco, Thank you Ptosco. It worked after I applied your fix.
I am trying to learn python and rdkit on the fly. Any suggestion for good learning material for a starter. Especially good resources for cheminformatics related stuff where i can utilize databases, molecular finger and biological activities.

@bp-kelley
Copy link
Contributor

The RDKit blog is a good start:

http://rdkit.blogspot.com

It doesn't talk about databases, but it will give you a head start on some techniques.

@abuhaby
Copy link
Author

abuhaby commented Mar 11, 2020

I will try that. Thanks.

@abuhaby abuhaby closed this as completed Apr 1, 2020
@seyonechithrananda
Copy link

@ptosco Thanks for the fix! Ran into the same issue and realized I had accidentally called the list, not the SMILES string itself :)

@abuhaby Brian is right. You are looping on smiles_list but then pass smiles_list to Chem.MolFromSmiles rather than smiles. Your code should be:

smiles_list = ['C(C(=O)O)N' , 'NC@@HC(O)=O']
mol_list = []
for smiles in smiles_list:
    mol = Chem.MolFromSmiles(smiles)
    mol_list.append(mol)
img = Draw.MolsToGridImage(mol_list)

or, more concisely and efficiently:

mol_list = [Chem.MolFromSmiles(smiles) for smiles in smiles_list]
img = Draw.MolsToGridImage(mol_list)

@Inioluwajeremiah
Copy link

I had the same issue but later discovered that it was because some rows didn't have the canonical smiles notation but rather NaN. This makes it impossible to iterate through the column successfully while trying to generate descriptors using the for loop.

@Inioluwajeremiah
Copy link

Do a data clean up to resolve the issue. In my case, the line of code below solved it

 df2 = df[df.canonical_smiles.notna()] 

@charlesxu90
Copy link

I had the same issue but later discovered that it was because some rows didn't have the canonical smiles notation but rather NaN. This makes it impossible to iterate through the column successfully while trying to generate descriptors using the for loop.

This explains my problem. There's a Nan in the smiles list, which causes my problem.

@Inioluwajeremiah
Copy link

Inioluwajeremiah commented Feb 27, 2022 via email

@acchu69
Copy link

acchu69 commented Feb 26, 2023

facing the same issue
for this part of the code
df = pd.DataFrame(load_data[0])
smiless=df.astype(str)
smiles_list = [smiless]
mol_list = [Chem.MolFromSmiles(smiles) for smiles in smiles_list]
img = Draw.MolsToGridImage(mol_list)
st.write(img)
error message :
TypeError: No registered converter was able to produce a C++ rvalue of type class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > from this Python object of type DataFrame
traceback:
File "C:\Users\Admin\Desktop\alzheimers dd app\app.py", line 101, in
mol_list = [Chem.MolFromSmiles(smiles) for smiles in smiles_list]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Admin\Desktop\alzheimers dd app\app.py", line 101, in
mol_list = [Chem.MolFromSmiles(smiles) for smiles in smiles_list]
^^^^^^^^^^^^^^^^^^^^^^^^^^

@ptosco
Copy link
Contributor

ptosco commented Feb 26, 2023

@acchu69 Please do not post on closed issues - post in Discussions if you have a question as it may help others.
In your code above, smiless is a DataFrame, as you call astype(str) on the whole DataFrame:

import pandas as pd

df = pd.DataFrame({"index": [1,2], "smiles": ["C", "CC"]})
type(df.astype(str))
pandas.core.frame.DataFrame

If you want a list of SMILES as strings, you need something like:

smiles_list = df.smiles.astype(str).to_list()
smiles_list
['C', 'CC']

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants