def read_geometry(self, primary=False, **kwargs): """ Reads a geometry from the Sile """ # 1st line is number of supercells nsc = _a.fromiteri(map(int, self.readline().split()[:3])) na, ns = map(int, self.readline().split()[:2]) # Convert species to atom objects try: species = get_sile(self.file.rsplit('REF', 1)[0] + 'orbocc').read_atom() except: species = [Atom(s) for s in self.readline().split()[:ns]] # Total number of super-cells if primary: # Only read in the primary unit-cell ns = 1 else: ns = np.prod(nsc) cell = _a.fromiterd(map(float, self.readline().split())) try: cell.shape = (3, 3) if primary: cell[0, :] /= nsc[0] cell[1, :] /= nsc[1] cell[2, :] /= nsc[2] except: c = np.empty([3, 3], np.float64) c[0, 0] = 1. + cell[0] c[0, 1] = cell[5] / 2. c[0, 2] = cell[4] / 2. c[1, 0] = cell[5] / 2. c[1, 1] = 1. + cell[1] c[1, 2] = cell[3] / 2. c[2, 0] = cell[4] / 2. c[2, 1] = cell[3] / 2. c[2, 2] = 1. + cell[2] cell = c * Ang2Bohr sc = SuperCell(cell * Bohr2Ang, nsc=nsc) # Create list of coordinates and atoms xyz = np.empty([na * ns, 3], np.float64) atoms = [None] * na * ns # Read the geometry for ia in range(na * ns): # Retrieve line # ix iy iz ia is x y z line = self.readline().split() atoms[ia] = species[int(line[4]) - 1] xyz[ia, :] = _a.fromiterd(map(float, line[5:8])) return Geometry(xyz * Bohr2Ang, atoms, sc=sc)
def _r_geometry_sisl(self, na, header, sp, xyz): """ Read the geometry as though it was created with sisl """ # Default version of the header is 1 v = header.get("sisl-version", 1) nsc = list(map(int, header.pop("nsc").split())) cell = _a.fromiterd(header.pop("cell").split()).reshape(3, 3) return Geometry(xyz, atom=sp, sc=SuperCell(cell, nsc=nsc))
def _r_geometry_ase(self, na, header, sp, xyz): """ Read the geometry as though it was created with ASE """ # Convert F T to nsc # F = 1 # T = 3 nsc = list(map(lambda x: "FT".index(x) * 2 + 1, header.pop("pbc").strip('"').split())) cell = _a.fromiterd(header.pop("Lattice").strip('"').split()).reshape(3, 3) return Geometry(xyz, atom=sp, sc=SuperCell(cell, nsc=nsc))
def read_supercell(self): """ Reads a supercell from the Sile """ # 1st line is number of supercells nsc = _a.fromiteri(map(int, self.readline().split()[:3])) self.readline() # natoms, nspecies self.readline() # species cell = _a.fromiterd(map(float, self.readline().split()[:9])) # Typically ScaleUp uses very large unit-cells # so supercells will typically be restricted to [3, 3, 3] return SuperCell(cell * Bohr2Ang, nsc=nsc)
def read_data(self, *args, **kwargs): """ Read tabular data from the file. Parameters ---------- columns : list of int, optional only return the indices of the columns that are provided delimiter : str, optional the delimiter used in the file, will automatically try to guess if not specified ret_comment : bool, optional also return the comments at the top of the file (if queried) ret_header : bool, optional also return the header information (if queried) comment : str, optional lines starting with this are discarded as comments """ # Override the comment in the file self._comment = [kwargs.get('comment', self._comment[0])] # Skip to next line comment = [] header = '' # Also read comments line = self.readline(True) while line.startswith(self._comment[0] + ' '): comment.append(line) line = self.readline(True) if line.startswith(self._comment[0]): header = line line = self.readline() # Now we are ready to read the data dat = [[]] # First we need to figure out the separator: len_sep = 0 sep = kwargs.get('delimiter', '') if len(sep) == 0: for cur_sep in ['\t', ' ', ',']: s = line.split(cur_sep) if len(s) > len_sep: len_sep = len(s) sep = cur_sep if len(sep) == 0: raise ValueError(self.__class__.__name__ + '.read_data could not determine ' 'column separator...') empty = re.compile(r'\s*\n') while len(line) > 0: # If we start a line by a comment, or a newline # then we have a new data set if empty.match(line) is not None: if len(dat[-1]) > 0: dat[-1] = _a.asarrayd(dat[-1]) dat.append([]) else: line = [l for l in line.split(sep) if len(l) > 0] dat[-1].append(_a.fromiterd(map(float, line))) line = self.readline() if len(dat[-1]) > 0: dat[-1] = _a.asarrayd(dat[-1]) # Ensure we have no false positives dat = _a.asarrayd([d for d in dat if len(d) > 0]) if dat.shape[0] == 1: s = list(dat.shape) s.pop(0) dat.shape = tuple(s) if dat.ndim == 2: if dat.shape[1] == 1: # surely a 1D data dat.shape = (-1, ) # For 2D data we need to transpose because the data is # read row wise, but stored column wise if dat.ndim > 1: dat = np.swapaxes(dat, -2, -1) ret_comment = kwargs.get('ret_comment', False) ret_header = kwargs.get('ret_header', False) if ret_comment: if ret_header: return dat, comment, header return dat, comment elif ret_header: return dat, header return dat