Source code for aiida_quantumespresso.calculations.functions.create_kpoints_from_distance

# -*- coding: utf-8 -*-
"""Calculation function to compute a k-point mesh for a structure with a guaranteed minimum k-point distance."""
from aiida.engine import calcfunction


@calcfunction
[docs]def create_kpoints_from_distance(structure, distance, force_parity): """Generate a uniformly spaced kpoint mesh for a given structure. The spacing between kpoints in reciprocal space is guaranteed to be at least the defined distance. :param structure: the StructureData to which the mesh should apply :param distance: a Float with the desired distance between kpoints in reciprocal space :param force_parity: a Bool to specify whether the generated mesh should maintain parity :returns: a KpointsData with the generated mesh """ from aiida.orm import KpointsData from numpy import linalg epsilon = 1E-5 kpoints = KpointsData() kpoints.set_cell_from_structure(structure) kpoints.set_kpoints_mesh_from_density(distance.value, force_parity=force_parity.value) lengths_vector = [linalg.norm(vector) for vector in structure.cell] lengths_kpoint = kpoints.get_kpoints_mesh()[0] is_symmetric_cell = all(abs(length - lengths_vector[0]) < epsilon for length in lengths_vector) is_symmetric_mesh = all(length == lengths_kpoint[0] for length in lengths_kpoint) # If the vectors of the cell all have the same length, the kpoint mesh should be isotropic as well if is_symmetric_cell and not is_symmetric_mesh: nkpoints = max(lengths_kpoint) kpoints.set_kpoints_mesh([nkpoints, nkpoints, nkpoints]) return kpoints