Beispiel #1
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)
Beispiel #2
0
    def band_structure(
        self,
        mat=None,
        encut=None,
        line_density=20,
        nbands=None,
        copy_prev_chgcar=None,
    ):
        """
        Use in band-structure calculations.

        Args:
            mat :  Poscar object

            encut :  Plane-wave cut-off, 1.3 times will be used

            nbands : number of bands, increased to threee times

            line_density :  number of k-points between two
                            high-symmetry k-points

            copy_prev_chgcar :  path of CHGCAR file for Non-SCF step
        """
        # incar = self.use_incar_dict
        incar_dict = self.use_incar_dict.to_dict().copy()
        if copy_prev_chgcar is not None:
            shutil.copy2(copy_prev_chgcar, ".")

        if nbands is not None:
            nbands = int(nbands * 1.3)
            incar_dict.update({"NBANDS": nbands})
        data = {
            "ENCUT": encut,
            "NEDOS": 5000,
            "NELM": 500,
            "LORBIT": 11,
            "ISPIN": 2,
            "IBRION": 1,
            "LCHARG": ".FALSE.",
        }
        incar_dict.update(data)
        incar = Incar.from_dict(incar_dict)
        kpoints = Kpoints().kpath(mat.atoms, line_density=line_density)

        en, contcar = VaspJob(
            poscar=mat,
            incar=incar,
            vasp_cmd=self.vasp_cmd,
            output_file=self.output_file,
            stderr_file=self.stderr_file,
            copy_files=self.copy_files,
            attempts=self.attempts,
            pot_type=self.pot_type,
            kpoints=kpoints,
            jobname=str("MAIN-BAND-") + str(mat.comment.split()[0]),
        ).runjob()

        return en, contcar
Beispiel #3
0
    def mbj_loptics(self, mat=None, encut=None, nbands=None, length=20):
        """
        Use for TBmBJ meta-GGA calculation.

        Args:
            mat :  Poscar object

            encut :  Plane-wave cut-off, 1.3 times will be used

            nbands : number of bands, increased to threee times

            length :  K-points in length unit
        """
        # incar = self.use_incar_dict

        incar_dict = self.use_incar_dict.to_dict().copy()
        if nbands is not None:
            nbands = int(nbands * 3)
            incar_dict.update({"NBANDS": nbands})
        data = {
            "ENCUT": encut,
            "NEDOS": 5000,
            "NELM": 500,
            "LORBIT": 11,
            "ISPIN": 2,
            "METAGGA": "MBJ",
            "SIGMA": 0.1,
            "ISYM": 0,
            "LOPTICS": ".TRUE.",
            "IBRION": 1,
            "LCHARG": ".FALSE.",
        }
        incar_dict.update(data)
        incar = Incar.from_dict(incar_dict)
        kpoints = Kpoints().automatic_length_mesh(
            lattice_mat=mat.atoms.lattice_mat,
            length=length)  # Auto_Kpoints(mat=mat, length=length)

        en, contcar = VaspJob(
            poscar=mat,
            incar=incar,
            vasp_cmd=self.vasp_cmd,
            output_file=self.output_file,
            stderr_file=self.stderr_file,
            copy_files=self.copy_files,
            attempts=self.attempts,
            pot_type=self.pot_type,
            kpoints=kpoints,
            jobname=str("MAIN-MBJ-") + str(mat.comment.split()[0]),
        ).runjob()

        return en, contcar
Beispiel #4
0
 def from_dict(self, info={}):
     """Load the class from a dictionary."""
     return VaspJob(
         poscar=Poscar.from_dict(info["poscar"]),
         kpoints=Kpoints.from_dict(info["kpoints"]),
         incar=Incar.from_dict(info["incar"]),
         potcar=Potcar.from_dict(info["potcar"]),
         vasp_cmd=info["vasp_cmd"],
         copy_files=info["copy_files"],
         attempts=info["attempts"],
         output_file=info["output_file"],
         stderr_file=info["stderr_file"],
         jobname=info["jobname"],
     )
