def get_band_structure(self): """Return a BandStructureSymmLine object interpolating bands along a High symmetry path calculated from the structure using HighSymmKpath function""" kpath = HighSymmKpath(self.data.structure) kpt_line = [ Kpoint(k, self.data.structure.lattice) for k in kpath.get_kpoints(coords_are_cartesian=False)[0] ] kpoints = np.array([kp.frac_coords for kp in kpt_line]) labels_dict = { l: k for k, l in zip(*kpath.get_kpoints(coords_are_cartesian=False)) if l } lattvec = self.data.get_lattvec() egrid, vgrid = fite.getBands(kpoints, self.equivalences, lattvec, self.coeffs) bands_dict = {Spin.up: (egrid / units.eV)} sbs = BandStructureSymmLine( kpoints, bands_dict, self.data.structure.lattice.reciprocal_lattice, self.efermi / units.eV, labels_dict=labels_dict) return sbs
def hse06_bandstructure_kpoints(struct, nkpts=20): ''' Generate HSE06 bandstructure KPOINTS Append high-symmetry path points to the IBZKPT file and set weight of all the high-symmetry path points to zero and then write to "KPOINTS" High-symmetry path kpoints is saved as a backup file named 'KPOINTS_bak' Note: We asssert the IBZKPT file is valid ''' def chunks(lst, n): for i in range(0, len(lst), n): yield lst[i:i + n] hsk = HighSymmKpath(struct) sym_kpts = Kpoints.automatic_linemode(nkpts, hsk) sym_kpts.write_file("KPOINTS_bak") kpts = sym_kpts.kpts nsegs = sym_kpts.num_kpts kpoints_result = [] for rng in chunks(kpts, 2): start, end = rng kpoints_result.append(np.linspace(start, end, nsegs)) kpoints_result = np.array(kpoints_result).reshape((-1, 3)) KPOINTS = open('IBZKPT').readlines() for i in range(kpoints_result.shape[0]): x, y, z = kpoints_result[i, :] KPOINTS.append("{:20.14f}{:20.14f}{:20.14f}{:14}\n".format(x, y, z, 0)) KPOINTS[1] = "{:8}\n".format(len(KPOINTS) - 3) with open("KPOINTS", 'w') as f: print("".join(KPOINTS), file=f) pass
def extract_bs(mat): bs = None # Process the bandstructure for information if "bs" in mat["bandstructure"]: bs_dict = mat["bandstructure"]["bs"] # Add in structure if not already there if "structure" not in bs_dict: bs_dict["structure"] = mat["structure"] # Add in High Symm K Path if not already there if len(bs_dict.get("labels_dict", {})) == 0: labels = get(mat, "inputs.nscf_line.kpoints.labels", None) kpts = get(mat, "inputs.nscf_line.kpoints.kpoints", None) if labels and kpts: labels_dict = dict(zip(labels, kpts)) labels_dict.pop(None, None) else: struc = Structure.from_dict(mat["structure"]) labels_dict = HighSymmKpath(struc)._kpath["kpoints"] bs_dict["labels_dict"] = labels_dict bs = BandStructureSymmLine.from_dict( BandStructure.from_dict(bs_dict).as_dict()) return bs
def set_kpath(self, ndivsm, kptbounds=None, iscf=-2): """ Set the variables for the computation of the electronic band structure. Args: ndivsm: Number of divisions for the smallest segment. kptbounds: k-points defining the path in k-space. If None, we use the default high-symmetry k-path defined in the pymatgen database. """ if kptbounds is None: from pymatgen.symmetry.bandstructure import HighSymmKpath hsym_kpath = HighSymmKpath(self.structure) name2frac_coords = hsym_kpath.kpath["kpoints"] kpath = hsym_kpath.kpath["path"] frac_coords, names = [], [] for segment in kpath: for name in segment: fc = name2frac_coords[name] frac_coords.append(fc) names.append(name) kptbounds = np.array(frac_coords) kptbounds = np.reshape(kptbounds, (-1, 3)) # self.pop_vars(["ngkpt", "shiftk"]) ?? return self.set_vars(kptbounds=kptbounds, kptopt=-(len(kptbounds) - 1), ndivsm=ndivsm, iscf=iscf)
def setUp(self): with open(os.path.join(test_dir, 'si_structure.json'), 'r') as sth: si_str = Structure.from_dict(json.load(sth)) with open(os.path.join(test_dir, 'si_bandstructure_line.json'), 'r') as bsh: si_bs_line = BandStructureSymmLine.from_dict(json.load(bsh)) si_bs_line.structure = si_str with open(os.path.join(test_dir, 'si_bandstructure_uniform.json'), 'r') as bsh: si_bs_uniform = BandStructure.from_dict(json.load(bsh)) si_bs_uniform.structure = si_str self.si_kpts = list(HighSymmKpath(si_str).kpath['kpoints'].values()) self.df = pd.DataFrame({ 'bs_line': [si_bs_line], 'bs_uniform': [si_bs_uniform] }) with open(os.path.join(test_dir, 'VBr2_971787_bandstructure.json'), 'r') as bsh: vbr2_uniform = BandStructure.from_dict(json.load(bsh)) self.vbr2kpts = [ k.frac_coords for k in vbr2_uniform.labels_dict.values() ] self.vbr2kpts = [ [0.0, 0.0, 0.0], # \\Gamma [0.2, 0.0, 0.0], # between \\Gamma and M [0.5, 0.0, 0.0], # M [0.5, 0.0, 0.5] ] # L self.df2 = pd.DataFrame({'bs_line': [vbr2_uniform]})
def write_band_conf(self): """ prepare the input file(band.conf) for phonon band structure """ primi_structure = self.struc.get_primitive_structure() primi_lattice = primi_structure.lattice.matrix.T lattice = self.struc.lattice.matrix.T transformation = np.round(inv(lattice) @ primi_lattice, 5).flatten().tolist() t_string = [str(i) for i in transformation] kpath = HighSymmKpath(self.struc.get_primitive_structure()).kpath ##the primitive structure??? print(primi_structure.get_space_group_info()) kpath_string = 'BAND =' print('Please indicate the k-path, disconnect paths are indicated by \',\', we have the following kpoints:') print(kpath['kpoints']) a = input('Enter your input:') self.kpath_name = a a_split = a.split(',') for i, item in enumerate(a_split): for point in item.strip().split(' '): kpath_string += ' ' kpath_string += ' '.join([str(i) for i in kpath['kpoints'][point].tolist()]) if i < len(a_split)-1: kpath_string += ',' a = a.replace('\Gamma', '$\Gamma$') label_string = 'BAND_LABELS = ' + a with open(os.path.join(self.wd, self.dfpt_folder+'/band.conf'), 'w') as f: f.write('DIM = {} {} {}\n'.format(self.scaling_matrix[0], self.scaling_matrix[1], self.scaling_matrix[2])) f.write('PRIMITIVE_AXIS = ' + ' '.join(t_string) + '\n') f.write(kpath_string + '\n') f.write(label_string + '\n') f.write('FORCE_CONSTANTS = READ\n')
def write_band_structure_kpoints(structure, n_kpts=20, dim=2, ibzkpt_path="../"): """ Writes a KPOINTS file for band structure calculations. Does not use the typical linemode syntax for NSCF calculations, but uses the IBZKPT + high-symmetry path syntax described in http://cms.mpi.univie.ac.at/wiki/index.php/Si_bandstructure so that SCF calculations can be performed. This is more reliable than re-using the CHGCAR from a previous run, which often results in "dimensions on the CHGCAR are different" errors in VASP. Args: structure (Structure): structure for determining k-path n_kpts (int): number of divisions along high-symmetry lines dim (int): 2 for a 2D material, 3 for a 3D material. ibzkpt_path (str): location of IBZKPT file. Defaults to one directory up. """ ibz_lines = open(os.path.join(ibzkpt_path, "IBZKPT")).readlines() n_ibz_kpts = int(ibz_lines[1].split()[0]) kpath = HighSymmKpath(structure) Kpoints.automatic_linemode(n_kpts, kpath).write_file('KPOINTS') if dim == 2: remove_z_kpoints() linemode_lines = open('KPOINTS').readlines() abs_path = [] i = 4 while i < len(linemode_lines): start_kpt = linemode_lines[i].split() end_kpt = linemode_lines[i + 1].split() increments = [(float(end_kpt[0]) - float(start_kpt[0])) / 20, (float(end_kpt[1]) - float(start_kpt[1])) / 20, (float(end_kpt[2]) - float(start_kpt[2])) / 20] abs_path.append(start_kpt[:3] + ['0', start_kpt[4]]) for n in range(1, 20): abs_path.append([ str(float(start_kpt[0]) + increments[0] * n), str(float(start_kpt[1]) + increments[1] * n), str(float(start_kpt[2]) + increments[2] * n), '0' ]) abs_path.append(end_kpt[:3] + ['0', end_kpt[4]]) i += 3 n_linemode_kpts = len(abs_path) with open('KPOINTS', 'w') as kpts: kpts.write('Automatically generated mesh\n') kpts.write('{}\n'.format(n_ibz_kpts + n_linemode_kpts)) kpts.write('Reciprocal Lattice\n') for line in ibz_lines[3:]: kpts.write(line) for point in abs_path: kpts.write('{}\n'.format(' '.join(point)))
def _path(cls, ndivsm, structure=None, kpath_bounds=None, comment=None): """ Static constructor for path in k-space. Args: structure: :class:`Structure` object. kpath_bounds: List with the reduced coordinates of the k-points defining the path. ndivsm: Number of division for the smallest segment. comment: Comment string. Returns: :class:`KSampling` object. """ if kpath_bounds is None: # Compute the boundaries from the input structure. from pymatgen.symmetry.bandstructure import HighSymmKpath sp = HighSymmKpath(structure) # Flat the array since "path" is a a list of lists! kpath_labels = [] for labels in sp.kpath["path"]: kpath_labels.extend(labels) kpath_bounds = [] for label in kpath_labels: red_coord = sp.kpath["kpoints"][label] #print("label %s, red_coord %s" % (label, red_coord)) kpath_bounds.append(red_coord) return cls(mode=KSamplingModes.path, num_kpts=ndivsm, kpts=kpath_bounds, comment=comment if comment else "K-Path scheme")
def write_vasp_input(structure: IStructure, kpath_division: int, write_dir: str = "."): vasp_input = VaspInput( Incar.from_file("INCAR"), Kpoints.automatic_linemode(kpath_division, HighSymmKpath(structure)), Poscar(structure), Potcar.from_file("POTCAR")) vasp_input.write_input(write_dir)
def band_structure_kpath(struct,dirname,nkpts=30): #struct=Structure.from_file('POSCAR') #ana_struct=SpacegroupAnalyzer(struct) #pst=ana_struct.find_primitive() # First brillouin zone ibz = HighSymmKpath(struct) linemode_kpoints = Kpoints.automatic_linemode(nkpts,ibz) linemode_kpoints.write_file(os.path.join(dirname, "KPOINTS"))
def test_continuous_kpath(self): bs = loadfn(os.path.join(PymatgenTest.TEST_FILES_DIR, "Cu2O_361_bandstructure.json")) cont_bs = loadfn( os.path.join(PymatgenTest.TEST_FILES_DIR, "Cu2O_361_bandstructure_continuous.json") ) alt_bs = HighSymmKpath(bs.structure).get_continuous_path(bs) self.assertEqual(cont_bs.as_dict(), alt_bs.as_dict())
def hse06_bandstructure_kpoints(struct, nkpts=20, kmesh=(11, 11, 11), is_shift=(0, 0, 0), ibzkpt_file=False): ''' Generate HSE06 bandstructure KPOINTS Append high-symmetry path points to the IBZKPT file and set weight of all the high-symmetry path points to zero and then write to "KPOINTS" High-symmetry path kpoints is saved as a backup file named 'KPOINTS_bak' Note: We asssert the IBZKPT file is valid ''' def chunks(lst, n): for i in range(0, len(lst), n): yield lst[i:i + n] hsk = HighSymmKpath(struct) sym_kpts = Kpoints.automatic_linemode(nkpts, hsk) sym_kpts.write_file("KPOINTS_bak") # high-symmetry k-points kpts = sym_kpts.kpts nsegs = sym_kpts.num_kpts # Line mode k-points line_kpts = [] for rng in chunks(kpts, 2): start, end = rng line_kpts.append(np.linspace(start, end, nsegs)) ln_kpts_vec = np.array(line_kpts).reshape((-1, 3)) ln_kpts_wht = np.zeros(ln_kpts_vec.shape[0]) ln_kpts = np.c_[ln_kpts_vec, ln_kpts_wht] if ibzkpt_file: kpoints = open('IBZKPT', "r").readlines() kpoints[1] = "{:8}\n".format( int(kpoints[1].strip()) + ln_kpts.shape[0]) with open("KPOINTS", "w") as K: K.write("".join(kpoints)) np.savetxt(K, ln_kpts, fmt="%20.14f%20.14f%20.14f%14d") else: # generate irreducible k-points in the BZ ana_struct = SpacegroupAnalyzer(struct) ir_kpts_with_wht = ana_struct.get_ir_reciprocal_mesh(mesh=kmesh, is_shift=is_shift) ir_kpts_vec = np.array([x[0] for x in ir_kpts_with_wht]) ir_kpts_wht = np.array([x[1] for x in ir_kpts_with_wht]) ir_kpts = np.c_[ir_kpts_vec, ir_kpts_wht] with open("KPOINTS", "w") as K: K.write("Generated by MAPTOOL\n") K.write("{:8d}\n".format(ln_kpts.shape[0] + ir_kpts.shape[0])) K.write("Reciprocal Lattice\n") np.savetxt(K, ir_kpts, fmt="%20.14f%20.14f%20.14f%14d") np.savetxt(K, ln_kpts, fmt="%20.14f%20.14f%20.14f%14d")
def get_kpoints(strt=''): kpath = HighSymmKpath(strt) kp=kpath.kpath['kpoints'] uniqe_lbl=[] uniqe_k=[] for i, j in kp.items(): uniqe_lbl.append(j) uniqe_k.append(i) return uniqe_lbl,uniqe_k
def get_line_mode_band_structure( self, line_density: int = 50, energy_cutoff: Optional[float] = None, scissor: Optional[float] = None, bandgap: Optional[float] = None, symprec: float = 0.01, ) -> BandStructureSymmLine: """Gets the interpolated band structure along high symmetry directions. Args: line_density: The maximum number of k-points between each two consecutive high-symmetry k-points energy_cutoff: The energy cut-off to determine which bands are included in the interpolation. If the energy of a band falls within the cut-off at any k-point it will be included. For metals the range is defined as the Fermi level ± energy_cutoff. For gapped materials, the energy range is from the VBM - energy_cutoff to the CBM + energy_cutoff. scissor: The amount by which the band gap is scissored. Cannot be used in conjunction with the ``bandgap`` option. Has no effect for metallic systems. bandgap: Automatically adjust the band gap to this value. Cannot be used in conjunction with the ``scissor`` option. Has no effect for metallic systems. symprec: The symmetry tolerance used to determine the space group and high-symmetry path. Returns: The line mode band structure. """ hsk = HighSymmKpath(self._band_structure.structure, symprec=symprec) kpoints, labels = hsk.get_kpoints(line_density=line_density, coords_are_cartesian=True) labels_dict = { label: kpoint for kpoint, label in zip(kpoints, labels) if label != "" } energies = self.get_energies( kpoints, scissor=scissor, bandgap=bandgap, atomic_units=False, energy_cutoff=energy_cutoff, coords_are_cartesian=True, ) return BandStructureSymmLine( kpoints, energies, self._band_structure.structure.lattice, self._band_structure.efermi, labels_dict, coords_are_cartesian=True, )
def test_remove_z_kpoints(self): os.chdir(os.path.join(PACKAGE_PATH, 'stability/tests/BiTeCl')) structure = Structure.from_file('POSCAR') kpath = HighSymmKpath(structure) Kpoints.automatic_linemode(20, kpath).write_file('KPOINTS') remove_z_kpoints() test_lines = open('KPOINTS').readlines() control_lines = open('../BiTeCl_control/KPOINTS').readlines() self.assertEqual(test_lines, control_lines) os.system('rm KPOINTS')
def get_kpoints_wannier(structure, n_kpts=1, dim=2): kpath = HighSymmKpath(structure) os.system('mv KPOINTS K_temp') Kpoints.automatic_linemode(n_kpts, kpath).write_file('KPOINTS') if dim == 2: remove_z_kpoints() path = find_kpath(f='KPOINTS') os.system('rm KPOINTS') os.system('mv K_temp KPOINTS') return path
def get_band_structure(self, kpaths=None, kpoints_lbls_dict=None, density=20): """ Return a BandStructureSymmLine object interpolating bands along a High symmetry path calculated from the structure using HighSymmKpath function. If kpaths and kpoints_lbls_dict are provided, a custom path is interpolated. kpaths: List of lists of following kpoints labels defining the segments of the path. E.g. [['L','M'],['L','X']] kpoints_lbls_dict: Dict where keys are the kpoint labels used in kpaths and values are their fractional coordinates. E.g. {'L':np.array(0.5,0.5,0.5)}, 'M':np.array(0.5,0.,0.5), 'X':np.array(0.5,0.5,0.)} density: Number of points in each segment. """ if isinstance(kpaths, list) and isinstance(kpoints_lbls_dict, dict): kpoints = [] for kpath in kpaths: for i, k in enumerate(kpath[:-1]): sta = kpoints_lbls_dict[kpath[i]] end = kpoints_lbls_dict[kpath[i + 1]] kpoints.append(np.linspace(sta, end, density)) kpoints = np.concatenate(kpoints) else: kpath = HighSymmKpath(self.data.structure) kpoints = np.vstack( kpath.get_kpoints(density, coords_are_cartesian=False)[0]) kpoints_lbls_dict = kpath.kpath["kpoints"] lattvec = self.data.get_lattvec() egrid, vgrid = fite.getBands(kpoints, self.equivalences, lattvec, self.coeffs) # print(egrid.shape) if self.data.is_spin_polarized: h = sum(np.array_split(self.accepted, 2)[0]) egrid = np.array_split(egrid, [h], axis=0) bands_dict = { Spin.up: (egrid[0] / units.eV), Spin.down: (egrid[1] / units.eV), } else: bands_dict = {Spin.up: (egrid / units.eV)} sbs = BandStructureSymmLine( kpoints, bands_dict, self.data.structure.lattice.reciprocal_lattice, self.efermi / units.eV, labels_dict=kpoints_lbls_dict, ) return sbs
def get_BandStructureSymmLine(self): eigenvalues = self.eigenvalues eigendict = {Spin.up: eigenvalues} highsymmkpath = HighSymmKpath( self.get_Structure().get_primitive_structure()).kpath return BandStructureSymmLine(efermi=self.fermi_energy, eigenvals=eigendict, kpoints=self.k_points, structure=self.get_Structure(), labels_dict=highsymmkpath['kpoints'], lattice=self.get_reciprocal_Lattice())
def test_kpath_acentered(self): species = ['K', 'La', 'Ti'] coords = [[.345, 5, .77298], [.1345, 5.1, .77298], [.7, .8, .9]] lattice = Lattice.orthorhombic(2, 9, 1) struct = Structure.from_spacegroup(38, lattice, species, coords) kpath = HighSymmKpath(struct) kpoints = kpath._kpath['kpoints'] labels = list(kpoints.keys()) self.assertEqual( sorted(labels), sorted( ['\\Gamma', 'A', 'A_1', 'R', 'S', 'T', 'X', 'X_1', 'Y', 'Z'])) self.assertEqual(kpoints['\\Gamma'][0], 0.00000000) self.assertAlmostEqual(kpoints['\\Gamma'][1], 0.00000000) self.assertAlmostEqual(kpoints['\\Gamma'][2], 0.00000000) self.assertAlmostEqual(kpoints['A'][0], 0.25308642) self.assertAlmostEqual(kpoints['A'][1], 0.25308642) self.assertAlmostEqual(kpoints['A'][2], 0.50000000) self.assertAlmostEqual(kpoints['A_1'][0], -0.25308642) self.assertAlmostEqual(kpoints['A_1'][1], 0.74691358) self.assertAlmostEqual(kpoints['A_1'][2], 0.50000000) self.assertAlmostEqual(kpoints['R'][0], 0.00000000) self.assertAlmostEqual(kpoints['R'][1], 0.50000000) self.assertAlmostEqual(kpoints['R'][2], 0.50000000) self.assertAlmostEqual(kpoints['S'][0], 0.00000000) self.assertAlmostEqual(kpoints['S'][1], 0.50000000) self.assertAlmostEqual(kpoints['S'][2], 0.00000000) self.assertAlmostEqual(kpoints['T'][0], -0.50000000) self.assertAlmostEqual(kpoints['T'][1], 0.50000000) self.assertAlmostEqual(kpoints['T'][2], 0.50000000) self.assertAlmostEqual(kpoints['X'][0], 0.25308642) self.assertAlmostEqual(kpoints['X'][1], 0.25308642) self.assertAlmostEqual(kpoints['X'][2], 0.00000000) self.assertAlmostEqual(kpoints['X_1'][0], -0.25308642) self.assertAlmostEqual(kpoints['X_1'][1], 0.74691358) self.assertAlmostEqual(kpoints['X_1'][2], 0.00000000) self.assertAlmostEqual(kpoints['Y'][0], -0.50000000) self.assertAlmostEqual(kpoints['Y'][1], 0.50000000) self.assertAlmostEqual(kpoints['Y'][2], 0.00000000) self.assertAlmostEqual(kpoints['Z'][0], 0.00000000) self.assertAlmostEqual(kpoints['Z'][1], 0.00000000) self.assertAlmostEqual(kpoints['Z'][2], 0.50000000)
def write_kpoints_along_hs_path(self, divisions=5): """ writes a KPOINTS file for band structure calculation use """ hs_kpoints_file_name = os.path.join(self._save_to_path, 'KPOINTS') structure = Structure.from_file( os.path.join(self._save_to_path, 'POSCAR')) kpath = HighSymmKpath(structure) kpts = Kpoints.automatic_linemode(divisions=divisions, ibz=kpath) kpts.write_file(hs_kpoints_file_name)
def calculate_standard_path(structure): lattice = mg.Lattice(structure.lattice_vectors) atoms = structure.atoms structure_mg = mg.Structure(lattice, atoms[:, 3], atoms[:, :3]) hs_path = HighSymmKpath(structure_mg, symprec=0.1) if not hs_path.kpath: # fix for bug in pymatgen that for certain structures no path is returned raise Exception('High symmetry path generation failed.') conv_path = convert_hs_path_to_own(hs_path) return conv_path
def write_POSCAR_with_standard_primitive(POSCAR_input="POSCAR", POSCAR_output="POSCAR.lobster", symprec=0.01): """ writes a POSCAR with the standard primitive cell. This is needed to arrive at the correct kpath Args: POSCAR_input (str): filename of input POSCAR POSCAR_output (str): filename of output POSCAR symprec (float): precision to find symmetry """ structure = Structure.from_file(POSCAR_input) kpath = HighSymmKpath(structure, symprec=symprec) new_structure = kpath.prim new_structure.to(fmt="POSCAR", filename=POSCAR_output)
def run_task(self, fw_spec): user_incar_settings= {"NPAR": 2} if self.line: MPNonSCFVaspInputSet.from_previous_vasp_run(os.getcwd(), mode="Line", copy_chgcar=False, user_incar_settings=user_incar_settings, kpoints_line_density=self.kpoints_line_density) kpath = HighSymmKpath(Poscar.from_file("POSCAR").structure) return FWAction(stored_data={"kpath": kpath.kpath, "kpath_name": kpath.name}) else: MPNonSCFVaspInputSet.from_previous_vasp_run(os.getcwd(), mode="Uniform", copy_chgcar=False, user_incar_settings=user_incar_settings, kpoints_density=self.kpoints_density) return FWAction()
def band_structure_kpath(struct, dirname, nkpts=30): """ Generate KPOINTS file for band structure calculation via pymatgen's symmetry analyzing system. """ #struct=Structure.from_file('POSCAR') #ana_struct=SpacegroupAnalyzer(struct) #pst=ana_struct.find_primitive() # First brillouin zone ibz = HighSymmKpath(struct) linemode_kpoints = Kpoints.automatic_linemode(nkpts, ibz) linemode_kpoints.write_file(os.path.join(dirname, "KPOINTS"))
def get_prim(structure: Structure) -> Structure: """ get a primitive structure Args: structure: Structure object Returns: Structure object """ kpath = HighSymmKpath(structure, symprec=0.01) structure = kpath.prim return structure
def get_path_dependent_Kpoints(self, divisions = 10): ''' Gets the primitive unit cell from the CONTCAR file as primitive_structure ''' ''' Gets the high symmetry k path of the primitive unit cell as k_path ''' ''' Returns the pymatgen.io.vasp.inputs.Kpoints object, with symmetric k points specified ''' ''' NOTE: divisions is the number of points sampled along each path between k points, default = 10''' primitive_structure = Structure.from_file(self.cwd + '/CONTCAR', primitive=True) k_path = HighSymmKpath(primitive_structure) kpoints = Kpoints.automatic_linemode(divisions, k_path) return kpoints
def test_kpath_generation(self): triclinic = [1, 2] monoclinic = range(3, 16) orthorhombic = range(16, 75) tetragonal = range(75, 143) rhombohedral = range(143, 168) hexagonal = range(168, 195) cubic = range(195, 231) species = ['K', 'La', 'Ti'] coords = [[.345, 5, .77298], [.1345, 5.1, .77298], [.7, .8, .9]] for i in range(230): sg_num = i + 1 if sg_num in triclinic: lattice = Lattice([[3.0233057319441246, 0, 0], [0, 7.9850357844548681, 0], [0, 0, 8.1136762279561818]]) elif sg_num in monoclinic: lattice = Lattice.monoclinic(2, 9, 1, 99) elif sg_num in orthorhombic: lattice = Lattice.orthorhombic(2, 9, 1) elif sg_num in tetragonal: lattice = Lattice.tetragonal(2, 9) elif sg_num in rhombohedral: lattice = Lattice.hexagonal(2, 95) elif sg_num in hexagonal: lattice = Lattice.hexagonal(2, 9) elif sg_num in cubic: lattice = Lattice.cubic(2) struct = Structure.from_spacegroup(sg_num, lattice, species, coords) kpath = HighSymmKpath( struct ) #Throws error if something doesn't work, causing test to fail. struct_file_path = os.path.join(test_dir_structs, 'ICSD_170.cif') struct = Structure.from_file(struct_file_path) hkp = HighSymmKpath(struct) self.assertEqual(hkp.name, 'MCLC5')
def test_remove_z_kpoints(self): os.chdir(os.path.join(ROOT, 'BiTeCl')) structure = Structure.from_file('POSCAR') kpath = HighSymmKpath(structure) Kpoints.automatic_linemode(20, kpath).write_file('KPOINTS') remove_z_kpoints() test_file = open('KPOINTS') test_lines = test_file.readlines() control_file = open('../BiTeCl_control/KPOINTS') control_lines = control_file.readlines() self.assertEqual(test_lines, control_lines) os.system('rm KPOINTS') test_file.close() control_file.close()
def __init__(self, mp_id, incar_settings: dict): self.mp_id = str(mp_id) self.structure = mpr.get_structure_by_material_id(self.mp_id) self.primitive_structure = self.structure.get_primitive_structure() self.kpath = HighSymmKpath(self.primitive_structure) # self.new_kpoints = self.add_kpoints(self.kpath) self.add_kpoints(self.kpath) # Add inverse kpoints intp kpath.__dict__['kpoints '] self.relaxed_structure = MPRelaxSet(self.structure, user_incar_settings=incar_settings) self.relaxed_structure.potcar_functional = 'PW91' # Vasp functional set as potpaw_GGA
def get_highsympath(filename): ''' Get the high symmetry path of phonon spectrum. ''' struct = pmg.Structure.from_file(filename) finder = SpacegroupAnalyzer(struct) prims = finder.get_primitive_standard_structure() HKpath = HighSymmKpath(struct) Keys = list() Coords = list() for key in HKpath.kpath['kpoints']: Keys.append(key) Coords.append(HKpath.kpath['kpoints'][key]) count = 0 Keylist = list() Coordslist = list() for i in np.arange(len(Keys) - 1): if (count - 1) % 3 == 0: #count-1 can be intergely divided by 3 Keylist.append(Keys[0]) Coordslist.append(Coords[0]) count += 1 Keylist.append(Keys[i + 1]) Coordslist.append(Coords[i + 1]) count += 1 if (count - 1) % 3 == 0: Keylist.append(Keys[0]) Coordslist.append(Coords[0]) print('Please set \"BAND\" parameter of phonopy as this:%s' % os.linesep) for coord in Coordslist: print('%.4f %.4f %.4f ' % (coord[0], coord[1], coord[2]), end='') print('%s' % os.linesep) transmat = np.eye(3) if prims.num_sites != struct.num_sites: S_T = np.transpose(struct.lattice.matrix) P_T = np.transpose(prims.lattice.matrix) transmat = inv(S_T) @ P_T print( 'We notice your structure could have a primitive cell. Please set \"PRIMITIVE_AXIS\" parameter of phonopy as this:%s' % os.linesep) for coord in transmat: print('%.8f %.8f %.8f ' % (coord[0], coord[1], coord[2]), end='') print('%s' % os.linesep) return Keylist, Coordslist, prims, transmat