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


# @ <SNIPPET-2DPROPMAP-PCHARGE>
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)[N+]#C")
oedepict.OEPrepareDepiction(mol)

tagname = "PartialCharge"
SetPartialCharge(mol, tagname)

width, height = 450, 350
opts = oedepict.OE2DMolDisplayOptions(width, height, oedepict.OEScale_AutoScale)
opts.SetAtomColorStyle(oedepict.OEAtomColorStyle_WhiteMonochrome)
opts.SetTitleLocation(oedepict.OETitleLocation_Hidden)
opts.SetScale(oegrapheme.OEGetMoleculeSurfaceScale(mol, opts))
disp = oedepict.OE2DMolDisplay(mol, opts)

propmap = oegrapheme.OE2DPropMap(opts.GetBackgroundColor())
propmap.SetNegativeColor(oechem.OEDarkRed)
propmap.SetPositiveColor(oechem.OEDarkBlue)
propmap.Render(disp, tagname)

oedepict.OERenderMolecule("Draw2DPropMapPartialCharge.png", disp)
# @ </SNIPPET-2DPROPMAP-PCHARGE>
oedepict.OERenderMolecule("Draw2DPropMapPartialCharge.pdf", disp)
