Ejemplo n.º 1
0
    def read_es(self, **kwargs):
        """ Returns the electronic structure from the siesta.TSHS file """

        # First read the geometry
        geom = self.read_geom()

        # Now read the sizes used...
        sizes = _siesta.read_tshs_sizes(self.file)
        spin = sizes[0]
        no = sizes[2]
        nnz = sizes[4]
        ncol, col, dH, dS = _siesta.read_tshs_es(self.file, spin, no, nnz)

        # Create the Hamiltonian container
        H = Hamiltonian(geom, nnzpr=1, orthogonal=False, spin=spin)

        # Create the new sparse matrix
        H._data.ncol = np.array(ncol, np.int32)
        ptr = np.cumsum(ncol)
        ptr = np.insert(ptr, 0, 0)
        H._data.ptr = np.array(ptr, np.int32)
        # Correct fortran indices
        H._data.col = np.array(col, np.int32) - 1
        H._data._nnz = len(col)

        H._data._D = np.empty([nnz, spin + 1], np.float64)
        for i in range(spin):
            # this is because of the F-ordering
            H._data._D[:, i] = dH[:, i]
        H._data._D[:, spin] = dS[:]

        return H
Ejemplo n.º 2
0
    def read_es(self, **kwargs):
        """ Returns a tight-binding model from the underlying NetCDF file """

        # Get the default spin channel
        ispin = kwargs.get('ispin', -1)
        spin = 1
        if ispin == -1:
            spin = len(self._dimension('spin'))

        # First read the geometry
        geom = self.read_geom()

        # Populate the things
        sp = self._crt_grp(self, 'SPARSE')
        v = sp.variables['isc_off']
        # pre-allocate the super-cells
        geom.sc.set_nsc(np.amax(v[:, :], axis=0) * 2 + 1)
        geom.sc.sc_off[:, :] = v[:, :]

        # Now create the tight-binding stuff (we re-create the
        # array, hence just allocate the smallest amount possible)
        ham = Hamiltonian(geom, nnzpr=1, orthogonal=False, spin=spin)

        # Use Ef to move H to Ef = 0
        Ef = float(self._value('Ef')[0]) * Ry2eV**ham._E_order
        S = np.array(sp.variables['S'][:], np.float64)

        ncol = np.array(sp.variables['n_col'][:], np.int32)
        # Update maximum number of connections (in case future stuff happens)
        ptr = np.append(np.array(0, np.int32), np.cumsum(ncol)).flatten()
        col = np.array(sp.variables['list_col'][:], np.int32) - 1

        # Copy information over
        ham._data.ncol = ncol
        ham._data.ptr = ptr
        ham._data.col = col
        ham._nnz = len(col)

        # Create new container
        H = np.array(sp.variables['H'][ispin, :],
                     np.float64) * Ry2eV**ham._E_order
        # Correct for the Fermi-level, Ef == 0
        H -= Ef * S[:]

        ham._data._D = np.empty([ham._data.ptr[-1], spin + 1], np.float64)
        if ispin == -1:
            for i in range(spin):
                # Create new container
                H = np.array(sp.variables['H'][i, :],
                             np.float64) * Ry2eV**ham._E_order
                # Correct for the Fermi-level, Ef == 0
                H -= Ef * S[:]
                ham._data._D[:, i] = H[:]
        else:
            # Create new container
            H = np.array(sp.variables['H'][ispin, :],
                         np.float64) * Ry2eV**ham._E_order
            # Correct for the Fermi-level, Ef == 0
            H -= Ef * S[:]
            ham._data._D[:, 0] = H[:]
        ham._data._D[:, ham.S_idx] = S[:]

        return ham