OEDepict Examples

Generating 2D Coordinates

/***********************************************************************
* Copyright 2004-2015 OpenEye Scientific Software, Inc.
************************************************************************
* Generates 2D coordinates
***********************************************************************/
using System;
using OpenEye.OEChem;
using OpenEye.OEDepict;

public class Depict
{
    public static int Main(string[] args)
    {
        OEInterface itf = new OEInterface(interfaceData);
        OEDepict.OEConfigurePrepareDepictionOptions(itf, OEPrepareDepictionSetup.SuppressHydrogens |
                                                         OEPrepareDepictionSetup.DepictOrientation);

        if (!OEChem.OEParseCommandLine(itf, args, "Depict"))
        {
            OEChem.OEThrow.Fatal("Unable to interpret command line");
        }

        oemolistream ifs = new oemolistream();
        if (!ifs.open(itf.GetString("-in")))
        {
            OEChem.OEThrow.Fatal("Cannot open input file!");
        }

        oemolostream ofs = new oemolostream(".sdf");
        if (itf.HasString("-out"))
        {
            string oname = itf.GetString("-out");
            if (!ofs.open(oname))
            {
                OEChem.OEThrow.Fatal("Cannot open output file!");
            }
            if (!OEChem.OEIs2DFormat(ofs.GetFormat()))
            {
                OEChem.OEThrow.Fatal("Invalid output format for 2D coordinates");
            }
        }

        if (itf.HasString("-ringdict"))
        {
            string rdfname = itf.GetString("-ringdict");
            if (!OEChem.OEInit2DRingDictionary(rdfname))
            {
              OEChem.OEThrow.Warning("Cannot use user-defined ring dictionary!");
            }
        }

        OEPrepareDepictionOptions popts = new OEPrepareDepictionOptions();
        OEDepict.OESetupPrepareDepictionOptions(popts, itf);
        popts.SetClearCoords(true);

        OEGraphMol mol = new OEGraphMol();
        while (OEChem.OEReadMolecule(ifs, mol))
        {
            OEDepict.OEPrepareDepiction(mol, popts);
            OEChem.OEWriteMolecule(ofs, mol);
        }

        return 0;
    }

    private static string interfaceData = @"
!BRIEF [-in] <input> [-out] <output> [-ringdict] <rd file>

!CATEGORY ""input/output options :""

  !PARAMETER -in
    !ALIAS -i
    !TYPE string
    !REQUIRED true
    !KEYLESS 1
    !VISIBILITY simple
    !BRIEF Input filename
  !END

  !PARAMETER -out
    !ALIAS -o
    !TYPE string
    !REQUIRED false
    !KEYLESS 2
    !VISIBILITY simple
    !BRIEF Output filename
  !END

  !PARAMETER -ringdict
    !ALIAS -rd
    !TYPE string
    !REQUIRED false
    !VISIBILITY simple
    !BRIEF User-defined 2D ring dictionary
    !DETAIL
        2D ring dictionaries can be generated by the following OEChem examples:
        C++    - createringdict.cpp
        Python - createringdict.py
        Java   - CreateRingDict.java
        C#     - CreateRingDict.cs
  !END

!END
";
}

Depicting Substructure Search Match

/****************************************************************************
* Copyright (C) 2011-2015 OpenEye Scientific Software, Inc.
*****************************************************************************
* Depict a molecule and highlight the substructure specified by
* the given SMARTS pattern
****************************************************************************/
using System;
using OpenEye.OEChem;
using OpenEye.OEDepict;

