#!/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 OEDEPICT DOCUMENTATION
###############################################################


def DepictPeptide(opts, smiles, basefilename):

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

    image = oedepict.OEImage(400, 200)
    oegrapheme.OEDrawPeptide(image, mol, opts)

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


smiles = "CCC(C)[C@H]1C(=O)N[C@@H](C(=O)N[C@H](C(=O)N[C@@H](C(=O)N[C@H](C(=O)NCCCC[C@@H]" \
         "(C(=O)N[C@@H](C(=O)N1)CCCN)NC(=O)[C@H](C(C)CC)NC(=O)[C@@H](CCC(=O)O)NC(=O)[C@H]" \
         "(CC(C)C)NC(=O)C2CSC(=N2)NC(C(C)CC)N)CC(=O)N)CC(=O)O)CC3=CN=C[NH]3)Cc4ccccc4 bacitracin"

# @ <SNIPPET-OEPEPTIDEDISPLAYOPTIONS-DEFAULT>
opts = oegrapheme.OEPeptideDisplayOptions()
# @ </SNIPPET-OEPEPTIDEDISPLAYOPTIONS-DEFAULT>
DepictPeptide(opts, smiles, "OEPeptideDisplayOptions_Default")

# @ <SNIPPET-OEPEPTIDEDISPLAYOPTIONS-SETLABELSTYLE>
opts = oegrapheme.OEPeptideDisplayOptions()
opts.SetLabelStyle(oegrapheme.OEPeptideLabelStyle_SingleLetter)
# @ </SNIPPET-OEPEPTIDEDISPLAYOPTIONS-SETLABELSTYLE>
DepictPeptide(opts, smiles, "OEPeptideDisplayOptions_SetLabelStyle")

# @ <SNIPPET-OEPEPTIDEDISPLAYOPTIONS-SETINTERACTIVE>
opts = oegrapheme.OEPeptideDisplayOptions()
opts.SetInteractive(True)
# @ </SNIPPET-OEPEPTIDEDISPLAYOPTIONS-SETINTERACTIVE>
DepictPeptide(opts, smiles, "OEPeptideDisplayOptions_SetInteractive")

# @ <SNIPPET-OEPEPTIDEDISPLAYOPTIONS-SETAMINOACIDSCALE>
opts = oegrapheme.OEPeptideDisplayOptions()
opts.SetInteractive(True)
opts.SetAminoAcidScale(0.75)
# @ </SNIPPET-OEPEPTIDEDISPLAYOPTIONS-SETAMINOACIDSCALE>
DepictPeptide(opts, smiles, "OEPeptideDisplayOptions_SetAminoAcidScale")
