def test_to_dict_from_dict(self): k = Kpoints.monkhorst_automatic([2, 2, 2], [0, 0, 0]) d = k.to_dict k2 = Kpoints.from_dict(d) self.assertEqual(k.kpts, k2.kpts) self.assertEqual(k.style, k2.style) self.assertEqual(k.kpts_shift, k2.kpts_shift)
def test_static_constructors(self): kpoints = Kpoints.gamma_automatic([3, 3, 3], [0, 0, 0]) self.assertEqual(kpoints.style, "Gamma") self.assertEqual(kpoints.kpts, [[3, 3, 3]]) kpoints = Kpoints.monkhorst_automatic([2, 2, 2], [0, 0, 0]) self.assertEqual(kpoints.style, "Monkhorst") self.assertEqual(kpoints.kpts, [[2, 2, 2]]) kpoints = Kpoints.automatic(100) self.assertEqual(kpoints.style, "Automatic") self.assertEqual(kpoints.kpts, [[100]]) filepath = os.path.join(test_dir, 'POSCAR') poscar = Poscar.from_file(filepath) kpoints = Kpoints.automatic_density(poscar.structure, 500) self.assertEqual(kpoints.kpts, [[2, 4, 4]]) self.assertEqual(kpoints.style, "Monkhorst") kpoints = Kpoints.automatic_density(poscar.structure, 500, True) self.assertEqual(kpoints.style, "Gamma") kpoints = Kpoints.automatic_density_by_vol(poscar.structure, 1000) self.assertEqual(kpoints.kpts, [[6, 11, 13]]) self.assertEqual(kpoints.style, "Gamma") s = poscar.structure s.make_supercell(3) kpoints = Kpoints.automatic_density(s, 500) self.assertEqual(kpoints.kpts, [[1, 1, 1]]) self.assertEqual(kpoints.style, "Gamma")
def test_static_constructors(self): kpoints = Kpoints.gamma_automatic([3, 3, 3], [0, 0, 0]) self.assertEqual(kpoints.style, "Gamma") self.assertEqual(kpoints.kpts, [[3, 3, 3]]) kpoints = Kpoints.monkhorst_automatic([2, 2, 2], [0, 0, 0]) self.assertEqual(kpoints.style, "Monkhorst") self.assertEqual(kpoints.kpts, [[2, 2, 2]]) kpoints = Kpoints.automatic(100) self.assertEqual(kpoints.style, "Automatic") self.assertEqual(kpoints.kpts, [[100]]) filepath = os.path.join(test_dir, "POSCAR") poscar = Poscar.from_file(filepath) kpoints = Kpoints.automatic_density(poscar.structure, 500) self.assertEqual(kpoints.kpts, [[2, 3, 4]])
def test_static_constructors(self): kpoints = Kpoints.gamma_automatic([3, 3, 3], [0, 0, 0]) self.assertEqual(kpoints.style, "Gamma") self.assertEqual(kpoints.kpts, [[3, 3, 3]]) kpoints = Kpoints.monkhorst_automatic([2, 2, 2], [0, 0, 0]) self.assertEqual(kpoints.style, "Monkhorst") self.assertEqual(kpoints.kpts, [[2, 2, 2]]) kpoints = Kpoints.automatic(100) self.assertEqual(kpoints.style, "Automatic") self.assertEqual(kpoints.kpts, [[100]]) filepath = os.path.join(test_dir, 'POSCAR') poscar = Poscar.from_file(filepath) kpoints = Kpoints.automatic_density(poscar.structure, 500) self.assertEqual(kpoints.kpts, [[2, 3, 4]])
def from_previous_vasp_run(previous_vasp_dir, output_dir='.', user_incar_settings=None, make_dir_if_not_present=True): """ Generate a set of Vasp input files for static calculations from a directory of previous Vasp run. Args: previous_vasp_dir: The directory contains the outputs(vasprun.xml and OUTCAR) of previous vasp run. output_dir: The directory to write the VASP input files for the static calculations. Default to write in the current directory. make_dir_if_not_present: Set to True if you want the directory (and the whole path) to be created if it is not present. """ try: vasp_run = Vasprun(os.path.join(previous_vasp_dir, "vasprun.xml"), parse_dos=False, parse_eigen=None) outcar = Outcar(os.path.join(previous_vasp_dir, "OUTCAR")) previous_incar = vasp_run.incar previous_kpoints = vasp_run.kpoints previous_final_structure = vasp_run.final_structure except: traceback.format_exc() raise RuntimeError("Can't get valid results from previous run") structure = MPStaticVaspInputSet.get_structure(vasp_run, outcar) mpsvip = MPStaticVaspInputSet() mpsvip.write_input(structure, output_dir, make_dir_if_not_present) #new_incar = Incar.from_file(os.path.join(output_dir, "INCAR")) new_incar = mpsvip.get_incar(structure) # Use previous run INCAR and override necessary parameters previous_incar.update({"IBRION": -1, "ISMEAR": -5, "LAECHG": True, "LCHARG": True, "LORBIT": 11, "LVHAR": True, "LWAVE": False, "NSW": 0, "ICHARG": 0}) for incar_key in ["MAGMOM", "NUPDOWN"]: if new_incar.get(incar_key, None): previous_incar.update({incar_key: new_incar[incar_key]}) else: previous_incar.pop(incar_key, None) # use new LDAUU when possible b/c the Poscar might have changed # representation if previous_incar.get('LDAU'): u = previous_incar.get('LDAUU', []) j = previous_incar.get('LDAUJ', []) if sum([u[x] - j[x] for x, y in enumerate(u)]) > 0: for tag in ('LDAUU', 'LDAUL', 'LDAUJ'): previous_incar.update({tag: new_incar[tag]}) # Compare ediff between previous and staticinputset values, # choose the tighter ediff previous_incar.update({"EDIFF": min(previous_incar.get("EDIFF", 1), new_incar["EDIFF"])}) # add user settings if user_incar_settings: previous_incar.update(user_incar_settings) previous_incar.write_file(os.path.join(output_dir, "INCAR")) # Prefer to use k-point scheme from previous run previous_kpoints_density = np.prod(previous_kpoints.kpts[0]) / \ previous_final_structure.lattice.reciprocal_lattice.volume new_kpoints_density = max(previous_kpoints_density, 90) new_kpoints = mpsvip.get_kpoints(structure, kpoints_density=new_kpoints_density) if previous_kpoints.style[0] != new_kpoints.style[0]: if previous_kpoints.style[0] == "M" and \ SymmetryFinder(structure, 0.01).get_lattice_type() != \ "hexagonal": k_div = (kp + 1 if kp % 2 == 1 else kp for kp in new_kpoints.kpts[0]) Kpoints.monkhorst_automatic(k_div). \ write_file(os.path.join(output_dir, "KPOINTS")) else: Kpoints.gamma_automatic(new_kpoints.kpts[0]). \ write_file(os.path.join(output_dir, "KPOINTS")) else: new_kpoints.write_file(os.path.join(output_dir, "KPOINTS"))
slab_potcar.write_file("./Slab_with_vdw/POTCAR") #set the common INCAR file and KPOINTS incar_dict = { 'SYSTEM': 'ligand_PbS', 'ENCUT': 600, 'ISIF': 2, 'IBRION': 2, 'ALGO': 'Normal', 'ISMEAR': 1, 'ISPIN': 1, 'EDIFF': 1e-06, 'EDIFFG': -0.005, 'NPAR': 8, 'SIGMA': 0.1, 'PREC': 'Accurate', 'IVDW': 2, 'NSW': 1000 } incar = Incar.from_dict(incar_dict) kpoints = Kpoints.monkhorst_automatic(kpts= (8, 8, 1), shift= (0, 0, 0)) #write the files in appropriate directory incar.write_file("./Interface_with_vdw/INCAR") incar.write_file("./Slab_with_vdw/INCAR") kpoints.write_file("./Interface_with_vdw/KPOINTS") kpoints.write_file("./Slab_with_vdw/KPOINTS") shu.copy("./submit_job", "./Interface_with_vdw/") shu.copy("./submit_job", "./Slab_with_vdw")
def from_previous_vasp_run(previous_vasp_dir, output_dir='.', user_incar_settings=None, make_dir_if_not_present=True): """ Generate a set of Vasp input files for static calculations from a directory of previous Vasp run. Args: previous_vasp_dir: The directory contains the outputs(vasprun.xml and OUTCAR) of previous vasp run. output_dir: The directory to write the VASP input files for the static calculations. Default to write in the current directory. make_dir_if_not_present: Set to True if you want the directory (and the whole path) to be created if it is not present. """ try: vasp_run = Vasprun(os.path.join(previous_vasp_dir, "vasprun.xml"), parse_dos=False, parse_eigen=None) outcar = Outcar(os.path.join(previous_vasp_dir, "OUTCAR")) previous_incar = Incar.from_file(os.path.join(previous_vasp_dir, "INCAR")) kpoints = Kpoints.from_file(os.path.join(previous_vasp_dir, "KPOINTS")) except: traceback.format_exc() raise RuntimeError("Can't get valid results from previous run") structure = MPStaticVaspInputSet.get_structure( vasp_run, outcar) mpsvip = MPStaticVaspInputSet() mpsvip.write_input(structure, output_dir, make_dir_if_not_present) new_incar = Incar.from_file(os.path.join(output_dir, "INCAR")) # Use previous run INCAR and override necessary parameters previous_incar.update({"IBRION": -1, "ISMEAR": -5, "LAECHG": True, "LCHARG": True, "LORBIT": 11, "LVHAR": True, "LWAVE": False, "NSW": 0, "ICHARG": 0}) # Compare ediff between previous and staticinputset values, # choose the tigher ediff previous_incar.update({"EDIFF": min(previous_incar["EDIFF"], new_incar["EDIFF"])}) # add user settings if user_incar_settings: previous_incar.update(user_incar_settings) previous_incar.write_file(os.path.join(output_dir, "INCAR")) # Prefer to use k-point scheme from previous run kpoints_out = Kpoints.from_file(os.path.join(output_dir, "KPOINTS")) if kpoints.style != kpoints_out.style and \ SymmetryFinder(structure, 0.01).get_lattice_type() != \ "hexagonal": k_div = (kp + 1 if kp % 2 == 1 else kp for kp in kpoints_out.kpts[0]) Kpoints.monkhorst_automatic(k_div).write_file( os.path.join(output_dir, "KPOINTS"))
def get_calibration_task(structure, phase="CalibrateBulk", \ slab_interface_params={'hkl':[1,0,0], 'ligand': None},\ turn_knobs={}, incar_params={}, other_params={}): """ returns general calibration task for a structure Args: structure : pymatgen structure to be calibrated (can be a bulk, ligand, slab or interface) phase : calibration type, viz. CalibrateBulk, CalibrateMolecule, CalibrateSlab, CalibrateInterface hkl : in case of Slab and Interface miller indices of facet turn_knobs : specifies the parameters to be calibrated incar_params : dictionary of additional incar parameters, refer defined incar_dict for defaults other_params : other parameters for calibration, viz. job_dir, is_matrix, etc. described in the calibrate module """ #structure definition poscar = Poscar(structure) incar_dict = { 'SYSTEM': 'slab', 'ENCUT': 500, 'ISIF': 2, 'IBRION': 2, 'ISMEAR': 1, 'EDIFF': 1e-05, 'NPAR': 4, 'SIGMA': 0.1, 'PREC': 'Accurate' } if incar_params: incar_dict.update(incar_params) incar = Incar.from_dict(incar_dict) kpoints = Kpoints.monkhorst_automatic(kpts=(8, 8, 1)) que = { 'nnodes':1, 'nprocs':16, 'walltime':'48:00:00', 'job_bin': '/home/km468/Software/VASP/vaspsol_kappa.5.3.5/vasp' } # calibration task: relax hkl calparams = {} calparams['calibrate'] = phase calparams['incar'] = incar.as_dict() calparams['poscar'] = poscar.as_dict() calparams['kpoints'] = kpoints.as_dict() calparams['que_params'] = que calparams['turn_knobs'] = turn_knobs if phase == 'CalibrateSlab': calparams['system'] = {'hkl':slab_interface_params['hkl'], 'ligand':slab_interface_params['ligand'] } elif phase == 'CalibrateInterface': calparams['system'] = {'hkl':hkl, 'ligand':structure.ligand.reduced_formula } calparams['other_params'] = { 'is_matrix':False, 'from_ase':True, 'Grid_type':'M' } if other_params: calparams['other_params'].update(other_params) return MPINTCalibrateTask(calparams)
def from_previous_vasp_run(previous_vasp_dir, output_dir='.', user_incar_settings=None, make_dir_if_not_present=True): """ Generate a set of Vasp input files for static calculations from a directory of previous Vasp run. Args: previous_vasp_dir: The directory contains the outputs(vasprun.xml and OUTCAR) of previous vasp run. output_dir: The directory to write the VASP input files for the static calculations. Default to write in the current directory. make_dir_if_not_present: Set to True if you want the directory (and the whole path) to be created if it is not present. """ try: vasp_run = Vasprun(os.path.join(previous_vasp_dir, "vasprun.xml"), parse_dos=False, parse_eigen=None) outcar = Outcar(os.path.join(previous_vasp_dir, "OUTCAR")) previous_incar = vasp_run.incar previous_kpoints = vasp_run.kpoints previous_final_structure = vasp_run.final_structure except: traceback.format_exc() raise RuntimeError("Can't get valid results from previous run") structure = MPStaticVaspInputSet.get_structure(vasp_run, outcar) mpsvip = MPStaticVaspInputSet() mpsvip.write_input(structure, output_dir, make_dir_if_not_present) #new_incar = Incar.from_file(os.path.join(output_dir, "INCAR")) new_incar = mpsvip.get_incar(structure) # Use previous run INCAR and override necessary parameters previous_incar.update({ "IBRION": -1, "ISMEAR": -5, "LAECHG": True, "LCHARG": True, "LORBIT": 11, "LVHAR": True, "LWAVE": False, "NSW": 0, "ICHARG": 0 }) for incar_key in ["MAGMOM", "NUPDOWN"]: if new_incar.get(incar_key, None): previous_incar.update({incar_key: new_incar[incar_key]}) else: previous_incar.pop(incar_key, None) # use new LDAUU when possible b/c the Poscar might have changed # representation if previous_incar.get('LDAU'): u = previous_incar.get('LDAUU', []) j = previous_incar.get('LDAUJ', []) if sum([u[x] - j[x] for x, y in enumerate(u)]) > 0: for tag in ('LDAUU', 'LDAUL', 'LDAUJ'): previous_incar.update({tag: new_incar[tag]}) # Compare ediff between previous and staticinputset values, # choose the tighter ediff previous_incar.update( {"EDIFF": min(previous_incar.get("EDIFF", 1), new_incar["EDIFF"])}) # add user settings if user_incar_settings: previous_incar.update(user_incar_settings) previous_incar.write_file(os.path.join(output_dir, "INCAR")) # Prefer to use k-point scheme from previous run previous_kpoints_density = np.prod(previous_kpoints.kpts[0]) / \ previous_final_structure.lattice.reciprocal_lattice.volume new_kpoints_density = max(previous_kpoints_density, 90) new_kpoints = mpsvip.get_kpoints(structure, kpoints_density=new_kpoints_density) if previous_kpoints.style[0] != new_kpoints.style[0]: if previous_kpoints.style[0] == "M" and \ SymmetryFinder(structure, 0.01).get_lattice_type() != \ "hexagonal": k_div = (kp + 1 if kp % 2 == 1 else kp for kp in new_kpoints.kpts[0]) Kpoints.monkhorst_automatic(k_div). \ write_file(os.path.join(output_dir, "KPOINTS")) else: Kpoints.gamma_automatic(new_kpoints.kpts[0]). \ write_file(os.path.join(output_dir, "KPOINTS")) else: new_kpoints.write_file(os.path.join(output_dir, "KPOINTS"))
def from_previous_vasp_run(previous_vasp_dir, output_dir='.', user_incar_settings=None, make_dir_if_not_present=True, kpoints_density=90, sym_prec=0.1): """ Generate a set of Vasp input files for static calculations from a directory of previous Vasp run. Args: previous_vasp_dir (str): Directory containing the outputs( vasprun.xml and OUTCAR) of previous vasp run. output_dir (str): Directory to write the VASP input files for the static calculations. Defaults to current directory. make_dir_if_not_present (bool): Set to True if you want the directory (and the whole path) to be created if it is not present. kpoints_density (int): kpoints density for the reciprocal cell of structure. Might need to increase the default value when calculating metallic materials. sym_prec (float): Tolerance for symmetry finding """ # Read input and output from previous run try: vasp_run = Vasprun(os.path.join(previous_vasp_dir, "vasprun.xml"), parse_dos=False, parse_eigen=None) outcar = Outcar(os.path.join(previous_vasp_dir, "OUTCAR")) previous_incar = vasp_run.incar previous_kpoints = vasp_run.kpoints except: traceback.format_exc() raise RuntimeError("Can't get valid results from previous run") mpsvip = MPStaticVaspInputSet(kpoints_density=kpoints_density, sym_prec=sym_prec) structure = mpsvip.get_structure(vasp_run, outcar) mpsvip.write_input(structure, output_dir, make_dir_if_not_present) new_incar = mpsvip.get_incar(structure) # Use previous run INCAR and override necessary parameters previous_incar.update({"IBRION": -1, "ISMEAR": -5, "LAECHG": True, "LCHARG": True, "LORBIT": 11, "LVHAR": True, "LWAVE": False, "NSW": 0, "ICHARG": 0}) for incar_key in ["MAGMOM", "NUPDOWN"]: if new_incar.get(incar_key, None): previous_incar.update({incar_key: new_incar[incar_key]}) else: previous_incar.pop(incar_key, None) # use new LDAUU when possible b/c the Poscar might have changed # representation if previous_incar.get('LDAU'): u = previous_incar.get('LDAUU', []) j = previous_incar.get('LDAUJ', []) if sum([u[x] - j[x] for x, y in enumerate(u)]) > 0: for tag in ('LDAUU', 'LDAUL', 'LDAUJ'): previous_incar.update({tag: new_incar[tag]}) # ensure to have LMAXMIX for GGA+U static run if "LMAXMIX" not in previous_incar: previous_incar.update({"LMAXMIX": new_incar["LMAXMIX"]}) # Compare ediff between previous and staticinputset values, # choose the tighter ediff previous_incar.update({"EDIFF": min(previous_incar.get("EDIFF", 1), new_incar["EDIFF"])}) # add user settings if user_incar_settings: previous_incar.update(user_incar_settings) previous_incar.write_file(os.path.join(output_dir, "INCAR")) # Perform checking on INCAR parameters if any([previous_incar.get("NSW", 0) != 0, previous_incar["IBRION"] != -1, previous_incar["LCHARG"] != True, any([sum(previous_incar["LDAUU"])<=0, previous_incar["LMAXMIX"]<4]) if previous_incar.get("LDAU") else False]): raise ValueError("Incompatible INCAR parameters!") # Prefer to use k-point scheme from previous run new_kpoints = mpsvip.get_kpoints(structure) if previous_kpoints.style[0] != new_kpoints.style[0]: if previous_kpoints.style[0] == "M" and \ SymmetryFinder(structure, 0.1).get_lattice_type() != \ "hexagonal": k_div = (kp + 1 if kp % 2 == 1 else kp for kp in new_kpoints.kpts[0]) Kpoints.monkhorst_automatic(k_div). \ write_file(os.path.join(output_dir, "KPOINTS")) else: Kpoints.gamma_automatic(new_kpoints.kpts[0]). \ write_file(os.path.join(output_dir, "KPOINTS")) else: new_kpoints.write_file(os.path.join(output_dir, "KPOINTS"))
def get_calibration_task(structure, phase="CalibrateBulk", \ slab_interface_params={'hkl':[1,0,0], 'ligand': None},\ turn_knobs={}, incar_params={}, other_params={}): """ returns general calibration task for a structure Args: structure : pymatgen structure to be calibrated (can be a bulk, ligand, slab or interface) phase : calibration type, viz. CalibrateBulk, CalibrateMolecule, CalibrateSlab, CalibrateInterface hkl : in case of Slab and Interface miller indices of facet turn_knobs : specifies the parameters to be calibrated incar_params : dictionary of additional incar parameters, refer defined incar_dict for defaults other_params : other parameters for calibration, viz. job_dir, is_matrix, etc. described in the calibrate module """ #structure definition poscar = Poscar(structure) incar_dict = { 'SYSTEM': 'slab', 'ENCUT': 500, 'ISIF': 2, 'IBRION': 2, 'ISMEAR': 1, 'EDIFF': 1e-05, 'NPAR': 4, 'SIGMA': 0.1, 'PREC': 'Accurate' } if incar_params: incar_dict.update(incar_params) incar = Incar.from_dict(incar_dict) kpoints = Kpoints.monkhorst_automatic(kpts=(8, 8, 1)) que = { 'nnodes': 1, 'nprocs': 16, 'walltime': '48:00:00', 'job_bin': '/home/km468/Software/VASP/vaspsol_kappa.5.3.5/vasp' } # calibration task: relax hkl calparams = {} calparams['calibrate'] = phase calparams['incar'] = incar.as_dict() calparams['poscar'] = poscar.as_dict() calparams['kpoints'] = kpoints.as_dict() calparams['que_params'] = que calparams['turn_knobs'] = turn_knobs if phase == 'CalibrateSlab': calparams['system'] = { 'hkl': slab_interface_params['hkl'], 'ligand': slab_interface_params['ligand'] } elif phase == 'CalibrateInterface': calparams['system'] = { 'hkl': hkl, 'ligand': structure.ligand.reduced_formula } calparams['other_params'] = { 'is_matrix': False, 'from_ase': True, 'Grid_type': 'M' } if other_params: calparams['other_params'].update(other_params) return MPINTCalibrateTask(calparams)