예제 #1
0
파일: _help.py 프로젝트: sofiasanz/sisl
 def _csr_to_siesta(geom, csr):
     raise SislError('sisl cannot convert the sparse matrix into a Siesta conforming sparsity pattern! Please install with fortran support!')
예제 #2
0
파일: cube.py 프로젝트: sofiasanz/sisl
    def read_grid(self, imag=None):
        """ Returns `Grid` object from the CUBE file

        Parameters
        ----------
        imag : str or Sile or Grid
            the imaginary part of the grid. If the geometries does not match
            an error will be raised.
        """
        if not imag is None:
            if not isinstance(imag, Grid):
                imag = Grid.read(imag)
        geom = self.read_geometry()
        if geom is None:
            self.fh.seek(0)
            sc = self.read_supercell()
        else:
            sc = geom.sc

        # Now seek behind to read grid sizes
        self.fh.seek(0)

        # Skip headers and origin
        self.readline()
        self.readline()
        na = int(self.readline().split()[0])

        ngrid = [0] * 3
        for i in [0, 1, 2]:
            tmp = self.readline().split()
            ngrid[i] = int(tmp[0])

        # Read past the atoms
        for i in range(na):
            self.readline()

        if geom is None:
            grid = Grid(ngrid, dtype=np.float64, sc=sc)
        else:
            grid = Grid(ngrid, dtype=np.float64, geometry=geom)
        grid.grid.shape = (-1, )

        # TODO check performance of this
        # We are currently doing this to enable reading
        #  1-column data and 6-column data.
        lines = [
            item for sublist in self.fh.readlines()
            for item in sublist.split()
        ]
        grid.grid[:] = np.array(lines).astype(grid.dtype)
        grid.grid.shape = ngrid

        if imag is None:
            return grid

        # We are expecting an imaginary part
        if not grid.geometry.equal(imag.geometry):
            raise SislError(
                str(self) + ' and its imaginary part does not have the same '
                'geometry. Hence a combined complex Grid cannot be formed.')
        if grid != imag:
            raise SislError(
                str(self) + ' and its imaginary part does not have the same '
                'shape. Hence a combined complex Grid cannot be formed.')

        # Now we have a complex grid
        grid.grid = grid.grid + 1j * imag.grid

        return grid