mims-harvard/TDC

MolConverter SMILES to ECFP6 fails

ayushnoori opened this issue · 4 comments

MolConverter SMILES to ECFP6 fails with a NameError. I attempt the following, where x is some SMILES structure:

converter = MolConvert(src = 'SMILES', dst = 'ECPF6')
converter(x)

For example, I try:

converter('Clc1ccccc1C2C(=C(/N/C(=C2/C(=O)OCC)COCCN)C)\C(=O)OC')

This produces the following error:

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_28932/1253083184.py in <module>
      1 converter = MolConvert(src = 'SMILES', dst = 'ECFP6')
----> 2 converter('Clc1ccccc1C2C(=C(/N/C(=C2/C(=O)OCC)COCCN)C)\C(=O)OC')
      3 
      4 # converted_mol = converter(split['train']['Drug'][0])
      5 # converted_mol

~\.conda\envs\gnn\lib\site-packages\tdc\chem_utils\featurize\molconvert.py in __call__(self, x)
    800       if type(x) == str:
    801         if self.func != smiles2morgan:
--> 802           return self.func(x)
    803         else:
    804           return self.func(x, radius = self._radius, nBits = self._nbits)

~\.conda\envs\gnn\lib\site-packages\tdc\chem_utils\featurize\molconvert.py in <lambda>(x)
    767             elif dst == 'PubChem':
    768                 f2 = smiles2pubchem
--> 769             self.func = lambda x:f2(f1(x))
    770         elif src in threeD_format:
    771             pass

NameError: free variable 'f2' referenced before assignment in enclosing scope

The same approach works for ECFP2 and ECFP4.

i will take a look. btw, dst should be ECFP6 instead of ECPF6.

Ah, typo in the title! Thanks for letting me know - fixed (and correct in the code above).

it is fixed now. please download the code repo and use "python setup.py install" to re-install it. thanks so much for pointing it out! feel free to let me know when you have any further questions! thanks

Absolutely! I also noticed another error when dst = PubChem but haven't checked to see if it's reproducible. Will check later and open a new issue if I still encounter the error.

P.S. @kexinhuang12345 it's resolved!