r"""computes the potential energy at point rvec
777191
def folding_model_energy(rvec, rcut):
    """
    r = np.linalg.norm(rvec) - rcut
    rr = r ** 2
    if r < 0.0:
        return -2.5 * rr
    return 0.5 * (r - 2.0) * rr
1322220
def energy(context, features):
    """"""
    fritz = context.obj
    fritz.login()

    for actor in fritz.get_actors():
        if actor.temperature is not None:
            click.echo("{} ({}): {:.2f} Watt current, {:.3f} wH total, {:.2f} °C".format(
                actor.name.encode('utf-8'),
                actor.actor_id,
                (actor.get_power() or 0.0) / 1000,
                (actor.get_energy() or 0.0) / 100,
                actor.temperature
            ))
        else:
            click.echo("{} ({}): {:.2f} Watt current, {:.3f} wH total, offline".format(
                actor.name.encode('utf-8'),
                actor.actor_id,
                (actor.get_power() or 0.0) / 1000,
                (actor.get_energy() or 0.0) / 100
            ))
        if features:
            click.echo("  Features: PowerMeter: {}, Temperatur: {}, Switch: {}".format(
                actor.has_powermeter, actor.has_temperature, actor.has_switch
            ))
644943
def final_energy(self):
        
        try:
            final_istep = self.ionic_steps[-1]
            if final_istep["e_wo_entrp"] != final_istep[
                'electronic_steps'][-1]["e_0_energy"]:
                warnings.warn("Final e_wo_entrp differs from the final "
                              "electronic step. VASP may have included some "
                              "corrections, e.g., vdw. Vasprun will return "
                              "the final e_wo_entrp, i.e., including "
                              "corrections in such instances.")
                return final_istep["e_wo_entrp"]
            return final_istep['electronic_steps'][-1]["e_0_energy"]
        except (IndexError, KeyError):
            warnings.warn("Calculation does not have a total energy. "
                          "Possibly a GW or similar kind of run. A value of "
                          "infinity is returned.")
            return float('inf')
336044
def read_total_energies(pathname,colnum):
    

    print("--Reading total energies from %s/..." % pathname)

    # Initialize Return variables
    E_kn = numpy.zeros([NumTemps, NumIterations], numpy.float64)
    
    #Read files
    for k in range(NumTemps):
        #Construct each TEMP#/ener_box#.output name and read in the file
        filename = os.path.join(pathname,'TEMP' + str(k), 'ener_box'+ str(k) + '.output')
        infile = open(filename, 'r')
        lines = infile.readlines()
        infile.close()
        numLines = len(lines)

        #Initialize arrays for E
        E_from_file = numpy.zeros(NumIterations, numpy.float64)

        #Parse lines in each file
        for n in range(NumIterations):
            m = numLines - 2 - n #Count down (the 2 is for index purposes(1) and to not use the double-counted last line (1))
            elements = lines[m].split()
            E_from_file[n] = float(elements[colnum])

        #Add in the E's for each timestep (n) at this temperature (k)
        E_kn[k] = E_from_file;
    return E_kn
775158
def generator(self, t):
        """"""
        self.check_fit()

        return (1.0 / self.theta) * (np.power(t, -self.theta) - 1)
1078245
def energy_ES(q, v):
    """"""
    # Body 0 is the sun, Body 1 is the earth
    m0 = mass[0]
    m1 = mass[1]

    # Positions of sun and earth
    q0: np.ndarray = q[:, slices[0]]
    q1: np.ndarray = q[:, slices[1]]

    # Velocities of sun and earth
    v0: np.ndarray = v[:, slices[0]]
    v1: np.ndarray = v[:, slices[1]]

    # Kinetic energy is 1/2 mv^2
    T0: np.ndarray = 0.5 * m0 * np.sum(v0 * v0, axis=1)
    T1: np.ndarray = 0.5 * m1 * np.sum(v1 * v1, axis=1)
    T: np.ndarray = T0 + T1
    
    # Potential energy is -G m1 m2  / r
    dv_01 = q1 - q0
    r_01 = np.linalg.norm(dv_01, axis=1)
    U_01: np.ndarray = -G * m0 * m1 / r_01
    U: np.ndarray = U_01
    
    # Total energy H = T + U
    H = T + U
    
    return H, T, U
1321606
def energy(self):
        """"""
        arr = self.src.copy()
        arr = self.apply_color(arr, self.state)

        scores = [histogram_distance(self.ref[i], arr[i]) for i in range(3)]

        # Important: scale by 100 for readability
        return sum(scores) * 100
