class PRLRelaxSet(DictSet): """ Set for performing relaxations. The smearing must be set to give the correct forces. The default is tuned for metal relaxations. Kpoints have a 6000 kpoints per reciprocal atom default. """ CONFIG = _load_yaml_config("MPRelaxSet") # we never are comparing relaxations, only using them for optimizing structures. CONFIG['INCAR'].pop('ENCUT') # use the ENCUT set by PREC CONFIG['KPOINTS'].update({ 'grid_density': 6000, }) CONFIG['KPOINTS'].pop('reciprocal_density') # to be explicit CONFIG['INCAR'].update({ 'EDIFF_PER_ATOM': 1e-4, 'ISMEAR': 1, 'SIGMA': 0.2, 'LREAL': False, 'PREC': 'HIGH', 'ALGO': 'NORMAL', }) # now we reset the potentials CONFIG['POTCAR'].update(POTCAR_UPDATES) def __init__(self, structure, **kwargs): self.kwargs = kwargs super(PRLRelaxSet, self).__init__(structure, PRLRelaxSet.CONFIG, **kwargs)
class StaticSet(DictSet): """Set tuned for metal relaxations (correct smearing). Add `isif` parameter to the set to easily allow for overriding ISIF setting. Kpoints have a 6000 reciprocal density default. """ CONFIG = _load_yaml_config("MPRelaxSet") CONFIG['KPOINTS'].update({ 'grid_density': 8000, }) CONFIG['KPOINTS'].pop('reciprocal_density') # to be explicit CONFIG['INCAR'].update({ 'EDIFF_PER_ATOM': 1e-6, 'ENCUT': 520, # MP compatibility 'ISMEAR': -5, "NSW": 0, "IBRION": -1, 'LREAL': False, 'ALGO': 'NORMAL', # other settings from MPStaticSet "LAECHG": True, "LCHARG": True, "LWAVE": False, "LORBIT": 11, "LVHAR": True, "ICHARG": 2, "NEDOS": 5001, }) # now we reset the potentials CONFIG['POTCAR_FUNCTIONAL'] = 'PBE' CONFIG['POTCAR'].update(POTCAR_UPDATES) def __init__(self, structure, isif=2, **kwargs): # pop the old kwargs, backwards compatibility from the complex StaticSet self.isif = isif old_kwargs = [ 'prev_incar', 'prev_kpoints', 'grid_density', 'lepsilon', 'lcalcpol' ] for k in old_kwargs: try: kwargs.pop(k) except KeyError: pass self.kwargs = kwargs uis = copy.deepcopy(kwargs.get('user_incar_settings', {})) uis['ISIF'] = isif if 'ISPIN' not in uis: if magnetic_check(structure): uis.update({'ISPIN': 2}) else: uis.update({'ISPIN': 1}) StaticSet.CONFIG['INCAR'].update(uis) super(StaticSet, self).__init__(structure, StaticSet.CONFIG, sort_structure=False, **kwargs)
class RelaxSet(DictSet): """ Set for performing relaxations. The smearing must be set to give the correct forces. The default is tuned for metal relaxations. Kpoints have a 8000 kpoints per reciprocal atom default. """ CONFIG = _load_yaml_config("MPRelaxSet") # we never are comparing relaxations, only using them for optimizing structures. CONFIG['INCAR'].pop('ENCUT') # use the ENCUT set by PREC CONFIG['KPOINTS'].update({ 'grid_density': 8000, }) CONFIG['KPOINTS'].pop('reciprocal_density') # to be explicit CONFIG['INCAR'].update({ 'EDIFF_PER_ATOM': 1e-5, 'ISMEAR': 1, 'SIGMA': 0.2, 'LREAL': False, 'PREC': 'Accurate', 'ALGO': 'NORMAL', 'LWAVE': False, 'LCHARG': False, 'ISIF': 3, "ICHARG": 2, 'ENCUT': 520, }) # now we reset the potentials CONFIG['POTCAR_FUNCTIONAL'] = 'PBE' CONFIG['POTCAR'].update(POTCAR_UPDATES) def __init__(self, structure, volume_relax=False, isif=None, **kwargs): """If volume relax is True, will do volume only, ISIF 7""" self.kwargs = kwargs self.volume_relax = volume_relax self.isif = isif uis = copy.deepcopy(kwargs.get('user_incar_settings', {})) if self.volume_relax and self.isif is not None: raise ValueError( "isif cannot have a value while volume_relax is True.") if self.volume_relax: uis.update({'ISIF': 7}) #uis['ISIF'] = 7 if self.isif is not None: uis.update({'ISIF': self.isif}) if 'ISPIN' not in uis: if magnetic_check(structure): uis.update({'ISPIN': 2}) else: uis.update({'ISPIN': 1}) RelaxSet.CONFIG['INCAR'].update(uis) super(RelaxSet, self).__init__(structure, RelaxSet.CONFIG, sort_structure=False, **kwargs)
class ForceConstantsSet(DictSet): """ Set for calculating force constants calculations. Force constants are calculated by the finite difference method with symmetry considered. The smearing must be set to give the correct forces. The default is tuned for metals. Kpoints have a 8000 kpoints per reciprocal atom default. """ CONFIG = _load_yaml_config("MPRelaxSet") # we never are comparing relaxations, only using them for optimizing structures. CONFIG['KPOINTS'].update({ 'grid_density': 8000, }) CONFIG['KPOINTS'].pop('reciprocal_density') # to be explicit CONFIG['INCAR'].pop('ENCUT') # use the ENCUT set by PREC CONFIG['INCAR'].update({ 'EDIFF_PER_ATOM': 1e-6, 'ISMEAR': 1, 'SIGMA': 0.2, 'LREAL': False, 'ISIF': 0, # only calculate the forces, stress tensor is not needed 'IBRION': 6, # calculate force constants by finite differences with symmetry 'POTIM': 0.015, # displacement distance 'NFREE': 2, # how many displacments to do. 2 gives +POTIM and -POTIM 'NSW': 1, # backwards compatibility setting 'PREC': 'Accurate', 'ALGO': 'NORMAL', 'SYMPREC': 1e-4, # some supercells seem to have issues with primcel VASP algorithm "ICHARG": 2, }) # now we reset the potentials CONFIG['POTCAR_FUNCTIONAL'] = 'PBE' CONFIG['POTCAR'].update(POTCAR_UPDATES) def __init__(self, structure, **kwargs): self.kwargs = kwargs uis = copy.deepcopy(kwargs.get('user_incar_settings', {})) if 'ISPIN' not in uis: if magnetic_check(structure): uis.update({'ISPIN': 2}) else: uis.update({'ISPIN': 1}) ForceConstantsSet.CONFIG['INCAR'].update(uis) super(ForceConstantsSet, self).__init__(structure, ForceConstantsSet.CONFIG, sort_structure=False, **kwargs)
class ForcesSet(DictSet): """Set tuned for generic force calculations (Gaussian smearing). """ CONFIG = _load_yaml_config("MPRelaxSet") CONFIG['KPOINTS'].update({ 'grid_density': 8000, }) CONFIG['KPOINTS'].pop('reciprocal_density') # to be explicit CONFIG['INCAR'].pop('ENCUT', None) CONFIG['INCAR'].update({ 'EDIFF_PER_ATOM': 1e-8, 'ISMEAR': 0, 'SIGMA': 0.05, "NSW": 0, "IBRION": -1, 'LREAL': False, 'ALGO': 'NORMAL', # other settings from MPStaticSet "LCHARG": False, "LORBIT": 11, "LVHAR": True, "LWAVE": False, "ICHARG": 2, "NEDOS": 5001, }) # now we reset the potentials CONFIG['POTCAR_FUNCTIONAL'] = 'PBE' CONFIG['POTCAR'].update(POTCAR_UPDATES) def __init__(self, structure, **kwargs): # pop the old kwargs, backwards compatibility from the complex StaticSet old_kwargs = [ 'prev_incar', 'prev_kpoints', 'grid_density', 'lepsilon', 'lcalcpol' ] for k in old_kwargs: try: kwargs.pop(k) except KeyError: pass self.kwargs = kwargs super(ForcesSet, self).__init__(structure, ForcesSet.CONFIG, sort_structure=False, **kwargs)
class RelaxSet(DictSet): """ Set for performing relaxations. The smearing must be set to give the correct forces. The default is tuned for metal relaxations. Kpoints have a 8000 kpoints per reciprocal atom default. """ CONFIG = _load_yaml_config("MPRelaxSet") # we never are comparing relaxations, only using them for optimizing structures. CONFIG['INCAR'].pop('ENCUT') # use the ENCUT set by PREC CONFIG['KPOINTS'].update({ 'grid_density': 8000, }) CONFIG['KPOINTS'].pop('reciprocal_density') # to be explicit CONFIG['INCAR'].update({ 'EDIFF_PER_ATOM': 1e-5, 'ISMEAR': 1, 'SIGMA': 0.2, 'LREAL': False, 'PREC': 'Accurate', 'ALGO': 'NORMAL', 'LWAVE': False, 'LCHARG': False, 'ISIF': 3, "ICHARG": 2, 'ENCUT': 520, }) # now we reset the potentials CONFIG['POTCAR'].update(POTCAR_UPDATES) def __init__(self, structure, volume_relax=False, **kwargs): """If volume relax is True, will do volume only, ISIF 7""" self.kwargs = kwargs self.volume_relax = volume_relax super(RelaxSet, self).__init__(structure, RelaxSet.CONFIG, **kwargs) if self.volume_relax: self.incar.update({'ISIF': 7})
class PRLRelaxSet(DictSet): """Set tuned for metal relaxations (correct smearing). Add `isif` parameter to the set to easily allow for overriding ISIF setting. Kpoints have a 6000 reciprocal density default. """ CONFIG = _load_yaml_config("MPRelaxSet") CONFIG['INCAR'].pop('ENCUT') CONFIG['KPOINTS'].update({ 'grid_density': 6000, }) CONFIG['KPOINTS'].pop('reciprocal_density') # to be explicit CONFIG['INCAR'].update({ 'ISMEAR': 1, 'SIGMA': 0.2, 'LREAL': False, 'PREC': 'HIGH', 'ALGO': 'NORMAL' }) def __init__(self, structure, **kwargs): self.kwargs = kwargs super(PRLRelaxSet, self).__init__(structure, PRLRelaxSet.CONFIG, **kwargs)
from pymatgen import MPRester from pymatgen.analysis.phase_diagram import PhaseDiagram from pymatgen.analysis.structure_matcher import StructureMatcher from pymatgen.analysis.structure_matcher import ElementComparator from pymatgen.core import Composition from pymatgen.entries.compatibility import MaterialsProjectCompatibility from pymatgen.entries.computed_entries import ComputedEntry from pymatgen.io.vasp.sets import _load_yaml_config from garnetdnn.formation_energy import get_descriptor, get_form_e, get_tote from garnetdnn.util import load_model_and_scaler, spe2form import itertools CONFIG = _load_yaml_config("MPRelaxSet") LDAUU = CONFIG["INCAR"]['LDAUU']['O'] m = MPRester("xNebFpxTfLhTnnIH") STD_FORMULA = { 'garnet': Composition("C3A2D3O12"), "perovskite": Composition("A2B2O6") } SITES = { 'garnet': ['c', 'a', 'd'], 'perovskite': ['a', 'b'] } # use list to preserve order SITE_INFO = { 'garnet': { 'c': { "num_atoms": 3,
class PRLStaticSet(DictSet): """Set tuned for metal relaxations (correct smearing). Add `isif` parameter to the set to easily allow for overriding ISIF setting. Kpoints have a 6000 reciprocal density default. """ CONFIG = _load_yaml_config("MPRelaxSet") CONFIG['KPOINTS'].update({ 'grid_density': 8000, }) CONFIG['KPOINTS'].pop('reciprocal_density') # to be explicit CONFIG['INCAR'].update({ 'EDIFF_PER_ATOM': 1e-6, 'ENCUT': 520, # MP compatibility 'ISMEAR': -5, "NSW": 0, "IBRION": -1, 'LREAL': False, 'ALGO': 'NORMAL', # other settings from MPStaticSet "LAECHG": True, "LCHARG": True, "LORBIT": 11, "LVHAR": True, "LWAVE": False, "ICHARG": 0, "NEDOS": 5001, }) # now we reset the potentials CONFIG['POTCAR'].update(POTCAR_UPDATES) def __init__(self, structure, prev_incar=None, prev_kpoints=None, lepsilon=False, lcalcpol=False, grid_density=8000, **kwargs): super(PRLStaticSet, self).__init__(structure, PRLStaticSet.CONFIG, **kwargs) if isinstance(prev_incar, six.string_types): prev_incar = Incar.from_file(prev_incar) if isinstance(prev_kpoints, six.string_types): prev_kpoints = Kpoints.from_file(prev_kpoints) self.prev_incar = prev_incar self.prev_kpoints = prev_kpoints self.grid_density = grid_density self.structure = structure self.kwargs = kwargs self.lepsilon = lepsilon self.lcalcpol = lcalcpol @property def incar(self): parent_incar = super(PRLStaticSet, self).incar incar = Incar(self.prev_incar) if self.prev_incar is not None else \ Incar(parent_incar) incar.update({ "IBRION": -1, "ISMEAR": -5, "LAECHG": True, "LCHARG": True, "LORBIT": 11, "LVHAR": True, "LWAVE": False, "NSW": 0, "ICHARG": 0, "ALGO": "Normal" }) for k in ["MAGMOM", "NUPDOWN"] + list( self.kwargs.get("user_incar_settings", {}).keys()): # For these parameters as well as user specified settings, override # the incar settings. if parent_incar.get(k, None) is not None: incar[k] = parent_incar[k] else: incar.pop(k, None) # use new LDAUU when possible b/c the Poscar might have changed # representation if incar.get('LDAU'): u = incar.get('LDAUU', []) j = incar.get('LDAUJ', []) if sum([u[x] - j[x] for x, y in enumerate(u)]) > 0: for tag in ('LDAUU', 'LDAUL', 'LDAUJ'): incar.update({tag: parent_incar[tag]}) # ensure to have LMAXMIX for GGA+U static run if "LMAXMIX" not in incar: incar.update({"LMAXMIX": parent_incar["LMAXMIX"]}) # Compare ediff between previous and staticinputset values, # choose the tighter ediff incar["EDIFF"] = min(incar.get("EDIFF", 1), parent_incar["EDIFF"]) return incar @property def kpoints(self): self._config_dict["KPOINTS"]["grid_density"] = self.grid_density kpoints = super(PRLStaticSet, self).kpoints # Prefer to use k-point scheme from previous run if self.prev_kpoints and self.prev_kpoints.style != kpoints.style: if self.prev_kpoints.style == Kpoints.supported_modes.Monkhorst: k_div = [ kp + 1 if kp % 2 == 1 else kp for kp in kpoints.kpts[0] ] kpoints = Kpoints.monkhorst_automatic(k_div) else: kpoints = Kpoints.gamma_automatic(kpoints.kpts[0]) return kpoints @classmethod def from_prev_calc(cls, prev_calc_dir, standardize=False, sym_prec=0.1, international_monoclinic=True, grid_density=8000, small_gap_multiply=None, **kwargs): """ Generate a set of Vasp input files for static calculations from a directory of previous Vasp run. Args: prev_calc_dir (str): Directory containing the outputs( vasprun.xml and OUTCAR) of previous vasp run. standardize (float): Whether to standardize to a primitive standard cell. Defaults to False. sym_prec (float): Tolerance for symmetry finding. If not 0, the final structure from the previous run will be symmetrized to get a primitive standard cell. Set to 0 if you don't want that. international_monoclinic (bool): Whether to use international convention (vs Curtarolo) for monoclinic. Defaults True. grid_density (int): density of k-mesh by reciprocal atom (defaults to 8000) small_gap_multiply ([float, float]): If the gap is less than 1st index, multiply the default reciprocal_density by the 2nd index. \\*\\*kwargs: All kwargs supported by MPStaticSet, other than prev_incar and prev_structure and prev_kpoints which are determined from the prev_calc_dir. """ vasprun, outcar = get_vasprun_outcar(prev_calc_dir) prev_incar = vasprun.incar prev_kpoints = vasprun.kpoints # We will make a standard structure for the given symprec. prev_structure = get_structure_from_prev_run( vasprun, outcar, sym_prec=standardize and sym_prec, international_monoclinic=international_monoclinic) # multiply the reciprocal density if needed: if small_gap_multiply: gap = vasprun.eigenvalue_band_properties[0] if gap <= small_gap_multiply[0]: grid_density = grid_density * small_gap_multiply[1] return PRLStaticSet(structure=prev_structure, prev_incar=prev_incar, prev_kpoints=prev_kpoints, grid_density=grid_density, **kwargs)
class ElasticSet(DictSet): """Set tuned for metal relaxations (correct smearing). Add `isif` parameter to the set to easily allow for overriding ISIF setting. Kpoints have a 6000 reciprocal density default. """ CONFIG = _load_yaml_config("MPRelaxSet") # 'EDIFF_PER_ATOM': 1e-6, CONFIG['INCAR'] = { 'EDIFF': 1e-6, 'ENCUT': 520, # MP compatibility 'ISMEAR': -5, "IBRION": 2, 'LREAL': False, 'ALGO': 'NORMAL', # other settings from MPStaticSet "LAECHG": True, "LCHARG": True, "LWAVE": False, #"LORBIT": 11, "LVHAR": True, "ICHARG": 0, "NSW": 99, "MAGMOM": CONFIG['INCAR']['MAGMOM'], "ISPIN": 2, "ISIF": 2, "PREC": "High" } # now we reset the potentials CONFIG['POTCAR_FUNCTIONAL'] = 'PBE' CONFIG['POTCAR'].update(POTCAR_UPDATES) def __init__(self, structure, **kwargs): # pop the old kwargs, backwards compatibility from the complex StaticSet uis = copy.deepcopy(kwargs.get('user_incar_settings', {})) """ old_kwargs = ['prev_incar', 'prev_kpoints', 'grid_density', 'lepsilon', 'lcalcpol', \ 'user_potcar_functional', 'user_incar_settings'] """ old_kwargs = [ 'prev_incar', 'prev_kpoints', 'grid_density', 'lepsilon', 'lcalcpol' ] for k in old_kwargs: try: kwargs.pop(k) except KeyError: pass self.kwargs = kwargs if 'ISPIN' not in uis: if magnetic_check(structure): uis.update({'ISPIN': 2}) else: uis.update({'ISPIN': 1}) if uis['ISPIN'] == 1: if 'MAGMON' in uis.keys(): uis.pop['MAGMOM'] for key in uis.keys(): if key not in ElasticSet.CONFIG['INCAR']: if key in {'NELM', 'EDIFF', 'NEDOS', 'KPOINT_BSE'}: continue ElasticSet.CONFIG['INCAR'][key] = uis[key] elif key == 'ISPIN': ElasticSet.CONFIG['INCAR'][key] = uis[key] elif key == 'ISMEAR': ElasticSet.CONFIG['INCAR'][key] = uis[key] elif key == 'SIGMA': ElasticSet.CONFIG['INCAR'][key] = uis[key] if 'ISPIN' in ElasticSet.CONFIG['INCAR']: if ElasticSet.CONFIG['INCAR']['ISPIN'] == 1: if 'MAGMOM' in ElasticSet.CONFIG['INCAR']: ElasticSet.CONFIG['INCAR'].pop('MAGMOM') if 'SIGMA' in ElasticSet.CONFIG[ 'INCAR'] and 'ISMEAR' in ElasticSet.CONFIG['INCAR']: if ElasticSet.CONFIG['INCAR']['ISMEAR'] == -5: ElasticSet.CONFIG['INCAR'].pop('SIGMA') from pymatgen.io.vasp.inputs import Kpoints if metal_check(structure): grid_density = 15625 #ElasticSet.CONFIG['INCAR']['ISMEAR'] = 1 #ElasticSet.CONFIG['INCAR']['SIGMA'] = 0.2 else: grid_density = 8000 kpoints = Kpoints.automatic_gamma_density(structure, grid_density) ElasticSet.CONFIG['KPOINTS'] = kpoints pot = kwargs.get('user_potcar_functional', None) if pot: ElasticSet.CONFIG['POTCAR_FUNCTIONAL'] = pot kwargs.update( {'user_potcar_functional': ElasticSet.CONFIG['POTCAR_FUNCTIONAL']}) kwargs.update({'user_incar_settings': ElasticSet.CONFIG['INCAR']}) super(ElasticSet, self).__init__(structure, ElasticSet.CONFIG, sort_structure=False, **kwargs)
class BornChargeSet(DictSet): """Set tuned for metal relaxations (correct smearing). Add `isif` parameter to the set to easily allow for overriding ISIF setting. Kpoints have a 6000 reciprocal density default. Provide by Yi Wang, Aug. 24, 2020 """ CONFIG = _load_yaml_config("MPRelaxSet") CONFIG['KPOINTS'].update({ 'grid_density': 8000, }) CONFIG['KPOINTS'].pop('reciprocal_density') # to be explicit CONFIG['INCAR'].update({ "LEPSILON": True, #For Born Effective Charge "NCORE": 1, #"NPAR": 1, #"LCALCEPS": True, #For Born Effective Charge "LRPA": False, 'EDIFF_PER_ATOM': 1e-6, 'ENCUT': 520, # MP compatibility 'ISMEAR': 0, "NSW": 0, "IBRION": -1, 'LREAL': False, 'ALGO': 'NORMAL', # other settings from MPStaticSet "LCHARG": False, "LWAVE": False, "ICHARG": 2, }) CONFIG['POTCAR_FUNCTIONAL'] = 'PBE' CONFIG['POTCAR'].update(POTCAR_UPDATES) def __init__(self, structure, isif=2, **kwargs): # pop the old kwargs, backwards compatibility from the complex StaticSet self.isif = isif uis = copy.deepcopy(kwargs.get('user_incar_settings', {})) """ old_kwargs = ['prev_incar', 'prev_kpoints', 'grid_density', 'lepsilon', 'lcalcpol', \ 'user_potcar_functional', 'user_incar_settings'] """ old_kwargs = [ 'prev_incar', 'prev_kpoints', 'grid_density', 'lepsilon', 'lcalcpol' ] for k in old_kwargs: try: kwargs.pop(k) except KeyError: pass self.kwargs = kwargs if 'ISPIN' not in uis: if magnetic_check(structure): uis.update({'ISPIN': 2}) else: uis.update({'ISPIN': 1}) else: if uis['ISPIN'] == 1: if 'MAGMON' in uis.keys(): uis.pop['MAGMOM'] for key in uis.keys(): if key not in BornChargeSet.CONFIG['INCAR']: if key in {'NELM', 'EDIFF', 'NEDOS', 'KPOINT_BSE'}: continue BornChargeSet.CONFIG['INCAR'][key] = uis[key] elif key == 'ISPIN': BornChargeSet.CONFIG['INCAR'][key] = uis[key] elif key == 'ISMEAR': BornChargeSet.CONFIG['INCAR'][key] = uis[key] elif key == 'SIGMA': BornChargeSet.CONFIG['INCAR'][key] = uis[key] if 'ISPIN' in BornChargeSet.CONFIG['INCAR']: if BornChargeSet.CONFIG['INCAR']['ISPIN'] == 1: if 'MAGMOM' in BornChargeSet.CONFIG['INCAR']: BornChargeSet.CONFIG['INCAR'].pop('MAGMOM') if 'SIGMA' in BornChargeSet.CONFIG[ 'INCAR'] and 'ISMEAR' in BornChargeSet.CONFIG['INCAR']: if BornChargeSet.CONFIG['INCAR']['ISMEAR'] == -5: BornChargeSet.CONFIG['INCAR'].pop('SIGMA') pot = kwargs.get('user_potcar_functional', None) if pot: BornChargeSet.CONFIG['POTCAR_FUNCTIONAL'] = pot kwargs.update({ 'user_potcar_functional': BornChargeSet.CONFIG['POTCAR_FUNCTIONAL'] }) kwargs.update({'user_incar_settings': BornChargeSet.CONFIG['INCAR']}) super(BornChargeSet, self).__init__(structure, BornChargeSet.CONFIG, sort_structure=False, **kwargs)
class RelaxSet(DictSet): """ Set for performing relaxations. The smearing must be set to give the correct forces. The default is tuned for metal relaxations. Kpoints have a 8000 kpoints per reciprocal atom default. """ CONFIG = _load_yaml_config("MPRelaxSet") # we never are comparing relaxations, only using them for optimizing structures. CONFIG['INCAR'].pop('ENCUT') # use the ENCUT set by PREC CONFIG['KPOINTS'].update({ 'grid_density': 8000, }) CONFIG['KPOINTS'].pop('reciprocal_density') # to be explicit CONFIG['INCAR'].update({ 'EDIFF_PER_ATOM': 1e-7, 'ISMEAR': 1, 'SIGMA': 0.2, 'LREAL': False, 'PREC': 'Accurate', 'ALGO': 'NORMAL', "LORBIT": 11, 'LWAVE': False, 'LCHARG': False, 'ISIF': 3, "ICHARG": 2, 'ENCUT': 520, }) # now we reset the potentials CONFIG['POTCAR_FUNCTIONAL'] = 'PBE' CONFIG['POTCAR'].update(POTCAR_UPDATES) def __init__(self, structure, volume_relax=False, isif=None, a_kwargs={}, **kwargs): """If volume relax is True, will do volume only, ISIF 7""" self.kwargs = copy.deepcopy(kwargs) self.volume_relax = volume_relax self.isif = isif self.a_kwargs = a_kwargs uis = copy.deepcopy(self.kwargs.get('user_incar_settings', {})) new_config = copy.deepcopy(RelaxSet.CONFIG) if self.volume_relax and self.isif is not None: raise ValueError( "isif cannot have a value while volume_relax is True.") if self.volume_relax: uis.update({'ISIF': 7}) #uis['ISIF'] = 7 if self.isif is not None: uis.update({'ISIF': self.isif}) if 'ISPIN' not in uis: if magnetic_check(structure): uis.update({'ISPIN': 2}) else: uis.update({'ISPIN': 1}) if 'magmom' in uis: if 'MAGMOM' in new_config['INCAR']: new_config['INCAR'].pop('MAGMOM') elif uis['ISPIN'] == 1: if 'MAGMON' in uis.keys(): uis.pop['MAGMOM'] if 'MAGMON' in new_config['INCAR']: new_config['INCAR'].pop['MAGMOM'] settings = self.a_kwargs.get('settings', {}) new_vasp_settings = settings.get('Relax_settings', None) or uis.get( 'Relax_settings', None) if new_vasp_settings: for ff in new_vasp_settings: if ff.lower() == 'prec': if 'ENCUT' in new_config['INCAR']: new_config['INCAR'].pop('ENCUT') new_config['INCAR'].update({ff: new_vasp_settings.get(ff)}) elif ff == 'grid_density': new_config['KPOINTS'].update( {ff: new_vasp_settings.get(ff)}) elif ff == 'k_mesh': kpoints = Kpoints(kpts=new_vasp_settings.get(ff)) new_config['KPOINTS'] = kpoints else: new_config['INCAR'].update({ff: new_vasp_settings.get(ff)}) new_config['INCAR'].update(uis) pot = self.kwargs.get('user_potcar_functional', None) if pot: new_config['POTCAR_FUNCTIONAL'] = pot super(RelaxSet, self).__init__(structure, new_config, sort_structure=False, **self.kwargs)
class ElasticSet(DictSet): """Set tuned for metal relaxations (correct smearing). Add `isif` parameter to the set to easily allow for overriding ISIF setting. Kpoints have a 6000 reciprocal density default. """ CONFIG = _load_yaml_config("MPRelaxSet") # 'EDIFF_PER_ATOM': 1e-6, CONFIG['INCAR'] = { 'EDIFF': 1e-6, #'ENCUT': 520, # MP compatibility 'ISMEAR': -5, "IBRION": 2, 'LREAL': False, 'ALGO': 'NORMAL', # other settings from MPStaticSet "LAECHG": True, "LCHARG": True, "LWAVE": False, "LORBIT": 11, "LVHAR": True, "ICHARG": 0, "NSW": 99, #"MAGMOM": CONFIG['INCAR']['MAGMOM'], "ISPIN": 2, "ISIF": 2, "PREC": "High" } # now we reset the potentials CONFIG['POTCAR_FUNCTIONAL'] = 'PBE' CONFIG['POTCAR'].update(POTCAR_UPDATES) def __init__(self, structure, a_kwargs={}, **kwargs): # pop the old kwargs, backwards compatibility from the complex StaticSet self.a_kwargs = a_kwargs uis = copy.deepcopy(kwargs.get('user_incar_settings', {})) new_config = copy.deepcopy(ElasticSet.CONFIG) if metal_check(structure): grid_density = 15625 else: grid_density = 8000 user_kpoints_settings = kwargs.get('user_kpoints_settings', {}) grid_density = user_kpoints_settings.get( 'grid_density') or grid_density old_kwargs = ['prev_incar', 'prev_kpoints', 'grid_density', 'lepsilon', 'lcalcpol', \ 'user_incar_settings', 'user_kpoints_settings'] for k in old_kwargs: try: kwargs.pop(k) except KeyError: pass self.kwargs = copy.deepcopy(kwargs) if 'ISPIN' not in uis: if magnetic_check(structure): uis.update({'ISPIN': 2}) else: uis.update({'ISPIN': 1}) if 'magmom' in uis: if 'MAGMOM' in new_config['INCAR']: new_config['INCAR'].pop('MAGMOM') elif uis['ISPIN'] == 1: if 'MAGMON' in uis.keys(): uis.pop['MAGMOM'] if 'MAGMON' in new_config['INCAR']: new_config['INCAR'].pop['MAGMOM'] for key in uis.keys(): if key == 'ENCUT': continue if key not in new_config['INCAR']: if key in {'NELM', 'EDIFF', 'NEDOS', 'KPOINT_BSE'}: continue new_config['INCAR'][key] = uis[key] elif key == 'ISPIN': new_config['INCAR'][key] = uis[key] elif key == 'ISMEAR': new_config['INCAR'][key] = uis[key] elif key == 'SIGMA': new_config['INCAR'][key] = uis[key] #avoid conflict betwwen HIHG and ENCUT """ for key in uis.keys(): if key == 'PREC': new_config['INCAR'][key] = uis[key] if 'ENCUT' in new_config['INCAR'] : new_config['INCAR'].pop('ENCUT') """ if 'SIGMA' in new_config['INCAR'] and 'ISMEAR' in new_config['INCAR']: if new_config['INCAR']['ISMEAR'] == -5: new_config['INCAR'].pop('SIGMA') from pymatgen.io.vasp.inputs import Kpoints kpoints = Kpoints(kpts=[ [31, 31, 31], ]) new_config['KPOINTS'] = kpoints from pymatgen.io.vasp.inputs import Kpoints settings = self.a_kwargs.get('settings', {}) new_vasp_settings = settings.get('Elastic_settings', None) or uis.get( 'Elastic_settings', None) if new_vasp_settings: for ff in new_vasp_settings: if ff.lower() == 'prec': if 'ENCUT' in new_config['INCAR']: new_config['INCAR'].pop('ENCUT') new_config['INCAR'].update({ff: new_vasp_settings.get(ff)}) elif ff == 'grid_density': new_config['KPOINTS'].update( {ff: new_vasp_settings.get(ff)}) elif ff == 'k_mesh': kpoints = Kpoints(kpts=new_vasp_settings.get(ff)) new_config['KPOINTS'] = kpoints else: new_config['INCAR'].update({ff: new_vasp_settings.get(ff)}) pot = self.kwargs.get('user_potcar_functional', None) if pot: new_config['POTCAR_FUNCTIONAL'] = pot super(ElasticSet, self).__init__(structure, new_config, sort_structure=False, **self.kwargs) self.config = new_config
class BornChargeSet(DictSet): """Set tuned for metal relaxations (correct smearing). Add `isif` parameter to the set to easily allow for overriding ISIF setting. Kpoints have a 6000 reciprocal density default. Provide by Yi Wang, Aug. 24, 2020 """ CONFIG = _load_yaml_config("MPRelaxSet") CONFIG['KPOINTS'].update({ 'grid_density': 8000, }) CONFIG['KPOINTS'].pop('reciprocal_density') # to be explicit CONFIG['INCAR'].update({ "LEPSILON": True, #For Born Effective Charge "NCORE": 1, #"NPAR": 1, #"LCALCEPS": True, #For Born Effective Charge "LRPA": False, 'EDIFF_PER_ATOM': 1e-6, #'ENCUT': 520, # MP compatibility 'ISMEAR': 0, "NSW": 0, "LORBIT": 11, "IBRION": -1, 'LREAL': False, 'ALGO': 'NORMAL', # other settings from MPStaticSet "LCHARG": False, "LWAVE": False, "ICHARG": 2, "PREC": "High" }) CONFIG['POTCAR_FUNCTIONAL'] = 'PBE' CONFIG['POTCAR'].update(POTCAR_UPDATES) def __init__(self, structure, isif=2, a_kwargs={}, **kwargs): # pop the old kwargs, backwards compatibility from the complex StaticSet self.a_kwargs = a_kwargs self.isif = isif uis = copy.deepcopy(kwargs.get('user_incar_settings', {})) new_config = copy.deepcopy(BornChargeSet.CONFIG) """ old_kwargs = ['prev_incar', 'prev_kpoints', 'grid_density', 'lepsilon', 'lcalcpol', \ 'user_potcar_functional', 'user_incar_settings'] """ old_kwargs = [ 'prev_incar', 'prev_kpoints', 'grid_density', 'lepsilon', 'lcalcpol' ] for k in old_kwargs: try: kwargs.pop(k) except KeyError: pass self.kwargs = copy.deepcopy(kwargs) if 'LCALCEPS' in uis: if 'LEPSILON' in new_config['INCAR']: new_config['INCAR'].pop('LEPSILON') if 'ISPIN' not in uis: if magnetic_check(structure): uis.update({'ISPIN': 2}) else: uis.update({'ISPIN': 1}) if 'magmom' in uis: if 'MAGMOM' in new_config['INCAR']: new_config['INCAR'].pop('MAGMOM') elif uis['ISPIN'] == 1: if 'MAGMON' in uis.keys(): uis.pop['MAGMOM'] if 'MAGMON' in new_config['INCAR']: new_config['INCAR'].pop['MAGMOM'] for key in uis.keys(): if key == 'ENCUT': continue if key not in new_config['INCAR']: if key in {'NELM', 'EDIFF', 'NEDOS', 'KPOINT_BSE'}: continue new_config['INCAR'][key] = uis[key] elif key == 'ISPIN': new_config['INCAR'][key] = uis[key] elif key == 'ISMEAR': new_config['INCAR'][key] = uis[key] elif key == 'SIGMA': new_config['INCAR'][key] = uis[key] if 'SIGMA' in new_config['INCAR'] and 'ISMEAR' in new_config['INCAR']: if new_config['INCAR']['ISMEAR'] == -5: new_config['INCAR'].pop('SIGMA') from pymatgen.io.vasp.inputs import Kpoints settings = self.a_kwargs.get('settings', {}) new_vasp_settings = settings.get('Born_settings', None) or uis.get( 'Born_settings', None) if new_vasp_settings: for ff in new_vasp_settings: if ff.lower() == 'prec': if 'ENCUT' in new_config['INCAR']: new_config['INCAR'].pop('ENCUT') new_config['INCAR'].update({ff: new_vasp_settings.get(ff)}) elif ff == 'grid_density': new_config['KPOINTS'].update( {ff: new_vasp_settings.get(ff)}) elif ff == 'k_mesh': kpoints = Kpoints(kpts=new_vasp_settings.get(ff)) new_config['KPOINTS'] = kpoints else: new_config['INCAR'].update({ff: new_vasp_settings.get(ff)}) pot = self.kwargs.get('user_potcar_functional', None) if pot: new_config['POTCAR_FUNCTIONAL'] = pot super(BornChargeSet, self).__init__(structure, new_config, sort_structure=False, **self.kwargs)
class StaticSet(DictSet): """Set tuned for metal relaxations (correct smearing). Add `isif` parameter to the set to easily allow for overriding ISIF setting. Kpoints have a 6000 reciprocal density default. """ CONFIG = _load_yaml_config("MPRelaxSet") CONFIG['KPOINTS'].update({ 'grid_density': 8000, }) CONFIG['KPOINTS'].pop('reciprocal_density') # to be explicit CONFIG['INCAR'].update({ 'EDIFF_PER_ATOM': 1e-6, 'ENCUT': 520, # MP compatibility 'ISMEAR': -5, "NSW": 0, "IBRION": -1, 'LREAL': False, 'ALGO': 'NORMAL', # other settings from MPStaticSet "LAECHG": True, "LCHARG": True, "LWAVE": False, "LORBIT": 11, "LVHAR": True, "ICHARG": 2, "NEDOS": 5001, }) # now we reset the potentials CONFIG['POTCAR_FUNCTIONAL'] = 'PBE' CONFIG['POTCAR'].update(POTCAR_UPDATES) def __init__(self, structure, isif=2, a_kwargs={}, **kwargs): # pop the old kwargs, backwards compatibility from the complex StaticSet self.isif = isif self.a_kwargs = a_kwargs old_kwargs = [ 'prev_incar', 'prev_kpoints', 'grid_density', 'lepsilon', 'lcalcpol' ] for k in old_kwargs: try: kwargs.pop(k) except KeyError: pass self.kwargs = copy.deepcopy(kwargs) uis = copy.deepcopy(self.kwargs.get('user_incar_settings', {})) uis['ISIF'] = isif new_config = copy.deepcopy(StaticSet.CONFIG) if 'ISPIN' not in uis: if magnetic_check(structure): uis.update({'ISPIN': 2}) else: uis.update({'ISPIN': 1}) if 'magmom' in uis: if 'MAGMOM' in new_config['INCAR']: new_config['INCAR'].pop('MAGMOM') elif uis['ISPIN'] == 1: if 'MAGMON' in uis.keys(): uis.pop['MAGMOM'] if 'MAGMON' in new_config['INCAR']: new_config['INCAR'].pop['MAGMOM'] settings = self.a_kwargs.get('settings', {}) new_vasp_settings = settings.get('Static_settings', None) or uis.get( 'Static_settings', None) if new_vasp_settings: for ff in new_vasp_settings: if ff.lower() == 'prec': if 'ENCUT' in new_config['INCAR']: new_config['INCAR'].pop('ENCUT') new_config['INCAR'].update({ff: new_vasp_settings.get(ff)}) elif ff == 'grid_density': new_config['KPOINTS'].update( {ff: new_vasp_settings.get(ff)}) elif ff == 'k_mesh': kpoints = Kpoints(kpts=new_vasp_settings.get(ff)) new_config['KPOINTS'] = kpoints else: new_config['INCAR'].update({ff: new_vasp_settings.get(ff)}) new_config['INCAR'].update(uis) pot = self.kwargs.get('user_potcar_functional', None) if pot: new_config['POTCAR_FUNCTIONAL'] = pot super(StaticSet, self).__init__(structure, new_config, sort_structure=False, **self.kwargs) self.config = new_config
class ForceConstantsSet(DictSet): """ Set for calculating force constants calculations. Force constants are calculated by the finite difference method with symmetry considered. The smearing must be set to give the correct forces. The default is tuned for metals. Kpoints have a 8000 kpoints per reciprocal atom default. """ CONFIG = _load_yaml_config("MPRelaxSet") # we never are comparing relaxations, only using them for optimizing structures. CONFIG['KPOINTS'].update({ 'grid_density': 8000, }) CONFIG['KPOINTS'].pop('reciprocal_density') # to be explicit CONFIG['INCAR'].pop('ENCUT') # use the ENCUT set by PREC CONFIG['INCAR'].update({ 'EDIFF': 5e-7, 'ISMEAR': 1, 'SIGMA': 0.2, 'LREAL': False, "LORBIT": 11, 'ISIF': 2, # only calculate the forces, stress tensor is not needed 'IBRION': 6, # calculate force constants by finite differences with symmetry 'POTIM': 0.015, # displacement distance 'NFREE': 2, # how many displacments to do. 2 gives +POTIM and -POTIM 'NSW': 1, # backwards compatibility setting 'PREC': 'Accurate', 'ALGO': 'Fast', 'SYMPREC': 1e-4, # some supercells seem to have issues with primcel VASP algorithm "ICHARG": 2, }) # now we reset the potentials CONFIG['POTCAR_FUNCTIONAL'] = 'PBE' CONFIG['POTCAR'].update(POTCAR_UPDATES) def __init__(self, structure, a_kwargs={}, **kwargs): self.kwargs = copy.deepcopy(kwargs) self.a_kwargs = a_kwargs uis = copy.deepcopy(self.kwargs.get('user_incar_settings', {})) new_config = copy.deepcopy(ForceConstantsSet.CONFIG) if 'ISPIN' not in uis: if magnetic_check(structure): uis.update({'ISPIN': 2}) else: uis.update({'ISPIN': 1}) if 'magmom' in uis: if 'MAGMOM' in new_config['INCAR']: new_config['INCAR'].pop('MAGMOM') elif uis['ISPIN'] == 1: if 'MAGMON' in uis.keys(): uis.pop['MAGMOM'] if 'MAGMON' in new_config['INCAR']: new_config['INCAR'].pop['MAGMOM'] new_config['INCAR'].update(uis) from pymatgen.io.vasp.inputs import Kpoints """ user_kpoints_settings = kwargs.get('user_kpoints_settings', {}) grid_density = user_kpoints_settings.get('grid_density') or None if grid_density is not None: #new_config['KPOINTS'].update({'grid_density': grid_density}) new_config['INCAR'].update({'PREC': 'High'}) kpoints = Kpoints.automatic_gamma_density(structure, grid_density) new_config['KPOINTS'] = kpoints """ settings = self.a_kwargs.get('settings', {}) new_vasp_settings = settings.get('Forceconstant_settings', None) or uis.get( 'Forceconstant_settings', None) if new_vasp_settings: for ff in new_vasp_settings: if ff.lower() == 'prec': if 'ENCUT' in new_config['INCAR']: new_config['INCAR'].pop('ENCUT') new_config['INCAR'].update({ff: new_vasp_settings.get(ff)}) elif ff == 'grid_density': new_config['KPOINTS'].update( {ff: new_vasp_settings.get(ff)}) elif ff == 'k_mesh': kpoints = Kpoints(kpts=new_vasp_settings.get(ff)) new_config['KPOINTS'] = kpoints else: new_config['INCAR'].update({ff: new_vasp_settings.get(ff)}) else: kpoints = Kpoints(kpts=[ [3, 3, 3], ]) new_config['KPOINTS'] = kpoints pot = self.kwargs.get('user_potcar_functional', None) if pot: new_config['POTCAR_FUNCTIONAL'] = pot super(ForceConstantsSet, self).__init__(structure, new_config, sort_structure=False, force_gamma=True, **self.kwargs)