AttributeError:“图像”对象没有属性“保存”

Mic*_*ael 1 image save rdkit

我正在遵循 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')    
Run Code Online (Sandbox Code Playgroud)

我的版本如下所示:

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')
Run Code Online (Sandbox Code Playgroud)

在这两种情况下,教程和我自己的代码,我得到相同的错误: AttributeError: 'Image' object has no attribute 'save'

现在,这很令人困惑,因为我只是遵循一个简单的教程。我查看了其他类似的主题,但我认为我的案例更加微不足道。我在这里缺少什么?

教程: https: //www.rdkit.org/docs/GettingStartedInPython.html

rap*_*lpy 6

虽然MolsToGridImage()默认情况下是returnPNG=False,但我必须在函数中明确设置它,它对我有用。

你应该试试:img=Draw.MolsToGridImage(ms, molsPerRow=10, returnPNG=False)