#!/usr/bin/env python
# (C) 2017 OpenEye Scientific Software Inc. All rights reserved.
#
# TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
# provided to current licensees or subscribers of OpenEye products or
# SaaS offerings (each a "Customer").
# Customer is hereby permitted to use, copy, and modify the Sample Code,
# subject to these terms. OpenEye 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 OpenEye 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 OpenEye 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 DepictMolecules(opts, smiles, basefilename, drawborder=False):

    mol = oechem.OEGraphMol()
    oechem.OESmilesToMol(mol, smiles)
    oedepict.OEPrepareDepiction(mol)

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

    if drawborder:
        oedepict.OEDrawBorder(image, oedepict.OELightGreyPen)

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


smiles = "Cc1cccnc1/C=C/[C@H](C(=O)O)O title"
smiles_pgroup = "c1ccc(cc1)COC(=O)C(CCOC2CCCCO2)N title"

opts = oedepict.OE2DMolDisplayOptions()
DepictMolecules(opts, smiles, "OE2DMolDisplayOptions_Default")


########################################################################
# AROMATIC
########################################################################

# @ <SNIPPET-OE2DMOLDISPLAY-OPTIONS-AROMATIC-STYLE>
width, height, scale = 300.0, 200.0, oedepict.OEScale_AutoScale
opts = oedepict.OE2DMolDisplayOptions(width, height, scale)
opts.SetAromaticStyle(oedepict.OEAromaticStyle_Circle)
# @ </SNIPPET-OE2DMOLDISPLAY-OPTIONS-AROMATIC-STYLE>
DepictMolecules(opts, smiles, "OE2DMolDisplayOptions_SetAromaticStyle")

########################################################################
# ATOM
########################################################################

# @ <SNIPPET-OE2DMOLDISPLAY-OPTIONS-ATOM-COLOR>
width, height, scale = 300.0, 200.0, oedepict.OEScale_AutoScale
opts = oedepict.OE2DMolDisplayOptions(width, height, scale)
opts.SetAtomColor(oechem.OEElemNo_O, oechem.OEColor(80, 0, 0))  # very dark red
opts.SetAtomColor(oechem.OEElemNo_N, oechem.OEColor(0, 0, 80))  # very dark blue
# @ </SNIPPET-OE2DMOLDISPLAY-OPTIONS-ATOM-COLOR>
DepictMolecules(opts, smiles, "OE2DMolDisplayOptions_SetAtomColor")

# @ <SNIPPET-OE2DMOLDISPLAY-OPTIONS-ATOM-COLOR-STYLE>
width, height, scale = 300.0, 200.0, oedepict.OEScale_AutoScale
opts = oedepict.OE2DMolDisplayOptions(width, height, scale)
opts.SetAtomColorStyle(oedepict.OEAtomColorStyle_BlackMonochrome)
# @ </SNIPPET-OE2DMOLDISPLAY-OPTIONS-ATOM-COLOR-STYLE>
DepictMolecules(opts, smiles, "OE2DMolDisplayOptions_SetAtomColorStyle")

# @ <SNIPPET-OE2DMOLDISPLAY-OPTIONS-ATOM-LABEL-FONT>
width, height, scale = 300.0, 200.0, oedepict.OEScale_AutoScale
opts = oedepict.OE2DMolDisplayOptions(width, height, scale)
font = oedepict.OEFont()
font.SetFamily(oedepict.OEFontFamily_Courier)
font.SetStyle(oedepict.OEFontStyle_Bold)
opts.SetAtomLabelFont(font)
# @ </SNIPPET-OE2DMOLDISPLAY-OPTIONS-ATOM-LABEL-FONT>
DepictMolecules(opts, smiles, "OE2DMolDisplayOptions_SetAtomLabelFont")

# @ <SNIPPET-OE2DMOLDISPLAY-OPTIONS-ATOM-LABEL-FONT-SCALE>
width, height, scale = 300.0, 200.0, oedepict.OEScale_AutoScale
opts = oedepict.OE2DMolDisplayOptions(width, height, scale)
opts.SetAtomLabelFontScale(1.5)
# @ </SNIPPET-OE2DMOLDISPLAY-OPTIONS-ATOM-LABEL-FONT-SCALE>
DepictMolecules(opts, smiles, "OE2DMolDisplayOptions_SetAtomLabelFontScale")

