Exemplo n.º 1
0
def test_out():
    assert (round(out.elastic_props()["KV"], 2)) == (87.27)
    out_efg = Outcar(
        os.path.join(os.path.dirname(__file__), "OUTCAR.EFG-JVASP-12148"))
    assert out_efg.efg_tensor_diag[0][0] == -4.766
    assert out_efg.quad_mom[0][0] == 0.023
    assert out_efg.converged == True
    td = out_efg.to_dict()
    fd = Outcar.from_dict(td)
Exemplo n.º 2
0
def test_dfpt():
    vrun = Vasprun(
        os.path.join(os.path.dirname(__file__), "vasprun.xml.JVASP-39"))
    out = Outcar(os.path.join(os.path.dirname(__file__), "OUTCAR.JVASP-39"))
    bec = round(vrun.dfpt_data["born_charges"][0][0][0], 2)
    eig = round(out.phonon_eigenvalues[2], 2)
    ionic_pz, total_pz = out.piezoelectric_tensor
    pz = total_pz[2][0]
    assert (bec, eig, pz) == (2.52, 19.58, -0.26756)
    # print (vrun.all_stresses)
    assert vrun.all_stresses[0][0][0] == -14.79381147
    assert vrun.all_forces[0][0][0] == 0
    assert vrun.all_energies[0] == -24.86360178
    assert vrun.all_structures[0].volume == 42.60334334259966
Exemplo n.º 3
0
def test_ir():
    vrun = Vasprun(
        os.path.join(os.path.dirname(__file__), "vasprun.xml.JVASP-39"))
    out = Outcar(os.path.join(os.path.dirname(__file__), "OUTCAR.JVASP-39"))
    phonon_eigenvectors = vrun.dfpt_data["phonon_eigenvectors"]
    vrun_eigs = vrun.dfpt_data["phonon_eigenvalues"]
    phonon_eigenvalues = out.phonon_eigenvalues
    masses = vrun.dfpt_data["masses"]
    born_charges = vrun.dfpt_data["born_charges"]
    x, y = ir_intensity(
        phonon_eigenvectors=phonon_eigenvectors,
        phonon_eigenvalues=phonon_eigenvalues,
        masses=masses,
        born_charges=born_charges,
    )
    assert round(y[2], 2) == 0
Exemplo n.º 4
0
def test_out():
    assert (round(out.elastic_props()["KV"], 2)) == (87.27)
    out_efg = Outcar(
        os.path.join(os.path.dirname(__file__), "OUTCAR.EFG-JVASP-12148"))
    out_efg_raw = Outcar(
        os.path.join(os.path.dirname(__file__),
                     "OUTCAR.EFG-JVASP-12148")).efg_raw_tensor
    assert out_efg.efg_tensor_diag()[0][0] == -4.766
    assert out_efg.efg_tensor_diag(std_conv=False)[0][0] == -4.766
    assert out_efg.quad_mom[0][0] == 0.023
    assert out_efg.converged == True
    td = out_efg.to_dict()
    fd = Outcar.from_dict(td)
    print("out_efg_raw", (out_efg_raw))
    print()
    print("out_efg_raw", np.linalg.eig(out_efg_raw)[0])
    print()
    print("out_efg", out_efg.efg_tensor_diag())
    print()
Exemplo n.º 5
0
from jarvis.io.vasp.outputs import Vasprun, Outcar
from jarvis.analysis.phonon.ir import ir_intensity, ir_intensity_phonopy
import os
import shutil

out = Outcar(
    os.path.join(os.path.dirname(__file__), "..", "..", "io", "vasp",
                 "OUTCAR.JVASP-39"))
vrun_file = os.path.join(
    os.path.dirname(__file__),
    "..",
    "..",
    "io",
    "vasp",
    "vasprun.xml.JVASP-39",
)
dirc = os.path.join(
    os.path.dirname(__file__),
    "..",
    "..",
    "io",
    "vasp",
)

vrun = Vasprun(vrun_file)


def test_ir():
    phonon_eigenvectors = vrun.dfpt_data["phonon_eigenvectors"]
    vrun_eigs = vrun.dfpt_data["phonon_eigenvalues"]
    phonon_eigenvalues = out.phonon_eigenvalues
