def det_gravity2(energy, dos, Erange=(-100, 0)):
    """Determine center of gravity for DOS and return values of energy for dos
    INPUT:
    energy - list of energies
    dos    - list of corresponding dos
    Erange - window of energy to determine center of gravity
    """
    sum_dos = 0
    sum_dos_E = 0
    for i, E in enumerate(energy):
        if E < Erange[0]:
            continue
        if E > Erange[1]:
            break
        sum_dos += dos[i]
        sum_dos_E += dos[i] * E
    gc = sum_dos_E / sum_dos
    return gc
