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
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 15 additions & 26 deletions datamol/data/__init__.py
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

Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,15 @@ def open_datamol_data_file(


@overload
def freesolv(as_df: Literal[True] = True) -> pd.DataFrame:
...
def freesolv(as_df: Literal[True] = True) -> pd.DataFrame: ...


@overload
def freesolv(as_df: Literal[False] = False) -> List[Mol]:
...
def freesolv(as_df: Literal[False] = False) -> List[Mol]: ...


@overload
def freesolv(as_df: bool = True) -> Union[List[Mol], pd.DataFrame]:
...
def freesolv(as_df: bool = True) -> Union[List[Mol], pd.DataFrame]: ...


def freesolv(as_df: bool = True) -> Union[List[Mol], pd.DataFrame]:
Expand All @@ -102,18 +99,17 @@ def freesolv(as_df: bool = True) -> Union[List[Mol], pd.DataFrame]:


@overload
def cdk2(as_df: Literal[True] = True, mol_column: Optional[str] = "mol") -> pd.DataFrame:
...
def cdk2(as_df: Literal[True] = True, mol_column: Optional[str] = "mol") -> pd.DataFrame: ...


@overload
def cdk2(as_df: Literal[False] = False, mol_column: Optional[str] = "mol") -> List[Mol]:
...
def cdk2(as_df: Literal[False] = False, mol_column: Optional[str] = "mol") -> List[Mol]: ...


@overload
def cdk2(as_df: bool = True, mol_column: Optional[str] = "mol") -> Union[List[Mol], pd.DataFrame]:
...
def cdk2(
as_df: bool = True, mol_column: Optional[str] = "mol"
) -> Union[List[Mol], pd.DataFrame]: ...


def cdk2(as_df: bool = True, mol_column: Optional[str] = "mol"):
Expand All @@ -130,20 +126,17 @@ def cdk2(as_df: bool = True, mol_column: Optional[str] = "mol"):


@overload
def solubility(as_df: Literal[True] = True, mol_column: Optional[str] = "mol") -> pd.DataFrame:
...
def solubility(as_df: Literal[True] = True, mol_column: Optional[str] = "mol") -> pd.DataFrame: ...


@overload
def solubility(as_df: Literal[False] = False, mol_column: Optional[str] = "mol") -> List[Mol]:
...
def solubility(as_df: Literal[False] = False, mol_column: Optional[str] = "mol") -> List[Mol]: ...


@overload
def solubility(
as_df: bool = True, mol_column: Optional[str] = "mol"
) -> Union[List[Mol], pd.DataFrame]:
...
) -> Union[List[Mol], pd.DataFrame]: ...


def solubility(as_df: bool = True, mol_column: Optional[str] = "mol"):
Expand Down Expand Up @@ -184,13 +177,11 @@ def solubility(as_df: bool = True, mol_column: Optional[str] = "mol"):


@overload
def chembl_drugs(as_df: Literal[True] = True) -> pd.DataFrame:
...
def chembl_drugs(as_df: Literal[True] = True) -> pd.DataFrame: ...


@overload
def chembl_drugs(as_df: Literal[False] = False) -> List[Mol]:
...
def chembl_drugs(as_df: Literal[False] = False) -> List[Mol]: ...


def chembl_drugs(as_df: bool = True) -> Union[List[Mol], pd.DataFrame]:
Expand All @@ -210,13 +201,11 @@ def chembl_drugs(as_df: bool = True) -> Union[List[Mol], pd.DataFrame]:


@overload
def chembl_samples(as_df: Literal[True] = True) -> pd.DataFrame:
...
def chembl_samples(as_df: Literal[True] = True) -> pd.DataFrame: ...


@overload
def chembl_samples(as_df: Literal[False] = False) -> List[Mol]:
...
def chembl_samples(as_df: Literal[False] = False) -> List[Mol]: ...


def chembl_samples(as_df: bool = True) -> Union[List[Mol], pd.DataFrame]:
Expand Down
9 changes: 3 additions & 6 deletions datamol/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ def read_sdf(
max_num_mols: Optional[int] = ...,
discard_invalid: bool = ...,
n_jobs: Optional[int] = ...,
) -> List[Mol]:
...
) -> List[Mol]: ...


@overload
Expand All @@ -134,8 +133,7 @@ def read_sdf(
max_num_mols: Optional[int] = ...,
discard_invalid: bool = ...,
n_jobs: Optional[int] = ...,
) -> pd.DataFrame:
...
) -> pd.DataFrame: ...


@overload
Expand All @@ -152,8 +150,7 @@ def read_sdf(
max_num_mols: Optional[int] = ...,
discard_invalid: bool = ...,
n_jobs: Optional[int] = ...,
) -> Union[List[Mol], pd.DataFrame]:
...
) -> Union[List[Mol], pd.DataFrame]: ...


def read_sdf(
Expand Down
15 changes: 15 additions & 0 deletions datamol/viz/_viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import Tuple
from typing import Optional
from typing import Any
from loguru import logger

from rdkit.Chem import Draw

Expand All @@ -22,6 +23,7 @@ def to_image(
highlight_bond: Optional[List[List[int]]] = None,
outfile: Optional[str] = None,
max_mols: int = 32,
max_mols_ipython: int = 50,
copy: bool = True,
indices: bool = False,
bond_indices: bool = False,
Expand All @@ -44,6 +46,7 @@ def to_image(
highlight_bond: The bonds to highlight.
outfile: Path where to save the image (local or remote path).
max_mols: The maximum number of molecules to display.
max_mols_ipython: The maximum number of molecules to display when running within an IPython environment.
copy: Whether to copy the molecules or not.
indices: Whether to draw the atom indices.
bond_indices: Whether to draw the bond indices.
Expand Down Expand Up @@ -120,6 +123,18 @@ def to_image(
else:
_kwargs[k] = v

# Check if we are in a Jupyter notebook or IPython display context
# If so, conditionally add the maxMols argument
in_notebook = dm.viz.utils.is_ipython_session()

if in_notebook:
_kwargs["maxMols"] = max_mols_ipython
if max_mols > max_mols_ipython:
logger.warning(
f"You have set max_mols to {max_mols}, which is higher than max_mols_ipython ({max_mols_ipython}). "
"Consider increasing max_mols_ipython if you want to display all molecules in an IPython environment."
)

image = Draw.MolsToGridImage(
mols,
legends=legends,
Expand Down
Loading