Skip to content

Commit cc3cc36

Browse files
authored
Merge pull request #222 from kkovary/221-max_mols-fix
pass max_mols to Draw.MolsToGridImage
2 parents 4fbb047 + ec2d34d commit cc3cc36

File tree

6 files changed

+36
-35
lines changed

6 files changed

+36
-35
lines changed

.github/workflows/code-check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424

2525
- name: Install black
2626
run: |
27-
pip install black>=23
27+
pip install black>=24
2828
2929
- name: Lint
3030
run: black --check .

binder/environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ dependencies:
3838
- pytest >=6.0
3939
- pytest-cov
4040
- pytest-xdist
41-
- black >=23
41+
- black >=24
4242
- jupyterlab
4343
- mypy
4444
- codecov

datamol/data/__init__.py

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,15 @@ def open_datamol_data_file(
6666

6767

6868
@overload
69-
def freesolv(as_df: Literal[True] = True) -> pd.DataFrame:
70-
...
69+
def freesolv(as_df: Literal[True] = True) -> pd.DataFrame: ...
7170

7271

7372
@overload
74-
def freesolv(as_df: Literal[False] = False) -> List[Mol]:
75-
...
73+
def freesolv(as_df: Literal[False] = False) -> List[Mol]: ...
7674

7775

7876
@overload
79-
def freesolv(as_df: bool = True) -> Union[List[Mol], pd.DataFrame]:
80-
...
77+
def freesolv(as_df: bool = True) -> Union[List[Mol], pd.DataFrame]: ...
8178

8279

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

103100

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

108104

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

113108

114109
@overload
115-
def cdk2(as_df: bool = True, mol_column: Optional[str] = "mol") -> Union[List[Mol], pd.DataFrame]:
116-
...
110+
def cdk2(
111+
as_df: bool = True, mol_column: Optional[str] = "mol"
112+
) -> Union[List[Mol], pd.DataFrame]: ...
117113

118114

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

131127

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

136131

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

141135

142136
@overload
143137
def solubility(
144138
as_df: bool = True, mol_column: Optional[str] = "mol"
145-
) -> Union[List[Mol], pd.DataFrame]:
146-
...
139+
) -> Union[List[Mol], pd.DataFrame]: ...
147140

148141

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

185178

186179
@overload
187-
def chembl_drugs(as_df: Literal[True] = True) -> pd.DataFrame:
188-
...
180+
def chembl_drugs(as_df: Literal[True] = True) -> pd.DataFrame: ...
189181

190182

191183
@overload
192-
def chembl_drugs(as_df: Literal[False] = False) -> List[Mol]:
193-
...
184+
def chembl_drugs(as_df: Literal[False] = False) -> List[Mol]: ...
194185

195186

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

211202

212203
@overload
213-
def chembl_samples(as_df: Literal[True] = True) -> pd.DataFrame:
214-
...
204+
def chembl_samples(as_df: Literal[True] = True) -> pd.DataFrame: ...
215205

216206

217207
@overload
218-
def chembl_samples(as_df: Literal[False] = False) -> List[Mol]:
219-
...
208+
def chembl_samples(as_df: Literal[False] = False) -> List[Mol]: ...
220209

221210

222211
def chembl_samples(as_df: bool = True) -> Union[List[Mol], pd.DataFrame]:

datamol/io.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,7 @@ def read_sdf(
116116
max_num_mols: Optional[int] = ...,
117117
discard_invalid: bool = ...,
118118
n_jobs: Optional[int] = ...,
119-
) -> List[Mol]:
120-
...
119+
) -> List[Mol]: ...
121120

122121

123122
@overload
@@ -134,8 +133,7 @@ def read_sdf(
134133
max_num_mols: Optional[int] = ...,
135134
discard_invalid: bool = ...,
136135
n_jobs: Optional[int] = ...,
137-
) -> pd.DataFrame:
138-
...
136+
) -> pd.DataFrame: ...
139137

140138

141139
@overload
@@ -152,8 +150,7 @@ def read_sdf(
152150
max_num_mols: Optional[int] = ...,
153151
discard_invalid: bool = ...,
154152
n_jobs: Optional[int] = ...,
155-
) -> Union[List[Mol], pd.DataFrame]:
156-
...
153+
) -> Union[List[Mol], pd.DataFrame]: ...
157154

158155

159156
def read_sdf(

datamol/viz/_viz.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from typing import Tuple
44
from typing import Optional
55
from typing import Any
6+
from loguru import logger
67

78
from rdkit.Chem import Draw
89

@@ -22,6 +23,7 @@ def to_image(
2223
highlight_bond: Optional[List[List[int]]] = None,
2324
outfile: Optional[str] = None,
2425
max_mols: int = 32,
26+
max_mols_ipython: int = 50,
2527
copy: bool = True,
2628
indices: bool = False,
2729
bond_indices: bool = False,
@@ -44,6 +46,7 @@ def to_image(
4446
highlight_bond: The bonds to highlight.
4547
outfile: Path where to save the image (local or remote path).
4648
max_mols: The maximum number of molecules to display.
49+
max_mols_ipython: The maximum number of molecules to display when running within an IPython environment.
4750
copy: Whether to copy the molecules or not.
4851
indices: Whether to draw the atom indices.
4952
bond_indices: Whether to draw the bond indices.
@@ -120,6 +123,18 @@ def to_image(
120123
else:
121124
_kwargs[k] = v
122125

126+
# Check if we are in a Jupyter notebook or IPython display context
127+
# If so, conditionally add the maxMols argument
128+
in_notebook = dm.viz.utils.is_ipython_session()
129+
130+
if in_notebook:
131+
_kwargs["maxMols"] = max_mols_ipython
132+
if max_mols > max_mols_ipython:
133+
logger.warning(
134+
f"You have set max_mols to {max_mols}, which is higher than max_mols_ipython ({max_mols_ipython}). "
135+
"Consider increasing max_mols_ipython if you want to display all molecules in an IPython environment."
136+
)
137+
123138
image = Draw.MolsToGridImage(
124139
mols,
125140
legends=legends,

env.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ dependencies:
3838
- pytest >=6.0
3939
- pytest-cov
4040
- pytest-xdist
41-
- black >=23
41+
- black >=24
4242
- ruff
4343
- jupyterlab
4444
- mypy

0 commit comments

Comments
 (0)