# @ <SNIPPET-OE2DMOLDISPLAY-OPTIONS-ATOM-PROP-LABEL-FONT>
width, height, scale = 300.0, 200.0, oedepict.OEScale_AutoScale
opts = oedepict.OE2DMolDisplayOptions(width, height, scale)
font = oedepict.OEFont()
font.SetStyle(oedepict.OEFontStyle_Bold)
font.SetColor(oechem.OEDarkGreen)
opts.SetAtomPropLabelFont(font)
opts.SetAtomPropertyFunctor(oedepict.OEDisplayAtomIdx())
# @ </SNIPPET-OE2DMOLDISPLAY-OPTIONS-ATOM-PROP-LABEL-FONT>
DepictMolecules(opts, smiles, "OE2DMolDisplayOptions_SetAtomPropLabelFont")

# @ <SNIPPET-OE2DMOLDISPLAY-OPTIONS-ATOM-PROPERTY-FUNCTOR>
width, height, scale = 300.0, 200.0, oedepict.OEScale_AutoScale
opts = oedepict.OE2DMolDisplayOptions(width, height, scale)
opts.SetAtomPropertyFunctor(oedepict.OEDisplayAtomIdx())
# @ </SNIPPET-OE2DMOLDISPLAY-OPTIONS-ATOM-PROPERTY-FUNCTOR>
DepictMolecules(opts, smiles, "OE2DMolDisplayOptions_SetAtomPropertyFunctor")

# @ <SNIPPET-OE2DMOLDISPLAY-OPTIONS-ATOM-PROP-LABEL-FONT-SCALE>
width, height, scale = 300.0, 200.0, oedepict.OEScale_AutoScale
opts = oedepict.OE2DMolDisplayOptions(width, height, scale)
opts.SetAtomPropLabelFontScale(1.5)
opts.SetAtomPropertyFunctor(oedepict.OEDisplayAtomIdx())
# @ </SNIPPET-OE2DMOLDISPLAY-OPTIONS-ATOM-PROP-LABEL-FONT-SCALE>
DepictMolecules(opts, smiles, "OE2DMolDisplayOptions_SetAtomPropLabelFontScale")

# @ <SNIPPET-OE2DMOLDISPLAY-OPTIONS-ATOM-STEREO-STYLE>
width, height, scale = 300.0, 200.0, oedepict.OEScale_AutoScale
opts = oedepict.OE2DMolDisplayOptions(width, height, scale)
opts.SetAtomStereoStyle(oedepict.OEAtomStereoStyle_Display_All |
                        oedepict.OEAtomStereoStyle_HashWedgeStyle_Standard)
# @ </SNIPPET-OE2DMOLDISPLAY-OPTIONS-ATOM-STEREO-STYLE>
DepictMolecules(opts, smiles, "OE2DMolDisplayOptions_SetAtomStereoStyle")

# @ <SNIPPET-OE2DMOLDISPLAY-OPTIONS-ATOM-VISIBILITY-FUNCTOR>
width, height, scale = 300.0, 200.0, oedepict.OEScale_AutoScale
opts = oedepict.OE2DMolDisplayOptions(width, height, scale)
opts.SetAtomVisibilityFunctor(oechem.OEAtomIsInRing())
# @ </SNIPPET-OE2DMOLDISPLAY-OPTIONS-ATOM-VISIBILITY-FUNCTOR>
DepictMolecules(opts, smiles, "OE2DMolDisplayOptions_SetAtomVisibilityFunctor")

########################################################################
# BACKGROUND
########################################################################

# @ <SNIPPET-OE2DMOLDISPLAY-OPTIONS-BACKGROUND-COLOR>
width, height, scale = 300.0, 200.0, oedepict.OEScale_AutoScale
opts = oedepict.OE2DMolDisplayOptions(width, height, scale)
opts.SetBackgroundColor(oechem.OEYellowTint)
# @ </SNIPPET-OE2DMOLDISPLAY-OPTIONS-BACKGROUND-COLOR>
DepictMolecules(opts, smiles, "OE2DMolDisplayOptions_SetBackgroundColor")

########################################################################
# BOND
########################################################################

# @ <SNIPPET-OE2DMOLDISPLAY-OPTIONS-BOND-COLOR-STYLE>
width, height, scale = 300.0, 200.0, oedepict.OEScale_AutoScale
opts = oedepict.OE2DMolDisplayOptions(width, height, scale)
opts.SetBondColorStyle(oedepict.OEBondColorStyle_Monochrome)
# @ </SNIPPET-OE2DMOLDISPLAY-OPTIONS-BOND-COLOR-STYLE>
DepictMolecules(opts, smiles, "OE2DMolDisplayOptions_SetBondColorStyle")