public class Match2Img
{
    public static int Main(string[] args)
    {
        OEInterface itf = new OEInterface(interfaceData);
        OEDepict.OEConfigureImageOptions(itf);
        OEDepict.OEConfigurePrepareDepictionOptions(itf);
        OEDepict.OEConfigure2DMolDisplayOptions(itf);
        OEDepict.OEConfigureHighlightParams(itf);

        if (!OEChem.OEParseCommandLine(itf, args, "Match2Img"))
        {
            OEChem.OEThrow.Fatal("Unable to interpret command line");
        }

        string iname = itf.GetString("-in");
        string oname = itf.GetString("-out");

        string ext = OEChem.OEGetFileExtension(oname);
        if (!OEDepict.OEIsRegisteredImageFile(ext))
        {
            OEChem.OEThrow.Fatal("Unknown image type!");
        }

        oemolistream ifs = new oemolistream();
        if (!ifs.open(iname))
        {
            OEChem.OEThrow.Fatal("Cannot open input file!");
        }

        oeofstream ofs = new oeofstream();
        if (!ofs.open(oname))
        {
            OEChem.OEThrow.Fatal("Cannot open output file!");
        }

        OEGraphMol mol = new OEGraphMol();
        if (!OEChem.OEReadMolecule(ifs, mol))
        {
            OEChem.OEThrow.Fatal("Cannot read input file!");
        }

        string  smarts = itf.GetString("-smarts");

        OESubSearch ss = new OESubSearch();
        if (!ss.Init(smarts))
        {
            OEChem.OEThrow.Fatal("Cannot parse smarts: " + smarts);
        }

        OEPrepareDepictionOptions popts = new OEPrepareDepictionOptions();
        OEDepict.OESetupPrepareDepictionOptions(popts, itf);
        OEDepict.OEPrepareDepiction(mol, popts);

        double width = OEDepict.OEGetImageWidth(itf);
        double height = OEDepict.OEGetImageHeight(itf);
        OE2DMolDisplayOptions dopts = new OE2DMolDisplayOptions(width, height, OEScale.AutoScale);
        OEDepict.OESetup2DMolDisplayOptions(dopts, itf);
        dopts.SetMargins(10.0);

        OE2DMolDisplay disp = new OE2DMolDisplay(mol, dopts);

        uint    hstyle = OEDepict.OEGetHighlightStyle(itf);
        OEColor hcolor = OEDepict.OEGetHighlightColor(itf);

        OEChem.OEPrepareSearch(mol, ss);

        bool unique = true;
        foreach (OEMatchBase match in ss.Match(mol, unique))
        {
            OEDepict.OEAddHighlighting(disp, hcolor, hstyle, match);
        }

        OEDepict.OERenderMolecule(ofs, ext, disp);
        
        return 0;
    }
    private static string interfaceData = @"
!BRIEF [-in] <input> [-smarts] <smarts> [-out] <output image>

!CATEGORY ""input/output options :""

    !PARAMETER -in
      !ALIAS -i
      !TYPE string
      !REQUIRED true
      !KEYLESS 1
      !VISIBILITY simple
      !BRIEF Input filename
    !END

    !PARAMETER -smarts
      !TYPE string
      !REQUIRED true
      !KEYLESS 2
      !VISIBILITY simple
      !BRIEF SMARTS pattern
    !END

    !PARAMETER -out
      !ALIAS -o
      !TYPE string
      !REQUIRED true
      !KEYLESS 3
      !VISIBILITY simple
      !BRIEF Output filename
    !END

!END
";
}

Aligning Molecules Based on MCS

/*****************************************************************************
* Copyright 2011-2015 OpenEye Scientific Software, Inc.
*****************************************************************************
* Aligns the fit molecule(s) based on their maximum common substructure
* with the reference molecule.
****************************************************************************/
using System;
using OpenEye.OEChem;
using OpenEye.OEDepict;

public class MCSAlign2D
{
    public static int Main(string[] args)
    {
        OEInterface itf = new OEInterface(interfaceData);

        if (!OEChem.OEParseCommandLine(itf, args, "MCSAlign2D"))
            OEChem.OEThrow.Fatal("Unable to interpret command line");

        string rname = itf.GetString("-ref");
        string fname = itf.GetString("-fit");
        string oname = itf.GetString("-out");

        oemolistream rifs = new oemolistream();
        if (!rifs.open(rname))
        {
            OEChem.OEThrow.Fatal("Cannot open reference molecule file!");
        }

        OEGraphMol refmol = new OEGraphMol();
        if (!OEChem.OEReadMolecule(rifs, refmol))
        {
            OEChem.OEThrow.Fatal("Cannot read reference molecule!");
        }

        oemolistream fifs = new oemolistream();
        if (!fifs.open(fname))
        {
            OEChem.OEThrow.Fatal("Cannot open align molecule file!");
        }

        oemolostream ofs = new oemolostream();
        if (!ofs.open(oname))
        {
            OEChem.OEThrow.Fatal("Cannot open output file!");
        }
        if (!OEChem.OEIs2DFormat(ofs.GetFormat()))
        {
            OEChem.OEThrow.Fatal("Invalid output format for 2D coordinates");
        }

        OEDepict.OEPrepareDepiction(refmol);

        OEMCSSearch mcss = new OEMCSSearch(OEMCSType.Approximate);
        uint atomexpr = OEExprOpts.DefaultAtoms;
        uint bondexpr = OEExprOpts.DefaultBonds;
        mcss.Init(refmol, atomexpr, bondexpr);
        mcss.SetMCSFunc(new OEMCSMaxBondsCompleteCycles());

        OEChem.OEWriteConstMolecule(ofs, refmol);

        OEGraphMol fitmol = new OEGraphMol();
        while (OEChem.OEReadMolecule(fifs, fitmol))
        {
            OEAlignmentResult alignres = new OEAlignmentResult(OEDepict.OEPrepareAlignedDepiction(fitmol, mcss));
            if (alignres.IsValid())
            {
                OEChem.OEThrow.Info(fitmol.GetTitle() + "  mcs size: " + alignres.NumAtoms());
                OEChem.OEWriteMolecule(ofs, fitmol);
            }
        }

        return 0;
    }

