Beispiel #1
0
def _toPNG(mol):
  if hasattr(mol, '__sssAtoms'):
    highlightAtoms = mol.__sssAtoms
  else:
    highlightAtoms = []
  try:
    mol.GetAtomWithIdx(0).GetExplicitValence()
  except RuntimeError:
    mol.UpdatePropertyCache(False)

  if not hasattr(rdMolDraw2D, 'MolDraw2DCairo'):
    mc = copy.deepcopy(mol)
    try:
      img = Draw.MolToImage(mc, size=molSize, kekulize=kekulizeStructures,
                            highlightAtoms=highlightAtoms)
    except ValueError:  # <- can happen on a kekulization failure
      mc = copy.deepcopy(mol)
      img = Draw.MolToImage(mc, size=molSize, kekulize=False, highlightAtoms=highlightAtoms)
    bio = BytesIO()
    img.save(bio, format='PNG')
    return bio.getvalue()
  else:
    nmol = rdMolDraw2D.PrepareMolForDrawing(mol, kekulize=kekulizeStructures)
    d2d = rdMolDraw2D.MolDraw2DCairo(molSize[0], molSize[1])
    d2d.DrawMolecule(nmol, highlightAtoms=highlightAtoms)
    d2d.FinishDrawing()
    return d2d.GetDrawingText()
Beispiel #2
0
def _toPNG(mol):
    if hasattr(mol, '__sssAtoms'):
        highlightAtoms = mol.__sssAtoms
    else:
        highlightAtoms = []
    try:
        mol.GetAtomWithIdx(0).GetExplicitValence()
    except RuntimeError:
        mol.UpdatePropertyCache(False)

    mc = copy.deepcopy(mol)
    try:
        img = Draw.MolToImage(mc,
                              size=molSize,
                              kekulize=kekulizeStructures,
                              highlightAtoms=highlightAtoms)
    except ValueError:  # <- can happen on a kekulization failure
        mc = copy.deepcopy(mol)
        img = Draw.MolToImage(mc,
                              size=molSize,
                              kekulize=False,
                              highlightAtoms=highlightAtoms)

    bio = BytesIO()
    img.save(bio, format='PNG')
    return bio.getvalue()
Beispiel #3
0
def _toReactionPNG(rxn):
    rc = copy.deepcopy(rxn)
    img = Draw.ReactionToImage(rc,
                               subImgSize=(int(molSize[0] / 3), molSize[1]))
    bio = BytesIO()
    img.save(bio, format='PNG')
    return bio.getvalue()
Beispiel #4
0
def _toPNG(mol):
  if hasattr(mol, '__sssAtoms'):
    highlightAtoms = mol.__sssAtoms
  else:
    highlightAtoms = []
  try:
    mol.GetAtomWithIdx(0).GetExplicitValence()
  except RuntimeError:
    mol.UpdatePropertyCache(False)

  if not hasattr(rdMolDraw2D, 'MolDraw2DCairo'):
    mc = copy.deepcopy(mol)
    try:
      img = Draw.MolToImage(mc, size=molSize, kekulize=kekulizeStructures,
                            highlightAtoms=highlightAtoms)
    except ValueError:  # <- can happen on a kekulization failure
      mc = copy.deepcopy(mol)
      img = Draw.MolToImage(mc, size=molSize, kekulize=False, highlightAtoms=highlightAtoms)
    bio = BytesIO()
    img.save(bio, format='PNG')
    return bio.getvalue()
  else:
    nmol = rdMolDraw2D.PrepareMolForDrawing(mol, kekulize=kekulizeStructures)
    d2d = rdMolDraw2D.MolDraw2DCairo(molSize[0], molSize[1])
    d2d.DrawMolecule(nmol, highlightAtoms=highlightAtoms)
    d2d.FinishDrawing()
    return d2d.GetDrawingText()
Beispiel #5
0
def _toReactionPNG(rxn):
  rc = copy.deepcopy(rxn)
  img = Draw.ReactionToImage(rc, subImgSize=(int(molSize[0] / 3), molSize[1]),
                             highlightByReactant=highlightByReactant)
  bio = BytesIO()
  img.save(bio, format='PNG')
  return bio.getvalue()
Beispiel #6
0
def _get_image(x):
  """displayhook function for PIL Images, rendered as PNG"""
  bio = BytesIO()
  x.save(bio, format='PNG')
  s = b64encode(bio.getvalue()).decode('ascii')
  pd.set_option('display.max_columns', len(s) + 1000)
  pd.set_option('display.max_rows', len(s) + 1000)
  if len(s) + 100 > pd.get_option("display.max_colwidth"):
    pd.set_option("display.max_colwidth", len(s) + 1000)
  return s
Beispiel #7
0
def _get_image(x):
  """displayhook function for PIL Images, rendered as PNG"""
  bio = BytesIO()
  x.save(bio, format='PNG')
  s = b64encode(bio.getvalue()).decode('ascii')
  pd.set_option('display.max_columns', len(s) + 1000)
  pd.set_option('display.max_rows', len(s) + 1000)
  if len(s) + 100 > pd.get_option("display.max_colwidth"):
    pd.set_option("display.max_colwidth", len(s) + 1000)
  return s
Beispiel #8
0
def _get_image(x):
    """displayhook function for PIL Images, rendered as PNG"""
    import pandas as pd

    bio = BytesIO()
    x.save(bio, format="PNG")
    s = b64encode(bio.getvalue()).decode("ascii")
    pd.set_option("display.max_columns", len(s) + 1000)
    pd.set_option("display.max_rows", len(s) + 1000)
    if len(s) + 100 > pd.get_option("display.max_colwidth"):
        pd.set_option("display.max_colwidth", len(s) + 1000)
    return s
Beispiel #9
0
def _toPNG(mol):
    if hasattr(mol,'__sssAtoms'):
        highlightAtoms=mol.__sssAtoms
    else:
        highlightAtoms=[]
    try:
        mol.GetAtomWithIdx(0).GetExplicitValence()
    except RuntimeError:
        mol.UpdatePropertyCache(False)

    mc = copy.deepcopy(mol)
    try:
        img = Draw.MolToImage(mc,size=molSize,kekulize=kekulizeStructures,
                            highlightAtoms=highlightAtoms)
    except ValueError:  # <- can happen on a kekulization failure
        mc = copy.deepcopy(mol)
        img = Draw.MolToImage(mc,size=molSize,kekulize=False,
                            highlightAtoms=highlightAtoms)
    bio = BytesIO()
    img.save(bio,format='PNG')
    return bio.getvalue()
Beispiel #10
0
def display_pil_image(img):
  """displayhook function for PIL Images, rendered as PNG"""
  bio = BytesIO()
  img.save(bio, format='PNG')
  return bio.getvalue()
Beispiel #11
0
def display_pil_image(img):
    """displayhook function for PIL Images, rendered as PNG"""
    bio = BytesIO()
    img.save(bio,format='PNG')
    return bio.getvalue()