def change_specifier(self, new_specifier, pwi): scale, kaxes = pwi.get_common_vars('scale', 'kaxes') spec = self.specifier if spec == 'tpiba' or spec == '': kpoints = self.kpoints * (2 * pi) / scale elif spec == 'gamma': kpoints = array([[0, 0, 0]]) elif spec == 'crystal': kpoints = dot(self.kpoints, kaxes) elif spec == 'automatic': grid = array(self.grid, dtype=int) shift = .5 * array(self.shift) kpoints = kmesh(kaxes, grid, shift) elif spec == 'tpiba_b' or spec == 'crystal_b': self.error( 'specifiers tpiba_b and crystal_b have not yet been implemented in change_specifier' ) else: self.error( 'old specifier for k_points is invalid\n old specifier: ' + spec + '\n valid options: tpiba, gamma, crystal, automatic, tpiba_b, crystal_b' ) #end if spec = new_specifier if spec == 'tpiba' or spec == '': kpoints = kpoints / ((2 * pi) / scale) elif spec == 'gamma': kpoints = array([[0, 0, 0]]) elif spec == 'crystal': kpoints = dot(kpoints, inv(kaxes)) elif spec == 'automatic': if self.specifier != 'automatic': self.error( 'cannot map arbitrary kpoints into a Monkhorst-Pack mesh') #end if elif spec == 'tpiba_b' or spec == 'crystal_b': self.error( 'specifiers tpiba_b and crystal_b have not yet been implemented in change_specifier' ) else: self.error( 'new specifier for k_points is invalid\n new specifier: ' + spec + '\n valid options: tpiba, gamma, crystal, automatic, tpiba_b, crystal_b' ) #end if self.kpoints = kpoints self.specifier = new_specifier
def generate_kpoint(ks, kaxes, grids=True): is_string = isinstance(ks, str) if is_string: kgrid = 1, 1, 1 dft_kgrid = 1, 1, 1 if ks == 'G': kshift = 0, 0, 0 dft_kshift = 0, 0, 0 elif ks == 'L': kshift = .5, .5, .5 dft_kshift = 1, 1, 1 elif len(ks) > 1 and ks[1:].isdigit(): dft_kshift = tuple(array(tuple(ks[1:]), dtype=int)) if len(dft_kshift) != 3: error( 'kpoint string must have at least 3 entires for shift\n you provided {0}\n input kpoint string: {1}\n a valid example: {2}' .format(len(dft_kshift), ks, ks[0] + '111')) #end if kshift = empty((3, ), dtype=float) for d in range(3): dks = dft_kshift[d] if dks == 1: kshift[d] = .5 elif dks == 0: kshift[d] = 0 else: error( 'invalid value in kpoint string\n valid values are 0 or 1\n you provided: {0}\n full input string: {1}' .format(dks, ks)) #end if #end for kshift = tuple(kshift) #end if kpoint = kmesh(kaxes, kgrid, kshift)[0] else: kpoint = array(ks) #end if if not grids or not is_string: kgrid = None kshift = None dft_kgrid = None dft_kshift = None #end if k = obj(kpoint=kpoint, kgrid=kgrid, kshift=kshift, dft_kgrid=dft_kgrid, dft_kshift=dft_kshift) return k
def generate_kpoint(ks,kaxes,grids=True): is_string = isinstance(ks,str) if is_string: kgrid = 1,1,1 dft_kgrid = 1,1,1 if ks=='G': kshift = 0,0,0 dft_kshift = 0,0,0 elif ks=='L': kshift = .5,.5,.5 dft_kshift = 1,1,1 elif len(ks)>1 and ks[1:].isdigit(): dft_kshift = tuple(array(tuple(ks[1:]),dtype=int)) if len(dft_kshift)!=3: error('kpoint string must have at least 3 entires for shift\n you provided {0}\n input kpoint string: {1}\n a valid example: {2}'.format(len(dft_kshift),ks,ks[0]+'111')) #end if kshift = empty((3,),dtype=float) for d in range(3): dks = dft_kshift[d] if dks==1: kshift[d] = .5 elif dks==0: kshift[d] = 0 else: error('invalid value in kpoint string\n valid values are 0 or 1\n you provided: {0}\n full input string: {1}'.format(dks,ks)) #end if #end for kshift = tuple(kshift) #end if kpoint = kmesh(kaxes,kgrid,kshift)[0] else: kpoint = array(ks) #end if if not grids or not is_string: kgrid = None kshift = None dft_kgrid = None dft_kshift = None #end if k = obj( kpoint = kpoint, kgrid = kgrid, kshift = kshift, dft_kgrid = dft_kgrid, dft_kshift = dft_kshift ) return k
def change_specifier(self,new_specifier,pwi): scale,kaxes = pwi.get_common_vars('scale','kaxes') spec = self.specifier if spec=='tpiba' or spec=='': kpoints = self.kpoints*(2*pi)/scale elif spec=='gamma': kpoints = array([[0,0,0]]) elif spec=='crystal': kpoints = dot(self.kpoints,kaxes) elif spec=='automatic': grid = array(self.grid,dtype=int) shift = .5*array(self.shift) kpoints = kmesh(kaxes,grid,shift) elif spec=='tpiba_b' or spec=='crystal_b': self.error('specifiers tpiba_b and crystal_b have not yet been implemented in change_specifier') else: self.error('old specifier for k_points is invalid\n old specifier: '+spec+'\n valid options: tpiba, gamma, crystal, automatic, tpiba_b, crystal_b') #end if spec = new_specifier if spec=='tpiba' or spec=='': kpoints = kpoints/((2*pi)/scale) elif spec=='gamma': kpoints = array([[0,0,0]]) elif spec=='crystal': kpoints = dot(kpoints,inv(kaxes)) elif spec=='automatic': if self.specifier!='automatic': self.error('cannot map arbitrary kpoints into a Monkhorst-Pack mesh') #end if elif spec=='tpiba_b' or spec=='crystal_b': self.error('specifiers tpiba_b and crystal_b have not yet been implemented in change_specifier') else: self.error('new specifier for k_points is invalid\n new specifier: '+spec+'\n valid options: tpiba, gamma, crystal, automatic, tpiba_b, crystal_b') #end if self.kpoints = kpoints self.specifier = new_specifier