Simple usage#
The most straightforward way to use mols2grid! For a more advanced usage, see MolGrid.
- mols2grid.display(arg, **kwargs)[source]#
- mols2grid.display(df: dict, **kwargs)
- mols2grid.display(df: DataFrame, **kwargs)
- mols2grid.display(sdf: Path, **kwargs)
- mols2grid.display(sdf: str, **kwargs)
- mols2grid.display(mols: tuple, **kwargs)
- mols2grid.display(mols: list, **kwargs)
- mols2grid.display(mols: Series, **kwargs)
Display molecules on an interactive grid.
Parameters: Data#
- argpandas.DataFrame, SDF file or list of molecules
The input containing your molecules.
- smiles_colstr or None, default=âSMILESâ
If a pandas dataframe is used, name of the column with SMILES.
- mol_colstr or None, default=None
If a pandas dataframe is used, name of the column with RDKit molecules. If available, coordinates and atom/bonds annotations from this will be used for depiction.
Parameters: Display#
- templatestr, default=âinteractiveâ
Either
"interactive"or"static". Seerender()for more details.- sizetuple, default=(130, 90)
The size of the drawing canvas. The cell minimum width is set to the width of the image, so if the cell padding is increased, the image will be displayed smaller.
- useSVGbool, default=True
Use SVG images instead of PNG.
- prerenderbool, default=False
Prerender images for the entire dataset, or generate them on-the-fly. Prerendering is slow and memory-hungry, but required when
template="static"oruseSVG=False.- subset: list or None, default=None
Columns to be displayed in each cell of the grid. Each columnâs value will be displayed from top to bottom in the order provided. The
"img"and"mols2grid-id"columns are displayed by default, however you can still add the"img"column if you wish to change the display order.- tooltiplist, None or False, default=None
Columns to be displayed inside the tooltip. When no subset is set, all columns will be listed in the tooltip by default. Use
Falseto hide the tooltip.- tooltip_fmtstr, default=â<strong>{key}</strong>: {value}â
Format string of each key/value pair in the tooltip.
- tooltip_triggerstr, default=âfocusâ
Only available for the âstaticâ template. Sequence of triggers for the tooltip:
click,hoverorfocus- tooltip_placementstr, default=âautoâ
Position of the tooltip:
auto,top,bottom,leftorright- transformdict or None, default=None
Functions applied to specific items in all cells. The dict must follow a
key: functionstructure where the key must correspond to one of the columns insubsetortooltip. The function takes the itemâs value as input and transforms it, for example:transform={ "Solubility": lambda x: f"{x:.2f}", "Melting point": lambda x: f"MP: {5/9*(x-32):.1f}°C" }
These transformations only affect columns in
subsetandtooltip, and do not interfere withstyle.- sort_bystr or None, default=None
Sort the grid according to the following field (which must be present in
subsetortooltip).- truncate: bool, default=True/False
Whether to truncate the text in each cell if itâs too long. Defaults to
Truefor interactive grids,Falsefor static grid.- n_items_per_page, default=24
Only available for the âinteractiveâ template. Number of items to display per page. A multiple of 12 is recommended for optimal display.
- n_colsint, default=5
Only available for the âstaticâ template. Number of columns in the table.
- selectionbool, default=True
Only available for the âinteractiveâ template. Enables the selection of molecules and displays a checkbox at the top of each cell. In the context of a Jupyter Notebook, this gives you access to your selection (index and SMILES) through
mols2grid.get_selection()orMolGrid.get_selection(). In all cases, you can export your selection by clicking on the triple-dot menu.- cache_selectionbool, default=False
Only available for the âinteractiveâ template. Restores the selection from a previous grid with the same name.
- use_iframebool, default=False
Whether to use an iframe to display the grid. When the grid is displayed inside a Jupyter Notebook or JupyterLab, this will default to
True.- iframe_widthstr, default=â100%
Width of the iframe
- iframe_heightint or None, default=None
Height of the frame. When set to
None, the height is set dynamically based on the content.
Parameters: Mols#
- removeHsbool, default=False
Remove hydrogen atoms from the drawings.
- use_coordsbool, default=False
Use the coordinates of the molecules (only relevant when an SDF file, a list of molecules or a DataFrame of RDKit molecules were used as input.)
- coordGenbool, default=True
Use the CoordGen library instead of the RDKit one to depict the molecules in 2D.
- MolDrawOptionsrdkit.Chem.Draw.rdMolDraw2D.MolDrawOptions or None, default=None
Drawing options. Useful for making highly customized drawings.
- substruct_highlightbool or None, default=None
Highlight substructure when using the SMARTS search. Active by default when
prerender=False.- single_highlightbool, default=False
Highlight only the first match of the substructure query.
Parameters: CSS#
- borderstr, default=â1px solid #ccccccâ
Styling of the border around each cell.
- gapint, default=0
Size in pixels of the gap between cells.
- padint, default=10
Size in pixels of the cell padding.
- fontsizestr, default=â12pxâ
Font size of the text displayed in each cell.
- fontfamilystr, default=ââDejaVuâ, sans-serifâ
Font used for the text in each cell.
- textalignstr, default=âcenterâ
Alignment of the text in each cell.
- background_colorstr, default=âwhiteâ
Only available for the âinteractiveâ template. Background color of a cell.
- hover_colorstr, default=ârgba(0,0,0,0.05)â
Only available for the âinteractiveâ template. Background color when hovering a cell
- custom_cssstr or None, default=None
Custom CSS properties applied to the generated HTML. Please note that the CSS will apply to the entire page if no iframe is used (see
use_iframefor more details).- styledict or None, default=None
CSS styling applied to each item in a cell. The dict must follow a
key: functionstructure where the key must correspond to one of the columns insubsetortooltip. The function takes the itemâs value as input, and outputs a valid CSS styling. For example, if you want to color the text corresponding to the âSolubilityâ column in your dataframe:style={"Solubility": lambda x: "color: red" if x < -5 else ""}
You can also style a whole cell using the
__all__key, the corresponding function then has access to all values for each cell:style={"__all__": lambda x: "color: red" if x["Solubility"] < -5 else ""}
Parameters: Customization#
- namestr, default=âdefaultâ
Name of the grid. Used when retrieving selections from multiple grids at the same time
- renamedict or None, default=None
Rename the properties in the final document.
- custom_headerstr or None, default=None
Custom libraries to be loaded in the header of the document.
- callbackstr, callable or None, default=None
Only available for the âinteractiveâ template. JavaScript or Python callback to be executed when clicking on an image. A dictionnary containing the data for the full cell is directly available as
datain JS. For Python, the callback function must havedataas the first argument to the function. All the values in thedatadict are parsed as strings, except âmols2grid-idâ which is always an integer. Note that fields containing spaces in their name will be replaced by hyphens, i.e. âmol weightâ becomes available asdata["mol-weight"].
- returns:
view
- rtype:
IPython.core.display.HTML
Notes
You can also directly use RDKitâs
MolDrawOptionsparameters as arguments. Additionally,atomColourPaletteis available to customize the atom palette if youâre not prerendering image (prerender=False).New in version 0.1.0: Added
sort_by,custom_css,custom_headerandcallbackarguments. Added the ability to style an entire cell withstyle={"__all__": <function>}.New in version 0.2.0: Added
substruct_highlightargument.Changed in version 0.2.2: If both
subsetandtooltipareNone, the index and image will be directly displayed on the grid while the remaining fields will be in the tooltip.Changed in version 1.0.0:
callbackcan now be a lambda function. Ifprerender=True, substructure highlighting will be automatically disabled if it wasnât explicitely set toTrueinstead of raising an error.
- mols2grid.save(arg, **kwargs)[source]#
- mols2grid.save(df: DataFrame, **kwargs)
- mols2grid.save(sdf: Path, **kwargs)
- mols2grid.save(sdf: str, **kwargs)
- mols2grid.save(mols: tuple, **kwargs)
- mols2grid.save(mols: list, **kwargs)
- mols2grid.save(mols: Series, **kwargs)
Generate an interactive grid of molecules and save it.
- Parameters:
arg (pandas.DataFrame, SDF file or list of molecules) â The input containing your molecules.
output (str) â Name and path of the output document.
Notes
See
display()for the full list of arguments.