    private static string interfaceData = @"
!BRIEF [-ref] <input> [-fit] <input> [-out] <output>

!CATEGORY ""input/output options :""

    !PARAMETER -ref
      !ALIAS -r
      !TYPE string
      !REQUIRED true
      !KEYLESS 1
      !VISIBILITY simple
      !BRIEF Ref filename
    !END

    !PARAMETER -fit
      !ALIAS -f
      !TYPE string
      !REQUIRED true
      !KEYLESS 2
      !VISIBILITY simple
      !BRIEF Align filename
    !END

    !PARAMETER -out
      !ALIAS -o
      !TYPE string
      !REQUIRED true
      !KEYLESS 3
      !VISIBILITY simple
      !BRIEF Output filename
    !END

!END
";
}

Depicting MDL Query

/****************************************************************************
* Copyright 2011-2015 OpenEye Scientific Software, Inc.
*****************************************************************************
* Converts an MDL query structure into an image file.
* The output file format depends on its file extension.
****************************************************************************/
using System;
using OpenEye.OEChem;
using OpenEye.OEDepict;

public class MDLQuery2Img
{
    public static int Main(string[] args)
    {
        OEInterface itf = new OEInterface(interfaceData);
        OEDepict.OEConfigureImageOptions(itf);
        OEDepict.OEConfigure2DMolDisplayOptions(itf);

        if (!OEChem.OEParseCommandLine(itf, args, "MDLQuery2Img"))
        {
            OEChem.OEThrow.Fatal("Unable to uinterpret command line!");
        }

        string iname = itf.GetString("-in");
        string oname = itf.GetString("-out");

        string ext = OEChem.OEGetFileExtension(oname);
        if (!OEDepict.OEIsRegisteredImageFile(ext))
        {
            OEChem.OEThrow.Fatal("Unknown image type!");
        }

        oemolistream ifs = new oemolistream();
        if (!ifs.open(iname))
        {
            OEChem.OEThrow.Fatal("Cannot open input file!");
        }

        if (ifs.GetFormat() != OEFormat.MDL)
        {
            OEChem.OEThrow.Fatal("Input file is not an MDL query file");
        }

        oeofstream ofs = new oeofstream();
        if (!ofs.open(oname))
        {
            OEChem.OEThrow.Fatal("Cannot open output file!");
        }

        OEGraphMol mol = new OEGraphMol();
        if (!OEChem.OEReadMDLQueryFile(ifs, mol))
        {
            OEChem.OEThrow.Fatal("Cannot read mdl query input file!");
        }

        bool suppressH   = false;
        bool clearcoords = false;
        OEDepict.OEPrepareDepiction(mol, clearcoords, suppressH);

        double width  = OEDepict.OEGetImageWidth (itf);
        double height = OEDepict.OEGetImageHeight(itf);
        OE2DMolDisplayOptions opts = new OE2DMolDisplayOptions(width, height, OEScale.AutoScale);
        OEDepict.OESetup2DMolDisplayOptions(opts, itf);

        OE2DMolDisplay disp = new OE2DMolDisplay(mol, opts);
        OEDepict.OERenderMolecule(ofs, ext, disp);

        return 0;
    }
    private static string interfaceData = @"
!BRIEF [-in] <input> [-out] <output image>

!CATEGORY ""input/output options :""

    !PARAMETER -in
      !ALIAS -i
      !TYPE string
      !REQUIRED true
      !KEYLESS 1
      !VISIBILITY simple
      !BRIEF Input filename
    !END

    !PARAMETER -out
      !ALIAS -o
      !TYPE string
      !REQUIRED true
      !KEYLESS 2
      !VISIBILITY simple
      !BRIEF Output filename
    !END

!END
";

}

