OECalculateTriangleAreas

bool OECalculateTriangleAreas(const OESurface &surf, float *areas)

Will calculate the area of every triangle of surf and store the result in the array areas of that should be large enough to hold GetNumTriangles() floats. The array is indexed by the triangle indices.

Listing 1 demonstrates how to calculate the surface area contribution from each atom. It is assumed surf is an OESurface created from the molecule mol.

Listing 1: Calculates the surface area contribution from each atom

float[] areas = new float[surf.GetNumTriangles()];
OESpicoli.OECalculateTriangleAreas(surf, areas);

float[] atomareas = new float[mol.GetMaxAtomIdx()];
uint[] tri = new uint[3];
for (uint i = 0; i < surf.GetNumTriangles(); i++)
{
    surf.GetTriangle(i, tri);
    
    uint a1 = surf.GetAtomsElement(tri[0]);
    uint a2 = surf.GetAtomsElement(tri[1]);
    uint a3 = surf.GetAtomsElement(tri[2]);
    
    atomareas[a1] += areas[i] / 3.0f;
    atomareas[a2] += areas[i] / 3.0f;
    atomareas[a3] += areas[i] / 3.0f;
}

foreach (OEAtomBase atom in mol.GetAtoms())
{
    Console.WriteLine("atom {0:d} area = {1:0.00}", atom.GetIdx(), atomareas[atom.GetIdx()]);
}