Beispiel #5
0
 def lda(self):
     """Select LDA functional."""
     data = dict(
         PREC="Accurate",
         ISMEAR=0,
         IBRION=2,
         EDIFF="1E-7",
         NSW=1,
         NELM=400,
         ISIF=2,
         LCHARG=".FALSE.",
         LWAVE=".FALSE.",
     )
     inc = Incar(data)
     return GenericIncars(name="lda", incar=inc, pot_type="POT_LDA_PAW")
Beispiel #6
0
 def pbe(self):
     """Select GGA-PBE functional."""
     data = dict(
         PREC="Accurate",
         ISMEAR=0,
         IBRION=2,
         GGA="PE",
         EDIFF="1E-7",
         NSW=1,
         NELM=400,
         ISIF=2,
         LCHARG=".FALSE.",
         LWAVE=".FALSE.",
     )
     inc = Incar(data)
     return GenericIncars(name="pbe", incar=inc, pot_type="POT_GGA_PAW_PBE")
Beispiel #7
0
    def optimize_geometry(self, mat=None, encut=None, length=None):
        """
        Use in optimizing lattice-parameter and internal psotions.

        Args:
            mat :  Poscar object

            encut :  Plane-wave cut-off

            length :  K-points in length unit
        """
        incar_dict = self.use_incar_dict.to_dict().copy()
        data = {
            "ENCUT": encut,
            "EDIFFG": -1e-3,
            "ISIF": 3,
            "NEDOS": 5000,
            "NSW": 500,
            "NELM": 500,
            "LORBIT": 11,
            "LVTOT": ".TRUE.",
            "LVHAR": ".TRUE.",
            "ISPIN": 2,
            "LCHARG": ".TRUE.",
        }

        incar_dict.update(data)
        incar = Incar.from_dict(incar_dict)
        kpoints = Kpoints().automatic_length_mesh(
            lattice_mat=mat.atoms.lattice_mat,
            length=length)  # Auto_Kpoints(mat=mat, length=length)
        en, contcar = VaspJob(
            poscar=mat,
            incar=incar,
            vasp_cmd=self.vasp_cmd,
            output_file=self.output_file,
            stderr_file=self.stderr_file,
            copy_files=self.copy_files,
            attempts=self.attempts,
            pot_type=self.pot_type,
            kpoints=kpoints,
            jobname=str("MAIN-RELAX-") + str(mat.comment),
        ).runjob()
        return en, contcar
Beispiel #8
0
 def optb88vdw(self):
     """Select OptB88vdW functional."""
     data = dict(
         PREC="Accurate",
         ISMEAR=0,
         IBRION=2,
         GGA="BO",
         PARAM1=0.1833333333,
         PARAM2=0.2200000000,
         LUSE_VDW=".TRUE.",
         AGGAC=0.0000,
         EDIFF="1E-7",
         NSW=1,
         NELM=400,
         ISIF=2,
         LCHARG=".FALSE.",
         LWAVE=".FALSE.",
     )
     inc = Incar(data)
     return GenericIncars(name="optb88vdw",
                          incar=inc,
                          pot_type="POT_GGA_PAW_PBE")
