Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot pass drawOptions to MolsToGridImage when using notebook #3101

Closed
slochower opened this issue Apr 20, 2020 · 7 comments · Fixed by #4424
Closed

cannot pass drawOptions to MolsToGridImage when using notebook #3101

slochower opened this issue Apr 20, 2020 · 7 comments · Fixed by #4424
Labels
Milestone

Comments

@slochower
Copy link

Configuration:

  • RDKit Version: 2020.03.1
  • Operating system: macOS 10.14
  • Python version (if relevant): 3.7.5
  • Are you using conda? Yes
  • If you are using conda, which channel did you install the rdkit from? conda-forge

Description:

Based on #1854 and #2691, I believe it should be possible to pass drawingOptions to MolsToGridImage. I can't find documentation showing how these options can be passed as kwargs.

from rdkit import Chem
from rdkit.Chem.Draw.MolDrawing import DrawingOptions

UpdatedDrawingOptions = DrawingOptions()
UpdatedDrawingOptions.atomLabelFontSize = 16
UpdatedDrawingOptions.defaultColor = (0, 1, 0)

smiles = ["CCCC", "CCCCC"]
molecules = [Chem.MolFromSmiles(i) for i in smiles]
MolsToGridImage(molecules, options=UpdatedDrawingOptions)
---------------------------------------------------------------------------
ArgumentError                             Traceback (most recent call last)
<ipython-input-16-36b6c0d46c18> in <module>
      8 smiles = ["CCCC", "CCCCC"]
      9 molecules = [Chem.MolFromSmiles(i) for i in smiles]
---> 10 MolsToGridImage(molecules, options=UpdatedDrawingOptions)

~/opt/anaconda3/envs/XXX/lib/python3.7/site-packages/rdkit/Chem/Draw/IPythonConsole.py in ShowMols(mols, maxMols, **kwargs)
    191       if prop in kwargs:
    192         kwargs[prop] = kwargs[prop][:maxMols]
--> 193   res = fn(mols, drawOptions=drawOptions, **kwargs)
    194   if kwargs['useSVG']:
    195     return SVG(res)

~/opt/anaconda3/envs/XXX/lib/python3.7/site-packages/rdkit/Chem/Draw/__init__.py in MolsToGridImage(mols, molsPerRow, subImgSize, legends, highlightAtomLists, highlightBondLists, useSVG, **kwargs)
    577     return _MolsToGridImage(mols, molsPerRow=molsPerRow, subImgSize=subImgSize, legends=legends,
    578                             highlightAtomLists=highlightAtomLists,
--> 579                             highlightBondLists=highlightBondLists, **kwargs)
    580 
    581 

~/opt/anaconda3/envs/XXX/lib/python3.7/site-packages/rdkit/Chem/Draw/__init__.py in _MolsToGridImage(mols, molsPerRow, subImgSize, legends, highlightAtomLists, highlightBondLists, drawOptions, **kwargs)
    523           del kwargs[k]
    524     d2d.DrawMolecules(list(mols), legends=legends, highlightAtoms=highlightAtomLists,
--> 525                       highlightBonds=highlightBondLists, **kwargs)
    526     d2d.FinishDrawing()
    527     res = _drawerToImage(d2d)

ArgumentError: Python argument types in
    MolDraw2D.DrawMolecules(MolDraw2DCairo, list)
did not match C++ signature:
    DrawMolecules(RDKit::MolDraw2D {lvalue} self, boost::python::api::object mols, boost::python::api::object highlightAtoms=None, boost::python::api::object highlightBonds=None, boost::python::api::object highlightAtomColors=None, boost::python::api::object highlightBondColors=None, boost::python::api::object highlightAtomRadii=None, boost::python::api::object confIds=None, boost::python::api::object legends=None)
@AustinApple
Copy link

Hello, I also have the same problem now. Do you figure this out?

@slochower
Copy link
Author

Unfortunately not. I don't know a solution.

@wagerc97
Copy link

wagerc97 commented May 6, 2021

have you found a solution?

@DavidACosgrove
Copy link
Collaborator

DavidACosgrove commented May 6, 2021 via email

@dww100
Copy link

dww100 commented Aug 19, 2021

If I try

from rdkit import Chem
from rdkit.Chem import Draw
from rdkit.Chem.Draw import rdMolDraw2D

smiles = ["CCCC", "CCCCC"]
molecules = [Chem.MolFromSmiles(i) for i in smiles]
dopts = rdMolDraw2D.MolDrawOptions()
Draw.MolsToGridImage(molecules, drawOptions=dopts)

I get the error

TypeError: rdkit.Chem.Draw.MolsToGridImage() got multiple values for keyword argument 'drawOptions'

What am I doing wrong?

@ptosco
Copy link
Contributor

ptosco commented Aug 19, 2021

@dww100 That looks like a bug. If you apply the following patch to your rdkit/Chem/Draw/IPythonConsole.py file, it should then work:

diff --git a/rdkit/Chem/Draw/IPythonConsole.py b/rdkit/Chem/Draw/IPythonConsole.py
index ac78c2d..5ae5fc9 100644
--- a/rdkit/Chem/Draw/IPythonConsole.py
+++ b/rdkit/Chem/Draw/IPythonConsole.py
@@ -194,7 +194,9 @@ def ShowMols(mols, maxMols=50, **kwargs):
     for prop in ('legends', 'highlightAtoms', 'highlightBonds'):
       if prop in kwargs:
         kwargs[prop] = kwargs[prop][:maxMols]
-  res = fn(mols, drawOptions=drawOptions, **kwargs)
+  if not "drawOptions" in kwargs:
+    kwargs["drawOptions"] = drawOptions
+  res = fn(mols, **kwargs)
   if kwargs['useSVG']:
     return SVG(res)
   else:

@dww100
Copy link

dww100 commented Aug 19, 2021

Thanks @ptosco that works perfectly

ptosco pushed a commit to ptosco/rdkit that referenced this issue Aug 19, 2021
@ptosco ptosco mentioned this issue Aug 19, 2021
ptosco pushed a commit to ptosco/rdkit that referenced this issue Aug 19, 2021
@greglandrum greglandrum changed the title How to pass drawingOptions to MolsToGridImage? cannot pass drawOptions to MolsToGridImage when using notebook Aug 20, 2021
@greglandrum greglandrum added this to the 2021_03_5 milestone Aug 20, 2021
greglandrum pushed a commit that referenced this issue Aug 20, 2021
Co-authored-by: Paolo Tosco <paolo.tosco@novartis.com>
greglandrum pushed a commit that referenced this issue Aug 24, 2021
Co-authored-by: Paolo Tosco <paolo.tosco@novartis.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants