OEDepict Examples

Generating 2D Coordinates

/****************************************************************************
 * Copyright 2004-2015 OpenEye Scientific Software, Inc.
 *****************************************************************************
 * Generates 2D coordinates
 ****************************************************************************/
package openeye.examples.oedepict;

import java.net.URL;
import java.util.*;

import openeye.oechem.*;
import openeye.oedepict.*;

public class Depict {

    public static void main(String argv[]) {
        URL fileURL = Depict.class.getResource("Depict.txt");
        try {
            OEInterface itf = new OEInterface();
            oechem.OEConfigureFromURL(itf, fileURL);
            oedepict.OEConfigurePrepareDepictionOptions(itf, OEPrepareDepictionSetup.SuppressHydrogens |
                                                             OEPrepareDepictionSetup.DepictOrientation);

            if (!oechem.OEParseCommandLine(itf, argv, "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);
            }
            ifs.close();
            ofs.close();
        }
        catch (java.io.IOException e) {
            System.err.println("Unable to open interface file");
        }
    }
}

Depicting Substructure Search Match

/****************************************************************************
 * Copyright 2011-2015 OpenEye Scientific Software, Inc.
 *****************************************************************************
 * Depict a molecule and highlight the substructure specified by
 * the given SMARTS pattern
 ****************************************************************************/
package openeye.examples.oedepict;

import java.net.URL;
import java.util.*;

import openeye.oechem.*;
import openeye.oedepict.*;

public class Match2Img {

    public static void main(String argv[]) {
        URL fileURL = Match2Img.class.getResource("Match2Img.txt");
        try {
            OEInterface itf = new OEInterface();
            oechem.OEConfigureFromURL(itf, fileURL);
            oedepict.OEConfigureImageOptions(itf);
            oedepict.OEConfigurePrepareDepictionOptions(itf);
            oedepict.OEConfigure2DMolDisplayOptions(itf);
            oedepict.OEConfigureHighlightParams(itf);

            if (!oechem.OEParseCommandLine(itf, argv, "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!");
            }
            ifs.close();

            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);

            int     hstyle = oedepict.OEGetHighlightStyle(itf);
            OEColor hcolor = oedepict.OEGetHighlightColor(itf);

            oechem.OEPrepareSearch(mol, ss);

            boolean unique = true;
            for (OEMatchBase match : ss.Match(mol, unique)) {
                oedepict.OEAddHighlighting(disp, hcolor, hstyle, match);
            }

            oedepict.OERenderMolecule(ofs, ext, disp);
            ofs.close();
        }
        catch (java.io.IOException e) {
            System.err.println("Unable to open interface file");
        }
    }
}

Aligning Molecules Based on MCS

/****************************************************************************
 * Copyright 2011-2015 OpenEye Scientific Software, Inc.
 *****************************************************************************
 * Aligns the fit molecules based on their maximum common substructure
 * with the reference molecule.
 ****************************************************************************/
package openeye.examples.oedepict;

import java.net.URL;
import java.util.*;

import openeye.oechem.*;
import openeye.oedepict.*;

public class MCSAlign2D {

    public static void main(String argv[]) {
        URL fileURL = MCSAlign2D.class.getResource("MCSAlign2D.txt");
        try {
            OEInterface itf = new OEInterface();
            oechem.OEConfigureFromURL(itf, fileURL);

            if (!oechem.OEParseCommandLine(itf, argv, "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!");
            rifs.close();

            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);
            int atomexpr = OEExprOpts.DefaultAtoms;
            int 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);
                }
            }
            fifs.close();
            ofs.close();
        }
        catch (java.io.IOException e) {
            System.err.println("Unable to open interface file");
        }
    }
}

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.
 ****************************************************************************/
package openeye.examples.oedepict;

import java.net.URL;
import java.util.*;

import openeye.oechem.*;
import openeye.oedepict.*;

public class MDLQuery2Img {

    public static void main(String argv[]) {
        URL fileURL = MDLQuery2Img.class.getResource("MDLQuery2Img.txt");
        try {
            OEInterface itf = new OEInterface();
            oechem.OEConfigureFromURL(itf, fileURL);
            oedepict.OEConfigureImageOptions(itf);
            oedepict.OEConfigure2DMolDisplayOptions(itf);

            if (!oechem.OEParseCommandLine(itf, argv, "MDLQuery2Img"))
                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!");

            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!");
            ifs.close();

            boolean clearcoords = false;
            boolean suppressH   = 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);

            ofs.close();
        }
        catch (java.io.IOException e) {
            System.err.println("Unable to open interface file");
        }
    }
}

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.
 ****************************************************************************/
package openeye.examples.oedepict;

import java.net.URL;
import java.util.*;

import openeye.oechem.*;
import openeye.oedepict.*;

public class MDLReaction2Img {