Beispiel #9
0
    def converg_kpoint(self, length=0, mat=None, encut=500, tol=0.001):
        """
        Provide function to converg K-points.

        Args:
            lenght: K-point line density

            mat: Poscar object with structure information

        Returns:
               length1: K-point line density
        """
        pot_type = self.pot_type
        en1 = -10000
        convg_kp1 = False
        convg_kp2 = False
        length1 = length
        kp_list = []
        while not convg_kp2 and not convg_kp1:
            # while convg_kp1 !=True and  convg_kp2 !=True:
            incar_dict = self.use_incar_dict.to_dict().copy()
            incar_dict.update({"ENCUT": encut})
            incar = Incar.from_dict(incar_dict)
            # incar_dict["ENCUT"]= encut
            length1 = length1 + 5
            print("Incrementing length", length1)
            kpoints = Kpoints().automatic_length_mesh(
                lattice_mat=mat.atoms.lattice_mat,
                length=length)  # Auto_Kpoints(mat=mat, length=length)
            mesh = kpoints.kpts[0]
            if mesh not in kp_list:
                kp_list.append(mesh)
                en2, contc = VaspJob(
                    poscar=mat,
                    incar=incar,
                    pot_type=pot_type,
                    vasp_cmd=self.vasp_cmd,
                    output_file=self.output_file,
                    stderr_file=self.stderr_file,
                    copy_files=self.copy_files,
                    attempts=self.attempts,
                    kpoints=kpoints,
                    jobname=str("KPOINTS") + str(mat.comment) + str("-") +
                    str(length1),
                ).runjob()

                while abs(en2 - en1) > tol:
                    en1 = en2
                    print("Incrementing length", length1)
                    while mesh in kp_list:
                        length1 = length1 + 5
                        # Assuming you are not super unlucky
                        # kpoints = Auto_Kpoints(mat=mat, length=length1)
                        kpoints = Kpoints().automatic_length_mesh(
                            lattice_mat=mat.atoms.lattice_mat, length=length1
                        )  # Auto_Kpoints(mat=mat, length=length)
                        mesh = kpoints.kpts[0]

                    kpoints = Kpoints().automatic_length_mesh(
                        lattice_mat=mat.atoms.lattice_mat,
                        length=length1)  # Auto_Kpoints(mat=mat, length=length)
                    mesh = kpoints.kpts[0]
                    if mesh not in kp_list:
                        kp_list.append(mesh)
                        en2, contc = VaspJob(
                            poscar=mat,
                            incar=incar,
                            pot_type=pot_type,
                            kpoints=kpoints,
                            vasp_cmd=self.vasp_cmd,
                            output_file=self.output_file,
                            stderr_file=self.stderr_file,
                            copy_files=self.copy_files,
                            attempts=self.attempts,
                            jobname=str("KPOINTS") + str(mat.comment) +
                            str("-") + str(length1),
                        ).runjob()
                    else:
                        length1 = length1 + 5
                        # Assuming you are not super unlucky
                        # kpoints = Auto_Kpoints(mat=mat, length=length1)
                        kpoints = Kpoints().automatic_length_mesh(
                            lattice_mat=mat.atoms.lattice_mat, length=length1
                        )  # Auto_Kpoints(mat=mat, length=length)
                        mesh = kpoints.kpts[0]
                        kp_list.append(mesh)
                        en2, contc = VaspJob(
                            mat=mat,
                            incar=incar,
                            kpoints=kpoints,
                            vasp_cmd=self.vasp_cmd,
                            output_file=self.output_file,
                            stderr_file=self.stderr_file,
                            copy_files=self.copy_files,
                            attempts=self.attempts,
                            jobname=str("KPOINTS") + str(mat.comment) +
                            str("-") + str(length1),
                        ).runjob()
                convg_kp1 = True

                # Some extra points to check
                print("Some extra points to check for KPOINTS")
                length3 = length1 + 5
                # kpoints = Auto_Kpoints(mat=mat, length=length3)
                kpoints = Kpoints().automatic_length_mesh(
                    lattice_mat=mat.atoms.lattice_mat,
                    length=length3)  # Auto_Kpoints(mat=mat, length=length)
                mesh = kpoints.kpts[0]
                kp_list.append(mesh)
                en3, contc = VaspJob(
                    poscar=mat,
                    pot_type=pot_type,
                    incar=incar,
                    kpoints=kpoints,
                    vasp_cmd=self.vasp_cmd,
                    output_file=self.output_file,
                    stderr_file=self.stderr_file,
                    copy_files=self.copy_files,
                    attempts=self.attempts,
                    jobname=str("KPOINTS") + str(mat.comment) + str("-") +
                    str(length3),
                ).runjob()

                length4 = length3 + 5
                # kpoints = Auto_Kpoints(mat=mat, length=length4)
                kpoints = Kpoints().automatic_length_mesh(
                    lattice_mat=mat.atoms.lattice_mat,
                    length=length4)  # Auto_Kpoints(mat=mat, length=length)
                mesh = kpoints.kpts[0]
                kp_list.append(mesh)
                en4, contc = VaspJob(
                    poscar=mat,
                    pot_type=pot_type,
                    incar=incar,
                    kpoints=kpoints,
                    vasp_cmd=self.vasp_cmd,
                    output_file=self.output_file,
                    stderr_file=self.stderr_file,
                    copy_files=self.copy_files,
                    attempts=self.attempts,
                    jobname=str("KPOINTS") + str(mat.comment) + str("-") +
                    str(length4),
                ).runjob()

                length5 = length4 + 5
                # kpoints = Auto_Kpoints(mat=mat, length=length5)
                kpoints = Kpoints().automatic_length_mesh(
                    lattice_mat=mat.atoms.lattice_mat,
                    length=length5)  # Auto_Kpoints(mat=mat, length=length)
                mesh = kpoints.kpts[0]
                kp_list.append(mesh)
                en5, contc = VaspJob(
                    poscar=mat,
                    incar=incar,
                    pot_type=pot_type,
                    kpoints=kpoints,
                    vasp_cmd=self.vasp_cmd,
                    output_file=self.output_file,
                    stderr_file=self.stderr_file,
                    copy_files=self.copy_files,
                    attempts=self.attempts,
                    jobname=str("KPOINTS") + str(mat.comment) + str("-") +
                    str(length5),
                ).runjob()

                length6 = length5 + 5
                # kpoints = Auto_Kpoints(mat=mat, length=length6)
                kpoints = Kpoints().automatic_length_mesh(
                    lattice_mat=mat.atoms.lattice_mat,
                    length=length6)  # Auto_Kpoints(mat=mat, length=length)
                mesh = kpoints.kpts[0]
                kp_list.append(mesh)
                en6, contc = VaspJob(
                    poscar=mat,
                    vasp_cmd=self.vasp_cmd,
                    output_file=self.output_file,
                    stderr_file=self.stderr_file,
                    copy_files=self.copy_files,
                    attempts=self.attempts,
                    incar=incar,
                    pot_type=pot_type,
                    kpoints=kpoints,
                    jobname=str("KPOINTS") + str(mat.comment) + str("-") +
                    str(length6),
                ).runjob()
                length7 = length6 + 5
                # kpoints = Auto_Kpoints(mat=mat, length=length7)
                kpoints = Kpoints().automatic_length_mesh(
                    lattice_mat=mat.atoms.lattice_mat,
                    length=length7)  # Auto_Kpoints(mat=mat, length=length)
                mesh = kpoints.kpts[0]
                kp_list.append(mesh)
                en7, contc = VaspJob(
                    poscar=mat,
                    vasp_cmd=self.vasp_cmd,
                    output_file=self.output_file,
                    stderr_file=self.stderr_file,
                    copy_files=self.copy_files,
                    attempts=self.attempts,
                    incar=incar,
                    pot_type=pot_type,
                    kpoints=kpoints,
                    jobname=str("KPOINTS") + str(mat.comment) + str("-") +
                    str(length7),
                ).runjob()

                if (abs(en3 - en2) > tol or abs(en4 - en2) > tol
                        or abs(en5 - en2) > tol or abs(en6 - en2) > tol
                        or abs(en7 - en2) > tol):
                    fkp = open("EXTRA_KPOINTS", "w")
                    line = str("Extra KPOINTS needed ") + str(length1) + "\n"
                    fkp.write(line)
                    line = (str("en2 length1 ") + str(" ") + str(en2) +
                            str(" ") + str(length1) + "\n")
                    fkp.write(line)
                    line = (str("en3 length3 ") + str(" ") + str(en3) +
                            str(" ") + str(length3) + "\n")
                    fkp.write(line)
                    line = (str("en4 length4 ") + str(" ") + str(en4) +
                            str(" ") + str(length4) + "\n")
                    fkp.write(line)
                    line = (str("en5 length5 ") + str(" ") + str(en5) +
                            str(" ") + str(length5) + "\n")
                    fkp.write(line)
                    fkp.close()
                    en1 = en3
                    length1 = length3
                else:
                    print(
                        "KPOINTS convergence achieved for ",
                        mat.comment,
                        length1,
                    )
                    convg_kp2 = True

        return length1
