def read_overlap(self, **kwargs): """ Returns the overlap matrix from the TranSiesta file """ tshs_g = self.read_geometry() geom = _geometry_align(tshs_g, kwargs.get('geometry', tshs_g), self.__class__, 'read_overlap') # read the sizes used... sizes = _siesta.read_tshs_sizes(self.file) _bin_check(self, 'read_overlap', 'could not read sizes.') isc = _siesta.read_tshs_cell(self.file, sizes[3])[2].T _bin_check(self, 'read_overlap', 'could not read cell.') no = sizes[2] nnz = sizes[4] ncol, col, dS = _siesta.read_tshs_s(self.file, no, nnz) _bin_check(self, 'read_overlap', 'could not read overlap matrix.') # Create the Hamiltonian container S = Overlap(geom, nnzpr=1) # Create the new sparse matrix S._csr.ncol = ncol.astype(np.int32, copy=False) S._csr.ptr = np.insert(np.cumsum(ncol, dtype=np.int32), 0, 0) # Correct fortran indices S._csr.col = col.astype(np.int32, copy=False) - 1 S._csr._nnz = len(col) S._csr._D = _a.emptyd([nnz, 1]) S._csr._D[:, 0] = dS[:] # Convert to sisl supercell _csr_from_sc_off(S.geometry, isc, S._csr) return S
def __init__(self): bond = 1.42 sq3h = 3.**.5 * 0.5 self.sc = SuperCell(np.array([[1.5, sq3h, 0.], [1.5, -sq3h, 0.], [0., 0., 10.]], np.float64) * bond, nsc=[3, 3, 1]) n = 60 rf = np.linspace(0, bond * 1.01, n) rf = (rf, rf) orb = SphericalOrbital(1, rf, 2.) C = Atom(6, orb.toAtomicOrbital()) self.g = Geometry(np.array([[0., 0., 0.], [1., 0., 0.]], np.float64) * bond, atoms=C, sc=self.sc) self.S = Overlap(self.g)
def read_overlap(self, **kwargs): """ Returns the overlap matrix from the siesta.HSX file """ # Now read the sizes used... Gamma, spin, no, no_s, nnz = _siesta.read_hsx_sizes(self.file) _bin_check(self, 'read_overlap', 'could not read overlap matrix sizes.') ncol, col, dS = _siesta.read_hsx_s(self.file, Gamma, spin, no, no_s, nnz) _bin_check(self, 'read_overlap', 'could not read overlap matrix.') geom = kwargs.get('geometry', kwargs.get('geom', None)) if geom is None: warn(self.__class__.__name__ + ".read_overlap requires input geometry to assign S") if geom.no != no: raise SileError( str(self) + '.read_overlap could not use the ' 'passed geometry as the number of atoms or orbitals is ' 'inconsistent with HSX file.') # Create the Hamiltonian container S = Overlap(geom, nnzpr=1) # Create the new sparse matrix S._csr.ncol = ncol.astype(np.int32, copy=False) S._csr.ptr = np.insert(np.cumsum(ncol, dtype=np.int32), 0, 0) # Correct fortran indices S._csr.col = col.astype(np.int32, copy=False) - 1 S._csr._nnz = len(col) S._csr._D = _a.emptyf([nnz, 1]) S._csr._D[:, 0] = dS[:] # Convert the supercells to sisl supercells if no_s // no == np.product(geom.nsc): _csr_from_siesta(geom, S._csr) return S
def test_fromsp(self, setup): S = setup.S.copy() csr = S.tocsr() S2 = Overlap.fromsp(S.geometry, csr) assert np.allclose(csr.data, S2.tocsr().data)