#!/usr/bin/env python
# (C) 2022 Cadence Design Systems, Inc. (Cadence) 
# All rights reserved.
# TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
# provided to current licensees or subscribers of Cadence products or
# SaaS offerings (each a "Customer").
# Customer is hereby permitted to use, copy, and modify the Sample Code,
# subject to these terms. Cadence claims no rights to Customer's
# modifications. Modification of Sample Code is at Customer's sole and
# exclusive risk. Sample Code may require Customer to have a then
# current license or subscription to the applicable Cadence offering.
# THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED.  OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
# NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall Cadence be
# liable for any damages or liability in connection with the Sample Code
# or its use.

from openeye import oechem
from openeye import oedepict

###############################################################
# USED TO GENERATE CODE SNIPPETS FOR THE OEDEPICT DOCUMENTATION
###############################################################


def DepictMoleculesWithHighlight(smiles, ss, highlight, basefilename):

    mol = oechem.OEGraphMol()
    oechem.OESmilesToMol(mol, smiles)
    oedepict.OEPrepareDepiction(mol)
    opts = oedepict.OE2DMolDisplayOptions(220, 160, oedepict.OEScale_AutoScale)
    disp = oedepict.OE2DMolDisplay(mol, opts)

    unique = True
    for match in ss.Match(mol, unique):
        oedepict.OEAddHighlighting(disp, highlight, match)

    image = oedepict.OEImage(disp.GetWidth(), disp.GetHeight())
    oedepict.OERenderMolecule(image, disp)

    oedepict.OEWriteImage(basefilename + ".png", image)
    oedepict.OEWriteImage(basefilename + ".pdf", image)


smiles = "c1ccc2c(c1)cc(O)cn2"
ss = oechem.OESubSearch("c1ncc(O)cc1")

highlight = oedepict.OEHighlightByLasso(oechem.OEBlack)

# @ <SNIPPET-OEHIGHLIGHTBYLASSO-SETCOLOR>
highlight.SetColor(oechem.OEDarkGreen)
# @ </SNIPPET-OEHIGHLIGHTBYLASSO-SETCOLOR>
DepictMoleculesWithHighlight(smiles, ss, highlight, "OEHighlightByLasso_SetColor")

# @ <SNIPPET-OEHIGHLIGHTBYLASSO-SETPEN>
pen = oedepict.OEPen(oechem.OEGreenTint, oechem.OEDarkGreen,
                     oedepict.OEFill_On, 3.0, oedepict.OEStipple_Dot)
highlight.SetPen(pen)
# @ </SNIPPET-OEHIGHLIGHTBYLASSO-SETPEN>
DepictMoleculesWithHighlight(smiles, ss, highlight, "OEHighlightByLasso_SetPen")

# @ <SNIPPET-OEHIGHLIGHTBYLASSO-SETLASSOSCALE>
highlight = oedepict.OEHighlightByLasso(oechem.OEDarkGreen)
highlight.SetLassoScale(6.0)
# @ </SNIPPET-OEHIGHLIGHTBYLASSO-SETLASSOSCALE>
DepictMoleculesWithHighlight(smiles, ss, highlight, "OEHighlightByLasso_SetLassoScale")

# @ <SNIPPET-OEHIGHLIGHTBYLASSO-SETATOMLABELMONOCHROME>
highlight = oedepict.OEHighlightByLasso(oechem.OEDarkGreen)
highlight.SetAtomLabelMonochrome(False)
# @ </SNIPPET-OEHIGHLIGHTBYLASSO-SETATOMLABELMONOCHROME>
DepictMoleculesWithHighlight(smiles, ss, highlight, "OEHighlightByLasso_SetAtomLabelMonochrome")

# @ <SNIPPET-OEHIGHLIGHTBYLASSO-SETCONSIDERATOMLABELBOUNDINGBOX>
highligh = oedepict.OEHighlightByLasso(oechem.OEDarkGreen)
highlight.SetConsiderAtomLabelBoundingBox(True)
# @ </SNIPPET-OEHIGHLIGHTBYLASSO-SETCONSIDERATOMLABELBOUNDINGBOX>
DepictMoleculesWithHighlight(smiles, ss, highlight,
                             "OEHighlightByLasso_SetConsiderAtomLabelBoundingBox")

# @ <SNIPPET-OEHIGHLIGHTBYLASSO-SETLINEWIDTHSCALE>
highligh = oedepict.OEHighlightByLasso(oechem.OEDarkGreen)
highlight.SetLineWidthScale(3.0)
# @ </SNIPPET-OEHIGHLIGHTBYLASSO-SETLINEWIDTHSCALE>
DepictMoleculesWithHighlight(smiles, ss, highlight, "OEHighlightByLasso_SetLineWidthScale")