Exemplo n.º 6
0
        "examples",
        "vasp",
        "SiOptb88",
        "SiOptb88",
        "MAIN-RELAX-bulk@mp_149",
        "OSZICAR",
    )
)
out = Outcar(
    filename=os.path.join(
        os.path.dirname(__file__),
        "..",
        "..",
        "..",
        "..",
        "examples",
        "vasp",
        "SiOptb88",
        "SiOptb88",
        "MAIN-ELASTIC-bulk@mp_149",
        "OUTCAR",
    )
)
wder = Waveder(
    os.path.join(
        os.path.dirname(__file__),
        "..",
        "..",
        "..",
        "..",
        "examples",
Exemplo n.º 7
0
    def runjob(self):
        """Provide main function for running a generic VASP calculation."""
        # poscar=self.poscar
        # incar=self.incar
        # kpoints=self.kpoints
        # copy_files=self.copy_files

        # cwd = str(os.getcwd())
        if self.jobname == "":
            jobname = str(self.poscar.comment)
        # job_dir = str(self.jobname)
        run_file = (str(os.getcwd()) + str("/") + str(self.jobname) +
                    str(".json"))
        run_dir = str(os.getcwd()) + str("/") + str(self.jobname)
        if self.poscar.comment.startswith("Surf"):
            [a, b, c] = self.kpoints.kpts[0]
            # self.kpoints.kpts = [[a, b, 1]]
            self.kpoints = Kpoints3D(kpoints=[[a, b, 1]])
            try:
                pol = self.poscar.atoms.check_polar
                if pol:
                    COM = self.poscar.atoms.get_center_of_mass()
                    print("COM=", COM)
                    print("Found polar surface,setting dipole corrections")
                    self.incar.update({
                        "LDIPOL":
                        ".TRUE.",
                        "IDIPOL":
                        3,
                        "ISYM":
                        0,
                        "DIPOL":
                        str(COM[0]) + str(" ") + str(COM[2]) + str(" ") +
                        str(COM[2]),
                    })
                    print(
                        "Polar surface encountered in run_job",
                        self.poscar.comment,
                    )
            except Exception:
                pass
        wait = False
        json_file = str(self.jobname) + str(".json")
        print(
            "json should be here=",
            str(os.getcwd()) + str("/") + str(json_file),
        )
        print("json should be=", json_file, run_file, os.getcwd())
        if os.path.exists(str(os.getcwd()) + str("/") + str(json_file)):
            try:
                data_cal = loadjson(
                    str(os.getcwd()) + str("/") + str(json_file))
                tmp_outcar = (str(os.getcwd()) + str("/") +
                              str(json_file.split(".json")[0]) +
                              str("/OUTCAR"))
                print("outcar is", tmp_outcar)
                wait = Outcar(tmp_outcar).converged  # True
                print("outcar status", wait)
                if wait:
                    f_energy = data_cal[0]["final_energy"]
                    contcar = (str(os.getcwd()) + str("/") +
                               str(json_file.split(".json")[0]) +
                               str("/CONTCAR"))
                    return f_energy, contcar
            except Exception:
                pass
        attempt = 0
        while not wait:
            attempt = attempt + 1
            if attempt == self.attempts:
                wait = True
            # print("Setting up POTCAR")
            # if self.potcar is None:
            #  new_symb = list(set(self.poscar.atoms.elements))
            #  self.potcar = Potcar(elements=new_symb, pot_type=self.pot_type)
            if not os.path.exists(run_dir):
                print("Starting new job")
                os.makedirs(run_dir)
                os.chdir(run_dir)
                self.poscar.write_file("POSCAR")
            else:
                os.chdir(run_dir)
                if os.path.isfile("OUTCAR"):
                    try:
                        wait = Outcar(
                            "OUTCAR"
                        ).converged  # Vasprun("vasprun.xml").converged
                        # wait=Vasprun("vasprun.xml").converged
                    except Exception:
                        pass
                    try:
                        self.potcar.write_file("POTCAR")
                        print("FOUND OLD CONTCAR in", os.getcwd())
                        copy_cmd = str("cp CONTCAR POSCAR")
                        self.poscar.write_file("POSCAR")
                        # pos = Poscar.from_file("CONTCAR")
                        print("copy_cmd=", copy_cmd)
                        if ("ELAST" not in jobname
                                and "LEPSILON" not in jobname):
                            # Because in ELASTIC calculations
                            # structures are deformed
                            os.system(copy_cmd)
                        # time.sleep(3)
                    except Exception:
                        pass

            self.incar.write_file("INCAR")
            self.potcar.write_file("POTCAR")
            self.kpoints.write_file("KPOINTS")
            for i in self.copy_files:
                print("copying", i)
                shutil.copy2(i, "./")

            self.run()  # .wait()
            print("Queue 1")
            if os.path.isfile("OUTCAR"):
                try:
                    wait = Outcar(
                        "OUTCAR").converged  # Vasprun("vasprun.xml").converged
                except Exception:
                    pass
            print("End of the first loop", os.getcwd(), wait)

        f_energy = "na"
        # enp = "na"
        contcar = str(os.getcwd()) + str("/") + str("CONTCAR")
        final_str = Poscar.from_file(contcar).atoms
        vrun = Vasprun("vasprun.xml")
        f_energy = float(vrun.final_energy)
        # enp = float(f_energy) / float(final_str.num_atoms)
        # natoms = final_str.num_atoms
        os.chdir("../")
        if wait:
            data_cal = []
            data_cal.append({
                "jobname": self.jobname,
                "poscar": self.poscar.atoms.to_dict(),
                "incar": self.incar.to_dict(),
                "kpoints": self.kpoints.to_dict(),
                "final_energy": (f_energy),
                "contcar": final_str.to_dict(),
            })
            json_file = str(self.jobname) + str(".json")
            f_json = open(json_file, "w")
            f_json.write(json.dumps(data_cal))
            f_json.close()
            print("Wrote json file", f_energy)
            return f_energy, contcar
Exemplo n.º 8
0
def test_vasp_et():
    out = Outcar(outcar)
    et = ElasticTensor(out.elastic_props()["cij"])
    print(et.to_dict())