389129
def stSpectralRollOff(X, c, fs):
    """"""
    totalEnergy = numpy.sum(X ** 2)
    fftLength = len(X)
    Thres = c*totalEnergy
    # Ffind the spectral rolloff as the frequency position 
    # where the respective spectral energy is equal to c*totalEnergy
    CumSum = numpy.cumsum(X ** 2) + eps
    [a, ] = numpy.nonzero(CumSum > Thres)
    if len(a) > 0:
        mC = numpy.float64(a[0]) / (float(fftLength))
    else:
        mC = 0.0
    return (mC)
1142782
def energy_upperbound(self, spins):
        
        subtheta = self.theta.copy()
        subtheta.fix_variables(spins)

        # ok, let's start eliminating variables
        trees = self._trees

        if not trees:
            # if there are no variables to eliminate, then the offset of
            # subtheta is the exact value and we can just return it
            assert not subtheta.linear and not subtheta.quadratic
            return subtheta.offset

        energy = Plus(self.message_upperbound(trees, {}, subtheta), subtheta.offset)

        return energy
705375
def spectral_rolloff(data, coeff):
    """"""
    data = np.mean(data, axis=1)
    nFFT = len(data) // 2
    X = FFT(data, nFFT)

    totalEnergy = np.sum(X ** 2)
    fftLength = len(X)
    Thres = coeff * totalEnergy

    # Find the spectral rolloff as the frequency position where the
    # respective spectral energy is equal to c*totalEnergy
    CumSum = np.cumsum(X ** 2) + EPSILON
    [a, ] = np.nonzero(CumSum > Thres)
    if len(a) > 0:
        mC = np.float64(a[0]) / (float(fftLength))
    else:
        mC = 0.0

    return mC
130820
def _read_frame(self):
        """"""
        self._secfile.get_next("Frame Number")
        frame = ATRJFrame()
        # Read the time and energy
        energy_lines = self._secfile.get_next("Time/Energy")
        energy_words = energy_lines[0].split()
        frame.time = float(energy_words[0])*picosecond
        frame.step = int(energy_words[1])
        frame.total_energy = float(energy_words[2])*kcalmol
        # Read the coordinates
        coord_lines = self._secfile.get_next("Coordinates")
        frame.coordinates = np.zeros((self.num_atoms, 3), float)
        for index, line in enumerate(coord_lines):
            words = line.split()
            frame.coordinates[index, 0] = float(words[1])
            frame.coordinates[index, 1] = float(words[2])
            frame.coordinates[index, 2] = float(words[3])
        frame.coordinates *= angstrom
        # Done
        return frame
871138
def mass_3d(self, r, rho0, Rs):
        
        mass_3d = 2*np.pi*Rs**3*rho0 * r**2/(r + Rs)**2
        return mass_3d
284464
def get_potential_energy(self, a=None):
        """"""
        if a is None:
            a = self.a
        if self.mask is None:
            return -np.sum(np.dot(a.get_positions()[self.mask], self.force))
        else:
            return -np.sum(np.dot(a.get_positions(), self.force))
1269780
def _alpha2rho0(self, theta_Rs, Rs):

        

        rho0 = theta_Rs / (4. * Rs ** 2 * (1. + np.log(1. / 2.)))
        return rho0
725747
def from_dynacRepr(cls, pynacRepr):
        
        energyDefnFlag = int(pynacRepr[1][0][0])
        energy = float(pynacRepr[1][0][1])
        phase = float(pynacRepr[1][0][2])
        x = float(pynacRepr[1][0][3])
        y = float(pynacRepr[1][0][4])
        radius = float(pynacRepr[1][0][5])

        return cls(energy, phase, x, y, radius, energyDefnFlag)
1347429
def energy(self):
        
        """
        s, b, W, N = self.state, self.b, self.W, self.N
        self.E = - sum(s * b) - sum([s[i] * s[j] * W[i, j] for (i, j) in product(range(N), range(N)) if i < j])
        self.low_energies[-1] = self.E
        self.low_energies.sort()
        self.high_energies[-1] = self.E
        self.high_energies.sort()
        self.high_energies = self.high_energies[::-1]
        return self.E
437081
def get_spatially_integrated_flux( self, energies):
    
        
       
        if not isinstance(energies, np.ndarray):
            energies = np.array(energies, ndmin=1)

        # Get the differential flux from the spectral components

        results = [self.spatial_shape.get_total_spatial_integral(energies) * component.shape(energies) for component in self.components.values()]

        if isinstance(energies, u.Quantity):

            # Slow version with units

            # We need to sum like this (slower) because using np.sum will not preserve the units
            # (thanks astropy.units)

            differential_flux = sum(results)

        else:

            # Fast version without units, where x is supposed to be in the same units as currently defined in
            # units.get_units()

            differential_flux = np.sum(results, 0)

        return differential_flux