    public static void main(String argv[]) {
        URL fileURL = MDLReaction2Img.class.getResource("MDLReaction2Img.txt");
        try {
            OEInterface itf = new OEInterface();
            oechem.OEConfigureFromURL(itf, fileURL);
            oedepict.OEConfigureImageOptions(itf);
            oedepict.OEConfigure2DMolDisplayOptions(itf);

            if (!oechem.OEParseCommandLine(itf, argv, "MDLReaction2Img")) {
                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.OEReadMDLReactionQueryFile(ifs, mol)) {
                oechem.OEThrow.Fatal("Cannot read mdl reaction!");
            }
            ifs.close();

            boolean suppressH   = false;
            boolean 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);

            ofs.close();
        }
        catch (java.io.IOException e) {
            System.err.println("Unable to open interface file");
        }
    }
}

Depicting a Single Molecule

/****************************************************************************
 * Copyright 2011-2015 OpenEye Scientific Software, Inc.
 *****************************************************************************
 * Converts a molecule structure into an image file.
 * The output file format depends on its file extension.
 ****************************************************************************/
package openeye.examples.oedepict;

import java.net.URL;
import java.util.*;

import openeye.oechem.*;
import openeye.oedepict.*;

public class Mol2Img {

    public static void main(String argv[]) {
        URL fileURL = Mol2Img.class.getResource("Mol2Img.txt");
        try {
            OEInterface itf = new OEInterface();
            oechem.OEConfigureFromURL(itf, fileURL);
            oedepict.OEConfigureImageOptions(itf);
	    oedepict.OEConfigurePrepareDepictionOptions(itf);
            oedepict.OEConfigure2DMolDisplayOptions(itf);

            if (!oechem.OEParseCommandLine(itf, argv, "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!");
            ifs.close();

            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);

            ofs.close();
        }
        catch (java.io.IOException e) {
            System.err.println("Unable to open interface file");
        }
    }
}

Depicting Molecules in Multi-Page

/****************************************************************************
 * Copyright 2011-2015 OpenEye Scientific Software, Inc.
 *****************************************************************************
 * Converts molecules into a multi-page PDF document.
 ****************************************************************************/
package openeye.examples.oedepict;

import java.net.URL;
import java.util.*;

import openeye.oechem.*;
import openeye.oedepict.*;

public class Mols2PDF {

    public static void main(String argv[]) {
        URL fileURL = Mols2PDF.class.getResource("Mols2PDF.txt");
        try {
            OEInterface itf = new OEInterface();
            oechem.OEConfigureFromURL(itf, fileURL);
            oedepict.OEConfigureReportOptions(itf);
            oedepict.OEConfigurePrepareDepictionOptions(itf);
            oedepict.OEConfigure2DMolDisplayOptions(itf);

            if (!oechem.OEParseCommandLine(itf, argv, "Mols2PDF")) {
                return;
            }

            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);
            }
            ifs.close();

            int pagenum = 1;
            OEFont font = new OEFont(OEFontFamily.Default, OEFontStyle.Bold, 12, OEAlignment.Center, oechem.getOEBlack());
            for (OEImageBase footer : report.GetFooters()) {
                String text = "Page " + Integer.toString(pagenum) + " of " + Integer.toString(report.NumPages());
                oedepict.OEDrawTextToCenter(footer, text, font);
                pagenum += 1;
            }
            oedepict.OEWriteReport(ofs, ext, report);
            ofs.close();

        }
        catch (java.io.IOException e) {
            System.err.println("Unable to open interface file");
        }
    }
}

Depicting Molecules In a Grid

/****************************************************************************
 * Copyright 2011-2015 OpenEye Scientific Software, Inc.
 *****************************************************************************
 * Converts molecules into an image with grid layout.
 * The output file format depends on its file extension.
 ****************************************************************************/
package openeye.examples.oedepict;

import java.net.URL;
import java.util.*;

import openeye.oechem.*;
import openeye.oedepict.*;

public class Mols2Img {

    public static void main(String argv[]) {
        URL fileURL = Mols2Img.class.getResource("Mols2Img.txt");
        try {
            OEInterface itf = new OEInterface();
            oechem.OEConfigureFromURL(itf, fileURL);
            oedepict.OEConfigureImageWidth (itf, 400.0);
            oedepict.OEConfigureImageHeight(itf, 400.0);
            oedepict.OEConfigureImageGridParams(itf);
            oedepict.OEConfigurePrepareDepictionOptions(itf);
            oedepict.OEConfigure2DMolDisplayOptions(itf);

            if (!oechem.OEParseCommandLine(itf, argv, "Mols2Img")) {
                oechem.OEThrow.Fatal("Unable to interpret 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);

            int rows = oedepict.OEGetImageGridNumRows(itf);
            int 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();
            for (String iname : 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();
                }
                ifs.close();
            }
            oedepict.OEWriteImage(ofs, ext, image);
            ofs.close();
        }
        catch (java.io.IOException e) {
            System.err.println("Unable to open interface file");
        }
    }
}

Generating 2D Ring Dictionary Report

/****************************************************************************
 * Copyright 2015 OpenEye Scientific Software, Inc.
 *****************************************************************************
 * Converts a ring dictionary into a multi-page PDF document.
 ****************************************************************************/
package openeye.examples.oedepict;

import java.net.URL;
import java.util.*;

import openeye.oechem.*;
import openeye.oedepict.*;

public class RingDict2PDF {