Depicting MDL Reaction

/****************************************************************************
* Copyright 2011-2015 OpenEye Scientific Software, Inc.
*****************************************************************************
* Converts an MDL reaction into an image file.
* The output file format depends on its file extension.
****************************************************************************/
using System;
using OpenEye.OEChem;
using OpenEye.OEDepict;

public class MDLReaction2Img
{
    public static int Main(string[] args)
    {
        OEInterface itf = new OEInterface(interfaceData);
        OEDepict.OEConfigureImageOptions(itf);
        OEDepict.OEConfigure2DMolDisplayOptions(itf);

        if (!OEChem.OEParseCommandLine(itf, args, "MDLReaction2Img"))
        {
            OEChem.OEThrow.Fatal("Unable to uinterpret command line!");
        }

        string iname = itf.GetString("-in");
        string oname = itf.GetString("-out");

        string ext = OEChem.OEGetFileExtension(oname);
        if (!OEDepict.OEIsRegisteredImageFile(ext))
        {
            OEChem.OEThrow.Fatal("Unknown image type!");
        }

        oemolistream ifs = new oemolistream();
        if (!ifs.open(iname))
        {
            OEChem.OEThrow.Fatal("Cannot open input file!");
        }

        oeofstream ofs = new oeofstream();
        if (!ofs.open(oname))
        {
            OEChem.OEThrow.Fatal("Cannot open output file!");
        }

        OEGraphMol mol = new OEGraphMol();
        if (!OEChem.OEReadMDLReactionQueryFile(ifs, mol))
        {
            OEChem.OEThrow.Fatal("Cannot read mdl reaction!");
        }

        bool suppressH   = false;
        bool clearcoords = false;
        OEDepict.OEPrepareDepiction(mol, clearcoords, suppressH);

        double width  = OEDepict.OEGetImageWidth (itf);
        double height = OEDepict.OEGetImageHeight(itf);
        OE2DMolDisplayOptions opts = new OE2DMolDisplayOptions(width, height, OEScale.AutoScale);
        OEDepict.OESetup2DMolDisplayOptions(opts, itf);

        OE2DMolDisplay disp = new OE2DMolDisplay(mol, opts);
        OEDepict.OERenderMolecule(ofs, ext, disp);

        return 0;
    }
    private static string interfaceData = @"
!BRIEF [-in] <input> [-out] <output image>

!CATEGORY ""input/output options :""

    !PARAMETER -in
      !ALIAS -i
      !TYPE string
      !REQUIRED true
      !KEYLESS 1
      !VISIBILITY simple
      !BRIEF Input filename
    !END

    !PARAMETER -out
      !ALIAS -o
      !TYPE string
      !REQUIRED true
      !KEYLESS 2
      !VISIBILITY simple
      !BRIEF Output filename
    !END

!END
";

}

Depicting a Single Molecule

/****************************************************************************
* Copyright (C) 2011-2015 OpenEye Scientific Software, Inc.
*****************************************************************************
* Converts a molecule structure into an image file.
* The output file format depends on its file extension.
****************************************************************************/
using System;
using OpenEye.OEChem;
using OpenEye.OEDepict;