Beispiel #10
0
    def converg_encut(self,
                      encut=500,
                      mat=None,
                      starting_length=10,
                      tol=0.001):
        """
        Provide function to converg plane-wave cut-off.

        Args:
            encut: intial cutoff

            mat: Poscar object

        Returns:
               encut: converged cut-off
        """
        pot_type = self.pot_type
        en1 = -10000
        encut1 = encut
        convg_encut1 = False
        convg_encut2 = False

        incar_dict = self.use_incar_dict.to_dict().copy()
        while not convg_encut2 and not convg_encut1:
            # while convg_encut1 !=True and  convg_encut2 !=True:
            # tol = 0.001  # change 0.001
            encut_list = []
            encut_list.append(encut)
            length = starting_length
            encut1 = encut + 50
            # incar_dict = self.use_incar_dict
            # print ('incar_dict',incar_dict)
            incar_dict.update({"ENCUT": encut})
            # print (use_incar_dict)
            incar = Incar.from_dict(incar_dict)
            kpoints = Kpoints().automatic_length_mesh(
                lattice_mat=mat.atoms.lattice_mat,
                length=length)  # Auto_Kpoints(mat=mat, length=length)
            print(
                "running smart_converge for",
                str(mat.comment) + str("-") + str("ENCUT") + str("-") +
                str(encut),
            )
            en2, contc = VaspJob(
                poscar=mat,
                incar=incar,
                pot_type=pot_type,
                vasp_cmd=self.vasp_cmd,
                output_file=self.output_file,
                stderr_file=self.stderr_file,
                copy_files=self.copy_files,
                attempts=self.attempts,
                kpoints=kpoints,
                jobname=str("ENCUT") + str(mat.comment) + str("-") +
                str(encut),
            ).runjob()
            while abs(en2 - en1) > tol:
                en1 = en2
                encut1 = encut + 50
                encut_list.append(encut)
                print("Incrementing encut", encut)
                incar_dict.update({"ENCUT": encut1})
                incar = Incar.from_dict(incar_dict)
                print(
                    "running smart_converge for",
                    str(mat.comment) + str("-") + str("ENCUT") + str("-") +
                    str(encut),
                )
                en2, contc = VaspJob(
                    poscar=mat,
                    vasp_cmd=self.vasp_cmd,
                    output_file=self.output_file,
                    stderr_file=self.stderr_file,
                    copy_files=self.copy_files,
                    attempts=self.attempts,
                    incar=incar,
                    pot_type=pot_type,
                    kpoints=kpoints,
                    jobname=str("ENCUT") + str(mat.comment) + str("-") +
                    str(encut),
                ).runjob()
            convg_encut1 = True

            # Some extra points to check
            print("Some extra points to check for ENCUT")

            encut2 = encut1 + 50
            incar_dict["ENCUT"] = encut2
            incar = Incar.from_dict(incar_dict)
            en3, contc = VaspJob(
                vasp_cmd=self.vasp_cmd,
                output_file=self.output_file,
                stderr_file=self.stderr_file,
                copy_files=self.copy_files,
                attempts=self.attempts,
                poscar=mat,
                incar=incar,
                pot_type=pot_type,
                kpoints=kpoints,
                jobname=str("ENCUT") + str(mat.comment) + str("-") +
                str(encut2),
            ).runjob()

            encut3 = encut2 + 50
            incar_dict["ENCUT"] = encut3
            incar = Incar.from_dict(incar_dict)
            en4, contc = VaspJob(
                poscar=mat,
                vasp_cmd=self.vasp_cmd,
                output_file=self.output_file,
                stderr_file=self.stderr_file,
                copy_files=self.copy_files,
                attempts=self.attempts,
                incar=incar,
                pot_type=pot_type,
                kpoints=kpoints,
                jobname=str("ENCUT") + str(mat.comment) + str("-") +
                str(encut3),
            ).runjob()

            encut4 = encut3 + 50
            incar_dict["ENCUT"] = encut4
            incar = Incar.from_dict(incar_dict)
            en5, contc = VaspJob(
                poscar=mat,
                incar=incar,
                pot_type=pot_type,
                kpoints=kpoints,
                vasp_cmd=self.vasp_cmd,
                output_file=self.output_file,
                stderr_file=self.stderr_file,
                copy_files=self.copy_files,
                attempts=self.attempts,
                jobname=str("ENCUT") + str(mat.comment) + str("-") +
                str(encut4),
            ).runjob()

            encut5 = encut4 + 50
            incar_dict["ENCUT"] = encut5
            incar = Incar.from_dict(incar_dict)
            en6, contc = VaspJob(
                poscar=mat,
                vasp_cmd=self.vasp_cmd,
                output_file=self.output_file,
                stderr_file=self.stderr_file,
                copy_files=self.copy_files,
                attempts=self.attempts,
                pot_type=pot_type,
                incar=incar,
                kpoints=kpoints,
                jobname=str("ENCUT") + str(mat.comment) + str("-") +
                str(encut5),
            ).runjob()

            encut6 = encut5 + 50
            incar_dict["ENCUT"] = encut6
            incar = Incar.from_dict(incar_dict)
            en7, contc = VaspJob(
                poscar=mat,
                vasp_cmd=self.vasp_cmd,
                output_file=self.output_file,
                stderr_file=self.stderr_file,
                copy_files=self.copy_files,
                attempts=self.attempts,
                pot_type=pot_type,
                incar=incar,
                kpoints=kpoints,
                jobname=str("ENCUT") + str(mat.comment) + str("-") +
                str(encut6),
            ).runjob()

            if (abs(en3 - en2) > tol or abs(en4 - en2) > tol
                    or abs(en5 - en2) > tol or abs(en6 - en2) > tol
                    or abs(en7 - en2) > tol):

                en1 = en3
                encut = encut1
                fen = open("EXTRA_ENCUT", "w")
                line = str("Extra ENCUT needed ") + str(encut) + "\n"
                fen.write(line)
                fen.close()
            else:
                print("ENCUT convergence achieved for ", mat.comment, encut)
                convg_encut2 = True
        return encut
