I've recently had similar concerns.
The issue that I've had is that MolsToGridImage() sets a single scale, and
uses that scale for all the molecules (such that a phenyl ring is the same
size for all your molecules). This is great when you're displaying a set of
related compounds, where having everything on the same scale helps to
identify commonalities and differences between the different molecules.
It's less useful when you're looking at a wide variety of arbitrary
molecules, of potentially different scales, where the larger ones force the
smaller ones to be vanishingly small.
My solution was to write the following function, based on the internals of
MolsToGridImage()
----
from rdkit.Chem import AllChem
import rdkit.Chem.Draw
from rdkit.Chem.Draw import rdMolDraw2D
try:
import Image
except ImportError:
from PIL import Image
from io import BytesIO
def DrawMolsZoomed(mols, molsPerRow=3, subImgSize=(200, 200)):
nRows = len(mols) // molsPerRow
if len(mols) % molsPerRow: nRows += 1
fullSize = (molsPerRow * subImgSize[0], nRows * subImgSize[1])
full_image = Image.new('RGBA', fullSize )
for ii, mol in enumerate(mols):
if mol.GetNumConformers() == 0:
AllChem.Compute2DCoords(mol)
column = ii % molsPerRow
row = ii // molsPerRow
offset = ( column*subImgSize[0], row * subImgSize[1] )
d2d = rdMolDraw2D.MolDraw2DCairo(subImgSize[0], subImgSize[1])
d2d.DrawMolecule(mol)
d2d.FinishDrawing()
sub = Image.open(BytesIO(d2d.GetDrawingText()))
full_image.paste(sub,box=offset)
return full_image
----
On Mon, Nov 26, 2018 at 4:52 PM Sundar <[email protected]> wrote:
> How to reduce the space between each row of images while using
> Draw.MolsToGridImage to render an image?
> Currently the default space is unnecessarily big.
>
> --
> Thanks,
> Sundar
> _______________________________________________
> Rdkit-discuss mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
>
_______________________________________________
Rdkit-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss