def run_task(self, fw_spec): user_incar_settings = {"NCORE": 8} # vol = Poscar.from_file("POSCAR").structure.volume # kppra_vol = self.kpoints_density / vol if self.line: MPNonSCFSet.from_prev_calc( os.getcwd(), mode="Line", copy_chgcar=False, user_incar_settings=user_incar_settings, kpoints_line_density=self.kpoints_line_density).write_input( '.') kpath = HighSymmKpath(Poscar.from_file("POSCAR").structure) return FWAction(stored_data={ "kpath": kpath.kpath, "kpath_name": kpath.name }) else: MPNonSCFSet.from_prev_calc( os.getcwd(), mode="Uniform", copy_chgcar=False, user_incar_settings=user_incar_settings, reciprocal_density=self.kpoints_density).write_input('.') return FWAction()
def Write_NONSCF_KPOINTS(self, mode="line", nedos=601, reciprocal_density=100, sym_prec=0.1, kpoints_line_density=20, optics=False, **kwargs): """ generate KPOINTS for DOS (mode="uniform") or band struture (mode="line") by pymatgen.io.vasp.set.MPNonSCFSet input arguments: -mode (str): 'line' or 'uniform' -nedos (int): default 601. Only valid at mode='uniform' -reciprocal_density (int): default 100. Only valid at mode='uniform' -sym_prec (float): default 0.1 -kpoints_line_density (int): default 20. Only valid at mode='line' -optics (bool) """ vis = MPNonSCFSet(structure=self.structure, mode=mode, nedos=nedos, reciprocal_density=reciprocal_density, sym_prec=sym_prec, kpoints_line_density=kpoints_line_density, optics=optics) vis.kpoints.write_file(os.path.join(self.cal_loc, "KPOINTS"))
def Write_NONSCF_KPOINTS(structure_filename="./POSCAR", mode='line', nedos=601, reciprocal_density=100, sym_prec=0.1, kpoints_line_density=20, optics=False, **kwargs): """ generate KPOINTS for DOS (mode="uniform") or band struture (mode="line") by pymatgen.io.vasp.set.MPNonSCFSet input arguments: -structure_filename (str): a file that can be understood by pymatgen.Structure.from_file. -mode (str): 'line' or 'uniform' -nedos (int): default 601. Only valid at mode='uniform' -reciprocal_density (int): default 100. Only valid at mode='uniform' -sym_prec (float): default 0.1 -kpoints_line_density (int): default 20. Only valid at mode='line' -optics (bool) """ #print(os.getcwd()) #print(os.listdir()) #print(structure_filename) struct = Structure.from_file(structure_filename) vis = MPNonSCFSet(structure=struct, mode=mode, nedos=nedos, reciprocal_density=reciprocal_density, sym_prec=sym_prec, kpoints_line_density=kpoints_line_density, optics=optics) folder = os.path.split(structure_filename)[0] vis.kpoints.write_file(os.path.join(folder, "KPOINTS"))
def write_vasp(self, k0_rlv, scfdir, destdir): '''Generate VASP nscf input files ''' r = Vasprun(join(scfdir, 'vasprun.xml')) rlv = r.lattice_rec.matrix is_k_spin = True try: len(k0_rlv[0]) except: is_k_spin = False k0_up = k0_rlv k0_dn = None if is_k_spin: k0_up, k0_dn = k0_rlv[0], k0_rlv[1] list_k = self.kpoints(rlv, k0_up) if r.is_spin and is_k_spin: list_k = np.concatenate((list_k, self.kpoints(rlv, k0_dn))) nscf = MPNonSCFSet.from_prev_calc(scfdir, user_incar_settings={ "NCORE": 4, "EDIFF": "1E-7" }) nscf.write_input(destdir) mode = Kpoints.supported_modes.Reciprocal kpt = Kpoints(style=mode, kpts=list_k, num_kpts=len(list_k), kpts_weights=[1.0] * len(list_k), comment="5-point stencil h:{}".format(self.h)) kpt.write_file(join(destdir, 'KPOINTS'))
def setUp(self): coords = list() coords.append([0, 0, 0]) coords.append([0.75, 0.5, 0.75]) lattice = [ [3.8401979337, 0.00, 0.00], [1.9200989668, 3.3257101909, 0.00], [0.00, -2.2171384943, 3.1355090603], ] structure = Structure(lattice, ["Si", "Si"], coords) input_sets = { "GGA Structure Optimization": MPRelaxSet(structure), "GGA Static": MPStaticSet(structure), "GGA NSCF Line": MPNonSCFSet(structure, mode="line"), "GGA NSCF Uniform": MPNonSCFSet(structure, mode="uniform"), } tasks = [] t_id = 1 for task_type, input_set in input_sets.items(): doc = { "true_task_type": task_type, "last_updated": datetime.now(), "task_id": t_id, "state": "successful", "orig_inputs": { "incar": input_set.incar.as_dict(), "kpoints": input_set.kpoints.as_dict(), }, "output": { "structure": structure.as_dict() }, } t_id += 1 tasks.append(doc) self.test_tasks = MemoryStore("tasks") self.task_types = MemoryStore("task_types") self.test_tasks.connect() self.task_types.connect() self.test_tasks.update(tasks)
def run_task(self, fw_spec): material_id = self["material_id"] mode = self["mode"] dest_root = fw_spec["_fw_env"]["run_dest_root"] dest = "{}/{}/bs/{}/static".format(dest_root, os.environ["USER"], material_id) user_incar_settings = fw_spec.get("user_incar_settings", {}) if mode.lower() == "line": vasp_input_set = MPNonSCFSet.from_prev_calc( dest, standardize=1e-3, user_incar_settings=user_incar_settings, mode=mode) dec = MontyDecoder() vis = dec.process_decoded(vasp_input_set.as_dict()) vis.write_input(".") elif mode.lower() == "uniform": vasp_input_set = MPNonSCFSet.from_prev_calc( dest, user_incar_settings=user_incar_settings, mode=mode) dec = MontyDecoder() vis = dec.process_decoded(vasp_input_set.as_dict()) vis.write_input(".")
def run_task(self, fw_spec): vis = MPNonSCFSet.from_prev_calc( prev_calc_dir=self.get("prev_calc_dir", "."), copy_chgcar=self.get("copy_chgcar", False), user_incar_settings=self.get("user_incar_settings", {}), nbands_factor=self.get("nbands_factor", 2), reciprocal_density=self.get("reciprocal_density", 100), kpoints_line_density=self.get("kpoints_line_density", 30), small_gap_multiply=self.get("small_gap_multiply", None), standardize=self.get("standardize", False), sym_prec=self.get("sym_prec", 0.1), mode=self.get("mode", "line"), **self.get("other_params", {})) vis.write_input(".")
def run_task(self, fw_spec): vis = MPNonSCFSet.from_prev_calc( prev_calc_dir=self["prev_calc_dir"], copy_chgcar=self.get("copy_chgcar", False), nbands_factor=self.get("nbands_factor", 1.2), reciprocal_density=self.get("reciprocal_density", 100), kpoints_line_density=self.get("kpoints_line_density", 20), 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), mode=self.get("mode", "uniform"), nedos=self.get("nedos", 601), optics=self.get("optics", False), **self.get("other_params", {})) vis.write_input(".")
def run_task(self, fw_spec): vis = MPNonSCFSet.from_prev_calc( prev_calc_dir=self.get("prev_calc_dir", "."), copy_chgcar=self.get("copy_chgcar", False), nbands_factor=self.get("nbands_factor", 1.2), reciprocal_density=self.get("reciprocal_density", 100), kpoints_line_density=self.get("kpoints_line_density", 20), 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), mode=self.get("mode", "uniform"), nedos=self.get("nedos", 601), optics=self.get("optics", False), **self.get("other_params", {})) vis.write_input(".")
def Scf (self): from pymatgen.io.vasp.sets import MPNonSCFSet import shutil import os filePath=self.dire for dirpath, dirnames, filenames in os.walk(filePath): # print(dirpath) for name in dirnames: if 'dos' not in str(name): path = os.path.join(filePath, name) custom_settings = {"LAECHG": "False", "LVHAR": "False",'NPAR':4} # user custom incar settings dos = MPNonSCFSet.from_prev_calc(path, mode="line",reciprocal_density=200, user_incar_settings=custom_settings) os.chdir(self.dire) dos.write_input("dos_"+str(name)) pat = os.path.join(self.dire, "dos_"+str(name)) diree = os.chdir(pat) #定义一个更改当前目录的变量 dire2 = './vaspstd_sub' #确立脚本名称 shutil.copy(r"C:\Users\41958\.spyder-py3\vaspstd_sub", dire2 ) shutil.copy(os.path.join(path,'WAVECAR'), os.path.join(pat,'WAVECAR') )
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)
'NELM': 60, "LVHAR": "False", # "LWAVE": "True", "ISMEAR": 1, "SYMPREC": 1e-8, # "LELF": "True", } static = MPStaticSet(struc, user_incar_settings=myset) static.write_input(static_dir) run_vasp(cmd, static_dir) os.system('cp ' + static_dir + '/vasprun.xml ./static-vasprun.xml') # 2nd run to obtain dos dos = MPNonSCFSet.from_prev_calc(static_dir, mode="uniform", reciprocal_density=200, user_incar_settings=myset) dos.write_input(dos_dir) run_vasp(cmd, dos_dir) os.system('cp ' + dos_dir + '/vasprun.xml ./dos-vasprun.xml') # 3rd run to obtain Band structure band = MPNonSCFSet.from_prev_calc(static_dir, mode="line", standardize=True, user_incar_settings=myset) band.write_input(band_dir) run_vasp(cmd, band_dir) os.system('cp ' + band_dir + '/vasprun.xml ./band-vasprun.xml') os.system('cp ' + band_dir + '/KPOINTS ./')
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)