Chemical viewer for 2D structures of small molecules
Project description
👀 mols2grid
mols2grid is a Python chemical viewer for 2D structures of small molecules, based on RDKit.
➡️ Check the demo notebook here
Installation ℹ️
mols2grid was developped for Python 3.6+ and requires rdkit, pandas and jinja2 as dependencies.
To install mols2grid from a clean conda environment:
conda install -c conda-forge rdkit
pip install mols2grid
Usage 📜
import mols2grid
mols2grid.display("path/to/molecules.sdf",
# RDKit's MolDrawOptions parameters
fixedBondLength=25,
# rename fields for the output document
mapping={"SOL": "Solubility",
"SOL_classification": "Class",
"NAME": "Name"},
# set what's displayed on the grid
subset=["ID", "img", "Solubility"],
# set what's displayed on the tooltips
tooltip=["Name", "smiles", "Class", "Solubility"],
# style for the grid labels and tooltips
style={"Solubility": lambda x: "color: red" if x < -3 else "color: black"})
Input parameters
You can setup the grid from various inputs:
- a pandas DataFrame (with a column of SMILES, controlled by the
smiles_col="SMILES"
parameter), - a list of RDKit molecules (with properties accessible through the
mol.GetPropsAsDict()
method), - or an SDF file
You can also rename each field of your input with the mapping
parameter. Please note that 2 fields are automatically added regardless of your input: SMILES
and img
. If a "SMILES" field already exists, it will not be overwritten.
Parameters for the drawing of each molecule
useSVG=True
: use SVG images or PNGcoordGen=True
: use the coordGen library instead of the RDKit one to depict the molecules in 2Dsize=(160, 120)
: size of each image- and all the arguments available in RDKit's MolDrawOptions, like
addStereoAnnotation=True
Parameters for the grid
You can control the general look of the document through the template
argument:
template="pages"
(default) which is displayed above. It integrates nicely with Jupyter notebookstemplate="table"
, which displays the full list of molecules (no pages). Useful if you ever need to print the full list of molecules on paper (or print to PDF)
Both templates can be configured with the same parameters (a lot of which are CSS declarations):
subset=None
: list or None
Columns to be displayed in each cell of the grid. Each column's value will be displayed from top to bottom in the same order given here. Use"img"
for the image of the molecule. Default: all columns (with "img" in first position)tooltip=None
: list or None
Columns to be displayed as a tooltip when hovering/clicking on the image of a cell. UseNone
for no tooltip.tooltip_fmt="<strong>{key}</strong>: {value}"
: str
Format string of each key/value pair in the tooltiptooltip_trigger="click hover"
: str
Sequence of triggers for the tooltip: (click, hover, focus)tooltip_placement="bottom"
: str
Position of the tooltip: auto, top, bottom, left, rightcell_width=160
: int
Max width of each cell, in pixelsn_cols=5
: int
Number of columns per pageborder="1px solid #cccccc"
: str
Styling of the border around each cell (CSS)gap=0
: int or str
Size of the margin around each cell (CSS)fontsize="12pt"
: str
Font size of the text displayed in each cell (CSS)fontfamily"'DejaVu', sans-serif"
: str
Font used for the text in each cell (CSS)textalign="center"
: str
Alignment of the text in each cell (CSS)hover_color="#e7e7e7"
: str
Background color when hovering a cell (CSS)style=None
: dict or None
CSS styling applied to each item in a cell. The dict must follow akey: function
structure where the key must correspond to one of the columns insubset
ortooltip
. 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 < -3 else "color: black"}
The pages
template comes with additional parameters:
n_rows=3
: int
Number of rows per page
License
Unless otherwise noted, all files in this directory and all subdirectories are distributed under the Apache License, Version 2.0:
Copyright 2021 Cédric BOUYSSET
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for mols2grid-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8225a0acce806d145cff5cc90dfcbbd1db048d2195055384c4e9f2f0c1134684 |
|
MD5 | 356e61178fadc20e7e52669930387f45 |
|
BLAKE2b-256 | 7148bf641f31a735e88a6fb43f2cb3ed38a9c05571ace5770e5126e88f3581f0 |