def read_sc(self, *args, **kwargs): """ Returns `SuperCell` object from the FDF file """ f, lc = self._read('LatticeConstant') s = float(lc.split()[1]) if 'ang' in lc.lower(): pass elif 'bohr' in lc.lower(): s *= Bohr2Ang # Read in cell cell = np.empty([3, 3], np.float64) f, lc = self._read_block('LatticeVectors') if f: for i in range(3): cell[i, :] = [float(k) for k in lc[i].split()[:3]] else: f, lc = self._read_block('LatticeParameters') if f: tmp = [float(k) for k in lc[0].split()[:6]] cell = SuperCell.tocell(*tmp) if not f: # the fdf file contains neither the latticevectors or parameters raise SileError( 'Could not find Vectors or Parameters block in file') cell *= s return SuperCell(cell)
def _r_supercell_fdf(self, *args, **kwargs): """ Returns `SuperCell` object from the FDF file """ s = self.get('LatticeConstant', unit='Ang') if s is None: raise SileError('Could not find LatticeConstant in file') # Read in cell cell = np.empty([3, 3], np.float64) lc = self.get('LatticeVectors') if lc: for i in range(3): cell[i, :] = [float(k) for k in lc[i].split()[:3]] else: lc = self.get('LatticeParameters') if lc: tmp = [float(k) for k in lc[0].split()[:6]] cell = SuperCell.tocell(*tmp) if lc is None: # the fdf file contains neither the latticevectors or parameters raise SileError( 'Could not find LatticeVectors or LatticeParameters block in file' ) cell *= s # When reading from the fdf, the warning should be suppressed with warnings.catch_warnings(): warnings.simplefilter("ignore") nsc = self.read_supercell_nsc() return SuperCell(cell, nsc=nsc)
def read_supercell(self): """ Read supercell from the contained file """ f, line = self._step_record('CRYST1') if not f: raise SileError(str(self) + ' does not contain a CRYST1 record.') a = float(line[6:15]) b = float(line[15:24]) c = float(line[24:33]) alpha = float(line[33:40]) beta = float(line[40:47]) gamma = float(line[47:54]) cell = SuperCell.tocell([a, b, c, alpha, beta, gamma]) f, line = self._step_record('SCALE1') if f: cell[0, :] = float(line[11:20]), float(line[21:30]), float(line[31:40]) f, line = self._step_record('SCALE2') if not f: raise SileError(str(self) + ' found SCALE1 but not SCALE2!') cell[1, :] = float(line[11:20]), float(line[21:30]), float(line[31:40]) f, line = self._step_record('SCALE3') if not f: raise SileError(str(self) + ' found SCALE1 but not SCALE3!') cell[2, :] = float(line[11:20]), float(line[21:30]), float(line[31:40]) origo = np.zeros(3) for i in range(3): f, line = self._step_record('ORIGX{}'.format(i + 1)) if f: origo[i] = float(line[45:55]) return SuperCell(cell, origo=origo)