1

I am using rdkit to use tanimoto similarity to compare molecular fingerprints. However, when I do so, it gives me an error regarding C++. I'm not sure whats incorrect in my code. I provided a code a used earlier that ran sucessfully to help to figure out what the issue is/ what difference between the two codes makes the second one run incorrectly. Thank you.

CORRECT CODE:

from rdkit import Chem
from rdkit.Chem import AllChem
from rdkit import DataStructs

ms = [Chem.MolFromSmiles('CCOC')]
ms2 = [Chem.MolFromSmiles('CCO')]
fps = [Chem.RDKFingerprint(x) for x in ms]
fps2 = [Chem.RDKFingerprint(x) for x in ms2]
simil = DataStructs.FingerprintSimilarity(fps[0], fps2[0])
print(simil)
output: 0.6

INCORRECT CODE:

p11 = ['CO']
stringz = ['CCO']
for x in p11:
    ms = [Chem.MolFromSmiles(x)]
    fps = [Chem.RDKFingerprint(x) for x in ms]
for x in stringz:
    ms1 = [Chem.MolFromSmiles(stringz)]
    fps2 = [Chem.RDKFingerprint(x) for x in ms1]
    simil = DataStructs.FingerprintSimilarity(fps, fps2)
print(simil)

ERROR MESSAGE:

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

1 Answers1

0

The error is in the line

ms1 = [Chem.MolFromSmiles(stringz)]

You're passing stringz as input which is a list. It should be

ms1 = [Chem.MolFromSmiles(x)]
betelgeuse
  • 1,136
  • 3
  • 13
  • 25