It’s hard to remove the white background of molecular 2D figures created directly with RDKit. They don’t look good when placed in PowerPoint. This article provided a way to make TRANSPARENT ones.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
from rdkit import Chem
from rdkit import rdBase
from rdkit.Chem import Draw
from rdkit.Chem.Draw import rdMolDraw2D
from rdkit.Chem import rdDepictor
rdDepictor.SetPreferCoordGen(True)
from rdkit.Chem import rdMolDescriptors
from rdkit.Chem import rdFMCS
from rdkit import DataStructs
import io
from PIL import Image
def show_png(data):
bio = io.BytesIO(data)
img = Image.open(bio)
return img
smi = "CCCCCC" #Take cyclohexane as an example
drawer = rdMolDraw2D.MolDraw2DCairo(300,300) #You can adjust the image size
drawer.drawOptions().clearBackground = False
drawer.drawOptions().addStereoAnnotation = False
drawer.DrawMolecule(Chem.MolFromSmiles(smi))
drawer.FinishDrawing()
mol = drawer.GetDrawingText()
show_png(mol)
|
Right click and save it, done!
Cheers!🍺