4.2 Molecular File Formats

In addition to SMILES strings, OEChem is able to read numerous other molecular file formats, including MDL SD files, Tripos Mol2 files and PDB files. The format of an input file or stream may be associated with a oemolstream using the SetFormat method, and may be retrieved with GetFormat. These take (or return) and integer constant defined in C++. The following table shows the constants and the corresponding file formats supported by OEChem. A value of OEFormat.UNDEFINED (zero) means that there is no file format associated with the molstream. Note that the default format associated with an oemolstream is OEFormat.SMI.

File Format Description Read? Write?
OEFormat.OEB New Style OpenEye OEBinary Yes Yes
OEFormat.BIN Old Style OEBinary Yes Yes
OEFormat.CAN Canonical SMILES Yes Yes
OEFormat.FASTA FASTA protein sequence Yes Yes
OEFormat.ISM Isomeric SMILES Yes Yes
OEFormat.MDL MDL Mol File Yes Yes
OEFormat.MF Molecular Formula (Hill order) No Yes
OEFormat.MOL2 Tripos Sybyl mol2 file Yes Yes
OEFormat.MOL2H Sybyl mol2 with explicit hydrogens Yes Yes
OEFormat.MOPAC MOPAC file format(s) Yes Yes
OEFormat.PDB Protein Databank PDB file Yes Yes
OEFormat.SDF MDL SD File Yes Yes
OEFormat.SMI Absolute SMILES Yes Yes
OEFormat.XYZ XMol XYZ format Yes Yes

The following example shows how to use oemolstreams to convert MDL SD files into Tripos Mol2 files.

 1 /**************************************************************
 2  * Copyright 2005, OpenEye Scientific Software, Inc.
 3  *************************************************************/
 4 import openeye.oechem.*;
 5
 6 public class Sdf2Mol2 {
 7   public static void main(String argv[]) {
 8     oemolistream ifs = new oemolistream();
 9     oemolostream ofs = new oemolostream();
10
11     ifs.SetFormat(OEFormat.SDF);
12     ofs.SetFormat(OEFormat.MOL2);
13
14     OEGraphMol mol = new OEGraphMol();
15     while (oechem.OEReadMolecule(ifs, mol)) {
16       oechem.OEWriteMolecule(ofs, mol);
17     }
18   }
19 }
20

Listing:4.3 Converting SDF to MOL2 using stdin/stdout

In general, the SetFormat method should only be called on an oemolistream before the first connection table is read.