Exemplo n.º 1
0
def get_wann_electron(jid="JVASP-816"):
    """Download electron WTBH if available."""
    w = ""
    ef = ""
    fls = data("raw_files")
    for i in fls["WANN"]:
        if i["name"].split(".zip")[0] == jid:
            r = requests.get(i["download_url"])
            z = zipfile.ZipFile(io.BytesIO(r.content))
            wdat = z.read("wannier90_hr.dat").decode("utf-8")
            js_file = jid + ".json"
            js = z.read(js_file).decode("utf-8")
            fd, path = tempfile.mkstemp()
            with os.fdopen(fd, "w") as tmp:
                tmp.write(wdat)
            w = WannierHam(path)
            fd, path = tempfile.mkstemp()
            with os.fdopen(fd, "w") as tmp:
                tmp.write(js)
            d = loadjson(path)
            ef = d["info_mesh"]["efermi"]
            fd, path = tempfile.mkstemp()
            pos = z.read("POSCAR").decode("utf-8")
            with os.fdopen(fd, "w") as tmp:
                tmp.write(pos)
            atoms = Poscar.from_file(path).atoms
    return w, ef, atoms
Exemplo n.º 2
0
def test_inputs():
    p = Poscar.from_file(pos)
    print(p)
    td = p.to_dict()
    print("td is:", td)
    fd = Poscar.from_dict(td)
    new_file, filename = tempfile.mkstemp()
    p.write_file(filename)
    i = Incar.from_file(inc)
    i.update({"ENCUT": 1000})
    assert (round(p.atoms.density, 2), i.to_dict()["ISIF"]) == (2.25, "3")
    f = open(pos, "r")
    lines = f.read()
    f.close()
    p = Poscar.from_string(lines)
    assert (round(p.atoms.density, 2), i.to_dict()["ISIF"]) == (2.25, "3")
    d = i.to_dict()
    ii = Incar.from_dict(d)
    pot = os.path.join(
        os.path.dirname(__file__), "POT_GGA_PAW_PBE", "Xe", "POTCAR",
    )
    potc = IndividualPotcarData.from_file(pot)
    print(potc)
    os.environ["JARVIS_VASP_PSP_DIR"] = os.path.join(os.path.dirname(__file__))
    new_file, filename = tempfile.mkstemp()
    pot = Potcar(elements=["Xe"])
    td = pot.to_dict()
    fd = Potcar.from_dict(td)
    print(pot)
    pot.write_file(filename)
Exemplo n.º 3
0
def test_input():
    p = Poscar.from_file(pos).atoms
    wtin = WTin(wtin=wtin_file, atoms=p, wannierout=wout).write_wt_in()
    wtc = WTin(wtin=wtin_file, atoms=p, wannierout=wout)
    td = wtc.to_dict()
    fd = WTin.from_dict(td)
    assert (os.path.isfile(wtin_file)) == (True)
    os.remove(wtin_file)
Exemplo n.º 4
0
    def workflow(self, generic_incar=""):
        """
        Use for functional based high-throughput calculations.

        This will converge k-points, cut-offs,
        and then carry several property calculations.

        Args:
            mat : Poscar object
        """
        job = JobFactory(
            use_incar_dict=generic_incar.incar,
            pot_type=generic_incar.pot_type,
            vasp_cmd=self.vasp_cmd,
            copy_files=self.copy_files,
            attempts=self.attempts,
            stderr_file=self.stderr_file,
            output_file=self.output_file,
            poscar=self.mat,
        )
        encut = job.converg_encut(mat=self.mat)
        length = job.converg_kpoint(mat=self.mat)
        energy, contcar_path = job.optimize_geometry(mat=self.mat,
                                                     encut=encut,
                                                     length=length)
        optimized_mat = Poscar.from_file(contcar_path)
        vrun = Vasprun(contcar_path.replace("CONTCAR", "vasprun.xml"))
        chg_path = contcar_path.replace("CONTCAR", "CHGCAR")
        nbands = int(vrun.all_input_parameters["NBANDS"])
        enB, contcB = job.band_structure(
            mat=optimized_mat,
            encut=encut,
            line_density=20,
            nbands=2 * nbands,
            copy_prev_chgcar=chg_path,
        )
        enL, contcL = job.loptics(mat=optimized_mat,
                                  encut=encut,
                                  nbands=2 * nbands,
                                  length=length)
        enM, contcM = job.mbj_loptics(mat=optimized_mat,
                                      encut=encut,
                                      nbands=2 * nbands,
                                      length=length)
        enE, contcE = job.elastic(mat=optimized_mat,
                                  encut=encut,
                                  nbands=2 * nbands,
                                  length=length)