# @ <SNIPPET-OE2DMOLDISPLAY-OPTIONS-BOND-PROP-LABEL-FONT>
width, height, scale = 300.0, 200.0, oedepict.OEScale_AutoScale
opts = oedepict.OE2DMolDisplayOptions(width, height, scale)
font = oedepict.OEFont()
font.SetStyle(oedepict.OEFontStyle_Bold)
font.SetColor(oechem.OEDarkGreen)
opts.SetBondPropLabelFont(font)
opts.SetBondPropertyFunctor(oedepict.OEDisplayBondIdx())
# @ </SNIPPET-OE2DMOLDISPLAY-OPTIONS-BOND-PROP-LABEL-FONT>
DepictMolecules(opts, smiles, "OE2DMolDisplayOptions_SetBondPropLabelFont")

# @ <SNIPPET-OE2DMOLDISPLAY-OPTIONS-BOND-PROPERTY-FUNCTOR>
width, height, scale = 300.0, 200.0, oedepict.OEScale_AutoScale
opts = oedepict.OE2DMolDisplayOptions(width, height, scale)
opts.SetBondPropertyFunctor(oedepict.OEDisplayBondIdx())
# @ </SNIPPET-OE2DMOLDISPLAY-OPTIONS-BOND-PROPERTY-FUNCTOR>
DepictMolecules(opts, smiles, "OE2DMolDisplayOptions_SetBondPropertyFunctor")

# @ <SNIPPET-OE2DMOLDISPLAY-OPTIONS-BOND-PROP-LABEL-FONT-SCALE>
width, height, scale = 300.0, 200.0, oedepict.OEScale_AutoScale
opts = oedepict.OE2DMolDisplayOptions(width, height, scale)
opts.SetBondPropLabelFontScale(1.5)
opts.SetBondPropertyFunctor(oedepict.OEDisplayBondIdx())
# @ </SNIPPET-OE2DMOLDISPLAY-OPTIONS-BOND-PROP-LABEL-FONT-SCALE>
DepictMolecules(opts, smiles, "OE2DMolDisplayOptions_SetBondPropLabelFontScale")

# @ <SNIPPET-OE2DMOLDISPLAY-OPTIONS-BOND-STEREO-STYLE>
width, height, scale = 300.0, 200.0, oedepict.OEScale_AutoScale
opts = oedepict.OE2DMolDisplayOptions(width, height, scale)
opts.SetBondStereoStyle(oedepict.OEBondStereoStyle_Display_All)
# @ </SNIPPET-OE2DMOLDISPLAY-OPTIONS-BOND-STEREO-STYLE>
DepictMolecules(opts, smiles, "OE2DMolDisplayOptions_SetBondStereoStyle")

# @ <SNIPPET-OE2DMOLDISPLAY-OPTIONS-DEFAULT-BOND-PEN>
width, height, scale = 300.0, 200.0, oedepict.OEScale_AutoScale
opts = oedepict.OE2DMolDisplayOptions(width, height, scale)
pen = oedepict.OEPen(oechem.OEBlack, oechem.OEBlack, oedepict.OEFill_On, 5.0)
opts.SetDefaultBondPen(pen)
# @ </SNIPPET-OE2DMOLDISPLAY-OPTIONS-DEFAULT-BOND-PEN>
DepictMolecules(opts, smiles, "OE2DMolDisplayOptions_SetDefaultBondPen")

# @ <SNIPPET-OE2DMOLDISPLAY-OPTIONS-BOND-LINE-GAP-SCALE>
width, height, scale = 300.0, 200.0, oedepict.OEScale_AutoScale
opts = oedepict.OE2DMolDisplayOptions(width, height, scale)
opts.SetBondLineGapScale(0.5)
# @ </SNIPPET-OE2DMOLDISPLAY-OPTIONS-BOND-LINE-GAP-SCALE>
DepictMolecules(opts, smiles, "OE2DMolDisplayOptions_SetBondLineGapScale")

# @ <SNIPPET-OE2DMOLDISPLAY-OPTIONS-BOND-LINE-ATOM-LABEL-GAP-SCALE>
width, height, scale = 300.0, 200.0, oedepict.OEScale_AutoScale
opts = oedepict.OE2DMolDisplayOptions(width, height, scale)
opts.SetBondLineAtomLabelGapScale(2.0)
# @ </SNIPPET-OE2DMOLDISPLAY-OPTIONS-BOND-LINE-ATOM-LABEL-GAP-SCALE>
DepictMolecules(opts, smiles, "OE2DMolDisplayOptions_SetBondLineAtomLabelGapScale")

