def test_static_constructors(self): kpoints = Kpoints.gamma_automatic([3, 3, 3], [0, 0, 0]) self.assertEqual(kpoints.style, Kpoints.supported_modes.Gamma) self.assertEqual(kpoints.kpts, [[3, 3, 3]]) kpoints = Kpoints.monkhorst_automatic([2, 2, 2], [0, 0, 0]) self.assertEqual(kpoints.style, Kpoints.supported_modes.Monkhorst) self.assertEqual(kpoints.kpts, [[2, 2, 2]]) kpoints = Kpoints.automatic(100) self.assertEqual(kpoints.style, Kpoints.supported_modes.Automatic) self.assertEqual(kpoints.kpts, [[100]]) filepath = self.TEST_FILES_DIR / 'POSCAR' poscar = Poscar.from_file(filepath) kpoints = Kpoints.automatic_density(poscar.structure, 500) self.assertEqual(kpoints.kpts, [[1, 3, 3]]) self.assertEqual(kpoints.style, Kpoints.supported_modes.Gamma) kpoints = Kpoints.automatic_density(poscar.structure, 500, True) self.assertEqual(kpoints.style, Kpoints.supported_modes.Gamma) kpoints = Kpoints.automatic_density_by_vol(poscar.structure, 1000) self.assertEqual(kpoints.kpts, [[6, 10, 13]]) self.assertEqual(kpoints.style, Kpoints.supported_modes.Gamma) s = poscar.structure s.make_supercell(3) kpoints = Kpoints.automatic_density(s, 500) self.assertEqual(kpoints.kpts, [[1, 1, 1]]) self.assertEqual(kpoints.style, Kpoints.supported_modes.Gamma) kpoints = Kpoints.from_string("""k-point mesh 0 G 10 10 10 0.5 0.5 0.5 """) self.assertArrayAlmostEqual(kpoints.kpts_shift, [0.5, 0.5, 0.5])
def test_static_constructors(self): kpoints = Kpoints.gamma_automatic([3, 3, 3], [0, 0, 0]) self.assertEqual(kpoints.style, Kpoints.supported_modes.Gamma) self.assertEqual(kpoints.kpts, [[3, 3, 3]]) kpoints = Kpoints.monkhorst_automatic([2, 2, 2], [0, 0, 0]) self.assertEqual(kpoints.style, Kpoints.supported_modes.Monkhorst) self.assertEqual(kpoints.kpts, [[2, 2, 2]]) kpoints = Kpoints.automatic(100) self.assertEqual(kpoints.style, Kpoints.supported_modes.Automatic) self.assertEqual(kpoints.kpts, [[100]]) filepath = os.path.join(test_dir, 'POSCAR') poscar = Poscar.from_file(filepath) kpoints = Kpoints.automatic_density(poscar.structure, 500) self.assertEqual(kpoints.kpts, [[1, 3, 3]]) self.assertEqual(kpoints.style, Kpoints.supported_modes.Gamma) kpoints = Kpoints.automatic_density(poscar.structure, 500, True) self.assertEqual(kpoints.style, Kpoints.supported_modes.Gamma) kpoints = Kpoints.automatic_density_by_vol(poscar.structure, 1000) self.assertEqual(kpoints.kpts, [[6, 10, 13]]) self.assertEqual(kpoints.style, Kpoints.supported_modes.Gamma) s = poscar.structure s.make_supercell(3) kpoints = Kpoints.automatic_density(s, 500) self.assertEqual(kpoints.kpts, [[1, 1, 1]]) self.assertEqual(kpoints.style, Kpoints.supported_modes.Gamma) kpoints = Kpoints.from_string("""k-point mesh 0 G 10 10 10 0.5 0.5 0.5 """) self.assertArrayAlmostEqual(kpoints.kpts_shift, [0.5, 0.5, 0.5])
def generate_3Dkpoints(struct,dirname): #print(" input the dimensionality and mesh grid density ") tip=''' Accuracy Levels: (1) Low: 0.04~0.03; (2) Medium: 0.03~0.02; (2) Fine: 0.02~0.01; ''' warn_tip(1,tip) print("Input KP-Resolved Value (unit: 2*PI/Ang):") wait_sep() in_str="" while in_str=="": in_str=input().strip() delta_k=float(in_str) (lka,lkb,lkc)=struct.lattice.reciprocal_lattice.abc ka=ceil(lka/(2*np.pi)/delta_k) kb=ceil(lkb/(2*np.pi)/delta_k) ka_dis=np.linspace(-0.5,0.5,ka) kb_dis=np.linspace(-0.5,0.5,kb) kxx,kyy=np.meshgrid(ka_dis,kb_dis) kpts=[[i[0], i[1], 0.0] for i in zip(kxx.flat,kyy.flat)] tmp_K="3D K-meshs by maptool with : "+ str(ka)+"x"+ str(kb)+ "\n 1\nReciprocal\n 0 0 0 1" # initialize a Kpionts instance from template string reciprocal_kpoints=Kpoints.from_string(tmp_K) reciprocal_kpoints.labels=None reciprocal_kpoints.kpts=kpts reciprocal_kpoints.num_kpts=ka*kb reciprocal_kpoints.kpts_weights=[1.0]*(ka*kb) reciprocal_kpoints.write_file(os.path.join(dirname, "KPOINTS"))
def get_kpoints( structure, min_distance=0, min_total_kpoints=1, kppra=None, gap_distance=7, remove_symmetry=None, include_gamma="auto", header="simple", incar=None, ): """ Get kpoints object from JHU servlet, per Wisesa-McGill-Mueller methodology. Refer to http://muellergroup.jhu.edu/K-Points.html and P. Wisesa, K. A. McGill, T. Mueller, Phys. Rev. B 93, 155109 (2016) Args: structure (Structure): structure object min_distance (float): The minimum allowed distance between lattice points on the real-space superlattice min_total_kpoints (int): The minimum allowed number of total k-points in the Brillouin zone. kppra (float): minimum k-points per reciprocal atom. gap_distance (float): auto-detection threshold for non-periodicity (in slabs, nanowires, etc.) remove_symmetry (string): optional flag to control symmetry options, can be none, structural, time_reversal, or all include_gamma (string or bool): whether to include gamma point header (string): "verbose" or "simple", denotes the verbosity of the header incar (Incar): incar object to upload """ config = locals() config.pop("structure", "incar") # Generate PRECALC string precalc = "".join([f"{k}={v}\n" for k, v in config.items()]) precalc = precalc.replace("_", "").upper() precalc = precalc.replace("REMOVESYMMETRY", "REMOVE_SYMMETRY") precalc = precalc.replace("TIMEREVERSAL", "TIME_REVERSAL") url = "http://muellergroup.jhu.edu:8080/PreCalcServer/PreCalcServlet" temp_dir_name = tempfile.mkdtemp() cwd = os.getcwd() os.chdir(temp_dir_name) with open("PRECALC", "w+") as precalc_file, open("POSCAR", "w+") as poscar_file, open( "INCAR", "w+") as incar_file: precalc_file.write(precalc) poscar_file.write(structure.to("POSCAR")) files = [("fileupload", precalc_file), ("fileupload", poscar_file)] if incar: incar_file.write(incar.get_string()) files.append(("fileupload", incar_file)) precalc_file.seek(0) poscar_file.seek(0) incar_file.seek(0) r = requests.post(url, files=files) kpoints = Kpoints.from_string(r.text) os.chdir(cwd) shutil.rmtree(temp_dir_name) return kpoints
def get_kpoints(structure, min_distance=0, min_total_kpoints=1, kppra=None, gap_distance=7, remove_symmetry=None, include_gamma="auto", header="simple", incar=None): """ Get kpoints object from JHU servlet, per Wisesa-McGill-Mueller methodology. Refer to http://muellergroup.jhu.edu/K-Points.html and P. Wisesa, K. A. McGill, T. Mueller, Phys. Rev. B 93, 155109 (2016) Args: structure (Structure): structure object min_distance (float): The minimum allowed distance between lattice points on the real-space superlattice min_total_kpoints (int): The minimum allowed number of total k-points in the Brillouin zone. kppra (float): minimum k-points per reciprocal atom. gap_distance (float): auto-detection threshold for non-periodicity (in slabs, nanowires, etc.) remove_symmetry (string): optional flag to control symmetry options, can be none, structural, time_reversal, or all include_gamma (string or bool): whether to include gamma point header (string): "verbose" or "simple", denotes the verbosity of the header incar (Incar): incar object to upload """ config = locals() config.pop("structure", "incar") # Generate PRECALC string precalc = ''.join(["{}={}\n".format(k, v) for k, v in config.items()]) precalc = precalc.replace('_', '').upper() precalc = precalc.replace('REMOVESYMMETRY', 'REMOVE_SYMMETRY') precalc = precalc.replace('TIMEREVERSAL', 'TIME_REVERSAL') url = "http://muellergroup.jhu.edu:8080/PreCalcServer/PreCalcServlet" temp_dir_name = tempfile.mkdtemp() cwd = os.getcwd() os.chdir(temp_dir_name) precalc_file = open("PRECALC", 'w+') poscar_file = open("POSCAR", 'w+') incar_file = open("INCAR", 'w+') precalc_file.write(precalc) poscar_file.write(structure.to("POSCAR")) files = [("fileupload", precalc_file), ("fileupload", poscar_file)] if incar: incar_file.write(incar.get_string()) files.append(("fileupload", incar_file)) precalc_file.seek(0) poscar_file.seek(0) incar_file.seek(0) r = requests.post(url, files=files) precalc_file.close() poscar_file.close() incar_file.close() kpoints = Kpoints.from_string(r.text) os.chdir(cwd) shutil.rmtree(temp_dir_name) return kpoints