Exemplo n.º 5
0
    def all_optb88vdw_props(self, mat=None):
        """
        Use for OptB88vdW functional based high-throughput calculations.

        This will converge k-points, cut-offs,
        and then carry several property calculations.

        Args:
            mat : Poscar object
        """
        optb88 = GenericIncars().optb88vdw()
        job = JobFactory(use_incar_dict=optb88.incar, pot_type=optb88.pot_type)
        encut = job.converg_encut(mat=mat)
        length = job.converg_kpoint(mat=mat)
        energy, contcar_path = job.optimize_geometry(mat=mat,
                                                     encut=encut,
                                                     length=length)
        optimized_mat = Poscar.from_file(contcar_path)
        vrun = Vasprun(contcar_path.replace("CONTCAR", "vasprun.xml"))
        chg_path = contcar_path.replace("CONTCAR", "CHGCAR")
        nbands = int(vrun.all_input_parameters["NBANDS"])
        enB, contcB = job.band_structure(
            mat=optimized_mat,
            encut=encut,
            line_density=20,
            nbands=2 * nbands,
            copy_prev_chgcar=chg_path,
        )
        enL, contcL = job.loptics(mat=optimized_mat,
                                  encut=encut,
                                  nbands=2 * nbands,
                                  length=length)
        enM, contcM = job.mbj_loptics(mat=optimized_mat,
                                      encut=encut,
                                      nbands=2 * nbands,
                                      length=length)
        enE, contcE = job.elastic(mat=optimized_mat,
                                  encut=encut,
                                  nbands=2 * nbands,
                                  length=length)
Exemplo n.º 6
0
from jarvis.io.wannier.inputs import Wannier90win
from jarvis.core.atoms import Atoms
import os
from jarvis.io.vasp.inputs import Poscar

win = os.path.join(os.path.dirname(__file__), "win.input")

s1 = Poscar.from_file(
    os.path.join(
        os.path.dirname(__file__),
        "..",
        "..",
        "analysis",
        "structure",
        "POSCAR",
    )).atoms
s2 = Poscar.from_file(
    os.path.join(
        os.path.dirname(__file__),
        "..",
        "..",
        "analysis",
        "structure",
        "POSCAR-Cmcm",
    )).atoms
