Compute difference in conduction band min and valence band max
436101
def _get_bandgap_from_bands(energies, nelec):
        """"""
        nelec = int(nelec)
        valence = [x[nelec-1] for x in energies]
        conduction = [x[nelec] for x in energies]
        return max(min(conduction) - max(valence), 0.0)
1112055
def main():
    

    # Eigendecomposition:
    #   (4.537, [-0.971555, -0.0578339+0.229643j])
    #   (0.349, [-0.236813, 0.237270-0.942137j])
    # |b> = (0.64510-0.47848j, 0.35490-0.47848j)
    # |x> = (-0.0662724-0.214548j, 0.784392-0.578192j)
    A = np.array([[4.30213466-6.01593490e-08j,
                   0.23531802+9.34386156e-01j],
                  [0.23531882-9.34388383e-01j,
                   0.58386534+6.01593489e-08j]])
    t = 0.358166*math.pi
    register_size = 4
    input_prep_gates = [cirq.Rx(1.276359), cirq.Rz(1.276359)]
    expected = (0.144130, 0.413217, -0.899154)

    # Set C to be the smallest eigenvalue that can be represented by the
    # circuit.
    C = 2*math.pi / (2**register_size * t)

    # Simulate circuit
    print("Expected observable outputs:")
    print("X =", expected[0])
    print("Y =", expected[1])
    print("Z =", expected[2])
    print("Actual: ")
    simulate(hhl_circuit(A, C, t, register_size, *input_prep_gates))
188749
def minimum(attrs, inputs, proto_obj):
    """"""
    # MXNet minimum compares only two symbols at a time.
    # ONNX can send more than two to compare.
    # Breaking into multiple mxnet ops to compare two symbols at a time
    if len(inputs) > 1:
        mxnet_op = symbol.minimum(inputs[0], inputs[1])
        for op_input in inputs[2:]:
            mxnet_op = symbol.minimum(mxnet_op, op_input)
    else:
        mxnet_op = symbol.minimum(inputs[0], inputs[0])
    return mxnet_op, attrs, inputs
767896
def eigenvalue_band_properties(self):
        
        vbm = -float("inf")
        vbm_kpoint = None
        cbm = float("inf")
        cbm_kpoint = None
        for spin, d in self.eigenvalues.items():
            for k, val in enumerate(d):
                for (eigenval, occu) in val:
                    if occu > self.occu_tol and eigenval > vbm:
                        vbm = eigenval
                        vbm_kpoint = k
                    elif occu <= self.occu_tol and eigenval < cbm:
                        cbm = eigenval
                        cbm_kpoint = k
        return max(cbm - vbm, 0), cbm, vbm, vbm_kpoint == cbm_kpoint
255886
def getoptT(X, W, Y, Z, S, M_E, E, m0, rho):
    ''' 
    '''
    iter_max = 20
    norm2WZ = np.linalg.norm(W, ord='fro')**2 + np.linalg.norm(Z, ord='fro')**2
    f = np.zeros(iter_max + 1)
    f[0] = F_t(X, Y, S, M_E, E, m0, rho)

    t = -1e-1
    for i in range(iter_max):
        f[i + 1] = F_t(X + t * W, Y + t * Z, S, M_E, E, m0, rho)

        if f[i + 1] - f[0] <= 0.5 * t * norm2WZ:
            return t
        t /= 2
    return t
14744
def _min(self):
        """"""
        return (
            self.range[0] if (self.range and self.range[0] is not None) else
            (min(self._values) if self._values else None)
        )
378130
def pivot_wavelength_ee(bpass):
    
    from scipy.integrate import simps
    return np.sqrt(simps(bpass.resp, bpass.wlen) /
                   simps(bpass.resp / bpass.wlen**2, bpass.wlen))
970897
def estimate_band_connection(prev_eigvecs, eigvecs, prev_band_order):
    
    metric = np.abs(np.dot(prev_eigvecs.conjugate().T, eigvecs))
    connection_order = []
    for overlaps in metric:
        maxval = 0
        for i in reversed(range(len(metric))):
            val = overlaps[i]
            if i in connection_order:
                continue
            if val > maxval:
                maxval = val
                maxindex = i
        connection_order.append(maxindex)

    band_order = [connection_order[x] for x in prev_band_order]

    return band_order
1027165
private static int min(int a, int b, int c) {
        int r = a;
        if (r > b) r = b;
        if (r > c) r = c;
        return r;
    }
490477
def _delta_t_supconj_perpass(period, ecc, per0):
    
    ups_sc = np.pi/2-per0
    E_sc = 2*np.arctan( np.sqrt((1-ecc)/(1+ecc)) * np.tan(ups_sc/2) )
    M_sc = E_sc - ecc*np.sin(E_sc)
    return period*(M_sc/2./np.pi)
