SimonBoothroyd / plotmol

Interactive plotting of data annotated with molecule structures.
MIT License
10 stars 4 forks source link

Side by side multi molecules #14

Open jthorton opened 10 months ago

jthorton commented 10 months ago

Plotmol will currently draw multiple molecules in the tooltip image above each other it would be great to have the option to draw the molecules side by side as well. For this we could try and split the molecule using Chem.GetMolFrags(rdkit_mol, asMols=True) and if we have more than one molecule we can break up the SVG into a grid and rdkit should work out where to place the molecules automatically.

rdkit_mol = Chem.RemoveHs(Chem.MolFromSmiles(smiles))
rdkit_mol = Draw.PrepareMolForDrawing(rdkit_mol, forceCoords=True)
mols = Chem.GetMolFrags(rdkit_mol, asMols=True)
if len(mols) == 2:
    drawer = Draw.rdMolDraw2D.MolDraw2DSVG(400, 200, 200, 200)
    drawer.DrawMolecules(mols)
else:
    drawer = Draw.rdMolDraw2D.MolDraw2DSVG(400, 200)
    drawer.DrawMolecule(rdkit_mol)
SimonBoothroyd commented 10 months ago

Great suggestion! Would you be up to put in a PR for this?