public class Mol2Img
{
    public static int Main(string[] args)
    {
        OEInterface itf = new OEInterface(interfaceData);
        OEDepict.OEConfigureImageOptions(itf);
        OEDepict.OEConfigurePrepareDepictionOptions(itf);
        OEDepict.OEConfigure2DMolDisplayOptions(itf);

        if (!OEChem.OEParseCommandLine(itf, args, "Mol2Img"))
        {
            OEChem.OEThrow.Fatal("Unable to interpret command line");
        }

        string iname = itf.GetString("-in");
        string oname = itf.GetString("-out");

        string ext = OEChem.OEGetFileExtension(oname);
        if (!OEDepict.OEIsRegisteredImageFile(ext))
        {
            OEChem.OEThrow.Fatal("Unknown image type!");
        }

        oemolistream ifs = new oemolistream();
        if (!ifs.open(iname))
        {
            OEChem.OEThrow.Fatal("Cannot open input file!");
        }

        oeofstream ofs = new oeofstream();
        if (!ofs.open(oname))
        {
            OEChem.OEThrow.Fatal("Cannot open output file!");
        }

        OEGraphMol mol = new OEGraphMol();
        if (!OEChem.OEReadMolecule(ifs, mol))
        {
            OEChem.OEThrow.Fatal("Cannot read input file!");
        }

        if (itf.HasString("-ringdict"))
        {
            string rdfname = itf.GetString("-ringdict");
            if (!OEChem.OEInit2DRingDictionary(rdfname))
            {
              OEChem.OEThrow.Warning("Cannot use user-defined ring dictionary!");
            }
        }

        OEPrepareDepictionOptions popts = new OEPrepareDepictionOptions();
        OEDepict.OESetupPrepareDepictionOptions(popts, itf);
        OEDepict.OEPrepareDepiction(mol, popts);

        double width = OEDepict.OEGetImageWidth(itf);
        double height = OEDepict.OEGetImageHeight(itf);
        OE2DMolDisplayOptions opts = new OE2DMolDisplayOptions(width, height, OEScale.AutoScale);
        OEDepict.OESetup2DMolDisplayOptions(opts, itf);

        OE2DMolDisplay disp = new OE2DMolDisplay(mol, opts);
        OEDepict.OERenderMolecule(ofs, ext, disp);

        return 0;
    }
    private static string interfaceData = @"
!BRIEF [-in] <input> [-out] <output image>  [-ringdict] <rd file>

!CATEGORY ""input/output options :""

  !PARAMETER -in
    !ALIAS -i
    !TYPE string
    !REQUIRED true
    !KEYLESS 1
    !VISIBILITY simple
    !BRIEF Input filename
  !END

  !PARAMETER -out
    !ALIAS -o
    !TYPE string
    !REQUIRED true
    !KEYLESS 2
    !VISIBILITY simple
    !BRIEF Output filename
  !END

  !PARAMETER -ringdict
    !ALIAS -rd
    !TYPE string
    !REQUIRED false
    !VISIBILITY simple
    !BRIEF User-defined 2D ring dictionary
    !DETAIL
        2D ring dictionaries can be generated by the following OEChem examples:
        C++    - createringdict.cpp
        Python - createringdict.py
        Java   - CreateRingDict.java
        C#     - CreateRingDict.cs
  !END

!END
";
}

Depicting Molecules in Multi-Page

/****************************************************************************
 * Copyright (C) 2011-2015 OpenEye Scientific Software, Inc.
 *****************************************************************************
 * Converts molecules into a multi-page PDF document.
 ****************************************************************************/
using System;
using OpenEye.OEChem;
using OpenEye.OEDepict;

public class Mols2PDF
{
    public static void Main(string[] args)
    {
        OEInterface itf = new OEInterface(interfaceData);
        OEDepict.OEConfigureReportOptions(itf);
        OEDepict.OEConfigurePrepareDepictionOptions(itf);
        OEDepict.OEConfigure2DMolDisplayOptions(itf);

        if (!OEChem.OEParseCommandLine(itf, args, "Mols2PDF"))
        {
            OEChem.OEThrow.Fatal("Unable to interpret command line");
        }

        string iname = itf.GetString("-in");
        oemolistream ifs = new  oemolistream();
        if (!ifs.open(iname))
        {
            OEChem.OEThrow.Fatal("Cannot open" + iname + " input file!");
        }

        string oname = itf.GetString("-out");
        string ext = OEChem.OEGetFileExtension(oname);
        if (!ext.Equals("pdf"))
        {
            OEChem.OEThrow.Fatal("Output must be PDF format.");
        }

        oeofstream ofs = new oeofstream();
        if (!ofs.open(oname))
        {
            OEChem.OEThrow.Fatal("Cannot open " + oname + " output file!");
        }

        if (itf.HasString("-ringdict"))
        {
            string rdfname = itf.GetString("-ringdict");
            if (!OEChem.OEInit2DRingDictionary(rdfname))
            {
              OEChem.OEThrow.Warning("Cannot use user-defined ring dictionary!");
            }
        }

        OEReportOptions ropts = new OEReportOptions();
        OEDepict.OESetupReportOptions(ropts, itf);
        ropts.SetFooterHeight(25.0);
        OEReport report = new OEReport(ropts);

        OEPrepareDepictionOptions popts = new OEPrepareDepictionOptions();
        OEDepict.OESetupPrepareDepictionOptions(popts, itf);

        OE2DMolDisplayOptions dopts = new OE2DMolDisplayOptions();
        OEDepict.OESetup2DMolDisplayOptions(dopts, itf);
        dopts.SetDimensions(report.GetCellWidth(), report.GetCellHeight(), OEScale.AutoScale);

        OEGraphMol mol = new OEGraphMol();
        while (OEChem.OEReadMolecule(ifs, mol))
        {
            OEImageBase cell = report.NewCell();
            OEDepict.OEPrepareDepiction(mol, popts);
            OE2DMolDisplay disp = new OE2DMolDisplay(mol, dopts);
            OEDepict.OERenderMolecule(cell, disp);
        }

        uint pagenum = 1;
        OEFont font = new OEFont(OEFontFamily.Default, OEFontStyle.Bold, 12, OEAlignment.Center, OEChem.OEBlack);
        foreach (OEImageBase footer in report.GetFooters())
        {
            string text = "Page " + pagenum.ToString() + " of " + report.NumPages().ToString();
            OEDepict.OEDrawTextToCenter(footer, text, font);
            pagenum += 1;
        }
        OEDepict.OEWriteReport(ofs, ext, report);
    }
    private static string interfaceData = @"
!BRIEF [-in] <input> [-out] <output pdf>  [-ringdict] <rd file>

!CATEGORY ""input/output options :""