847218
function(signal1, signal2, options){
    options = options || {};
    options.epsilon = options.epsilon || 1E-08;
    var sig1 = Signal(signal1);
    var sig2 = Signal(signal2);
    if(signal1.length != signal2.length) return false;
    var diffSQ = _.reduce(_.range(signal1.length), function(d,idx){
      var diff = (sig1[idx].value-sig2[idx].value);
        return d + diff * diff;
    },0);
    return diffSQ/signal1.length < options.epsilon;
  }
1144900
def prox_min(X, step, thresh=0):
    
    thresh_ = _step_gamma(step, thresh)
    below = X - thresh_ < 0
    X[below] = thresh_
    return X
610738
def _auto_set_energy_range(self):
        
        emins = [min([e_k[0] for e_k in self._bs.bands[Spin.up]])]
        emaxs = [max([e_k[0] for e_k in self._bs.bands[Spin.up]])]

        if self._bs.is_spin_polarized:
            emins.append(min([e_k[0] for e_k in
                              self._bs.bands[Spin.down]]))

            emaxs.append(max([e_k[0] for e_k in
                              self._bs.bands[Spin.down]]))

        min_eigenval = Energy(min(emins) - self._bs.efermi, "eV"). \
            to("Ry")
        max_eigenval = Energy(max(emaxs) - self._bs.efermi, "eV"). \
            to("Ry")

        # set energy range to buffer around min/max EV
        # buffer does not increase CPU time but will help get equal
        # energies for spin up/down for band structure
        const = Energy(2, "eV").to("Ry")
        self._ll = min_eigenval - const
        self._hl = max_eigenval + const

        en_range = Energy(max((abs(self._ll), abs(self._hl))),
                          "Ry").to("eV")

        self.energy_span_around_fermi = en_range * 1.01
        print("energy_span_around_fermi = ",
              self.energy_span_around_fermi)
666667
def get_band_structure(self):
        """"""

        kpath = HighSymmKpath(self.data.structure)
        kpt_line = [Kpoint(k, self.data.structure.lattice) for k
                    in
                    kpath.get_kpoints(coords_are_cartesian=False)[
                        0]]
        kpoints = np.array(
            [kp.frac_coords for kp in kpt_line])

        labels_dict = {l: k for k, l in zip(
            *kpath.get_kpoints(coords_are_cartesian=False)) if l}

        lattvec = self.data.get_lattvec()
        egrid, vgrid = fite.getBands(kpoints, self.equivalences, lattvec, self.coeffs)

        bands_dict = {Spin.up: (egrid / units.eV)}

        sbs = BandStructureSymmLine(kpoints, bands_dict,
                                    self.data.structure.lattice.reciprocal_lattice,
                                    self.efermi / units.eV,
                                    labels_dict=labels_dict)
        return sbs
654140
def get_direct_band_gap_dict(self):
        
        if self.is_metal():
            raise ValueError("get_direct_band_gap_dict should"
                             "only be used with non-metals")
        direct_gap_dict = {}
        for spin, v in self.bands.items():
            above = v[np.all(v > self.efermi, axis=1)]
            min_above = np.min(above, axis=0)
            below = v[np.all(v < self.efermi, axis=1)]
            max_below = np.max(below, axis=0)
            diff = min_above - max_below
            kpoint_index = np.argmin(diff)
            band_indices = [np.argmax(below[:, kpoint_index]),
                            np.argmin(above[:, kpoint_index]) + len(below)]
            direct_gap_dict[spin] = {"value": diff[kpoint_index],
                                     "kpoint_index": kpoint_index,
                                     "band_indices": band_indices}
        return direct_gap_dict
925192
def compare(self, other, t_threshold=1e-3):
        
        return compute_rmsd(self.t, other.t) < t_threshold
1043919
def compute_sens(self, elem_file, elec_file, configs):
        
        CRMod_config = CRMod.config()
        # activate 2D mode and set sink nr
        if self.options.sink is not None:
            print('2D mode with sink {0}'.format(self.options.sink))
            CRMod_config['2D'] = 0
            CRMod_config['fictitious_sink'] = 'T'
            CRMod_config['sink_node'] = self.options.sink

        CRMod_config['write_sens'] = 'T'
        CRMod_instance = CRMod.CRMod(CRMod_config)
        CRMod_instance.elemfile = elem_file
        CRMod_instance.elecfile = elec_file
        CRMod_instance.configdata = configs

        resistivity = 100
        # get number of elements
        fid = open(elem_file, 'r')
        fid.readline()
        elements = int(fid.readline().strip().split()[1])
        fid.close()

        # create rho.dat file
        rhodata = '{0}\n'.format(elements)
        for i in range(0, elements):
            rhodata += '{0}   0\n'.format(resistivity)
        CRMod_instance.rhodata = rhodata

        CRMod_instance.run_in_tempdir()
        volt_file = CRMod_instance.volt_file
        sens_files = CRMod_instance.sens_files
        return sens_files, volt_file, CRMod_instance.temp_dir