    public static void main(String argv[]) {
        URL fileURL = RingDict2PDF.class.getResource("RingDict2PDF.txt");
        try {
            OEInterface itf = new OEInterface();
            oechem.OEConfigureFromURL(itf, fileURL);
            oedepict.OEConfigureReportOptions(itf);

            if (!oechem.OEParseCommandLine(itf, argv, "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);

        }
        catch (java.io.IOException e) {
            System.err.println("Unable to open interface file");
        }
    }
}

Depicting MDL Query Substructure Search Hits

/****************************************************************************
 * Copyright 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.
 ****************************************************************************/
package openeye.examples.oedepict;

import java.net.URL;
import java.util.*;

import openeye.oechem.*;
import openeye.oedepict.*;

public class ViewMDLSearch {

    public static void main(String argv[]) {
        URL fileURL = ViewMDLSearch.class.getResource("ViewMDLSearch.txt");
        try {
            OEInterface itf = new OEInterface();
            oechem.OEConfigureFromURL(itf, fileURL);
            oedepict.OEConfigureReportOptions(itf);
            oedepict.OEConfigure2DMolDisplayOptions(itf);
            oedepict.OEConfigureHighlightParams(itf);

            if (!oechem.OEParseCommandLine(itf, argv, "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!");
            }
            qfile.close();

            oedepict.OEPrepareDepiction(depictquery);
            int 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!");
            }

            int  hstyle = oedepict.OEGetHighlightStyle(itf);
            OEColor  hcolor = oedepict.OEGetHighlightColor(itf);
            boolean 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);

            boolean unique = true;
            OEGraphMol mol = new OEGraphMol();
            while (oechem.OEReadMolecule(ifs, mol)) {
                oechem.OEPrepareSearch(mol, ss);
                Iterator<OEMatchBase> miter = ss.Match(mol, unique);
                if (miter != null && miter.hasNext()) {
                    OEMatchBase match = miter.next();

                    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.getOELightGreyPen());
                }
            }
            ifs.close();

            // render query structure in each header
            dopts.SetDimensions(report.GetHeaderWidth(), report.GetHeaderHeight(), OEScale.AutoScale);
            OE2DMolDisplay disp = new OE2DMolDisplay(depictquery, dopts);
            for (OEImageBase header : report.GetHeaders()) {
                oedepict.OERenderMolecule(header, disp);
                oedepict.OEDrawBorder(header, oedepict.getOELightGreyPen());
            }

            oedepict.OEWriteReport(oname, report);
        }
        catch (java.io.IOException e) {
            System.err.println("Unable to open interface file");
        }
    }
}
// ****************************************************************************
//  Copyright 2014 OpenEye Scientific Software, Inc.
// *****************************************************************************

package openeye.docexamples.oedepict;

import java.net.URL;
import java.util.*;
import java.io.IOException;

import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import java.io.File;

import openeye.oechem.*;
import openeye.oedepict.*;

public class JavaImageBase {

    public static void main(String[] argv) {
        OEInterface itf = null; 

        try {
            URL fileURL = JavaImageBase.class.getResource("JavaImageBase.txt");
            itf = new OEInterface();
            oechem.OEConfigureFromURL(itf, fileURL);
        } catch (IOException e) {
            System.err.println("Unable to open interface file");
            System.exit(1);
        }

        oedepict.OEConfigureImageWidth (itf, 400.0);
        oedepict.OEConfigureImageHeight(itf, 400.0);
        oedepict.OEConfigure2DMolDisplayOptions(itf);

        if (!oechem.OEParseCommandLine(itf, argv, "JavaImageBase")) {
            oechem.OEThrow.Fatal("Unable to interpret command line!");
        }

        String oname = itf.GetString("-out");
        String ext = oechem.OEGetFileExtension(oname);
        if (!oedepict.OEIsRegisteredImageFile(ext)) {
            oechem.OEThrow.Fatal("Unknown image type!");
        }

        double width  = oedepict.OEGetImageWidth(itf);
        double height = oedepict.OEGetImageHeight(itf);

        BufferedImage bufferedImage = new BufferedImage((int)width, (int)height, BufferedImage.TYPE_INT_RGB); 
        OEJavaImageBase image = new OEJavaImageBase(bufferedImage.getGraphics(), width, height);

        OEGraphMol mol = new OEGraphMol();
        oemolistream ifs = new oemolistream();
        String iname = itf.GetString("-in");
        if (!ifs.open(iname)) {
            oechem.OEThrow.Fatal("Cannot open " + iname + " input file!");
        }
        oechem.OEReadMolecule(ifs, mol);
        ifs.close();
        oedepict.OEPrepareDepiction(mol, false, true);

        OE2DMolDisplayOptions opts = new OE2DMolDisplayOptions();
        oedepict.OESetup2DMolDisplayOptions(opts, itf);
        OE2DMolDisplay disp = new OE2DMolDisplay(mol, opts);

        oedepict.OERenderMolecule(image, disp);

        try { 
            File f = new File(oname);
            ImageIO.write(bufferedImage, ext, f);
        } catch(IOException e) { 
            System.err.println("Unable to save output file: " + e.getMessage());
            System.exit(1);
        }
    }
}