openforcefield / openff-qcsubmit

Automated tools for submitting molecules to QCFractal
https://openff-qcsubmit.readthedocs.io/en/latest/index.html
MIT License
26 stars 4 forks source link

dataset.visualize `might` fail with rdkit backend #200

Closed pavankum closed 7 months ago

pavankum commented 2 years ago

If I use dataset.visualize() with rdkit backend it fails with

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [7], in <cell line: 6>()
      3 dataset.export_dataset("dataset.json.bz2")
      4 dataset.molecules_to_file("dataset.smi", "smi")
----> 6 dataset.visualize("dataset.pdf", columns=4)

File ~/anaconda3/envs/dataset-submission/lib/python3.8/site-packages/openff/qcsubmit/datasets/datasets.py:865, in _BaseDataset.visualize(self, file_name, columns, toolkit)
    861         off_mol.properties["dihedrals"] = data.dihedrals
    863     molecules.append(off_mol)
--> 865 molecules_to_pdf(molecules, file_name, columns, toolkit)

File ~/anaconda3/envs/dataset-submission/lib/python3.8/site-packages/openff/qcsubmit/utils/visualize.py:46, in molecules_to_pdf(molecules, file_name, columns, toolkit)
     44     available, pdf_func = toolkits[toolkit]
     45     if available:
---> 46         return pdf_func(molecules, file_name, columns)
     48 raise ImportError(
     49     "No backend toolkit was found to generate the pdf please install openeye "
     50     "and/or rdkit."
     51 )

File ~/anaconda3/envs/dataset-submission/lib/python3.8/site-packages/openff/qcsubmit/utils/visualize.py:193, in _create_rdkit_pdf(molecules, file_name, columns)
    190     # write the pdf to bytes and pass straight to the pdf merger
    191     images.append(image)
--> 193 images[0].save(file_name, append_images=images[1:], save_all=True)

AttributeError: 'Image' object has no attribute 'save'

The solution is to add returnPNG=False argument for Draw.MolsToGridImage as mentioned here even though the default argument is False for that flag. I don't understand the logic of this workaround though, I didn't dig much.

lilyminium commented 7 months ago

Can verify that this bug still fails and the fix suggested by Pavan works!