# @ <SNIPPET-OE2DMOLDISPLAY-OPTIONS-BOND-WIDTH-SCALING>
width, height, scale = 300.0, 200.0, oedepict.OEScale_AutoScale
opts = oedepict.OE2DMolDisplayOptions(width, height, scale)
opts.SetBondWidthScaling(True)
# @ </SNIPPET-OE2DMOLDISPLAY-OPTIONS-BOND-WIDTH-SCALING>
DepictMolecules(opts, smiles, "OE2DMolDisplayOptions_SetBondWidthScaling")

########################################################################
#
########################################################################

# @ <SNIPPET-OE2DMOLDISPLAY-OPTIONS-HYDROGEN-STYLE>
width, height, scale = 300.0, 200.0, oedepict.OEScale_AutoScale
opts = oedepict.OE2DMolDisplayOptions(width, height, scale)
opts.SetHydrogenStyle(oedepict.OEHydrogenStyle_ImplicitTerminal)
# @ </SNIPPET-OE2DMOLDISPLAY-OPTIONS-HYDROGEN-STYLE>
DepictMolecules(opts, smiles, "OE2DMolDisplayOptions_SetHydrogenStyle")

########################################################################
# SUPER ATOMS
########################################################################

# @ <SNIPPET-OE2DMOLDISPLAY-OPTIONS-SUPER-ATOM-LABEL-FONT>
width, height, scale = 300.0, 200.0, oedepict.OEScale_AutoScale
opts = oedepict.OE2DMolDisplayOptions(width, height, scale)
font = oedepict.OEFont()
font.SetColor(oechem.OEDarkRed)
opts.SetSuperAtomLabelFont(font)
opts.SetSuperAtomStyle(oedepict.OESuperAtomStyle_All)
# @ </SNIPPET-OE2DMOLDISPLAY-OPTIONS-SUPER-ATOM-LABEL-FONT>
DepictMolecules(opts, smiles, "OE2DMolDisplayOptions_SetSuperAtomLabelFont")

# @ <SNIPPET-OE2DMOLDISPLAY-OPTIONS-SUPER-ATOM-STYLE>
width, height, scale = 300.0, 200.0, oedepict.OEScale_AutoScale
opts = oedepict.OE2DMolDisplayOptions(width, height, scale)
opts.SetSuperAtomStyle(oedepict.OESuperAtomStyle_All)
# @ </SNIPPET-OE2DMOLDISPLAY-OPTIONS-SUPER-ATOM-STYLE>
DepictMolecules(opts, smiles, "OE2DMolDisplayOptions_SetSuperAtomStyle")

########################################################################
# PROTECTIVE GROUP
########################################################################

# @ <SNIPPET-OE2DMOLDISPLAY-OPTIONS-PROTECTIVE-GROUP-LABEL-FONT>
width, height, scale = 300.0, 200.0, oedepict.OEScale_AutoScale
opts = oedepict.OE2DMolDisplayOptions(width, height, scale)
font = oedepict.OEFont()
font.SetColor(oechem.OEDarkRed)
opts.SetProtectiveGroupLabelFont(font)
opts.SetProtectiveGroupStyle(oedepict.OEProtectiveGroupStyle_All)
# @ </SNIPPET-OE2DMOLDISPLAY-OPTIONS-PROTECTIVE-GROUP-LABEL-FONT>
DepictMolecules(opts, smiles_pgroup, "OE2DMolDisplayOptions_SetProtectiveGroupLabelFont")

# @ <SNIPPET-OE2DMOLDISPLAY-OPTIONS-PROTECTIVE-GROUP-STYLE>
width, height, scale = 300.0, 200.0, oedepict.OEScale_AutoScale
opts = oedepict.OE2DMolDisplayOptions(width, height, scale)
opts.SetProtectiveGroupStyle(oedepict.OEProtectiveGroupStyle_All)
# @ </SNIPPET-OE2DMOLDISPLAY-OPTIONS-PROTECTIVE-GROUP-STYLE>
DepictMolecules(opts, smiles_pgroup, "OE2DMolDisplayOptions_SetProtectiveGroupStyle")

########################################################################
# TITLE
########################################################################

# @ <SNIPPET-OE2DMOLDISPLAY-OPTIONS-TITLE-FONT>
width, height, scale = 300.0, 200.0, oedepict.OEScale_AutoScale
opts = oedepict.OE2DMolDisplayOptions(width, height, scale)
font = oedepict.OEFont()
font.SetStyle(oedepict.OEFontStyle_Bold)
font.SetColor(oechem.OEDarkBrown)
opts.SetTitleFont(font)
# @ </SNIPPET-OE2DMOLDISPLAY-OPTIONS-TITLE-FONT>
DepictMolecules(opts, smiles, "OE2DMolDisplayOptions_SetTitleFont")

