"""Render structures used in the overview from explicit SMILES.""" from pathlib import Path from rdkit import Chem from rdkit.Chem.Draw import rdMolDraw2D import cairosvg HERE=Path(__file__).resolve().parent structures={ 'parent_acid':'O=C(O)c1ccccc1', 'parent_amine':'Nc1ccccc1', 'parent_aminoacid':'Nc1ccc(C(=O)O)cc1', 'product':'CNC(=O)c1ccc(NC(C)=O)cc1', } for name,smiles in structures.items(): drawer=rdMolDraw2D.MolDraw2DSVG(420,180) if name == "product" else rdMolDraw2D.MolDraw2DSVG(240,140) options=drawer.drawOptions() options.useBWAtomPalette() options.clearBackground=False options.bondLineWidth=2 options.fixedBondLength=28 options.fixedFontSize=26 if name == "product" else 24 options.fontFile=str(HERE/'fonts/Ubuntu-Regular.ttf') drawer.DrawMolecule(Chem.MolFromSmiles(smiles)) drawer.FinishDrawing() svg=drawer.GetDrawingText() (HERE/f'{name}.svg').write_text(svg) cairosvg.svg2pdf(bytestring=svg.encode(),write_to=str(HERE/f'{name}.pdf'))