Exemplo n.º 1
0
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)
Exemplo n.º 2
0
class VaspInputTest(PymatgenTest):
    def setUp(self):
        filepath = self.TEST_FILES_DIR / "INCAR"
        incar = Incar.from_file(filepath)
        filepath = self.TEST_FILES_DIR / "POSCAR"
        poscar = Poscar.from_file(filepath, check_for_POTCAR=False)
        if "PMG_VASP_PSP_DIR" not in os.environ:
            os.environ["PMG_VASP_PSP_DIR"] = str(self.TEST_FILES_DIR)
        filepath = self.TEST_FILES_DIR / "POTCAR"
        potcar = Potcar.from_file(filepath)
        filepath = self.TEST_FILES_DIR / "KPOINTS.auto"
        kpoints = Kpoints.from_file(filepath)
        self.vinput = VaspInput(incar, kpoints, poscar, potcar)

    def test_to_from_dict(self):
        d = self.vinput.as_dict()
        vinput = VaspInput.from_dict(d)
        comp = vinput["POSCAR"].structure.composition
        self.assertEqual(comp, Composition("Fe4P4O16"))

    def test_write(self):
        tmp_dir = Path("VaspInput.testing")
        self.vinput.write_input(tmp_dir)

        filepath = tmp_dir / "INCAR"
        incar = Incar.from_file(filepath)
        self.assertEqual(incar["NSW"], 99)

        for name in ("INCAR", "POSCAR", "POTCAR", "KPOINTS"):
            (tmp_dir / name).unlink()

        tmp_dir.rmdir()

    def test_run_vasp(self):
        # To add some test.
        with ScratchDir(".") as d:
            self.vinput.run_vasp(d, vasp_cmd=["cat", "INCAR"])
            with open(os.path.join(d, "vasp.out"), "r") as f:
                output = f.read()
                self.assertEqual(output.split("\n")[0], "ALGO = Damped")

    def test_from_directory(self):
        vi = VaspInput.from_directory(
            self.TEST_FILES_DIR, optional_files={"CONTCAR.Li2O": Poscar}
        )
        self.assertEqual(vi["INCAR"]["ALGO"], "Damped")
        self.assertIn("CONTCAR.Li2O", vi)
        d = vi.as_dict()
        vinput = VaspInput.from_dict(d)
        self.assertIn("CONTCAR.Li2O", vinput)
Exemplo n.º 3
0
class VaspInputTest(PymatgenTest):
    def setUp(self):
        filepath = self.TEST_FILES_DIR / 'INCAR'
        incar = Incar.from_file(filepath)
        filepath = self.TEST_FILES_DIR / 'POSCAR'
        poscar = Poscar.from_file(filepath,check_for_POTCAR=False)
        if "PMG_VASP_PSP_DIR" not in os.environ:
            os.environ["PMG_VASP_PSP_DIR"] = str(self.TEST_FILES_DIR)
        filepath = self.TEST_FILES_DIR / 'POTCAR'
        potcar = Potcar.from_file(filepath)
        filepath = self.TEST_FILES_DIR / 'KPOINTS.auto'
        kpoints = Kpoints.from_file(filepath)
        self.vinput = VaspInput(incar, kpoints, poscar, potcar)

    def test_to_from_dict(self):
        d = self.vinput.as_dict()
        vinput = VaspInput.from_dict(d)
        comp = vinput["POSCAR"].structure.composition
        self.assertEqual(comp, Composition("Fe4P4O16"))

    def test_write(self):
        tmp_dir = Path("VaspInput.testing")
        self.vinput.write_input(tmp_dir)

        filepath = tmp_dir / "INCAR"
        incar = Incar.from_file(filepath)
        self.assertEqual(incar["NSW"], 99)

        for name in ("INCAR", "POSCAR", "POTCAR", "KPOINTS"):
            (tmp_dir / name).unlink()

        tmp_dir.rmdir()

    def test_run_vasp(self):
        # To add some test.
        with ScratchDir(".") as d:
            self.vinput.run_vasp(d, vasp_cmd=["cat", "INCAR"])
            with open(os.path.join(d, "vasp.out"), "r") as f:
                output = f.read()
                self.assertEqual(output.split("\n")[0], "ALGO = Damped")

    def test_from_directory(self):
        vi = VaspInput.from_directory(self.TEST_FILES_DIR,
                                      optional_files={"CONTCAR.Li2O": Poscar})
        self.assertEqual(vi["INCAR"]["ALGO"], "Damped")
        self.assertIn("CONTCAR.Li2O", vi)
        d = vi.as_dict()
        vinput = VaspInput.from_dict(d)
        self.assertIn("CONTCAR.Li2O", vinput)
