1

I am following the basic tutorial for RDKit.

p = Chem.MolFromSmiles('[nH]1cnc2cncnc21')
subms = [x for x in ms if x.HasSubstructMatch(p)]
len(subms)

AllChem.Compute2DCoords(p)

for m in subms: AllChem.GenerateDepictionMatching2DStructure(m,p)
    img=Draw.MolsToGridImage(subms,molsPerRow=4,subImgSize=(200,200),legends=[x.GetProp("_Name") for x in subms])    
    img.save('images/cdk2_molgrid.aligned.o.png')    

My version looks like this:

NP=pd.read_excel(r'C:\Users\BajMic\NPPics.xlsx', header=0, index_col=False, keep_default_na=True)
NP['mol']=NP.smiles.apply(getMol)

ms= [i for i in NP['mol'] if i is not None]
img=Draw.MolsToGridImage(ms, molsPerRow=10)
img.save('Pic.png')

In both cases, the tutorial and my own code, I get the same error: AttributeError: 'Image' object has no attribute 'save'

Now, this is confusing, because I was just following a simple tutorial. I looked at other similar topic, but I think my case is much more trivial. What am I missing here?

Tutorial: https://www.rdkit.org/docs/GettingStartedInPython.html

Michael
  • 47
  • 2
  • 5

1 Answers1

5

Although in MolsToGridImage() default is returnPNG=False, I have to set it explicit in the function and it works for me.

You should try: img=Draw.MolsToGridImage(ms, molsPerRow=10, returnPNG=False)

rapelpy
  • 1,684
  • 1
  • 11
  • 14