Exemple #1
0
def generate_old_polarization_folders(structures):
    """
    Generate the polarization calculations (old format) from the completed scf calculation
    """
    for name in structures:
        for i in range(3):
            # compute the Berry phase along the x-i, y- and z-directions (IGPAR = 1,2,3)
            # Note: calculations usualy are very sensetive to the choice of "NPPSTR" parameter. You might consider to reduce it.
            MPStaticSet.from_prev_calc(
                name,
                user_incar_settings={
                    "LBERRY": True,
                    "IGPAR": i + 1,
                    "ICHARG": 2,
                    "NPAR": 2,
                    "ALGO": "Fast",
                    "NPPSTR": 6,
                    "LAECHG": False,
                    "LVHAR": False,
                    "ISIF": 2
                },
                user_kpoints_settings={
                    "reciprocal_density": 500
                }).write_input(os.path.join(name, 'Berry_' + str(i + 1)))
            shutil.copy(os.path.join(name, 'CHGCAR'),
                        os.path.join(name, 'Berry_' + str(i + 1)))
Exemple #2
0
    def run_task(self, fw_spec):
        lepsilon = self.get("lepsilon")

        default_reciprocal_density = 200 if lepsilon else 100  # more k-points for dielectric calc.
        other_params = self.get("other_params", {})
        user_incar_settings = other_params.get("user_incar_settings", {})

        # for lepsilon runs, set EDIFF to 1E-5 unless user says otherwise
        if lepsilon and "EDIFF" not in user_incar_settings and \
                        "EDIFF_PER_ATOM" not in user_incar_settings:
            if "user_incar_settings" not in other_params:
                other_params["user_incar_settings"] = {}
            other_params["user_incar_settings"]["EDIFF"] = 1E-5

        vis = MPStaticSet.from_prev_calc(
            prev_calc_dir=self.get("prev_calc_dir", "."),
            reciprocal_density=self.get("reciprocal_density",
                                        default_reciprocal_density),
            small_gap_multiply=self.get("small_gap_multiply", None),
            standardize=self.get("standardize", False),
            sym_prec=self.get("sym_prec", 0.1),
            international_monoclinic=self.get("international_monoclinic",
                                              True),
            lepsilon=lepsilon,
            **other_params)
        vis.write_input(".")
Exemple #3
0
    def Static (self):
        from pymatgen.io.vasp.sets import MPStaticSet
        import shutil
        import os
        filePath=self.dire
        for dirpath, dirnames, filenames in os.walk(filePath):
            # print(dirpath)
            for name in dirnames:
                if 'static' not in str(name):
                    path = os.path.join(filePath, name)
                    custom_settings = {"NELM": 60,'NPAR':4} # user custom incar settings
                    static = MPStaticSet.from_prev_calc(path, standardize=True,
                                                        user_incar_settings=custom_settings)
                    
                    diree = os.chdir(self.dire)

                    static.write_input("static_"+str(name))


                    pat = os.path.join(self.dire, "static_"+str(name))
                    os.chdir(pat)
                    #定义一个更改当前目录的变量
                    dire2 = './vaspstd_sub' 
                    #确立脚本名称
                    shutil.copy(r"C:\Users\41958\.spyder-py3\vaspstd_sub", dire2 )
    def run_task(self, fw_spec):
        lepsilon = self.get("lepsilon")

        default_reciprocal_density = 100 if not lepsilon else 200
        other_params = self.get("other_params", {})

        # for lepsilon runs, set EDIFF to 1E-5 unless user says otherwise
        user_incar_settings = self.get("other_params", {}).get("user_incar_settings", {})

        if lepsilon and "EDIFF" not in user_incar_settings and "EDIFF_PER_ATOM" not in user_incar_settings:
            if "user_incar_settings" not in other_params:
                other_params["user_incar_settings"] = {}
            other_params["user_incar_settings"]["EDIFF"] = 1e-5

        vis = MPStaticSet.from_prev_calc(
            prev_calc_dir=self["prev_calc_dir"],
            reciprocal_density=self.get("reciprocal_density", default_reciprocal_density),
            small_gap_multiply=self.get("small_gap_multiply", None),
            standardize=self.get("standardize", False),
            sym_prec=self.get("sym_prec", 0.1),
            international_monoclinic=self.get("international_monoclinic", True),
            lepsilon=lepsilon,
            **other_params
        )
        vis.write_input(".")
