def test_kpt_bands_to_dict_from_dict(self): file_name = os.path.join(test_dir, 'KPOINTS.band') k = Kpoints.from_file(file_name) d = k.to_dict import json json.dumps(d) #This doesn't work k2 = Kpoints.from_dict(d) self.assertEqual(k.kpts, k2.kpts) self.assertEqual(k.style, k2.style) self.assertEqual(k.kpts_shift, k2.kpts_shift) self.assertEqual(k.num_kpts, k2.num_kpts)
def test_init(self): filepath = os.path.join(test_dir, "KPOINTS.auto") kpoints = Kpoints.from_file(filepath) self.assertEqual(kpoints.kpts, [[10]], "Wrong kpoint lattice read") filepath = os.path.join(test_dir, "KPOINTS.cartesian") kpoints = Kpoints.from_file(filepath) self.assertEqual(kpoints.kpts, [[0.25, 0, 0], [0, 0.25, 0], [0, 0, 0.25]], "Wrong kpoint lattice read") self.assertEqual(kpoints.kpts_shift, [0.5, 0.5, 0.5], "Wrong kpoint shift read") filepath = os.path.join(test_dir, "KPOINTS") kpoints = Kpoints.from_file(filepath) self.assertEqual(kpoints.kpts, [[2, 4, 6]]) filepath = os.path.join(test_dir, "KPOINTS.band") kpoints = Kpoints.from_file(filepath) self.assertIsNotNone(kpoints.labels) self.assertEqual(kpoints.style, "Line_mode") filepath = os.path.join(test_dir, "KPOINTS.explicit") kpoints = Kpoints.from_file(filepath) self.assertIsNotNone(kpoints.kpts_weights) filepath = os.path.join(test_dir, "KPOINTS.explicit_tet") kpoints = Kpoints.from_file(filepath) self.assertEqual(kpoints.tet_connections, [(6, [1, 2, 3, 4])])
def test_init(self): filepath = os.path.join(test_dir, 'KPOINTS.auto') kpoints = Kpoints.from_file(filepath) self.assertEqual(kpoints.kpts, [[10]], "Wrong kpoint lattice read") filepath = os.path.join(test_dir, 'KPOINTS.cartesian') kpoints = Kpoints.from_file(filepath) self.assertEqual(kpoints.kpts, [[0.25, 0, 0], [0, 0.25, 0], [0, 0, 0.25]], "Wrong kpoint lattice read") self.assertEqual(kpoints.kpts_shift, [0.5, 0.5, 0.5], "Wrong kpoint shift read") filepath = os.path.join(test_dir, 'KPOINTS') kpoints = Kpoints.from_file(filepath) self.assertEqual(kpoints.kpts, [[2, 4, 6]]) filepath = os.path.join(test_dir, 'KPOINTS.band') kpoints = Kpoints.from_file(filepath) self.assertIsNotNone(kpoints.labels) self.assertEqual(kpoints.style, "Line_mode") filepath = os.path.join(test_dir, 'KPOINTS.explicit') kpoints = Kpoints.from_file(filepath) self.assertIsNotNone(kpoints.kpts_weights) filepath = os.path.join(test_dir, 'KPOINTS.explicit_tet') kpoints = Kpoints.from_file(filepath) self.assertEqual(kpoints.tet_connections, [(6, [1, 2, 3, 4])])
def setUp(self): filepath = os.path.join(test_dir, "INCAR") incar = Incar.from_file(filepath) filepath = os.path.join(test_dir, "POSCAR") poscar = Poscar.from_file(filepath) if "VASP_PSP_DIR" not in os.environ: test_potcar_dir = os.path.abspath( os.path.join(os.path.dirname(__file__), "..", "..", "..", "..", "test_files") ) os.environ["VASP_PSP_DIR"] = test_potcar_dir filepath = os.path.join(test_dir, "POTCAR") potcar = Potcar.from_file(filepath) filepath = os.path.join(test_dir, "KPOINTS.auto") kpoints = Kpoints.from_file(filepath) self.vinput = VaspInput(incar, kpoints, poscar, potcar)
def setUp(self): filepath = os.path.join(test_dir, 'INCAR') incar = Incar.from_file(filepath) filepath = os.path.join(test_dir, 'POSCAR') poscar = Poscar.from_file(filepath) if "VASP_PSP_DIR" not in os.environ: test_potcar_dir = os.path.abspath( os.path.join(os.path.dirname(__file__), "..", "..", "..", "..", "test_files")) os.environ["VASP_PSP_DIR"] = test_potcar_dir filepath = os.path.join(test_dir, 'POTCAR') potcar = Potcar.from_file(filepath) filepath = os.path.join(test_dir, 'KPOINTS.auto') kpoints = Kpoints.from_file(filepath) self.vinput = VaspInput(incar, kpoints, poscar, potcar)
def test_kpt_bands_to_dict_from_dict(self): file_name = os.path.join(test_dir, "KPOINTS.band") k = Kpoints.from_file(file_name) d = k.to_dict
def test_kpt_bands_to_dict_from_dict(self): file_name = os.path.join(test_dir, 'KPOINTS.band') k = Kpoints.from_file(file_name) d = k.to_dict
def from_previous_vasp_run(previous_vasp_dir, output_dir='.', user_incar_settings=None, make_dir_if_not_present=True): """ Generate a set of Vasp input files for static calculations from a directory of previous Vasp run. Args: previous_vasp_dir: The directory contains the outputs(vasprun.xml and OUTCAR) of previous vasp run. output_dir: The directory to write the VASP input files for the static calculations. Default to write in the current directory. make_dir_if_not_present: Set to True if you want the directory (and the whole path) to be created if it is not present. """ try: vasp_run = Vasprun(os.path.join(previous_vasp_dir, "vasprun.xml"), parse_dos=False, parse_eigen=None) outcar = Outcar(os.path.join(previous_vasp_dir, "OUTCAR")) previous_incar = Incar.from_file(os.path.join(previous_vasp_dir, "INCAR")) kpoints = Kpoints.from_file(os.path.join(previous_vasp_dir, "KPOINTS")) except: traceback.format_exc() raise RuntimeError("Can't get valid results from previous run") structure = MPStaticVaspInputSet.get_structure( vasp_run, outcar) mpsvip = MPStaticVaspInputSet() mpsvip.write_input(structure, output_dir, make_dir_if_not_present) new_incar = Incar.from_file(os.path.join(output_dir, "INCAR")) # Use previous run INCAR and override necessary parameters previous_incar.update({"IBRION": -1, "ISMEAR": -5, "LAECHG": True, "LCHARG": True, "LORBIT": 11, "LVHAR": True, "LWAVE": False, "NSW": 0, "ICHARG": 0}) # Compare ediff between previous and staticinputset values, # choose the tigher ediff previous_incar.update({"EDIFF": min(previous_incar["EDIFF"], new_incar["EDIFF"])}) # add user settings if user_incar_settings: previous_incar.update(user_incar_settings) previous_incar.write_file(os.path.join(output_dir, "INCAR")) # Prefer to use k-point scheme from previous run kpoints_out = Kpoints.from_file(os.path.join(output_dir, "KPOINTS")) if kpoints.style != kpoints_out.style and \ SymmetryFinder(structure, 0.01).get_lattice_type() != \ "hexagonal": k_div = (kp + 1 if kp % 2 == 1 else kp for kp in kpoints_out.kpts[0]) Kpoints.monkhorst_automatic(k_div).write_file( os.path.join(output_dir, "KPOINTS"))