5.4 Example Program

The following code example is a simple example of how to use the oeproton library provided in QuacPac to assign partial charges to an OEGraphMol. The program opens the file foo.sdf and reads all of the molecules in the file. Each molecule has its partial charge calculated with the AM1BCC method (including AM1 optimization). Each hydrogen is then made to be implicit, and it's partial charge is added to the partial charge on it's parent heavy-atom. Finally, each molecule is written to the file foo.mol2.

 1 /******************************************************************************
 2  * Copyright (C) 2006,2007,2008 OpenEye Scientific Software, Inc.
 3  *****************************************************************************/
 4 package openeye.examples.oequacpac;
 5
 6 import openeye.oechem.*;
 7 import openeye.oequacpac.*;
 8
 9 public class MMFF94Charge {
10   public static void main(String[] args) {
11     if (args.length!=2) {
12       System.out.println("MMFF94Charge <infile> <outfile>");
13       System.exit(0);
14     }
15
16     oemolistream ifs = new oemolistream(args[0]);
17     oemolostream ofs = new oemolostream(args[1]);
18
19     OEGraphMol mol = new OEGraphMol();
20     boolean noHydrogen = true;
21     boolean debug = false;
22     while (oechem.OEReadMolecule(ifs, mol)) {
23     	oequacpac.OEAssignPartialCharges(mol, OECharges.MMFF94,
24                                          noHydrogen, debug);
25     	oechem.OEWriteMolecule(ofs, mol);
26     }
27   }
28 }

Listing:5.1 Calculating Partial Charges

This second example shows how to enumerate pKa states of a molecule. Molecules are read from the input file foo.smi. The OETyperMolFunction is created so that a default output stream (std::out, SMILES format) is used, aromaticity will be called, compounds are enumerated rather than only being counted, and a maximum of 200 states per molecule will be generated. The state counter is reset for each new molecule with the OETyperMolFunction::Reset function.

 1 /******************************************************************************
 2  * Copyright (C) 2006,2007,2008 OpenEye Scientific Software, Inc.
 3  *****************************************************************************/
 4 package openeye.examples.oequacpac;
 5
 6 import openeye.oechem.*;
 7 import openeye.oequacpac.*;
 8
 9 public class EnumerateFormalCharges {
10   public static void main(String[] args) {
11     if (args.length!=2) {
12       System.out.println("EnumerateFormalCharges <infile> <outfile>");
13       System.exit(0);
14     }
15
16     oemolistream ifs = new oemolistream(args[0]);
17     oemolostream ofs = new oemolostream(args[1]);
18
19     OEGraphMol mol = new OEGraphMol();
20     boolean aromatic = true;
21     boolean countOnly = false;
22     int maxCount = 100;
23     OETyperMolFunction tmf = new OETyperMolFunction(ofs, aromatic,
24                                                     countOnly, maxCount);
25
26     boolean verbose = false;
27     while (oechem.OEReadMolecule(ifs, mol)) {
28     	oequacpac.OEEnumerateFormalCharges(mol, tmf, verbose);
29     	tmf.Reset();
30     }
31   }
32 }

Listing:5.2 Enumerating Ionization States

This third example listing expands on the previous example. Here, rather than enumerate the pKa states to std::out, they are enumerated into a stringstream. Each enumerated pKa state is then passed into tautomer enumeration. In the tautomer enumeration phase, the number of states are only counted rather than being enumerated. In both phases, the enumeration is capped at 200 states per molecule. The states of both the ionization state counter and the tautomer counter are reinitialized with their Reset functions.

 1 /******************************************************************************
 2  * Copyright (C) 2006,2007,2008 OpenEye Scientific Software, Inc.
 3  *****************************************************************************/
 4 package openeye.examples.oequacpac;
 5
 6 import openeye.oechem.*;
 7 import openeye.oequacpac.*;
 8
 9 public class CountTautomers {
10   public static void main(String[] args) {
11     if (args.length!=1) {
12       System.out.println("CountTautomers <infile>");
13       System.exit(0);
14     }
15
16     oemolistream ifs = new oemolistream(args[0]);
17     oemolostream nulfs = new oemolostream(oechem.getOenul(), false);
18
19     OEGraphMol mol = new OEGraphMol();
20     OEGraphMol pkamol = new OEGraphMol();
21
22     boolean aromatic = true;
23     boolean tyCountOnly = false;
24     int maxCount = 200;
25     oemolostream ofs = new oemolostream();
26     OETyperMolFunction tymf = new OETyperMolFunction(ofs, aromatic, tyCountOnly, maxCount);
27
28     boolean taCountOnly = true;
29     OETautomerMolFunction tamf = new OETautomerMolFunction(nulfs,aromatic,taCountOnly,maxCount);
30
31     boolean verbose = false;
32
33     oemolistream iss = new oemolistream();
34     while (oechem.OEReadMolecule(ifs, mol)) {
35     	// enumerate pKa states
36     	ofs.openstring();
37     	oequacpac.OEEnumerateFormalCharges(mol, tymf, verbose);
38     	tymf.Reset();
39
40     	iss.openstring(ofs.GetString());
41
42     	// count tautomers of pKa states
43     	int count=0;
44     	while (oechem.OEReadMolecule(iss, pkamol)) {
45     		count += oequacpac.OEEnumerateTautomers(pkamol, tamf);
46     		tamf.Reset();
47     	}
48     	System.out.println(mol.GetTitle()+" has "+count+" tautomer/pka states");
49     }
50   }
51 }

Listing:5.3 Counting Tautomers