Exemple #5
0
def generate_new_polarization_folders(structures):
    """
    Generate the polarization calculations (new format) from the completed scf calculation
    """
    for name in structures:
        MPStaticSet.from_prev_calc(name,
                                   user_incar_settings={
                                       "LCALCPOL": True,
                                       "LAECHG": False,
                                       "LVHAR": False,
                                       "ISIF": 2
                                   },
                                   user_kpoints_settings={
                                       "reciprocal_density": 500
                                   }).write_input(
                                       os.path.join(name, 'Berry_new'))
        shutil.copy(os.path.join(name, 'CHGCAR'),
                    os.path.join(name, 'Berry_new'))
Exemple #6
0
 def run_task(self, fw_spec):
     material_id = self["material_id"]
     dest_root = fw_spec["_fw_en"]["run_dest_root"]
     dest = "{}/{}/bs/{}/relax".format(dest_root, os.environ["USER"],
                                       material_id)
     user_incar_settings = fw_spec.get("user_incar_settings", {})
     vasp_input_set = MPStaticSet.from_prev_calc(
         prev_calc_dir=dest,
         standardize=1e-3,
         user_incar_settings=user_incar_settings)
     dec = MontyDecoder()
     vis = dec.process_decoded(vasp_input_set.as_dict())
     vis.write_input(".")
Exemple #7
0
 def run_task(self, fw_spec):
     self.user_incar_settings.update({"NPAR": 2})
     # Get kpoint density per vol
     vol = Poscar.from_file("POSCAR").structure.volume
     kppra_vol = self.kpoints_density / vol
     new_set = MPStaticSet.from_prev_calc(
         os.getcwd(),
         user_incar_settings=self.user_incar_settings, 
         reciprocal_density=kppra_vol)
     new_set.write_input('.')
     structure = new_set.structure
     sga = SpacegroupAnalyzer(structure, 0.1)
     return FWAction(stored_data={
         'refined_structure': sga.get_refined_structure().as_dict(),
         'conventional_standard_structure': sga.get_conventional_standard_structure().as_dict(),
         'symmetry_dataset': sga.get_symmetry_dataset(),
         'symmetry_operations': [x.as_dict() for x in sga.get_symmetry_operations()]})