  !PARAMETER -in
    !ALIAS -i
    !TYPE string
    !REQUIRED true
    !KEYLESS 1
    !VISIBILITY simple
    !BRIEF Input filename
  !END

  !PARAMETER -out
    !ALIAS -o
    !TYPE string
    !REQUIRED true
    !KEYLESS 2
    !VISIBILITY simple
    !BRIEF Output filename
  !END

  !PARAMETER -ringdict
    !ALIAS -rd
    !TYPE string
    !REQUIRED false
    !VISIBILITY simple
    !BRIEF User-defined 2D ring dictionary
    !DETAIL
        2D ring dictionaries can be generated by the following OEChem examples:
        C++    - createringdict.cpp
        Python - createringdict.py
        Java   - CreateRingDict.java
        C#     - CreateRingDict.cs
  !END

!END
";

}

Depicting Molecules In a Grid

/****************************************************************************
* Copyright 2011-2015 OpenEye Scientific Software, Inc.
*****************************************************************************
* Converts molecules uinto an image with grid layout.
* The output file format depends on its file extension.
****************************************************************************/
using System;
using OpenEye.OEChem;
using OpenEye.OEDepict;

public class Mols2Img
{
    public static int Main(string[] args)
    {
        OEInterface itf = new OEInterface(interfaceData);
        OEDepict.OEConfigureImageWidth (itf, 400.0);
        OEDepict.OEConfigureImageHeight(itf, 400.0);
        OEDepict.OEConfigureImageGridParams(itf);
        OEDepict.OEConfigurePrepareDepictionOptions(itf);
        OEDepict.OEConfigure2DMolDisplayOptions(itf);

        if (!OEChem.OEParseCommandLine(itf, args, "Mols2Img"))
        {
            OEChem.OEThrow.Fatal("Unable to uinterpret command line!");
        }

        string oname = itf.GetString("-out");
        string ext = OEChem.OEGetFileExtension(oname);
        if (!OEDepict.OEIsRegisteredImageFile(ext))
        {
            OEChem.OEThrow.Fatal("Unknown image type!");
        }

        oeofstream ofs = new oeofstream();
        if (!ofs.open(oname))
        {
            OEChem.OEThrow.Fatal("Cannot open output file!");
        }

        double width  = OEDepict.OEGetImageWidth (itf);
        double height = OEDepict.OEGetImageHeight(itf);
        OEImage image = new OEImage(width, height);

        uint rows = OEDepict.OEGetImageGridNumRows(itf);
        uint cols = OEDepict.OEGetImageGridNumColumns(itf);
        OEImageGrid grid = new OEImageGrid(image, rows, cols);

        OEPrepareDepictionOptions popts = new OEPrepareDepictionOptions();
        OEDepict.OESetupPrepareDepictionOptions(popts, itf);

        OE2DMolDisplayOptions dopts = new OE2DMolDisplayOptions();
        OEDepict.OESetup2DMolDisplayOptions(dopts, itf);
        dopts.SetDimensions(grid.GetCellWidth(), grid.GetCellHeight(), OEScale.AutoScale);

        OEImageBaseIter celliter = grid.GetCells();
        foreach (string iname in itf.GetStringList("-in"))
        {
            oemolistream ifs = new oemolistream();
            if (!ifs.open(iname))
            {
                OEChem.OEThrow.Warning("Cannot open " + iname + " input file!");
                continue;
            }

            OEGraphMol mol = new OEGraphMol();
            while (OEChem.OEReadMolecule(ifs, mol) && celliter.IsValid())
            {
                OEDepict.OEPrepareDepiction(mol, popts);
                OE2DMolDisplay disp = new OE2DMolDisplay(mol, dopts);
                OEDepict.OERenderMolecule(celliter.Target(), disp);
                celliter.Increment();
            }
        }
        OEDepict.OEWriteImage(ofs, ext, image);
        return 0;
    }
    private static string interfaceData = @"
!BRIEF -in <input1> [ <input2> .. ] -out <output image>

!CATEGORY ""input/output options :""

