def MolDraw2DFromQPainter(qpainter, width=-1, height=-1, panelWidth=-1, panelHeight=-1): from PyQt5.Qt import QPainter try: # Prefer the PyQt5-bundled sip from PyQt5 import sip except ImportError: # No bundled sip, try the standalone package import sip from rdkit.Chem.Draw import rdMolDraw2DQt if not isinstance(qpainter, QPainter): raise ValueError("argument must be a QPainter instance") if width <= 0: width = qpainter.viewport().width() if height <= 0: height = qpainter.viewport().height() ptr = sip.unwrapinstance(qpainter) d2d = rdMolDraw2DQt.MolDraw2DFromQPainter_(width, height, ptr, panelWidth, panelWidth) # tie the lifetime of the QPainter to this MolDraw2D object d2d._qptr = qpainter return d2d
def testfunc(): m = Chem.MolFromSmiles('c1ccccc1O') Draw.PrepareMolForDrawing(m) qimg = QImage(250, 200, QImage.Format_RGB32) with QPainter(qimg) as qptr: p = sip.unwrapinstance(qptr) d2d = rdMolDraw2DQt.MolDraw2DFromQPainter_(250, 200, p, -1, -1) raise ValueError("expected")
def testSIPBasics(self): m = Chem.MolFromSmiles('c1ccccc1O') Draw.PrepareMolForDrawing(m) qimg = QImage(250, 200, QImage.Format_RGB32) with QPainter(qimg) as qptr: p = sip.unwrapinstance(qptr) d2d = rdMolDraw2DQt.MolDraw2DFromQPainter_(250, 200, p) d2d.DrawMolecule(m) qimg.save("testImageFromPyQt-1.png")