The search examples require that test data has been loaded, and domain indexes have been built.
An example molecule loader:
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.Statement;
import java.io.Console;
import openeye.oechem.OEGraphMol;
import openeye.oechem.OEMolBase;
import openeye.oechem.OEInterface;
import openeye.oechem.oechem;
import openeye.oechem.oemolistream;
import java.net.URL;
/***************************************************************************
MoleculeLoader demonstrate creating and loading molecules from a file
into a database table.
This test table is created prior to loading molecules from the input file.
The domain index is created after molecules are loaded.
***************************************************************************/
public class MoleculeLoader
{
public static void moleculeLoader(oemolistream ifs,
String password)
{
Connection conn = null;
Statement stmt = null;
PreparedStatement pstmt = null;
try
{
String ORACLE_SID = null;
String ORACLE_HOST = "localhost";
String ORACLE_PORT = "1521";
String ORACLE_USER = "arnachm1_test";
if (System.getenv("ORACLE_SID") != null)
ORACLE_SID = System.getenv("ORACLE_SID");
if (System.getenv("ORACLE_HOST") != null)
ORACLE_HOST = System.getenv("ORACLE_HOST");
if (System.getenv("ORACLE_USER") != null)
ORACLE_USER = System.getenv("ORACLE_USER");
String connectURL = "jdbc:oracle:thin:@" + ORACLE_HOST + ":" +
ORACLE_PORT + ":" + ORACLE_SID;
conn = Util.createConnection(connectURL,ORACLE_USER,password);
// First, create the table.
stmt = conn.createStatement();
String sql = "create table test (title varchar2(100)," +
"smiles varchar2(4000) not null,conf blob)";
stmt.execute(sql);
System.out.println("Created test table");
// Next, load the molecules.
sql = "insert into test(title, smiles) values (?, ?)";
pstmt = conn.prepareStatement(sql);
OEMolBase mol = new OEGraphMol();
int count = 0;
while (oechem.OEReadMolecule(ifs, mol))
{
String title = mol.GetTitle();
String ism = oechem.OECreateIsoSmiString(mol);
pstmt.setString(1, title);
pstmt.setString(2, ism);
pstmt.executeUpdate();
count++;
if (count % 1000 == 0)
{
conn.commit();
System.out.print("Loaded " + count + " molecules (so far)\r");
System.out.flush();
}
}
conn.commit();
System.out.println("Loaded " + count + " molecules (complete)");
System.out.println("Building domain index");
// Last, create the domain index.
stmt = conn.createStatement();
stmt.execute("create index test_structure_idx on test(smiles) " +
"indextype is c$arnachm1.structureIndexType");
System.out.println("Created index test_structure_idx");
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
Util.closeConnnection(conn);
Util.closeStatement(stmt);
Util.closeStatement(pstmt);
}
}
public static void main(String[] args)
{
URL fileURL = MoleculeLoader.class.getResource("MoleculeLoader.txt");
if (fileURL == null)
{
oechem.OEThrow.Fatal(
"Unable to open interface file MoleculeLoader.txt");
}
oemolistream ifs = null;
try
{
OEInterface itf = new OEInterface(fileURL,"MoleculeLoader", args);
String inputFilename = itf.GetString("-i");
String password = "";
if (itf.HasString("-p"))
{
password = itf.GetString("-p");
}
else //prompt for password
{
Console cons;
char [] tmp;
if ((cons = System.console()) != null &&
(tmp = cons.readPassword("Password: ")) != null)
{
password = new String(tmp);
}
}
ifs = new oemolistream();
if (!ifs.open(inputFilename))
{
oechem.OEThrow.Fatal("Unable to open %s for reading" +
inputFilename);
}
moleculeLoader(ifs,password);
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
if (ifs != null)
ifs.close();
}
}
}
An example of an exact match search:
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.io.Console;
import openeye.oechem.OEGraphMol;
import openeye.oechem.OEMolBase;
import openeye.oechem.OEInterface;
import openeye.oechem.oechem;
import openeye.oechem.oemolistream;
import openeye.oechem.oemolostream;
import java.net.URL;
/***************************************************************************
ExactMatch demonstrates exact match searching using the cartridge.
Takes a molecule file query_filename containing one or more query molecules
and searches the 'test' table for exact match molecules. The 'hit' molecules
are written to output_filename.
Assumes the test table and domain index have been created.
(see MoleculeLoader.java)
***************************************************************************/
public class ExactMatch
{
public static void exactMatch(oemolistream ifs,
oemolostream ofs,
String password,
String tableName,
String columnName)
{
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
String ORACLE_SID = null;
String ORACLE_HOST = "localhost";
String ORACLE_PORT = "1521";
String ORACLE_USER = "arnachm1_test";
if (System.getenv("ORACLE_SID") != null)
ORACLE_SID = System.getenv("ORACLE_SID");
if (System.getenv("ORACLE_HOST") != null)
ORACLE_HOST = System.getenv("ORACLE_HOST");
if (System.getenv("ORACLE_USER") != null)
ORACLE_USER = System.getenv("ORACLE_USER");
String connectURL = "jdbc:oracle:thin:@" + ORACLE_HOST + ":" +
ORACLE_PORT + ":" + ORACLE_SID;
conn = Util.createConnection(connectURL,ORACLE_USER,password);
String sql = "select " + columnName + ",title from " + tableName +
" where " + "c$arnachm1.exactMatch(" + columnName + ", ?, -1) = 1";
pstmt = conn.prepareStatement(sql);
OEMolBase mol = new OEGraphMol();
int queryCount = 0;
int hitCount = 0;
while (oechem.OEReadMolecule(ifs, mol))
{
String query = oechem.OECreateIsoSmiString(mol);
pstmt.setString(1, query);
rs = pstmt.executeQuery();
while (rs.next())
{
String smi = rs.getString(1);
String title = rs.getString(2);
mol.Clear();
oechem.OESmilesToMol(mol,smi);
mol.SetTitle(title);
oechem.OEWriteMolecule(ofs, mol);
hitCount++;
}
queryCount++;
}
System.out.println("Found " + hitCount + " exact matches for " +
queryCount + " queries");
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
Util.closeConnnection(conn);
Util.closeStatement(pstmt);
}
}
public static void main(String args[])
{
URL fileURL = ExactMatch.class.getResource("ExactMatch.txt");
if (fileURL == null)
{
oechem.OEThrow.Fatal("Unable to open interface file ExactMatch.txt");
}
oemolistream ifs = null;
oemolostream ofs = null;
try
{
OEInterface itf = new OEInterface(fileURL,"ExactMatch", args);
String inputFilename = itf.GetString("-i");
String outputFilename = itf.GetString("-o");
String tableName = itf.GetString("-tname");
String columnName = itf.GetString("-cname");
String password = "";
if (itf.HasString("-p"))
{
password = itf.GetString("-p");
}
else //prompt for password
{
Console cons;
char [] tmp;
if ((cons = System.console()) != null &&
(tmp = cons.readPassword("Password: ")) != null)
{
password = new String(tmp);
}
}
ifs = new oemolistream();
if (!ifs.open(inputFilename))
{
oechem.OEThrow.Fatal("Unable to open %s for reading " +
inputFilename);
}
ofs = new oemolostream();
if (!ofs.open(outputFilename))
{
oechem.OEThrow.Fatal("Unable to open %s for writing " +
outputFilename);
}
exactMatch(ifs,ofs,password,tableName,columnName);
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
if (ifs != null)
ifs.close();
if (ofs != null)
ofs.close();
}
}
}
An example of a similarity search:
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.io.Console;
import openeye.oechem.OEGraphMol;
import openeye.oechem.OEInterface;
import openeye.oechem.oechem;
import openeye.oechem.oemolistream;
import openeye.oechem.oemolostream;
import java.net.URL;
/***************************************************************************
Similarity demonstrates similarity searching using the data cartridge.
This takes a molecule file containing one of more query molecules and
searches the 'test' table for similar molecules with a Tanimoto >= the
provided cutoff. Each set of results is written to a separate molecule file
in the working directory (sim-hits-XXX.sdf) and the similarity of the
molecules to the query is stored in an SD tag.
***************************************************************************/
public class Similarity
{
public static void similarity(oemolistream ifs,
double cutoff,
String password,
String tableName,
String columnName)
{
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
String ORACLE_SID = null;
String ORACLE_HOST = "localhost";
String ORACLE_PORT = "1521";
String ORACLE_USER = "arnachm1_test";
if (System.getenv("ORACLE_SID") != null)
ORACLE_SID = System.getenv("ORACLE_SID");
if (System.getenv("ORACLE_HOST") != null)
ORACLE_HOST = System.getenv("ORACLE_HOST");
if (System.getenv("ORACLE_USER") != null)
ORACLE_USER = System.getenv("ORACLE_USER");
String connectURL = "jdbc:oracle:thin:@" + ORACLE_HOST + ":" +
ORACLE_PORT + ":" + ORACLE_SID;
conn = Util.createConnection(connectURL,ORACLE_USER,password);
pstmt = conn.prepareStatement("select " + columnName + ", title, " +
"c$arnachm1.similarityScore(1) from " + tableName + " where " +
"c$arnachm1.similarity(" + columnName + ", ?, ?, -1, 1) = 1");
String foo = "select " + columnName + ", title, " +
"c$arnachm1.similarityScore(1) from " + tableName + " where " +
"c$arnachm1.similarity(" + columnName + ", ?, ?, -1, 1) = 1";
System.out.println("sql = " + foo);
int count = 1;
String dir = System.getProperty("user.dir");
OEGraphMol mol = new OEGraphMol();
OEGraphMol outmol = new OEGraphMol();
while (oechem.OEReadMolecule(ifs, mol))
{
String query = oechem.OECreateIsoSmiString(mol);
pstmt.setString(1, query);
pstmt.setDouble(2, cutoff);
rs = pstmt.executeQuery();
String outputFilename = dir +
String.format("/sim-hits-%03d.sdf", (int)count);
oemolostream oms = new oemolostream(outputFilename);
int hitCount = 0;
while (rs.next())
{
String smi = rs.getString(1);
String title = rs.getString(2);
if (title == null || title.equals(""))
title = "Hit "+String.valueOf(hitCount+1);
String tan = String.format("%.3f",rs.getDouble(3));
outmol.Clear();
oechem.OESmilesToMol(outmol,smi);
outmol.SetTitle(title);
oechem.OESetSDData(outmol,"Tanimoto",tan);
oechem.OEWriteMolecule(oms, outmol);
hitCount++;
}
System.out.println("Found " + hitCount + " molecules with sim >= " +
cutoff + " for query " + query + " output to " +
outputFilename);
oms.close();
count++;
}
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
Util.closeConnnection(conn);
Util.closeStatement(pstmt);
}
}
public static void main(String[] args)
{
URL fileURL = Similarity.class.getResource("Similarity.txt");
if (fileURL == null)
{
oechem.OEThrow.Fatal("Unable to open interface file Similarity.txt");
}
oemolistream ifs = null;
try
{
OEInterface itf = new OEInterface(fileURL,"Similarity", args);
String inputFilename = itf.GetString("-i");
double cutoff = itf.GetDouble("-c");
String tableName = itf.GetString("-tname");
String columnName = itf.GetString("-cname");
String password = "";
if (itf.HasString("-p"))
{
password = itf.GetString("-p");
}
else //prompt for password
{
Console cons;
char [] tmp;
if ((cons = System.console()) != null &&
(tmp = cons.readPassword("Password: ")) != null)
{
password = new String(tmp);
}
}
ifs = new oemolistream();
if (!ifs.open(inputFilename))
{
oechem.OEThrow.Fatal("Unable to open %s for reading " +
inputFilename);
}
similarity(ifs,cutoff,password,tableName,columnName);
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
if (ifs != null)
ifs.close();
}
}
}
A substructure search using a SMARTS query:
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.io.Console;
import openeye.oechem.OEGraphMol;
import openeye.oechem.OEMolBase;
import openeye.oechem.OEInterface;
import openeye.oechem.oechem;
import openeye.oechem.oemolostream;
import java.net.URL;
/***************************************************************************
SubSearchSmarts demonstrates substructure searching using the data cartridge
where the query is an SMARTS string. This read the query from the command
line and runs a substructure search against the test table. The hits are
written to an output file.
***************************************************************************/
public class SubSearchSmarts
{
public static void subSearchSmarts(oemolostream ofs,
String pattern,
String password,
String tableName,
String columnName)
{
PreparedStatement pstmt = null;
ResultSet rs = null;
Connection conn = null;
try
{
String ORACLE_SID = null;
String ORACLE_HOST = "localhost";
String ORACLE_PORT = "1521";
String ORACLE_USER = "arnachm1_test";
if (System.getenv("ORACLE_SID") != null)
ORACLE_SID = System.getenv("ORACLE_SID");
if (System.getenv("ORACLE_HOST") != null)
ORACLE_HOST = System.getenv("ORACLE_HOST");
if (System.getenv("ORACLE_USER") != null)
ORACLE_USER = System.getenv("ORACLE_USER");
String connectURL = "jdbc:oracle:thin:@" + ORACLE_HOST + ":" +
ORACLE_PORT + ":" + ORACLE_SID;
conn = Util.createConnection(connectURL,ORACLE_USER,password);
pstmt = conn.prepareStatement("select " + columnName +
", title from " + tableName +
" where " + "c$arnachm1.substructure(" +
columnName + ", ?, -1) = 1");
pstmt.setString(1, pattern);
rs = pstmt.executeQuery();
OEMolBase mol = new OEGraphMol();
int hitCount = 0;
while (rs.next())
{
String smi = rs.getString(1);
String title = rs.getString(2);
mol.Clear();
oechem.OESmilesToMol(mol,smi);
mol.SetTitle(title);
oechem.OEWriteMolecule(ofs, mol);
hitCount++;
}
System.out.println("Found " + hitCount + " hits.");
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
Util.closeConnnection(conn);
Util.closeStatement(pstmt);
Util.closeResultSet(rs);
}
}
public static void main(String[] args)
{
URL fileURL = SubSearchSmarts.class.getResource("SubSearchSmarts.txt");
if (fileURL == null)
{
oechem.OEThrow.Fatal(
"Unable to open interface file SubSearchSmarts.txt");
}
oemolostream ofs = null;
try
{
OEInterface itf = new OEInterface(fileURL,"SubSearchSmarts", args);
String pattern = itf.GetString("-s");
String outputFilename = itf.GetString("-o");
String password = "";
String tableName = itf.GetString("-tname");
String columnName = itf.GetString("-cname");
if (itf.HasString("-p"))
{
password = itf.GetString("-p");
}
else //prompt for password
{
Console cons;
char [] tmp;
if ((cons = System.console()) != null &&
(tmp = cons.readPassword("Password: ")) != null)
{
password = new String(tmp);
}
}
ofs = new oemolostream();
if (!ofs.open(outputFilename))
{
oechem.OEThrow.Fatal("Unable to open %s for writing " +
outputFilename);
}
subSearchSmarts(ofs,pattern,password,tableName,columnName);
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
if (ofs != null)
ofs.close();
}
}
}
A substructure search using a MOL file query:
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.sql.Clob;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.io.Console;
import openeye.oechem.OEGraphMol;
import openeye.oechem.OEMolBase;
import openeye.oechem.OEInterface;
import openeye.oechem.oechem;
import openeye.oechem.oemolostream;
import oracle.sql.CLOB;
import java.net.URL;
/***************************************************************************
SubSearchMdl demonstrates substructure searching using the data cartridge
where the query is an MDL query. This read the query from a file and runs
a substructure search against the test table. The hits are written to an
output file.
***************************************************************************/
public class SubSearchMDL
{
private static String readMDLQuery(String filename) throws IOException
{
BufferedReader reader = null;
try
{
reader = new BufferedReader(new FileReader(filename));
String line = null;
StringBuilder stringBuilder = new StringBuilder();
String ls = System.getProperty("line.separator");
while ((line = reader.readLine()) != null)
{
stringBuilder.append(line);
stringBuilder.append(ls);
}
return stringBuilder.toString();
}
finally
{
if (reader != null)
reader.close();
}
}
private static void subSearchMDL(String mdl,
oemolostream ofs,
String password,
String tableName,
String columnName)
{
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
String ORACLE_SID = null;
String ORACLE_HOST = "localhost";
String ORACLE_PORT = "1521";
String ORACLE_USER = "arnachm1_test";
if (System.getenv("ORACLE_SID") != null)
ORACLE_SID = System.getenv("ORACLE_SID");
if (System.getenv("ORACLE_HOST") != null)
ORACLE_HOST = System.getenv("ORACLE_HOST");
if (System.getenv("ORACLE_USER") != null)
ORACLE_USER = System.getenv("ORACLE_USER");
String connectURL = "jdbc:oracle:thin:@" + ORACLE_HOST + ":" +
ORACLE_PORT + ":" + ORACLE_SID;
conn = Util.createConnection(connectURL,ORACLE_USER,password);
pstmt = conn.prepareStatement("select " + columnName +
", title from " + tableName +
" where " +
"c$arnachm1.mdl_clob_substructure(" +
columnName + ", ?, -1) = 1");
// Set parameters on prepared statement. In this case it is slightly
// complicated as we have to create a Clob first, set the string on that,
// then set that as the parameter on the prepared statement. This is often
// database dependent.
Clob clob = oracle.sql.CLOB.createTemporary(conn, false,
oracle.sql.CLOB.DURATION_SESSION);
clob.setString(1, mdl);
pstmt.setClob(1, clob);
rs = pstmt.executeQuery();
OEMolBase mol = new OEGraphMol();
int hitCount = 0;
while (rs.next())
{
String smi = rs.getString(1);
String title = rs.getString(2);
mol.Clear();
oechem.OESmilesToMol(mol,smi);
mol.SetTitle(title);
oechem.OEWriteMolecule(ofs, mol);
hitCount++;
}
ofs.close();
System.out.println("Found " + hitCount + " hits.");
// Important to free the Oracle CLOB.
((CLOB) clob).freeTemporary();
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
Util.closeConnnection(conn);
Util.closeStatement(pstmt);
}
}
public static void main(String[] args)
{
URL fileURL = SubSearchMDL.class.getResource("SubSearchMDL.txt");
if (fileURL == null)
{
oechem.OEThrow.Fatal("Unable to open interface file SubSearchMDL.txt");
}
oemolostream ofs = null;
try
{
OEInterface itf = new OEInterface(fileURL,"SubSearchMDL", args);
String inputFilename = itf.GetString("-i");
String outputFilename = itf.GetString("-o");
String tableName = itf.GetString("-tname");
String columnName = itf.GetString("-cname");
String password = "";
String mdl = readMDLQuery(inputFilename);
if (itf.HasString("-p"))
{
password = itf.GetString("-p");
}
else //prompt for password
{
Console cons;
char [] tmp;
if ((cons = System.console()) != null &&
(tmp = cons.readPassword("Password: ")) != null)
{
password = new String(tmp);
}
}
ofs = new oemolostream();
if (!ofs.open(outputFilename))
{
oechem.OEThrow.Fatal("Unable to open " + outputFilename +
" for writing" +
outputFilename);
}
subSearchMDL(mdl,ofs,password,tableName,columnName);
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
if (ofs != null)
ofs.close();
}
}
}
An example of populating a blob column with conformers stored in an OEBinary array:
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.Blob;
import java.io.Console;
import java.io.InputStream;
import java.io.ByteArrayInputStream;
import openeye.oechem.OEMol;
import openeye.oechem.OEMolBase;
import openeye.oechem.OEInterface;
import openeye.oechem.OEFormat;
import openeye.oechem.oechem;
import openeye.oechem.oemolistream;
import openeye.oechem.oemolostream;
import openeye.oechem.OEBinaryIOHandlerBase;
import java.net.URL;
/***************************************************************************
ConformerLoader demonstrates loading conformers from an OEBinary file
into a database table. This target table must be created prior to
loading molecules from the input file. The domain index is created
after molecules are loaded.
***************************************************************************/
public class ConformerLoader
{
public static void conformerLoader(oemolistream ifs,
String password,
String tableName,
String columnName)
{
Connection conn = null;
Statement stmt = null;
PreparedStatement pstmt = null;
try
{
String ORACLE_SID = null;
String ORACLE_HOST = "localhost";
String ORACLE_PORT = "1521";
String ORACLE_USER = "arnachm1_test";
if (System.getenv("ORACLE_SID") != null)
ORACLE_SID = System.getenv("ORACLE_SID");
if (System.getenv("ORACLE_HOST") != null)
ORACLE_HOST = System.getenv("ORACLE_HOST");
if (System.getenv("ORACLE_USER") != null)
ORACLE_USER = System.getenv("ORACLE_USER");
String connectURL = "jdbc:oracle:thin:@" + ORACLE_HOST + ":" +
ORACLE_PORT + ":" + ORACLE_SID;
conn = Util.createConnection(connectURL,ORACLE_USER,password);
int count = 0;
OEMol mol = new OEMol();
oemolostream ofs = new oemolostream();
ofs.SetFormat(OEFormat.OEB);
String sql = "update " + tableName +
" set " + columnName + " = ? where title = ?";
pstmt = conn.prepareStatement(sql);
while (oechem.OEReadMolecule(ifs, mol))
{
ofs.openstring();
oechem.OEWriteMolecule(ofs,mol);
ofs.close();
byte [] inputBytes = ofs.getByteArray();
InputStream is = new ByteArrayInputStream(inputBytes);
String title = mol.GetTitle();
pstmt.setBinaryStream(1, is, inputBytes.length);
pstmt.setString(2, title);
if (pstmt.executeUpdate() == 1)
count++;
else
System.out.println("Molecule '" + mol.GetTitle() + "' not found");
if (count % 10 == 0)
{
conn.commit();
System.out.print("Loaded " + count + " molecules (so far)\r");
System.out.flush();
}
}
conn.commit();
System.out.println("\rLoaded " + count + " molecules (complete)");
stmt = conn.createStatement();
sql = "create index test_conf_idx on " +
tableName + "(" + columnName + ") indextype is c$arnachm1.fastrocsIndexType";
stmt.execute(sql);
System.out.println("Created index test_conf_idx");
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
Util.closeConnnection(conn);
Util.closeStatement(stmt);
Util.closeStatement(pstmt);
}
}
public static void main(String[] args)
{
URL fileURL = ConformerLoader.class.getResource("ConformerLoader.txt");
if (fileURL == null)
{
oechem.OEThrow.Fatal(
"Unable to open interface file MoleculeLoader.txt");
}
oemolistream ifs = null;
try
{
OEInterface itf = new OEInterface(fileURL,"MoleculeLoader", args);
String inputFilename = itf.GetString("-i");
String password = "";
if (itf.HasString("-p"))
{
password = itf.GetString("-p");
}
else //prompt for password
{
Console cons;
char [] tmp;
if ((cons = System.console()) != null &&
(tmp = cons.readPassword("Password: ")) != null)
{
password = new String(tmp);
}
}
String tableName = itf.GetString("-tname");
String columnName = itf.GetString("-cname");
ifs = new oemolistream();
if (!ifs.open(inputFilename))
{
oechem.OEThrow.Fatal("Unable to open %s for reading" +
inputFilename);
}
OEBinaryIOHandlerBase hand = ifs.GetBinaryIOHandler();
hand.Clear();
oechem.OEInitHandler(hand,
oechem.OEBRotCompressOpts(),
oechem.OEBDefaultOpts());
conformerLoader(ifs,password,tableName,columnName);
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
if (ifs != null)
ifs.close();
}
}
}
A shape similarity search example:
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.sql.Clob;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.io.Console;
import openeye.oechem.OEGraphMol;
import openeye.oechem.OEMol;
import openeye.oechem.OEMolBase;
import openeye.oechem.OEInterface;
import openeye.oechem.oechem;
import openeye.oechem.oemolistream;
import openeye.oechem.oemolostream;
import openeye.oechem.OEFormat;
import oracle.sql.CLOB;
import java.net.URL;
/***************************************************************************
Runs a FastROCS search against the test table using the input query.
This fetches the hits from the database and outputs
the molecules to <output_filename>.
***************************************************************************/
public class ShapeSearch
{
private static void shapeSearch(OEMolBase query,
oemolostream ofs,
String password,
String tableName,
String columnName,
float tanCutoff,
int maxHits)
{
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
String ORACLE_SID = null;
String ORACLE_HOST = "localhost";
String ORACLE_PORT = "1521";
String ORACLE_USER = "arnachm1_test";
if (System.getenv("ORACLE_SID") != null)
ORACLE_SID = System.getenv("ORACLE_SID");
if (System.getenv("ORACLE_HOST") != null)
ORACLE_HOST = System.getenv("ORACLE_HOST");
if (System.getenv("ORACLE_USER") != null)
ORACLE_USER = System.getenv("ORACLE_USER");
String connectURL = "jdbc:oracle:thin:@" + ORACLE_HOST + ":" +
ORACLE_PORT + ":" + ORACLE_SID;
conn = Util.createConnection(connectURL,ORACLE_USER,password);
pstmt = conn.prepareStatement("select " +
"c$arnachm1.fastrocs_conformation(1) from " + tableName +
" where c$arnachm1.fastrocs(" +
columnName + ", ?, ?, ?, 1) = 1");
String molstr = "";
int dimension = query.GetDimension();
if (dimension == 3)
{
oemolostream qfs = new oemolostream();
qfs.SetFormat(OEFormat.SDF);
qfs.openstring();
oechem.OEWriteMolecule(qfs,query);
qfs.close();
molstr = qfs.GetString();
}
else
{
molstr = oechem.OEMolToSmiles(query);
}
Clob clob = oracle.sql.CLOB.createTemporary(conn, false,
oracle.sql.CLOB.DURATION_SESSION);
pstmt.setFloat(2, tanCutoff);
pstmt.setInt(3, maxHits);
if (dimension == 3)
{
clob.setString(1, molstr);
pstmt.setClob(1, clob);
}
else
{
pstmt.setString(1,molstr);
}
rs = pstmt.executeQuery();
OEGraphMol mol = new OEGraphMol();
int hitCount = 0;
oemolistream resfs = new oemolistream();
resfs.SetFormat(OEFormat.SDF);
while (rs.next())
{
resfs.openstring(rs.getString(1));
if (oechem.OEReadMolecule(resfs,mol))
{
oechem.OEWriteMolecule(ofs,mol);
}
else
{
oechem.OEThrow.Warning("Unable to read result molecule");
}
mol.Clear();
hitCount++;
}
// Important to free the Oracle CLOB.
((CLOB) clob).freeTemporary();
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
Util.closeConnnection(conn);
Util.closeStatement(pstmt);
}
}
public static void main(String[] args)
{
URL fileURL = ShapeSearch.class.getResource("ShapeSearch.txt");
if (fileURL == null)
{
oechem.OEThrow.Fatal("Unable to open interface file ShapeSearch.txt");
}
oemolostream ofs = null;
oemolistream ifs = null;
try
{
OEInterface itf = new OEInterface(fileURL,"ShapeSearch", args);
String password = "";
if (itf.HasString("-p"))
{
password = itf.GetString("-p");
}
else //prompt for password
{
Console cons;
char [] tmp;
if ((cons = System.console()) != null &&
(tmp = cons.readPassword("Password: ")) != null)
{
password = new String(tmp);
}
}
String outputFilename = itf.GetString("-o");
ofs = new oemolostream();
if (!ofs.open(outputFilename))
{
oechem.OEThrow.Fatal("Unable to open " + outputFilename +
" for writing");
}
String inputFilename = itf.GetString("-i");
ifs = new oemolistream();
if (!ifs.open(inputFilename))
{
oechem.OEThrow.Fatal("Unable to open input file %s " + inputFilename);
}
String tableName = itf.GetString("-tname");
String columnName = itf.GetString("-cname");
int maxHits = itf.GetInt("-max_hits");
float tanCutoff = itf.GetFloat("-tcut");
OEMol mol = new OEMol();
while (oechem.OEReadMolecule(ifs,mol))
{
shapeSearch(mol,ofs,password,tableName,
columnName,tanCutoff,maxHits);
}
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
if (ofs != null)
ofs.close();
if (ifs != null)
ifs.close();
}
}
}