This example demonstrates how to correlate portions of a surface with
atoms. OEMakeMolecularSurface automatically initializes the
atoms array with the atom index responsible for that particular
vertex. The atom indices can be used to map molecular properties onto
the surface using cliques. Most surface property calculations in
OESpicoli can use cliques.
Only one clique is used in this example. The cliques array is
initially all NULL (zero). Vertices considered ``polar'' are marked
with the clique of one. OESurfaceCliqueArea is then used to
calculate the polar surface area. The area is then averaged over all
the conformers of the molecule.
1 /*******************************************************************
2 * Copyright 2006, OpenEye Scientific Software, Inc.
3 *******************************************************************/
4 #include "openeye.h"
5
6 #include "oeplatform.h"
7 #include "oesystem.h"
8 #include "oechem.h"
9 #include "oespicoli.h"
10
11 using namespace OESpicoli;
12 using namespace OEChem;
13 using namespace OESystem;
14 using namespace OEPlatform;
15
16 bool MakeCliques(OESurface &surf, const OEMolBase &mol)
17 {
18 OEAtomBase *atom;
19 for (unsigned int i=0;i<surf.GetNumVertices();++i)
20 {
21 atom=mol.GetAtom(OEHasAtomIdx(surf.GetAtomsElement(i)));
22 if (atom->IsOxygen() || atom->IsNitrogen() || atom->IsPolarHydrogen())
23 surf.SetVertexCliqueElement(i, 1);
24 }
25 return true;
26 }
27
28 bool AverageSurfaceArea(const OEMCMolBase &mcmol, float *area, float *parea)
29 {
30 float a=0.0f;
31 float pa=0.0f;
32 for (OEIter<OEConfBase> conf=mcmol.GetConfs();conf;++conf)
33 {
34 OESurface surf;
35 OEMakeMolecularSurface(surf, conf, 0.5f);
36 //MakeCliques(surf, conf);
37
38 a += OESurfaceArea(surf);
39 pa += OESurfaceCliqueArea(surf, 1);
40 }
41 a /= mcmol.NumConfs();
42 pa /= mcmol.NumConfs();
43
44 *area = a;
45 *parea = pa;
46
47 return true;
48 }
49
50 int main(int argc, char *argv[])
51 {
52 if (argc!=2)
53 OEThrow.Usage("%s <molecules>", argv[0]);
54
55 float area, polararea;
56 oemolistream ifs(argv[1]);
57 OEMol mol;
58 while (OEReadMolecule(ifs, mol))
59 {
60 OEAssignBondiVdWRadii(mol);
61 AverageSurfaceArea(mol, &area, &polararea);
62 oeerr << mol.GetTitle() << oeendl;
63 oeerr << "molecule has " << mol.NumConfs() << " conformers" << oeendl;
64 oeerr << "Average total surface area: " << area << oeendl;
65 oeerr << "Average polar area : " << polararea << oeendl;
66 oeerr << "Average % polar : " << polararea/area
67 << oeendl << oeendl;
68 }
69 return 0;
70 }
Polar surface area information can also be mapped onto the surface as the surface color. This surface can then be stored on its associated molecule to be written out and viewed.
1 /*******************************************************************
2 * Copyright 2006, 2007, OpenEye Scientific Software, Inc.
3 *******************************************************************/
4 #include "openeye.h"
5
6 #include "oeplatform.h"
7 #include "oesystem.h"
8 #include "oechem.h"
9 #include "oespicoli.h"
10
11 using namespace OESpicoli;
12 using namespace OEChem;
13 using namespace OESystem;
14 using namespace OEPlatform;
15
16 bool ColorSurface(OESurface &surf, const OEMolBase &mol)
17 {
18 OEAtomBase *atom;
19 for (unsigned int i=0;i<surf.GetNumVertices();++i)
20 {
21 atom=mol.GetAtom(OEHasAtomIdx(surf.GetAtomsElement(i)));
22 if (atom->IsOxygen() || atom->IsNitrogen() || atom->IsPolarHydrogen())
23 surf.SetColorElement(i, 0.0f, 0.0f, 1.0f);
24 else
25 surf.SetColorElement(i, 1.0f, 0.0f, 0.0f);
26 }
27 return true;
28 }
29
30 int main(int argc, char *argv[])
31 {
32 if (argc!=3)
33 OEThrow.Usage("%s <molecules> <oebfile>", argv[0]);
34
35 oemolistream ifs(argv[1]);
36 oemolostream ofs(argv[2]);
37 OEInitSurfaceHandlers(ofs);
38
39 OEGraphMol mol;
40 while (OEReadMolecule(ifs, mol))
41 {
42 OEAssignBondiVdWRadii(mol);
43
44 OESurface surf;
45 OEMakeMolecularSurface(surf, mol, 0.5f);
46 ColorSurface(surf, mol);
47 mol.SetData<OESurface>("psasurf", surf);
48
49 OEWriteMolecule(ofs, mol);
50 }
51 return 0;
52 }
Note that OEInitSurfaceHandlers has to be called on the
oemolostream in order for the surface to be attached to the
molecule.