最近使用RDKit出现TypeError: No registered converter was able to produce a C++ rvalue of type class std::basic_string<wchar_t,struct std::cahr_traits<wchar_t>,class std::allocator<w_char_t> > from this Python object oftype float
,发现RDKit的GitHub网站上已经有关于这个错误的讨论(网址)
abuhaby
- RDKit 版本:‘2019.03.4’
- 操作系统:Windows 10 64位
- Python版本:3.7
- 是否用conda:是
问题描述:
当我试图在jupyter notebook
中运行以下代码时:smiles_list = ['C(C(=O)ON','NC@@HC(O)=O'] mol_list = [] for smiles in smiles_list: mol = Chem.MolFromSmiles(smiles_list) mol_list.append(mol) img = Draw.MolToGridImage(mol_list) img
得到错误信息:
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
ptosco
你在遍历列表
smiles_list
,但是你没有把列表中的元素当成参数传递给Chem.MolFromSmiles
,而是把列表直接当做参数传递给函数,你的代码应该改为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)
或者更简洁的方式
mol_list = [Chem.MolFromSmiles(smiles) for smiles in smiles_list] img = Draw.MolsToGridImage(mol_list)
导致该错误的主要原因是传递给Chem.MolFromSmiles
函数的变量类型错误,正常的参数类型应该是字符串类型。