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

pass max_mols to Draw.MolsToGridImage #222

Merged
merged 8 commits into from
Feb 2, 2024

Conversation

kkovary
Copy link
Contributor

@kkovary kkovary commented Dec 13, 2023

Changelogs

closes #221

max_mols is passed to Draw.MolsToGridImage


Checklist:

  • Was this PR discussed in an issue? It is recommended to first discuss a new feature into a GitHub issue before opening a PR.
  • Add tests to cover the fixed bug(s) or the new introduced feature(s) (if appropriate).
  • Update the API documentation is a new function is added, or an existing one is deleted.
  • Write concise and explanatory changelogs below.
  • If possible, assign one of the following labels to the PR: feature, fix or test (or ask a maintainer to do it for you).

discussion related to that PR

@kkovary kkovary requested a review from hadim as a code owner December 13, 2023 19:39
@kkovary kkovary marked this pull request as draft December 13, 2023 19:53
@kkovary kkovary marked this pull request as ready for review December 13, 2023 20:44
Copy link

codecov bot commented Dec 13, 2023

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (4fbb047) 91.99% compared to head (ec2d34d) 92.33%.

Files Patch % Lines
datamol/viz/_viz.py 83.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #222      +/-   ##
==========================================
+ Coverage   91.99%   92.33%   +0.34%     
==========================================
  Files          46       46              
  Lines        3873     3863      -10     
==========================================
+ Hits         3563     3567       +4     
+ Misses        310      296      -14     
Flag Coverage Δ
unittests 92.33% <94.44%> (+0.34%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@hadim hadim added the feature label Dec 14, 2023
Copy link
Contributor

@hadim hadim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

See a comment below.

in_notebook = get_ipython() is not None

if in_notebook:
_kwargs["maxMols"] = max_mols
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder whether we should actually always pass max_mols to maxMols in Draw.MolsToGridImage below? What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hum actually I am not sure... what is your use case here?

On one side, I would say, the user will expect something like max_mols to be identical to the upstream maxMols. But on the other side, datamol is doing some preprocessing which where we "cut" to max_mols earlier.

Whatever our final decision, it should be clearly documented in the docstring!

Copy link
Contributor Author

@kkovary kkovary Dec 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My first commit here always passed max_mols to maxMols in Draw.MolsToGridImage, but all tests failed. It turns out this arg is only valid when running in an IPython context.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@kkovary kkovary Dec 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry I should've been more clear, tests related to to_image failed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I got it better now. So according to https://github.com/rdkit/rdkit/blob/c43f6d363a7aab6d4010bb50076c06608d5671be/rdkit/Chem/Draw/IPythonConsole.py#L247, maxMols is set to 50 by default and only available/triggered when running within IPython.

It sounds a bit strange to be honest, I wonder whether we should disconnect maxMols from the datamol max_mols and maybe connect it to a new argument max_mols_ipython and set it to the same default as rdkit (50).

It might sound complicated but it seems to better match what rdkit is doing and I feel it's best to provide a transparent and flexible interface to the downstream users.

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds good to me. Might be worth adding a logger warning to alert the user that they should be using max_mols_ipython if they want to plot >50 mols?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes good idea. Either a warning or make it clear in the docstring. Thanks!

@@ -3,6 +3,7 @@
from typing import Tuple
from typing import Optional
from typing import Any
from IPython.core.getipython import get_ipython
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have dm.viz.utils.is_ipython_session() and also I would prefer to avoid an IPython import at the top level (so it remains optional).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah nice, great to know!

@maclandrol
Copy link
Member

@kkovary, could you make the changes asked by @hadim in his last review ?

@kkovary
Copy link
Contributor Author

kkovary commented Jan 25, 2024

just got back from a long vacation, I'll get on it ASAP!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems like the gh runner is using a newer version of black and it's forcing the changes here as well as in datamol/viz/_viz.py

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you fix the black version in the requirements and the gh (to the newer version, should address the issue)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated, lmk if it looks good to you

@kkovary kkovary requested a review from hadim February 2, 2024 07:21
Copy link
Member

@maclandrol maclandrol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @kkovary !

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you fix the black version in the requirements and the gh (to the newer version, should address the issue)

@maclandrol maclandrol merged commit cc3cc36 into datamol-io:main Feb 2, 2024
15 checks passed
@kkovary kkovary deleted the 221-max_mols-fix branch February 2, 2024 19:03
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 this pull request may close these issues.

max_mols is limited to 50 in dm.to_image
3 participants