Beispiel #11
0
    def elastic(
        self,
        mat=None,
        encut=None,
        nbands=None,
        potim=0.015,
        npar=None,
        length=20,
    ):
        """
        Use for elastic property calculations using IBRION = 6.

        Enforces conventional standard structure.

        Args:
            mat :  Poscar object

            encut :  Plane-wave cut-off, 1.3 times will be used

            nbands : number of bands, generally high-value recommended

            npar : NPAR tag, see VASP manual, set it as number of cores

            length :  K-points in length unit
        """
        incar_dict = self.use_incar_dict.to_dict().copy()
        cvn = Spacegroup3D(mat.atoms).conventional_standard_structure
        comment = mat.comment
        p = Poscar(cvn, comment=comment)

        if npar is not None:
            incar_dict.update({"NPAR": npar})

        if nbands is not None:
            nbands = int(nbands * 3)
            incar_dict.update({"NBANDS": nbands})
        data = {
            "ENCUT": 1.3 * float(encut),
            "NEDOS": 5000,
            "ISIF": 3,
            "POTIM": potim,
            "ISPIN": 2,
            "IBRION": 6,
            "LCHARG": ".FALSE.",
        }
        incar_dict.update(data)
        incar = Incar.from_dict(incar_dict)
        kpoints = Kpoints().automatic_length_mesh(
            lattice_mat=p.atoms.lattice_mat,
            length=length)  # Auto_Kpoints(mat=mat, length=length)

        en, contcar = VaspJob(
            poscar=p,
            incar=incar,
            pot_type=self.pot_type,
            kpoints=kpoints,
            vasp_cmd=self.vasp_cmd,
            output_file=self.output_file,
            stderr_file=self.stderr_file,
            copy_files=self.copy_files,
            attempts=self.attempts,
            jobname=str("MAIN-ELASTIC-") + str(p.comment.split()[0]),
        ).runjob()

        return en, contcar