def monkhorst_list(cls): """ Initialize Monkhorst grid from a list explicitly defining the number of kpoint subdivisions along the crystal axis Example: .. code-block:: python Automatic Kpoint Scheme 0 Monkhorst 4 4 4 """ if cls.kpoint_params['sympath'] is not None: warnings.warn("Explicit monkhorst grid mode: Ignoring defined " "high symmetry path object") kpoints = cls.kpoint_params['kpoints'] if len(kpoints) != 3: raise KpointWrapperError("Expected list of length 3 for explict " "k-point grid input") shift = cls.kpoint_params['shift'] or [.0, .0, .0] if len(shift) != 3: raise KpointWrapperError("Expected list of length 3 for k-point " "grid shift") return Kpoints.monkhorst_automatic(kpts=kpoints, shift=shift)
def complete_parameter_list(cls): """ Complete the parameter list and perform minimal initial checking """ # only check for non-optional parameters common to all initialization # modes (delegate more specialized checks to the actual initialization # routines) if 'mode' not in cls.input_kpoints: raise KpointWrapperError("Missing non-optional parameter 'mode'") if 'kpoints' not in cls.input_kpoints: raise KpointWrapperError("Missing non-optional parameter " "'kpoints'") # check if set mode has one of the accepted values if cls.input_kpoints['mode'] not in cls._VALID_INIT_MODES: raise KpointWrapperError("Unknown value '{}' set for parameter " "'mode' (Allowed values: '{}'".format( cls.input_kpoints['mode'], cls._VALID_INIT_MODES)) # complement user defined parameter to complete the parameter list cls.kpoint_params = { 'mode': cls.input_kpoints.get('mode'), 'kpoints': cls.input_kpoints.get('kpoints'), 'shift': cls.input_kpoints.get('shift', None), 'sympath': cls.input_kpoints.get('sympath', None), }
def line_int(cls): """ Initialize list of kpoints along a high-symmetry path through the Brillouin zone. Uses a path defined by the pymatgen HighSymmPath class with a defined number of kpoint subdivisions between the path nodes. Example:: Line_mode KPOINTS file 100 Line_mode Reciprocal 0.0 0.0 0.0 ! Gamma 0.0 0.5 0.0 ! X 0.0 0.5 0.0 ! X ... 0.0 0.5 0.0 ! X 0.5 0.5 0.0 ! M 0.5 0.5 0.5 ! R """ if cls.kpoint_params['shift'] is not None: warnings.warn("Line kpoint mode: Ignoring defined shift") if cls.kpoint_params['sympath'] is None: raise KpointWrapperError("Missing non-optional kpoint line mode " "parameter 'sympath'") divisions = cls.kpoint_params['kpoints'] sympath = cls.kpoint_params['sympath'] return Kpoints.automatic_linemode(divisions, sympath)
def structure_from_input(cls): """ Obtain :class:`~pymatgen.core.structure.Structure` object from the given input structure """ if isinstance(cls.input_structure, Structure): return cls.input_structure elif isinstance(cls.input_structure, StructureData): return cls.input_structure.get_pymatgen_structure() elif isinstance(cls.input_structure, Poscar): return cls.input_structure.structure else: raise KpointWrapperError("Unsupported structure type '{}'".format( type(cls.input_structure)))
def gamma_list(cls): """ Initialize gamma grid from a list explicitly defining the number of kpoint subdivisions along the crystal axis Example:: Automatic Kpoint Scheme 0 Gamma 5 5 5 """ if cls.kpoint_params['sympath'] is not None: warnings.warn("Explicit gamma grid mode: Ignoring defined high " "symmetry path object") kpoints = cls.kpoint_params['kpoints'] if len(kpoints) != 3: raise KpointWrapperError("Expected list of length 3 for explict " "k-point grid input") shift = cls.kpoint_params['shift'] or [.0, .0, .0] if len(shift) != 3: raise KpointWrapperError("Expected list of length 3 for k-point " "grid shift") return Kpoints.gamma_automatic(kpts=kpoints, shift=shift)
def validate_and_initialize(cls): """ Initialize a new Kpoint object from user inputs """ cls.complete_parameter_list() try: initialization_function_name = cls.build_init_mode() init_kpoints = getattr(cls, initialization_function_name) except AttributeError: raise KpointWrapperError("Unsupported initialization mode '{}' " "for given parameters '{}'".format( initialization_function_name, cls.kpoint_params)) kpoint_object = init_kpoints() return kpoint_object
def gamma_float(cls): """ Initialize gamma grid using a given kpoint density. Enforces the usage of gamma grids. Example:: Automatic Kpoint Scheme 0 Gamma 5 5 5 """ # check if required input structure was given if cls.input_structure is None: raise KpointWrapperError("Missing non-optional kpoint density " "parameter 'structure'") if cls.kpoint_params['sympath'] is not None: warnings.warn("Gamma density grid mode: Ignoring defined " "high symmetry path object") structure = cls.structure_from_input() kpoints = cls.kpoint_params['kpoints'] return Kpoints.automatic_density(structure, kpoints, force_gamma=True)
def monkhorst_float(cls): """ Initialize kpoint grid using a given kpoint density. If the number of subdivisions is even a Monkhorst grid is constructured whereas gamma grids are used for odd kpoint subdivisions Example:: Automatic Kpoint Scheme 0 Monkhorst 4 4 4 """ # check if required input structure was given if cls.input_structure is None: raise KpointWrapperError("Missing non-optional kpoint density " "parameter 'structure'") if cls.kpoint_params['sympath'] is not None: warnings.warn("Monkhorst density grid mode: Ignoring defined " "high symmetry path object") structure = cls.structure_from_input() kpoints = cls.kpoint_params['kpoints'] return Kpoints.automatic_density(structure, kpoints, force_gamma=False)