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) 2004,2007, 2008 by OpenEye Scientific Software, Inc.
3 ***********************************************************************/
4 #include "oechem.h"
5 #include "oesystem.h"
6 #include "oequacpac.h"
7
8 using namespace OESystem;
9 using namespace OEChem;
10 using namespace OEProton;
11
12 int main(int argc, char *argv[])
13 {
14 if (argc!=3)
15 OEThrow.Usage("%s <mol-infile> <mol-outfile>", argv[0]);
16
17 oemolistream ifs(argv[1]);
18 if(!ifs)
19 OEThrow.Error("Unable to open %s for reading", argv[1]);
20
21 oemolostream ofs(argv[2]);
22 if(!ofs)
23 OEThrow.Error("Unable to open %s for writing", argv[2]);
24
25 OEGraphMol mol;
26 const bool noHydrogen = true;
27 const bool debug = false;
28 while(OEReadMolecule(ifs,mol))
29 {
30 OEAssignPartialCharges(mol,OECharges::MMFF94,noHydrogen,debug);
31 OEWriteMolecule(ofs,mol);
32 }
33
34 return 0;
35 }
36
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) 2004,2007, 2008 by OpenEye Scientific Software, Inc.
3 ***********************************************************************/
4 #include <iostream>
5 #include "oechem.h"
6 #include "oesystem.h"
7 #include "oequacpac.h"
8
9 using namespace OESystem;
10 using namespace OEChem;
11 using namespace OEProton;
12
13 int main(int argc, char *argv[])
14 {
15 if (argc!=3)
16 OEThrow.Usage("%s <mol-infile> <mol-outfile>", argv[0]);
17
18 oemolistream ifs(argv[1]);
19 if(!ifs)
20 OEThrow.Error("Unable to open %s for reading", argv[1]);
21
22 oemolostream ofs(argv[2]);
23 if(!ofs)
24 OEThrow.Error("Unable to open %s for writing", argv[2]);
25
26 OEGraphMol mol;
27 const bool aromatic = true;
28 const bool countOnly = false;
29 const unsigned int maxCount = 100;
30 OETyperMolFunction tmf(ofs,aromatic,countOnly,maxCount);
31 const bool verbose = false;
32 while(OEReadMolecule(ifs,mol))
33 {
34 OEEnumerateFormalCharges(mol,tmf,verbose);
35 tmf.Reset();
36 }
37
38 return 0;
39 }
40
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) 2004,2007, 2008 by OpenEye Scientific Software, Inc.
3 ***********************************************************************/
4 #include <iostream>
5 #include "oeplatform.h"
6 #include "oesystem.h"
7 #include "oechem.h"
8 #include "oequacpac.h"
9
10 using namespace OEPlatform;
11 using namespace OESystem;
12 using namespace OEChem;
13 using namespace OEProton;
14 using namespace std;
15
16 int main(int argc, char *argv[])
17 {
18 if (argc!=2)
19 OEThrow.Usage("%s <mol-infile>", argv[0]);
20
21 oemolistream ifs(argv[1]);
22 if(!ifs)
23 OEThrow.Error("Unable to open %s for reading", argv[1]);
24
25 oemolostream nulfs(&oenul,false);
26 if(!nulfs)
27 OEThrow.Error("Unable to declare oenul molstream.");
28
29 OEGraphMol mol,pkaState;
30 oemolostream ofs;
31 const bool aromatic = true;
32 const bool tyCountOnly = false;
33 const unsigned int maxCount = 200;
34 OETyperMolFunction tymf(ofs,aromatic,tyCountOnly,maxCount);
35 const bool verbose = false;
36
37 const bool taCountOnly = true;
38 OETautomerMolFunction tamf(nulfs,aromatic,taCountOnly,maxCount);
39 oemolistream iss;
40 unsigned int count;
41 while(OEReadMolecule(ifs,mol))
42 {
43 //enumerate pka states
44 ofs.openstring();
45 OEEnumerateFormalCharges(mol,tymf,verbose);
46 tymf.Reset();
47 iss.openstring(ofs.GetString());
48
49 //count tautomers of pka states
50 count = 0;
51 while(OEReadMolecule(iss,pkaState))
52 {
53 count += OEEnumerateTautomers(pkaState,tamf);
54 tamf.Reset();
55 }
56 cerr << count << " tautomer/pka states for " << mol.GetTitle() << endl;
57 }
58
59 return 0;
60 }
61