From 4e91d3259dc418a2e02c086361bacfe8d03e92fb Mon Sep 17 00:00:00 2001 From: Hadrien Mary Date: Thu, 22 Jun 2023 08:51:14 -0400 Subject: [PATCH 1/8] add a random seed for the layout in circle grid --- datamol/viz/_circle_grid.py | 10 ++++++++-- datamol/viz/utils.py | 12 ++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/datamol/viz/_circle_grid.py b/datamol/viz/_circle_grid.py index d332f5d1..dd881f64 100644 --- a/datamol/viz/_circle_grid.py +++ b/datamol/viz/_circle_grid.py @@ -98,6 +98,7 @@ def __init__( ring_mol_highlight_atoms: Optional[List[List[int]]] = None, ring_mol_highlight_bonds: Optional[List[List[int]]] = None, kekulize: bool = True, + layout_random_seed: Optional[int] = 19, **kwargs: Any, ): """Show molecules in concentric rings, with one molecule at the center @@ -121,7 +122,8 @@ def __init__( ring_mol_highlight_atoms: List of list of atom indices to highlight for molecules at each level of the concentric rings ring_mol_highlight_bonds: List of list of bond indices to highlight for molecules at each level of the concentric rings ring_color: Color of the concentric rings. Set to None to not draw any ring. - kekulize: Whether to kekulize the molecules before drawing + kekulize: Whether to kekulize the molecules before drawing. + layout_random_seed: Random seed for the layout of the molecules. Set to None for no seed. **kwargs: Additional arguments to pass to the drawing function. See RDKit documentation related to `MolDrawOptions` for more details at https://www.rdkit.org/docs/source/rdkit.Chem.Draw.rdMolDraw2D.html. @@ -146,6 +148,7 @@ def __init__( self.center_mol_highlight_atoms = center_mol_highlight_atoms self.center_mol_highlight_bonds = center_mol_highlight_bonds self.kekulize = kekulize + self.layout_random_seed = layout_random_seed self._global_legend_size = 0 if self.legend is not None: self._global_legend_size = max(25, self.margin) @@ -276,12 +279,15 @@ def draw(self): highlight_atom=self.center_mol_highlight_atoms, highlight_bond=self.center_mol_highlight_bonds, ) + + rng = random.Random(self.layout_random_seed) + # draw the ring mols self.draw_options.scalingFactor *= self.ring_scaler for i, mols in enumerate(self.ring_mols): radius = radius_list[i] ni = len(mols) - rand_unit = random.random() * 2 * math.pi + rand_unit = rng.random() * 2 * math.pi for k, mol in enumerate(mols): center_x = radius * math.cos(2 * k * math.pi / ni + rand_unit) + self.midpoint.x center_y = radius * math.sin(2 * k * math.pi / ni + rand_unit) + self.midpoint.y diff --git a/datamol/viz/utils.py b/datamol/viz/utils.py index cad4e268..3de0c732 100644 --- a/datamol/viz/utils.py +++ b/datamol/viz/utils.py @@ -6,6 +6,7 @@ from rdkit.Chem import Draw +import PIL.Image import PIL.PngImagePlugin import datamol as dm @@ -94,7 +95,14 @@ def drawer_to_image(drawer: Draw.rdMolDraw2D.MolDraw2D): def image_to_file( - image: Union[str, PIL.PngImagePlugin.PngImageFile, bytes], outfile, as_svg: bool = False + image: Union[ + str, + PIL.PngImagePlugin.PngImageFile, + bytes, + PIL.Image.Image, + ], + outfile, + as_svg: bool = False, ): """Save image to file. The image can be either a PNG or SVG depending @@ -115,7 +123,7 @@ def image_to_file( else: if isinstance(image, PIL.PngImagePlugin.PngImageFile): # type: ignore # in a terminal process - image.save(f) + image.save(f) # type: ignore else: # in a jupyter kernel process f.write(image.data) # type: ignore From bb63870e6357187454ccae96e77e631d9a43488e Mon Sep 17 00:00:00 2001 From: Hadrien Mary Date: Thu, 22 Jun 2023 08:51:59 -0400 Subject: [PATCH 2/8] remove left hover print statement in lasso viz --- datamol/viz/_lasso_highlight.py | 1 - 1 file changed, 1 deletion(-) diff --git a/datamol/viz/_lasso_highlight.py b/datamol/viz/_lasso_highlight.py index 80fb6e9d..08208079 100644 --- a/datamol/viz/_lasso_highlight.py +++ b/datamol/viz/_lasso_highlight.py @@ -334,7 +334,6 @@ def _draw_multi_matches( else: _color_list = color_list - print(len(_color_list), len(indices_set_lists)) if len(_color_list) < len(indices_set_lists): colors_to_add = [] for i in range(len(indices_set_lists) - len(_color_list)): From fd3ddf3b3fa87e34cfbe458e9e81a242d456a5c6 Mon Sep 17 00:00:00 2001 From: Hadrien Mary Date: Thu, 22 Jun 2023 09:26:58 -0400 Subject: [PATCH 3/8] allow hex string as colors --- datamol/__init__.py | 6 ++++-- datamol/types.py | 3 ++- datamol/viz/_circle_grid.py | 18 +++++++++++++----- datamol/viz/_lasso_highlight.py | 26 ++++++++++++++++++-------- datamol/viz/utils.py | 15 +++++++++++++++ tests/test_viz.py | 17 +++++++++++++++++ tests/test_viz_lasso_highlight.py | 9 +++++++++ 7 files changed, 78 insertions(+), 16 deletions(-) diff --git a/datamol/__init__.py b/datamol/__init__.py index c1e329c3..3ee604ff 100644 --- a/datamol/__init__.py +++ b/datamol/__init__.py @@ -22,7 +22,8 @@ "ChemicalReaction": "datamol.types", "Atom": "datamol.types", "Bond": "datamol.types", - "ColorTuple": "datamol.types", + "DatamolColor": "datamol.types", + "RDKitColor": "datamol.types", # utils "parallelized": "datamol.utils", "parallelized_with_batches": "datamol.utils", @@ -209,7 +210,8 @@ def __dir__(): from .types import ChemicalReaction from .types import Atom from .types import Bond - from .types import ColorTuple + from .types import DatamolColor + from .types import RDKitColor from . import utils diff --git a/datamol/types.py b/datamol/types.py index b48627e0..7c7fa71d 100644 --- a/datamol/types.py +++ b/datamol/types.py @@ -12,4 +12,5 @@ Atom: TypeAlias = Chem.rdchem.Atom Bond: TypeAlias = Chem.rdchem.Bond -ColorTuple = Union[Tuple[float, float, float, float], Tuple[float, float, float]] +RDKitColor = Union[Tuple[float, float, float, float], Tuple[float, float, float]] +DatamolColor = Union[RDKitColor, str] diff --git a/datamol/viz/_circle_grid.py b/datamol/viz/_circle_grid.py index dd881f64..1deccbf4 100644 --- a/datamol/viz/_circle_grid.py +++ b/datamol/viz/_circle_grid.py @@ -12,8 +12,11 @@ from .utils import drawer_to_image from .utils import prepare_mol_for_drawing from .utils import image_to_file -from datamol.types import ColorTuple +from .utils import to_rdkit_color + +from datamol.types import DatamolColor from datamol.types import Mol +from datamol.types import RDKitColor import datamol as dm @@ -27,12 +30,13 @@ def circle_grid( ring_scaler: float = 1.0, align: Optional[Union[Mol, str, bool]] = None, use_svg: bool = True, - ring_color: Optional[ColorTuple] = None, + ring_color: Optional[DatamolColor] = None, center_mol_highlight_atoms: Optional[List[int]] = None, center_mol_highlight_bonds: Optional[List[int]] = None, ring_mol_highlight_atoms: Optional[List[List[int]]] = None, ring_mol_highlight_bonds: Optional[List[List[int]]] = None, outfile: Optional[str] = None, + layout_random_seed: Optional[int] = 19, **kwargs: Any, ): """Show molecules in concentric rings, with one molecule at the center @@ -54,6 +58,8 @@ def circle_grid( ring_mol_highlight_atoms: List of list of atom indices to highlight for molecules at each level of the concentric rings ring_mol_highlight_bonds: List of list of bond indices to highlight for molecules at each level of the concentric rings ring_color: Color of the concentric rings. Set to None to not draw any ring. + kekulize: Whether to kekulize the molecules before drawing. + layout_random_seed: Random seed for the layout of the molecules. Set to None for no seed. outfile: Optional path to the save the output file. **kwargs: Additional arguments to pass to the drawing function. See RDKit documentation related to `MolDrawOptions` for more details at @@ -75,6 +81,7 @@ def circle_grid( center_mol_highlight_bonds=center_mol_highlight_bonds, ring_mol_highlight_atoms=ring_mol_highlight_atoms, ring_mol_highlight_bonds=ring_mol_highlight_bonds, + layout_random_seed=layout_random_seed, **kwargs, ) return grid(outfile=outfile) @@ -92,7 +99,7 @@ def __init__( align: Optional[Union[Mol, str, bool]] = None, use_svg: bool = True, line_width: Optional[float] = None, - ring_color: Optional[ColorTuple] = None, + ring_color: Optional[DatamolColor] = None, center_mol_highlight_atoms: Optional[List[int]] = None, center_mol_highlight_bonds: Optional[List[int]] = None, ring_mol_highlight_atoms: Optional[List[List[int]]] = None, @@ -143,6 +150,7 @@ def __init__( self.use_svg = use_svg self.line_width = line_width self.ring_color = ring_color + self.ring_color_rdkit: Optional[RDKitColor] = to_rdkit_color(ring_color) self.ring_mol_highlight_atoms = ring_mol_highlight_atoms self.ring_mol_highlight_bonds = ring_mol_highlight_bonds self.center_mol_highlight_atoms = center_mol_highlight_atoms @@ -329,8 +337,8 @@ def _draw_circles(self): for _, radius in enumerate(full_range): radius += self.margin // 2 if radius > self.margin: - if self.ring_color is not None: - self.canvas.SetColour(self.ring_color) + if self.ring_color_rdkit is not None: + self.canvas.SetColour(self.ring_color_rdkit) self.canvas.DrawArc(self.midpoint, radius, 0, 360, rawCoords=True) radius_list.append(radius + radius_step) return radius_list diff --git a/datamol/viz/_lasso_highlight.py b/datamol/viz/_lasso_highlight.py index 08208079..5bd5f689 100644 --- a/datamol/viz/_lasso_highlight.py +++ b/datamol/viz/_lasso_highlight.py @@ -20,9 +20,12 @@ import numpy as np import datamol as dm -from datamol.types import ColorTuple +from datamol.types import RDKitColor +from datamol.types import DatamolColor + from .utils import drawer_to_image from .utils import prepare_mol_for_drawing +from .utils import to_rdkit_color def _angle_to_coord(center: np.ndarray, angle: float, radius: float) -> np.ndarray: @@ -185,7 +188,7 @@ def _draw_substructurematch( rel_radius: float = 0.3, rel_width: float = 0.5, line_width: int = 2, - color: Optional[ColorTuple] = None, + color: Optional[RDKitColor] = None, offset: Optional[Tuple[int, int]] = None, ) -> None: """Draws the substructure defined by (atom-) `indices`, as lasso-highlight onto `canvas`. @@ -208,7 +211,7 @@ def _draw_substructurematch( # # Default color is gray. if not color: color = (0.5, 0.5, 0.5, 1) - canvas.SetColour(color) + canvas.SetColour(tuple(color)) # Selects first conformer and calculates the mean bond length conf = mol.GetConformer(0) @@ -311,7 +314,7 @@ def _draw_multi_matches( r_min: float = 0.3, r_dist: float = 0.13, relative_bond_width: float = 0.5, - color_list: Optional[List[ColorTuple]] = None, + color_list: Optional[List[DatamolColor]] = None, line_width: int = 2, offset: Optional[Tuple[int, int]] = None, ): @@ -365,7 +368,7 @@ def _draw_multi_matches( match_atoms, rel_radius=ar, rel_width=max(relative_bond_width, ar), - color=color, + color=to_rdkit_color(color), line_width=line_width, offset=offset, ) @@ -393,7 +396,7 @@ def lasso_highlight_image( r_min: float = 0.3, r_dist: float = 0.13, relative_bond_width: float = 0.5, - color_list: Optional[List[ColorTuple]] = None, + color_list: Optional[List[DatamolColor]] = None, line_width: int = 2, scale_padding: float = 1.0, verbose: bool = False, @@ -437,6 +440,7 @@ def lasso_highlight_image( for i, search_mol in enumerate(search_molecules): if isinstance(search_mol, str): search_molecules[i] = dm.from_smarts(search_mol) + if search_molecules[i] is None or not isinstance(search_molecules[i], dm.Mol): raise ValueError( f"Please enter valid search molecules or smarts: {search_molecules[i]}" @@ -461,11 +465,17 @@ def lasso_highlight_image( ## Step 1: setup drawer and canvas if use_svg: drawer = rdMolDraw2D.MolDraw2DSVG( - mol_size[0] * n_cols, mol_size[1] * n_rows, mol_size[0], mol_size[1] + mol_size[0] * n_cols, + mol_size[1] * n_rows, + mol_size[0], + mol_size[1], ) else: drawer = rdMolDraw2D.MolDraw2DCairo( - mol_size[0] * n_cols, mol_size[1] * n_rows, mol_size[0], mol_size[1] + mol_size[0] * n_cols, + mol_size[1] * n_rows, + mol_size[0], + mol_size[1], ) # Setting the drawing options diff --git a/datamol/viz/utils.py b/datamol/viz/utils.py index 3de0c732..37401d13 100644 --- a/datamol/viz/utils.py +++ b/datamol/viz/utils.py @@ -5,11 +5,16 @@ import fsspec from rdkit.Chem import Draw +from matplotlib import colors as mcolors import PIL.Image import PIL.PngImagePlugin + import datamol as dm +from datamol.types import RDKitColor +from datamol.types import DatamolColor + def prepare_mol_for_drawing(mol: Optional[dm.Mol], kekulize: bool = True) -> Optional[dm.Mol]: """Prepare the molecule before drawing to avoid any error due to unsanitized molecule @@ -127,3 +132,13 @@ def image_to_file( else: # in a jupyter kernel process f.write(image.data) # type: ignore + + +def to_rdkit_color(color: Optional[DatamolColor]) -> Optional[RDKitColor]: + """If required convert a datamol color (rgb, rgba or hex string) to an RDKit + color (rgb or rgba). + """ + if isinstance(color, str): + return mcolors.to_rgba(color) # type: ignore + else: + return color diff --git a/tests/test_viz.py b/tests/test_viz.py index ba031c45..70fabeb6 100644 --- a/tests/test_viz.py +++ b/tests/test_viz.py @@ -139,6 +139,23 @@ def test_circle_grid(tmp_path): ) +@pytest.mark.skipif( + not dm.is_greater_than_current_rdkit_version("2023.03"), + reason="Circle Grid requires rdkit>2022.09", +) +def test_circle_grid_with_hex_color(tmp_path): + mol = dm.to_mol("CC(=O)OC1=CC=CC=C1C(=O)O") + dm.viz.circle_grid( + mol, + [ + [dm.to_mol("CCC"), dm.to_mol("CCCCCCC")], + [dm.to_mol("CCCO"), dm.to_mol("CCCCCCCO")], + ], + ring_color="#ff1472", + layout_random_seed=None, + ) + + def test_to_image_align(): # Get a list of molecules data = dm.data.freesolv() diff --git a/tests/test_viz_lasso_highlight.py b/tests/test_viz_lasso_highlight.py index cfb80cb8..542c9464 100644 --- a/tests/test_viz_lasso_highlight.py +++ b/tests/test_viz_lasso_highlight.py @@ -192,3 +192,12 @@ def test_atom_indices_list(): search_molecules=None, atom_indices=[4, 5, 6], ) + + +def test_with_hex_color(): + dm.viz.lasso_highlight_image( + "CC(N)Cc1c[nH]c2ccc3c(c12)CCCO3", + search_molecules=None, + atom_indices=[4, 5, 6], + color_list=["#ff1472"], + ) From dcb4614f519bc75dd6be1b529357819b0160ca43 Mon Sep 17 00:00:00 2001 From: Hadrien Mary Date: Thu, 22 Jun 2023 09:41:08 -0400 Subject: [PATCH 4/8] typing --- datamol/viz/_circle_grid.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/datamol/viz/_circle_grid.py b/datamol/viz/_circle_grid.py index 1deccbf4..b5bd4fdc 100644 --- a/datamol/viz/_circle_grid.py +++ b/datamol/viz/_circle_grid.py @@ -36,6 +36,7 @@ def circle_grid( ring_mol_highlight_atoms: Optional[List[List[int]]] = None, ring_mol_highlight_bonds: Optional[List[List[int]]] = None, outfile: Optional[str] = None, + kekulize: bool = True, layout_random_seed: Optional[int] = 19, **kwargs: Any, ): @@ -81,6 +82,7 @@ def circle_grid( center_mol_highlight_bonds=center_mol_highlight_bonds, ring_mol_highlight_atoms=ring_mol_highlight_atoms, ring_mol_highlight_bonds=ring_mol_highlight_bonds, + kekulize=kekulize, layout_random_seed=layout_random_seed, **kwargs, ) From 72ea3fc654d408dd8fce5fb3a7043c65f5138fbd Mon Sep 17 00:00:00 2001 From: Hadrien Mary Date: Thu, 22 Jun 2023 09:57:33 -0400 Subject: [PATCH 5/8] add ring_mol_start_angles_degrees --- datamol/viz/_circle_grid.py | 15 ++++++++++++++- tests/test_viz.py | 21 +++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/datamol/viz/_circle_grid.py b/datamol/viz/_circle_grid.py index b5bd4fdc..2d4c29b0 100644 --- a/datamol/viz/_circle_grid.py +++ b/datamol/viz/_circle_grid.py @@ -31,6 +31,7 @@ def circle_grid( align: Optional[Union[Mol, str, bool]] = None, use_svg: bool = True, ring_color: Optional[DatamolColor] = None, + ring_mol_start_angles_degrees: Optional[List[float]] = None, center_mol_highlight_atoms: Optional[List[int]] = None, center_mol_highlight_bonds: Optional[List[int]] = None, ring_mol_highlight_atoms: Optional[List[List[int]]] = None, @@ -59,6 +60,8 @@ def circle_grid( ring_mol_highlight_atoms: List of list of atom indices to highlight for molecules at each level of the concentric rings ring_mol_highlight_bonds: List of list of bond indices to highlight for molecules at each level of the concentric rings ring_color: Color of the concentric rings. Set to None to not draw any ring. + ring_mol_start_angles_degrees: List of angles in degrees to start drawing the molecules at each level of the concentric + rings. If None then a random position will be used. kekulize: Whether to kekulize the molecules before drawing. layout_random_seed: Random seed for the layout of the molecules. Set to None for no seed. outfile: Optional path to the save the output file. @@ -78,6 +81,7 @@ def circle_grid( align=align, use_svg=use_svg, ring_color=ring_color, + ring_mol_start_angles_degrees=ring_mol_start_angles_degrees, center_mol_highlight_atoms=center_mol_highlight_atoms, center_mol_highlight_bonds=center_mol_highlight_bonds, ring_mol_highlight_atoms=ring_mol_highlight_atoms, @@ -102,6 +106,7 @@ def __init__( use_svg: bool = True, line_width: Optional[float] = None, ring_color: Optional[DatamolColor] = None, + ring_mol_start_angles_degrees: Optional[List[float]] = None, center_mol_highlight_atoms: Optional[List[int]] = None, center_mol_highlight_bonds: Optional[List[int]] = None, ring_mol_highlight_atoms: Optional[List[List[int]]] = None, @@ -131,6 +136,8 @@ def __init__( ring_mol_highlight_atoms: List of list of atom indices to highlight for molecules at each level of the concentric rings ring_mol_highlight_bonds: List of list of bond indices to highlight for molecules at each level of the concentric rings ring_color: Color of the concentric rings. Set to None to not draw any ring. + ring_mol_start_angles_degrees: List of angles in degrees to start drawing the molecules at each level of the concentric + rings. If None then a random position will be used. kekulize: Whether to kekulize the molecules before drawing. layout_random_seed: Random seed for the layout of the molecules. Set to None for no seed. **kwargs: Additional arguments to pass to the drawing function. See RDKit @@ -152,6 +159,7 @@ def __init__( self.use_svg = use_svg self.line_width = line_width self.ring_color = ring_color + self.ring_mol_start_angles_degrees= ring_mol_start_angles_degrees self.ring_color_rdkit: Optional[RDKitColor] = to_rdkit_color(ring_color) self.ring_mol_highlight_atoms = ring_mol_highlight_atoms self.ring_mol_highlight_bonds = ring_mol_highlight_bonds @@ -297,7 +305,12 @@ def draw(self): for i, mols in enumerate(self.ring_mols): radius = radius_list[i] ni = len(mols) - rand_unit = rng.random() * 2 * math.pi + + if self.ring_mol_start_angles_degrees is not None: + rand_unit = self.ring_mol_start_angles_degrees[i] + else: + rand_unit = rng.random() * 2 * math.pi + for k, mol in enumerate(mols): center_x = radius * math.cos(2 * k * math.pi / ni + rand_unit) + self.midpoint.x center_y = radius * math.sin(2 * k * math.pi / ni + rand_unit) + self.midpoint.y diff --git a/tests/test_viz.py b/tests/test_viz.py index 70fabeb6..10f87d76 100644 --- a/tests/test_viz.py +++ b/tests/test_viz.py @@ -156,6 +156,27 @@ def test_circle_grid_with_hex_color(tmp_path): ) +@pytest.mark.skipif( + not dm.is_greater_than_current_rdkit_version("2023.03"), + reason="Circle Grid requires rdkit>2022.09", +) +def test_circle_grid_with_angle_start(tmp_path): + mol = dm.to_mol("CC(=O)OC1=CC=CC=C1C(=O)O") + dm.viz.circle_grid( + mol, + [ + [dm.to_mol("CCC"), dm.to_mol("CCCCCCC"), dm.to_mol("CCCCCO")], + [ + dm.to_mol("CCCO"), + ], + ], + # ring_color=(0, 0, 0, 0.5), + ring_color="#ff1472aa", + layout_random_seed=19, + ring_mol_start_angles_degrees=[90, 90], + ) + + def test_to_image_align(): # Get a list of molecules data = dm.data.freesolv() From 83e5e6d3051608a3d7c29f4e467e9342a25a795b Mon Sep 17 00:00:00 2001 From: Hadrien Mary Date: Thu, 22 Jun 2023 09:58:51 -0400 Subject: [PATCH 6/8] format --- datamol/viz/_circle_grid.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datamol/viz/_circle_grid.py b/datamol/viz/_circle_grid.py index 2d4c29b0..b59a4269 100644 --- a/datamol/viz/_circle_grid.py +++ b/datamol/viz/_circle_grid.py @@ -159,7 +159,7 @@ def __init__( self.use_svg = use_svg self.line_width = line_width self.ring_color = ring_color - self.ring_mol_start_angles_degrees= ring_mol_start_angles_degrees + self.ring_mol_start_angles_degrees = ring_mol_start_angles_degrees self.ring_color_rdkit: Optional[RDKitColor] = to_rdkit_color(ring_color) self.ring_mol_highlight_atoms = ring_mol_highlight_atoms self.ring_mol_highlight_bonds = ring_mol_highlight_bonds From 1e1b90ad71226552d469faabe4258b6ad92970ef Mon Sep 17 00:00:00 2001 From: Hadrien Mary Date: Thu, 22 Jun 2023 10:08:13 -0400 Subject: [PATCH 7/8] deg to radian in circle grid --- datamol/viz/_circle_grid.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datamol/viz/_circle_grid.py b/datamol/viz/_circle_grid.py index b59a4269..d25eab93 100644 --- a/datamol/viz/_circle_grid.py +++ b/datamol/viz/_circle_grid.py @@ -307,7 +307,7 @@ def draw(self): ni = len(mols) if self.ring_mol_start_angles_degrees is not None: - rand_unit = self.ring_mol_start_angles_degrees[i] + rand_unit = np.deg2rad(self.ring_mol_start_angles_degrees[i]) else: rand_unit = rng.random() * 2 * math.pi From e01067a629b021d1bb6ae69f8112af437004cd2a Mon Sep 17 00:00:00 2001 From: Hadrien Mary Date: Thu, 22 Jun 2023 11:32:33 -0400 Subject: [PATCH 8/8] docstring for the win --- datamol/viz/utils.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/datamol/viz/utils.py b/datamol/viz/utils.py index 37401d13..bed1d922 100644 --- a/datamol/viz/utils.py +++ b/datamol/viz/utils.py @@ -137,8 +137,10 @@ def image_to_file( def to_rdkit_color(color: Optional[DatamolColor]) -> Optional[RDKitColor]: """If required convert a datamol color (rgb, rgba or hex string) to an RDKit color (rgb or rgba). + + Args: + color: A datamol color: hex, rgb, rgba or None. """ if isinstance(color, str): return mcolors.to_rgba(color) # type: ignore - else: - return color + return color