def findCenter(S):
    """Find the approximate center atom of a structure.

    The center of the structure is the atom closest to (0.5, 0.5, 0.5)

    Returns the index of the atom.
    """
    best = -1
    bestd = len(S)
    center = [0.5, 0.5, 0.5]
    for i in range(len(S)):
        d = S.lattice.dist(S[i].xyz, center)
        if d < bestd:
            bestd = d
            best = i
    return best