    !PARAMETER -in
      !ALIAS -i
      !TYPE string
      !LIST true
      !REQUIRED true
      !VISIBILITY simple
      !BRIEF Input filename(s)
    !END

    !PARAMETER -out
      !ALIAS -o
      !TYPE string
      !REQUIRED true
      !VISIBILITY simple
      !BRIEF Output filename
    !END

!END
";

}

Generating 2D Ring Dictionary Report

/****************************************************************************
 * Copyright 2015 OpenEye Scientific Software, Inc.
 *****************************************************************************
 * Converts a ring dictionary into a multi-page PDF document.
 ****************************************************************************/
using System;
using OpenEye.OEChem;
using OpenEye.OEDepict;

public class RingDict2PDF
{
    public static int Main(string[] args)
    {

        OEInterface itf = new OEInterface(interfaceData);
        OEDepict.OEConfigureReportOptions(itf);

        if (!OEChem.OEParseCommandLine(itf, args, "RingDict2PDF"))
        {
            OEChem.OEThrow.Fatal("Unable to interpret command line");
        }

        string ifname = itf.GetString("-ringdict");
        string ofname = itf.GetString("-out");

        if (!OEChem.OEIsValid2DRingDictionary(ifname))
        {
            OEChem.OEThrow.Fatal("Invalid ring dictionary file!");
        }

        OE2DRingDictionary ringdict = new OE2DRingDictionary(ifname);

        OEReportOptions ropts = new OEReportOptions();
        OEDepict.OESetupReportOptions(ropts, itf);

        OEDepict.OEWrite2DRingDictionaryReport(ofname, ringdict, ropts);

        return 0;
    }
    private static string interfaceData = @"
!BRIEF [-ringdict] <input ringdict> [-out] <output pdf>

!CATEGORY ""input/output options :""

    !PARAMETER -ringdict
      !ALIAS -rd
      !TYPE string
      !REQUIRED true
      !KEYLESS 1
      !VISIBILITY simple
      !BRIEF Input ring dictionary filename
      !DETAIL
        2D ring dictionaries can be generated by the following OEChem examples:
        C++    - createringdict.cpp
        Python - createringdict.py
        Java   - CreateRingDict.java
        C#     - CreateRingDict.cs
    !END

    !PARAMETER -out
      !ALIAS -o
      !TYPE string
      !REQUIRED true
      !KEYLESS 2
      !VISIBILITY simple
      !BRIEF Output filename
    !END

!END
";   
}

Depicting MDL Query Substructure Search Hits

/****************************************************************************
 * Copyright (C) 2011-2015 OpenEye Scientific Software, Inc.
 *****************************************************************************
 * Performs substructure search on a molecule using a MDL query and
 * generates an image file depicting one match per molecule.
 * The output file format depends on its file extension.
 ****************************************************************************/
using System;
using OpenEye.OEChem;
using OpenEye.OEDepict;