s3 = Poscar.from_file(
    os.path.join(
        os.path.dirname(__file__),
        "..",
        "..",
        "analysis",
Exemplo n.º 7
0
from jarvis.analysis.structure.spacegroup import (
    Spacegroup3D,
    symmetrically_distinct_miller_indices,
    get_wyckoff_position_operators,
)
from jarvis.core.atoms import Atoms
from jarvis.io.vasp.inputs import Poscar
import os
from collections import defaultdict
from jarvis.db.jsonutils import loadjson

s1 = Poscar.from_file(
    os.path.join(os.path.dirname(__file__), "..", "defects",
                 "POSCAR-667.vasp")).atoms
s2 = Poscar.from_file(
    os.path.join(os.path.dirname(__file__), "..", "..", "io", "wannier",
                 "POSCAR")).atoms
s3 = Poscar.from_file(
    os.path.join(os.path.dirname(__file__), "POSCAR-tetragonal")).atoms
s4 = Poscar.from_file(os.path.join(os.path.dirname(__file__),
                                   "POSCAR-Cmcm")).atoms
s5 = Poscar.from_file(os.path.join(os.path.dirname(__file__),
                                   "POSCAR-Aem2")).atoms
s6 = Poscar.from_file(os.path.join(os.path.dirname(__file__),
                                   "POSCAR-C2m")).atoms
s7 = Poscar.from_file(os.path.join(os.path.dirname(__file__),
                                   "POSCAR-Pc")).atoms
s8 = Poscar.from_file(os.path.join(os.path.dirname(__file__),
                                   "POSCAR-P-1")).atoms
s9 = Poscar.from_file(os.path.join(os.path.dirname(__file__),
                                   "POSCAR-P21m")).atoms
Exemplo n.º 8
0
    get_orbitals,
)
import os
import tempfile
from jarvis.core.kpoints import generate_kgrid
from jarvis.io.vasp.inputs import Poscar
import matplotlib.pyplot as plt

plt.switch_backend("agg")

new_file, filename = tempfile.mkstemp()
atoms = Poscar.from_file(
    os.path.join(
        os.path.dirname(__file__),
        "..",
        "..",
        "analysis",
        "structure",
        "POSCAR",
    )).atoms
wann_soc_win_hr = os.path.join(os.path.dirname(__file__), "wannier90_hr.dat")
wann_wout = os.path.join(os.path.dirname(__file__), "wannier90.wout")
soc_scfband_vrun = os.path.join(os.path.dirname(__file__),
                                "vasprun.xml")  # for JVASP-1067


def test_outputs_bi2se3():
    pp = get_projectors_for_formula(formula_dict={"Cr": 1, "I": 3})[0]
    orb = get_orbitals()[0]
    x = get_orbitals(
        projection_info=[["Cr", 4, ["s", "d"]], ["I", 3, ["s", "p"]]],
Exemplo n.º 9
0
def test_2d():
    p = Poscar.from_file(C).atoms
    vacs = Vacancy(atoms=p).generate_defects(enforce_c_size=10.0, extend=1)
    # print (vacs[0]._defect_structure)
    assert (Atoms.from_dict(
        vacs[0].to_dict()["defect_structure"]).num_atoms == 49)
Exemplo n.º 10
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.º 11
0
from jarvis.core.kpoints import (
    Kpoints3D,
    generate_kpath,
    generate_kgrid,
    HighSymmetryKpoint3DFactory,
)
from jarvis.analysis.structure.spacegroup import Spacegroup3D
from jarvis.core.atoms import Atoms
from jarvis.io.vasp.inputs import Poscar
import os
import tempfile

s1 = Poscar.from_file(
    os.path.join(os.path.dirname(__file__), "..", "analysis", "structure",
                 "POSCAR")).atoms
s2 = Poscar.from_file(
    os.path.join(os.path.dirname(__file__), "..", "analysis", "structure",
                 "POSCAR-Aem2")).atoms
s3 = Poscar.from_file(
    os.path.join(os.path.dirname(__file__), "..", "analysis", "structure",
                 "POSCAR-C2m")).atoms
s4 = Poscar.from_file(
    os.path.join(os.path.dirname(__file__), "..", "analysis", "structure",
                 "POSCAR-Cmcm")).atoms
s5 = Poscar.from_file(
    os.path.join(os.path.dirname(__file__), "..", "analysis", "structure",
                 "POSCAR-P-1")).atoms
s6 = Poscar.from_file(
    os.path.join(
        os.path.dirname(__file__),
        "..",
Exemplo n.º 12
0
    def from_poscar(self, filename="POSCAR"):
        """Read POSCAR/CONTCAR file from to make Atoms object."""
        from jarvis.io.vasp.inputs import Poscar

        return Poscar.from_file(filename).atoms
Exemplo n.º 13
0
def test_form_en():
    atoms = Poscar.from_file(p).atoms

    total_energy = -9.974648
    fen = form_enp(atoms=atoms, total_energy=total_energy)
    assert fen == -0.40429