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

areas = OEFloatArray(surf.GetNumTriangles())
OECalculateTriangleAreas(surf, areas)

atomareas = [0.0] * mol.GetMaxAtomIdx()

for i in range(surf.GetNumTriangles()):
    tri = surf.GetTriangle(i)

    a1 = surf.GetAtomsElement(tri[0])
    a2 = surf.GetAtomsElement(tri[1])
    a3 = surf.GetAtomsElement(tri[2])

    atomareas[a1] += areas[i]/3.0
    atomareas[a2] += areas[i]/3.0
    atomareas[a3] += areas[i]/3.0

for atom in mol.GetAtoms():
    print("atom %d area = %2.4f" % (atom.GetIdx(), atomareas[atom.GetIdx()]))