public class ViewMDLSearch
{
    public static void Main(string[] args)
    {
        OEInterface itf = new OEInterface(interfaceData);
        OEDepict.OEConfigureReportOptions(itf);
        OEDepict.OEConfigure2DMolDisplayOptions(itf);
        OEDepict.OEConfigureHighlightParams(itf);

        if (!OEChem.OEParseCommandLine(itf, args, "ViewMDLSearch"))
        {
            OEChem.OEThrow.Fatal("Unable to interpret command line");
        }

        string qname = itf.GetString("-query");
        string tname = itf.GetString("-target");
        string oname = itf.GetString("-out");

        string ext = OEChem.OEGetFileExtension(oname);
        if (!OEDepict.OEIsRegisteredMultiPageImageFile(ext))
        {
            OEChem.OEThrow.Fatal("Unknown multipage image type!");
        }

        oemolistream qfile = new oemolistream();
        if (!qfile.open(qname))
        {
            OEChem.OEThrow.Fatal("Cannot open mdl query file!");
        }

        if (qfile.GetFormat() != OEFormat.MDL && qfile.GetFormat() != OEFormat.SDF)
        {
            OEChem.OEThrow.Fatal("Query file has to be an MDL file!");
        }

        oemolistream ifs = new  oemolistream();
        if (!ifs.open(tname))
        {
            OEChem.OEThrow.Fatal("Cannot open target input file!");
        }

        OEGraphMol depictquery = new OEGraphMol();
        if (!OEChem.OEReadMDLQueryFile(qfile, depictquery))
        {
            OEChem.OEThrow.Fatal("Cannot read query molecule!");
        }

        OEDepict.OEPrepareDepiction(depictquery);
        uint queryopts = OEMDLQueryOpts.Default | OEMDLQueryOpts.SuppressExplicitH;
        OEQMol qmol = new OEQMol();
        OEChem.OEBuildMDLQueryExpressions(qmol, depictquery, queryopts);

        OESubSearch ss = new OESubSearch();
        if (!ss.Init(qmol))
        {
            OEChem.OEThrow.Fatal("Cannot initialize substructure search!");
        }

        uint  hstyle = OEDepict.OEGetHighlightStyle(itf);
        OEColor  hcolor = OEDepict.OEGetHighlightColor(itf);
        bool align  = itf.GetBool("-align");

        OEReportOptions ropts = new OEReportOptions();
        OEDepict.OESetupReportOptions(ropts, itf);
        ropts.SetHeaderHeight(140.0);
        OEReport report = new OEReport(ropts);

        OE2DMolDisplayOptions dopts = new  OE2DMolDisplayOptions();
        OEDepict.OESetup2DMolDisplayOptions(dopts, itf);
        dopts.SetDimensions(report.GetCellWidth(), report.GetCellHeight(), OEScale.AutoScale);

        bool unique = true;
        OEGraphMol mol = new OEGraphMol();
        while (OEChem.OEReadMolecule(ifs, mol))
        {
            OEChem.OEPrepareSearch(mol, ss);
            OEMatchBaseIter miter = ss.Match(mol, unique);
            if (miter != null && miter.IsValid())
            {
                OEMatchBase match = miter.Target();

                if (align)
                {
                    OEDepict.OEPrepareAlignedDepiction(mol, ss.GetPattern(), match);
                }
                else
                {
                    OEDepict.OEPrepareDepiction(mol);
                }

                OEImageBase cell = report.NewCell();
                OE2DMolDisplay disp = new OE2DMolDisplay(mol, dopts);
                OEDepict.OEAddHighlighting(disp, hcolor, hstyle, match);
                OEDepict.OERenderMolecule(cell, disp);
                OEDepict.OEDrawBorder(cell, OEDepict.OELightGreyPen);
                miter.Increment();
            }
        }

        // render query structure in each header
        dopts.SetDimensions(report.GetHeaderWidth(), report.GetHeaderHeight(), OEScale.AutoScale);
        OE2DMolDisplay newdisp = new OE2DMolDisplay(depictquery, dopts);
        foreach (OEImageBase header in report.GetHeaders())
        {
            OEDepict.OERenderMolecule(header, newdisp);
            OEDepict.OEDrawBorder(header, OEDepict.OELightGreyPen);
        }

        OEDepict.OEWriteReport(oname, report);
    }
    private static string interfaceData = @"
!BRIEF [-query] <input> [-target] <input> [-out] <output multipage image> [-align]

!CATEGORY ""input/output options :""
  !PARAMETER -query
    !ALIAS -q
    !TYPE string
    !REQUIRED true
    !KEYLESS 1
    !VISIBILITY simple
    !BRIEF Input query filename
  !END

  !PARAMETER -target
    !ALIAS -t
    !TYPE string
    !REQUIRED true
    !KEYLESS 2
    !VISIBILITY simple
    !BRIEF Input target filename
  !END

  !PARAMETER -out
    !ALIAS -o
    !TYPE string
    !REQUIRED true
    !KEYLESS 3
    !VISIBILITY simple
    !BRIEF Output postscript filename
  !END

!END

!CATEGORY ""general options :""

  !PARAMETER -align
    !TYPE bool
    !REQUIRED false
    !DEFAULT true
    !VISIBILITY simple
    !BRIEF Align hits to query
  !END
!END
";
}