Exemple #8
0
def get_jobs(args):
    # Returns a generator of jobs. Allows of "infinite" jobs.
    vasp_command = args.command.split()
    # save initial INCAR for rampU runs
    n_ramp_u = args.jobs.count('rampU')
    ramps = 0
    if n_ramp_u:
        incar = Incar.from_file('INCAR')
        ldauu = incar['LDAUU']
        ldauj = incar['LDAUJ']

    njobs = len(args.jobs)
    post_settings = [
    ]  # append to this list to have settings applied on next job
    for i, job in enumerate(args.jobs):
        final = False if i != njobs - 1 else True
        if any(c.isdigit() for c in job):
            suffix = "." + job
        else:
            suffix = ".{}{}".format(job, i + 1)
        settings = post_settings
        post_settings = []
        backup = True if i == 0 else False
        copy_magmom = False
        vinput = VaspInput.from_directory(".")
        if i > 0:
            settings.append({
                "file": "CONTCAR",
                "action": {
                    "_file_copy": {
                        "dest": "POSCAR"
                    }
                }
            })

        job_type = job.lower()
        auto_npar = True

        if args.no_auto_npar:
            auto_npar = False

        if job_type.startswith("static_derived"):
            from pymatgen.io.vasp.sets import MPStaticSet
            vis = MPStaticSet.from_prev_calc(".",
                                             user_incar_settings={
                                                 "LWAVE": True,
                                                 "EDIFF": 1e-6
                                             },
                                             ediff_per_atom=False)
            settings.extend([{
                "dict": "INCAR",
                "action": {
                    "_set": dict(vis.incar)
                }
            }, {
                'dict': 'KPOINTS',
                'action': {
                    '_set': vis.kpoints.as_dict()
                }
            }])

        if job_type.startswith("static_dielectric_derived"):
            from pymatgen.io.vasp.sets import MPStaticSet, MPStaticDielectricDFPTVaspInputSet

            # vis = MPStaticSet.from_prev_calc(
            #     ".", user_incar_settings={"EDIFF": 1e-6, "IBRION": 8,
            #                               "LEPSILON": True, 'LREAL':False,
            #                               "LPEAD": True, "ISMEAR": 0,
            #                               "SIGMA": 0.01},
            #     ediff_per_atom=False)
            vis = MPStaticDielectricDFPTVaspInputSet()
            incar = vis.get_incar(vinput["POSCAR"].structure)
            unset = {}
            for k in [
                    "NPAR", "KPOINT_BSE", "LAECHG", "LCHARG", "LVHAR", "NSW"
            ]:
                incar.pop(k, None)
                if k in vinput["INCAR"]:
                    unset[k] = 1
            kpoints = vis.get_kpoints(vinput["POSCAR"].structure)
            settings.extend([{
                "dict": "INCAR",
                "action": {
                    "_set": dict(incar),
                    "_unset": unset
                }
            }, {
                'dict': 'KPOINTS',
                'action': {
                    '_set': kpoints.as_dict()
                }
            }])
            auto_npar = False
        elif job_type.startswith("static"):
            m = [i * args.static_kpoint for i in vinput["KPOINTS"].kpts[0]]
            settings.extend([{
                "dict": "INCAR",
                "action": {
                    "_set": {
                        "NSW": 0
                    }
                }
            }, {
                'dict': 'KPOINTS',
                'action': {
                    '_set': {
                        'kpoints': [m]
                    }
                }
            }])

        elif job_type.startswith("nonscf_derived"):
            from pymatgen.io.vasp.sets import MPNonSCFSet
            vis = MPNonSCFSet.from_prev_calc(
                ".", copy_chgcar=False, user_incar_settings={"LWAVE": True})
            settings.extend([{
                "dict": "INCAR",
                "action": {
                    "_set": dict(vis.incar)
                }
            }, {
                'dict': 'KPOINTS',
                'action': {
                    '_set': vis.kpoints.as_dict()
                }
            }])

        elif job_type.startswith("optics_derived"):
            from pymatgen.io.vasp.sets import MPNonSCFSet
            vis = MPNonSCFSet.from_prev_calc(".",
                                             optics=True,
                                             copy_chgcar=False,
                                             nedos=2001,
                                             mode="uniform",
                                             nbands_factor=5,
                                             user_incar_settings={
                                                 "LWAVE": True,
                                                 "ALGO": "Exact",
                                                 "SIGMA": 0.01,
                                                 "EDIFF": 1e-6
                                             },
                                             ediff_per_atom=False)
            settings.extend([{
                "dict": "INCAR",
                "action": {
                    "_set": dict(vis.incar)
                }
            }, {
                'dict': 'KPOINTS',
                'action': {
                    '_set': vis.kpoints.as_dict()
                }
            }])

        elif job_type.startswith("rampu"):
            f = ramps / (n_ramp_u - 1)
            settings.append({
                "dict": "INCAR",
                "action": {
                    "_set": {
                        "LDAUJ": [j * f for j in ldauj],
                        "LDAUU": [u * f for u in ldauu]
                    }
                }
            })
            copy_magmom = True
            ramps += 1
        elif job_type.startswith("quick_relax") or job_type.startswith(\
                "quickrelax"):
            kpoints = vinput["KPOINTS"]
            incar = vinput["INCAR"]
            structure = vinput["POSCAR"].structure
            if "ISMEAR" in incar:
                post_settings.append({
                    "dict": "INCAR",
                    "action": {
                        "_set": {
                            "ISMEAR": incar["ISMEAR"]
                        }
                    }
                })
            else:
                post_settings.append({
                    "dict": "INCAR",
                    "action": {
                        "_unset": {
                            "ISMEAR": 1
                        }
                    }
                })
            post_settings.append({
                "dict": "KPOINTS",
                "action": {
                    "_set": kpoints.as_dict()
                }
            })
            # lattice vectors with length < 9 will get >1 KPOINT
            low_kpoints = Kpoints.gamma_automatic(
                [max(int(18 / l), 1) for l in structure.lattice.abc])
            settings.extend([{
                "dict": "INCAR",
                "action": {
                    "_set": {
                        "ISMEAR": 0
                    }
                }
            }, {
                'dict': 'KPOINTS',
                'action': {
                    '_set': low_kpoints.as_dict()
                }
            }])

            # let vasp determine encut (will be lower than
            # needed for compatibility with other runs)
            if "ENCUT" in incar:
                post_settings.append({
                    "dict": "INCAR",
                    "action": {
                        "_set": {
                            "ENCUT": incar["ENCUT"]
                        }
                    }
                })
                settings.append({
                    "dict": "INCAR",
                    "action": {
                        "_unset": {
                            "ENCUT": 1
                        }
                    }
                })

        elif job_type.startswith("relax"):
            pass
        elif job_type.startswith("full_relax"):
            for j in VaspJob.full_opt_run(vasp_command):
                yield j
        else:
            print("Unsupported job type: {}".format(job))
            sys.exit(-1)

        if not job_type.startswith("full_relax"):
            yield VaspJob(vasp_command,
                          final=final,
                          suffix=suffix,
                          backup=backup,
                          settings_override=settings,
                          copy_magmom=copy_magmom,
                          auto_npar=auto_npar)