# @ <SNIPPET-OE2DMOLDISPLAY-OPTIONS-TITLE-LOCATION>
width, height, scale = 300.0, 200.0, oedepict.OEScale_AutoScale
opts = oedepict.OE2DMolDisplayOptions(width, height, scale)
opts.SetTitleLocation(oedepict.OETitleLocation_Bottom)
# @ </SNIPPET-OE2DMOLDISPLAY-OPTIONS-TITLE-LOCATION>
DepictMolecules(opts, smiles, "OE2DMolDisplayOptions_SetTitleLocation")

# @ <SNIPPET-OE2DMOLDISPLAY-OPTIONS-TITLE-HEIGHT>
width, height, scale = 300.0, 200.0, oedepict.OEScale_AutoScale
opts = oedepict.OE2DMolDisplayOptions(width, height, scale)
opts.SetTitleHeight(20.0)
# @ </SNIPPET-OE2DMOLDISPLAY-OPTIONS-TITLE-HEIGHT>
DepictMolecules(opts, smiles, "OE2DMolDisplayOptions_SetTitleHeight")

# @ <SNIPPET-OE2DMOLDISPLAY-OPTIONS-TITLE-FONT-SCALE>
width, height, scale = 300.0, 200.0, oedepict.OEScale_AutoScale
opts = oedepict.OE2DMolDisplayOptions(width, height, scale)
opts.SetTitleFontScale(0.5)
# @ </SNIPPET-OE2DMOLDISPLAY-OPTIONS-TITLE-FONT-SCALE>
DepictMolecules(opts, smiles, "OE2DMolDisplayOptions_SetTitleFontScale")

########################################################################
# LAYOUT
########################################################################

drawborder = True

# @ <SNIPPET-OE2DMOLDISPLAY-OPTIONS-HEIGHT>
opts = oedepict.OE2DMolDisplayOptions()
opts.SetHeight(150.0)
# @ </SNIPPET-OE2DMOLDISPLAY-OPTIONS-HEIGHT>
DepictMolecules(opts, smiles, "OE2DMolDisplayOptions_SetHeight", drawborder)

# @ <SNIPPET-OE2DMOLDISPLAY-OPTIONS-WIDTH>
opts = oedepict.OE2DMolDisplayOptions()
opts.SetWidth(150.0)
# @ </SNIPPET-OE2DMOLDISPLAY-OPTIONS-WIDTH>
DepictMolecules(opts, smiles, "OE2DMolDisplayOptions_SetWidth", drawborder)

# @ <SNIPPET-OE2DMOLDISPLAY-OPTIONS-SCALE>
opts = oedepict.OE2DMolDisplayOptions()
opts.SetScale(20.0)
# @ </SNIPPET-OE2DMOLDISPLAY-OPTIONS-SCALE>
DepictMolecules(opts, smiles, "OE2DMolDisplayOptions_SetScale", drawborder)

# @ <SNIPPET-OE2DMOLDISPLAY-OPTIONS-DIMENSIONS>
opts = oedepict.OE2DMolDisplayOptions()
width, height, scale = 300.0, 300.0, 20.0
opts.SetDimensions(width, height, scale)
# @ </SNIPPET-OE2DMOLDISPLAY-OPTIONS-DIMENSIONS>
DepictMolecules(opts, smiles, "OE2DMolDisplayOptions_SetDimensions", drawborder)

# @ <SNIPPET-OE2DMOLDISPLAY-OPTIONS-SETMARGIN>
width, height, scale = 240.0, 180.0, oedepict.OEScale_AutoScale
opts = oedepict.OE2DMolDisplayOptions(width, height, scale)
opts.SetMargin(oedepict.OEMargin_Bottom, 25.0)
# @ </SNIPPET-OE2DMOLDISPLAY-OPTIONS-SETMARGIN>
DepictMolecules(opts, smiles, "OE2DMolDisplayOptions_SetMargin", drawborder)

# @ <SNIPPET-OE2DMOLDISPLAY-OPTIONS-SETMARGINS>
width, height, scale = 240.0, 180.0, oedepict.OEScale_AutoScale
opts = oedepict.OE2DMolDisplayOptions(width, height, scale)
opts.SetMargins(25.0)
# @ </SNIPPET-OE2DMOLDISPLAY-OPTIONS-SETMARGINS>
DepictMolecules(opts, smiles, "OE2DMolDisplayOptions_SetMargins", drawborder)
