#!/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
from openeye import oegrapheme

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


def DepictPropMap(propmap, mol, tagname, basefilename):

    width, height = 350, 250
    opts = oedepict.OE2DMolDisplayOptions(width, height, oedepict.OEScale_AutoScale)
    opts.SetTitleLocation(oedepict.OETitleLocation_Bottom)
    opts.SetAtomColorStyle(oedepict.OEAtomColorStyle_WhiteMonochrome)

    disp = oedepict.OE2DMolDisplay(mol, opts)
    below = disp.GetLayer(oedepict.OELayerPosition_Below)
    propmap.Render(below, disp, tagname)

    oedepict.OERenderMolecule(basefilename + ".png", disp)
    oedepict.OERenderMolecule(basefilename + ".pdf", disp)


def SetPartialCharge(mol, tagname):
    oechem.OEMMFFAtomTypes(mol)
    oechem.OEMMFF94PartialCharges(mol)

    tag = oechem.OEGetTag(tagname)
    for atom in mol.GetAtoms():
        atom.SetData(tag, atom.GetPartialCharge())


mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "Cc1cc(cc(c1[N+](=O)[O-])F)CC[N+]#C")

tagname = "PartialCharge"
SetPartialCharge(mol, tagname)

oedepict.OEPrepareDepiction(mol)

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

# @ <SNIPPET-OE2DPROPMAP-DEFAULT>
propmap = oegrapheme.OE2DPropMap()
# @ </SNIPPET-OE2DPROPMAP-DEFAULT>
DepictPropMap(propmap, mol, tagname, "OE2DPropMap_Default")

# @ <SNIPPET-OE2DPROPMAP-NEGATIVECOLOR>
propmap = oegrapheme.OE2DPropMap()
propmap.SetNegativeColor(oechem.OEDarkGreen)
# @ </SNIPPET-OE2DPROPMAP-NEGATIVECOLOR>
DepictPropMap(propmap, mol, tagname, "OE2DPropMap_SetNegativeColor")

# @ <SNIPPET-OE2DPROPMAP-MINVALUE>
propmap = oegrapheme.OE2DPropMap()
propmap.SetMinValue(0.0)
# @ </SNIPPET-OE2DPROPMAP-MINVALUE>
DepictPropMap(propmap, mol, tagname, "OE2DPropMap_SetMinValue")

# @ <SNIPPET-OE2DPROPMAP-POSITIVECOLOR>
propmap = oegrapheme.OE2DPropMap()
propmap.SetPositiveColor(oechem.OEDarkGreen)
# @ </SNIPPET-OE2DPROPMAP-POSITIVECOLOR>
DepictPropMap(propmap, mol, tagname, "OE2DPropMap_SetPositiveColor")

# @ <SNIPPET-OE2DPROPMAP-MAXVALUE>
propmap = oegrapheme.OE2DPropMap()
propmap.SetMaxValue(0.0)
# @ </SNIPPET-OE2DPROPMAP-MAXVALUE>
DepictPropMap(propmap, mol, tagname, "OE2DPropMap_SetMaxValue")

# @ <SNIPPET-OE2DPROPMAP-LEGEND-FONT>
propmap = oegrapheme.OE2DPropMap()
font = oedepict.OEFont()
font.SetStyle(oedepict.OEFontStyle_Bold)
font.SetColor(oechem.OEDarkBlue)
propmap.SetLegendFont(font)
# @ </SNIPPET-OE2DPROPMAP-LEGEND-FONT>
DepictPropMap(propmap, mol, tagname, "OE2DPropMap_SetLegendFont")

# @ <SNIPPET-OE2DPROPMAP-LEGEND-FONT-SCALE>
propmap = oegrapheme.OE2DPropMap()
propmap.SetLegendFontScale(1.5)
# @ </SNIPPET-OE2DPROPMAP-LEGEND-FONT-SCALE>
DepictPropMap(propmap, mol, tagname, "OE2DPropMap_SetLegendFontScale")

# @ <SNIPPET-OE2DPROPMAP-LEGEND-LOCATION>
propmap = oegrapheme.OE2DPropMap()
propmap.SetLegendLocation(oegrapheme.OELegendLocation_Left)
# @ </SNIPPET-OE2DPROPMAP-LEGEND-LOCATION>
DepictPropMap(propmap, mol, tagname, "OE2DPropMap_SetLegendLocation")

# @ <SNIPPET-OE2DPROPMAP-RESOLUTION>
propmap = oegrapheme.OE2DPropMap()
propmap.SetResolution(5)
# @ </SNIPPET-OE2DPROPMAP-RESOLUTION>
DepictPropMap(propmap, mol, tagname, "OE2DPropMap_SetResolution")

# @ <SNIPPET-OE2DPROPMAP-RADIUS-RATIO>
propmap = oegrapheme.OE2DPropMap()
propmap.SetRadiusRatio(0.75)
# @ </SNIPPET-OE2DPROPMAP-RADIUS-RATIO>
DepictPropMap(propmap, mol, tagname, "OE2DPropMap_SetRadiusRatio")