Exemple #9
0
def get_jobs(args):
    # Returns a generator of jobs. Allows of "infinite" jobs.
    vasp_command = args.command.split()
    # save initial INCAR for rampU runs
    n_ramp_u = args.jobs.count('rampU')
    ramps = 0
    if n_ramp_u:
        incar = Incar.from_file('INCAR')
        ldauu = incar['LDAUU']
        ldauj = incar['LDAUJ']

    njobs = len(args.jobs)
    post_settings = []  # append to this list to have settings applied on next job
    for i, job in enumerate(args.jobs):
        final = False if i != njobs - 1 else True
        if any(c.isdigit() for c in job):
            suffix = "." + job
        else:
            suffix = ".{}{}".format(job, i + 1)
        settings = post_settings
        post_settings = []
        backup = True if i == 0 else False
        copy_magmom = False
        vinput = VaspInput.from_directory(".")
        if i > 0:
            settings.append(
                {"file": "CONTCAR",
                 "action": {"_file_copy": {"dest": "POSCAR"}}})

        job_type = job.lower()
        auto_npar = True

        if args.no_auto_npar:
            auto_npar = False

        if job_type.startswith("static_derived"):
            from pymatgen.io.vasp.sets import MPStaticSet
            vis = MPStaticSet.from_prev_calc(
                ".", user_incar_settings={"LWAVE": True, "EDIFF": 1e-6},
                ediff_per_atom=False)
            settings.extend([
                {"dict"  : "INCAR",
                 "action": {"_set": dict(vis.incar)}},
                {'dict': 'KPOINTS',
                 'action': {'_set': vis.kpoints.as_dict()}}])

        if job_type.startswith("static_dielectric_derived"):
            from pymatgen.io.vasp.sets import MPStaticSet, MPStaticDielectricDFPTVaspInputSet

            # vis = MPStaticSet.from_prev_calc(
            #     ".", user_incar_settings={"EDIFF": 1e-6, "IBRION": 8,
            #                               "LEPSILON": True, 'LREAL':False,
            #                               "LPEAD": True, "ISMEAR": 0,
            #                               "SIGMA": 0.01},
            #     ediff_per_atom=False)
            vis = MPStaticDielectricDFPTVaspInputSet()
            incar = vis.get_incar(vinput["POSCAR"].structure)
            unset = {}
            for k in ["NPAR", "KPOINT_BSE", "LAECHG", "LCHARG", "LVHAR",
                      "NSW"]:
                incar.pop(k, None)
                if k in vinput["INCAR"]:
                    unset[k] = 1
            kpoints = vis.get_kpoints(vinput["POSCAR"].structure)
            settings.extend([
                {"dict": "INCAR",
                 "action": {"_set": dict(incar),
                            "_unset": unset}},
                {'dict': 'KPOINTS',
                 'action': {'_set': kpoints.as_dict()}}])
            auto_npar = False
        elif job_type.startswith("static"):
            m = [i * args.static_kpoint for i in vinput["KPOINTS"].kpts[0]]
            settings.extend([
                {"dict": "INCAR",
                 "action": {"_set": {"NSW": 0}}},
                {'dict': 'KPOINTS',
                 'action': {'_set': {'kpoints': [m]}}}])

        elif job_type.startswith("nonscf_derived"):
            from pymatgen.io.vasp.sets import MPNonSCFSet
            vis = MPNonSCFSet.from_prev_calc(".", copy_chgcar=False,
                                             user_incar_settings={"LWAVE": True})
            settings.extend([
                {"dict": "INCAR",
                 "action": {"_set": dict(vis.incar)}},
                {'dict': 'KPOINTS',
                 'action': {'_set': vis.kpoints.as_dict()}}])

        elif job_type.startswith("optics_derived"):
            from pymatgen.io.vasp.sets import MPNonSCFSet
            vis = MPNonSCFSet.from_prev_calc(
                ".", optics=True, copy_chgcar=False,
                nedos=2001, mode="uniform", nbands_factor=5,
                user_incar_settings={"LWAVE": True, "ALGO": "Exact", "SIGMA": 0.01, "EDIFF": 1e-6},
                ediff_per_atom=False)
            settings.extend([
                {"dict": "INCAR",
                 "action": {"_set": dict(vis.incar)}},
                {'dict': 'KPOINTS',
                 'action': {'_set': vis.kpoints.as_dict()}}])

        elif job_type.startswith("rampu"):
            f = ramps / (n_ramp_u - 1)
            settings.append(
                {"dict": "INCAR",
                 "action": {"_set": {"LDAUJ": [j * f for j in ldauj],
                                     "LDAUU": [u * f for u in ldauu]}}})
            copy_magmom = True
            ramps += 1
        elif job_type.startswith("quick_relax") or job_type.startswith(\
                "quickrelax"):
            kpoints = vinput["KPOINTS"]
            incar = vinput["INCAR"]
            structure = vinput["POSCAR"].structure
            if "ISMEAR" in incar:
                post_settings.append(
                    {"dict": "INCAR",
                     "action": {"_set": {"ISMEAR": incar["ISMEAR"]}}})
            else:
                post_settings.append(
                    {"dict": "INCAR",
                     "action": {"_unset": {"ISMEAR": 1}}})
            post_settings.append({"dict": "KPOINTS",
                                  "action": {"_set": kpoints.as_dict()}})
            # lattice vectors with length < 9 will get >1 KPOINT
            low_kpoints = Kpoints.gamma_automatic(
                [max(int(18/l), 1) for l in structure.lattice.abc])
            settings.extend([
                {"dict": "INCAR",
                 "action": {"_set": {"ISMEAR": 0}}},
                {'dict': 'KPOINTS',
                 'action': {'_set': low_kpoints.as_dict()}}])

            # let vasp determine encut (will be lower than
            # needed for compatibility with other runs)
            if "ENCUT" in incar:
                post_settings.append(
                    {"dict": "INCAR",
                     "action": {"_set": {"ENCUT": incar["ENCUT"]}}})
                settings.append(
                    {"dict": "INCAR",
                     "action": {"_unset": {"ENCUT": 1}}})

        elif job_type.startswith("relax"):
            pass
        elif job_type.startswith("full_relax"):
            for j in VaspJob.full_opt_run(
                    vasp_command):
                yield j
        else:
            print("Unsupported job type: {}".format(job))
            sys.exit(-1)

        if not job_type.startswith("full_relax"):
            yield VaspJob(vasp_command, final=final, suffix=suffix,
                          backup=backup, settings_override=settings,
                          copy_magmom=copy_magmom, auto_npar=auto_npar)