Exemplo n.º 4
0
class VaspInputTest(unittest.TestCase):

    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_to_from_dict(self):
        d = self.vinput.as_dict()
        vinput = VaspInput.from_dict(d)
        comp = vinput["POSCAR"].structure.composition
        self.assertEqual(comp, Composition("Fe4P4O16"))

    def test_write(self):
        tmp_dir = "VaspInput.testing"
        self.vinput.write_input(tmp_dir)

        filepath = os.path.join(tmp_dir, "INCAR")
        incar = Incar.from_file(filepath)
        self.assertEqual(incar["NSW"], 99)

        for name in ("INCAR", "POSCAR", "POTCAR", "KPOINTS"):
            os.remove(os.path.join(tmp_dir, name))

        os.rmdir(tmp_dir)

    def test_from_directory(self):
        vi = VaspInput.from_directory(test_dir,
                                      optional_files={"CONTCAR.Li2O": Poscar})
        self.assertEqual(vi["INCAR"]["ALGO"], "Damped")
        self.assertIn("CONTCAR.Li2O", vi)
        d = vi.as_dict()
        vinput = VaspInput.from_dict(d)
        self.assertIn("CONTCAR.Li2O", vinput)
Exemplo n.º 5
0
class VaspInputTest(unittest.TestCase):

    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_to_from_dict(self):
        d = self.vinput.as_dict()
        vinput = VaspInput.from_dict(d)
        comp = vinput["POSCAR"].structure.composition
        self.assertEqual(comp, Composition("Fe4P4O16"))

    def test_write(self):
        tmp_dir = "VaspInput.testing"
        self.vinput.write_input(tmp_dir)

        filepath = os.path.join(tmp_dir, "INCAR")
        incar = Incar.from_file(filepath)
        self.assertEqual(incar["NSW"], 99)

        for name in ("INCAR", "POSCAR", "POTCAR", "KPOINTS"):
            os.remove(os.path.join(tmp_dir, name))

        os.rmdir(tmp_dir)

    def test_from_directory(self):
        vi = VaspInput.from_directory(test_dir,
                                      optional_files={"CONTCAR.Li2O": Poscar})
        self.assertEqual(vi["INCAR"]["ALGO"], "Damped")
        self.assertIn("CONTCAR.Li2O", vi)
        d = vi.as_dict()
        vinput = VaspInput.from_dict(d)
        self.assertIn("CONTCAR.Li2O", vinput)
Exemplo n.º 6
0
    # POSCAR
    poscar = Poscar(struct)
    poscar_dict = poscar.as_dict()

    # KPOINTS
    k = 7
    kpoints = Kpoints.gamma_automatic(kpts=(k, k, k), shift=(0.0, 0.0, 0.0))

    # get POTCAR with right order from POSCAR
    # check for prevoius element - if it's the same don't write it twice
    prevoius_el = None
    # initializing potcar_symbols
    potcar_symbols = []
    #getting sites list
    sites = poscar_dict['structure']['sites']
    # getting label for element on site
    for site_index in range(0, len(sites)):
        el = sites[site_index]['label']
        # write only if it is different from the prevoious one
        if prevoius_el != el:
            potcar_symbols.append(potcar_choices[el])
            prevoius_el = el
    # set Potcar object
    potcar = Potcar(symbols=potcar_symbols,
                    functional='PBE',
                    sym_potcar_map=None)

    VASP_input = VaspInput(incar, kpoints, poscar, potcar)
    VASP_input.write_input(file_dir, make_dir_if_not_present=True)