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

`creating-datasets.ipynb` example is broken on RDKit #217

Closed Yoshanuikabundi closed 2 months ago

Yoshanuikabundi commented 1 year ago

The call to dataset.visualize("example-dataset.pdf") fails on RDKit 2023.03.2:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[18], line 1
----> 1 dataset.visualize("example-dataset.pdf")

File ~/Documents/openff/openff-docs/.soap/examples/lib/python3.10/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 ~/Documents/openff/openff-docs/.soap/examples/lib/python3.10/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 ~/Documents/openff/openff-docs/.soap/examples/lib/python3.10/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'

Seems to work with OpenEye. Ran into this while trying to add qcsubmit to the upcoming examples page (https://github.com/openforcefield/openff-docs/pull/7)

ntBre commented 2 months ago

I can't reproduce this with this version of RDKit or with 2024.03.3:

mamba create -n old -c conda-forge openff-toolkit openff-qcsubmit rdkit=2023.03.2
import qcportal
from openff.qcsubmit import workflow_components
from openff.qcsubmit.factories import OptimizationDatasetFactory
from openff.qcsubmit.workflow_components import TorsionIndexer
from openff.toolkit import Molecule

mol = Molecule.from_smiles("CCO")
dataset_factory = OptimizationDatasetFactory()
dataset_factory.add_workflow_components(workflow_components.StandardConformerGenerator(max_conformers=10))
dataset = dataset_factory.create_dataset(dataset_name="test", description="description", tagline="tagline1", molecules=[mol])
dataset.visualize("dataset.pdf")

I can reproduce a similar crash if the list of molecules is empty, but in that case the error is list index out of bounds, not 'Image' object has no attribute 'save'.

j-wags commented 2 months ago

Awesome, thanks for following up on this, @ntBre!