OEDepict ExamplesΒΆ

The following table lists the currently available OEDepict TK examples:

Program Description
Depict generating 2D coordinates
Match2Img depicting substructure search match
MCSAlign2D aligning molecules based on MCS
MDLQuery2Img depicting MDL query
MDLReaction2Img depicting MDL reaction
Mol2Img depicting a single molecule
Mols2PDF depicting molecules in a multi-page image
Mols2Img depicting molecules in a grid
RingDict2PDF.py generating 2D ring dictionary report
SMARTSAlign2D aligning molecules based on substructure search
ViewMDLSearch depicting MDL query substructure search hits

Examples:

// ****************************************************************************
//  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);
        }
    }
}