Exemple #1
0
    def kpoints(self):
        """
        Sets up the k-points for the static calculation.

        Returns:
            :class: pymatgen.io.vasp.inputs.Kpoints

        """
        settings = self.user_kpoints_settings or self._config_dict["KPOINTS"]

        if "k_resolution" in settings:
            # Use k_resolution to calculate kpoints
            k_kpoint_resolution = settings["k_resolution"]
            kpt_divisions = [
                int(np.ceil(l / k_kpoint_resolution))
                for l in self.structure.lattice.reciprocal_lattice.lengths
            ]

            return Kpoints.gamma_automatic(kpts=kpt_divisions)

        elif "gamma_density" in settings:
            return Kpoints.automatic_density_by_vol(
                self.structure,
                int(settings['gamma_density']),
                force_gamma=True)
        else:
            return super().kpoints
Exemple #2
0
    def test_static_constructors(self):
        kpoints = Kpoints.gamma_automatic([3, 3, 3], [0, 0, 0])
        self.assertEqual(kpoints.style, Kpoints.supported_modes.Gamma)
        self.assertEqual(kpoints.kpts, [[3, 3, 3]])
        kpoints = Kpoints.monkhorst_automatic([2, 2, 2], [0, 0, 0])
        self.assertEqual(kpoints.style, Kpoints.supported_modes.Monkhorst)
        self.assertEqual(kpoints.kpts, [[2, 2, 2]])
        kpoints = Kpoints.automatic(100)
        self.assertEqual(kpoints.style, Kpoints.supported_modes.Automatic)
        self.assertEqual(kpoints.kpts, [[100]])
        filepath = self.TEST_FILES_DIR / 'POSCAR'
        poscar = Poscar.from_file(filepath)
        kpoints = Kpoints.automatic_density(poscar.structure, 500)
        self.assertEqual(kpoints.kpts, [[1, 3, 3]])
        self.assertEqual(kpoints.style, Kpoints.supported_modes.Gamma)
        kpoints = Kpoints.automatic_density(poscar.structure, 500, True)
        self.assertEqual(kpoints.style, Kpoints.supported_modes.Gamma)
        kpoints = Kpoints.automatic_density_by_vol(poscar.structure, 1000)
        self.assertEqual(kpoints.kpts, [[6, 10, 13]])
        self.assertEqual(kpoints.style, Kpoints.supported_modes.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, Kpoints.supported_modes.Gamma)
        kpoints = Kpoints.from_string("""k-point mesh 
0
G
10 10 10
0.5 0.5 0.5
""")
        self.assertArrayAlmostEqual(kpoints.kpts_shift, [0.5, 0.5, 0.5])
Exemple #3
0
    def test_static_constructors(self):
        kpoints = Kpoints.gamma_automatic([3, 3, 3], [0, 0, 0])
        self.assertEqual(kpoints.style, Kpoints.supported_modes.Gamma)
        self.assertEqual(kpoints.kpts, [[3, 3, 3]])
        kpoints = Kpoints.monkhorst_automatic([2, 2, 2], [0, 0, 0])
        self.assertEqual(kpoints.style, Kpoints.supported_modes.Monkhorst)
        self.assertEqual(kpoints.kpts, [[2, 2, 2]])
        kpoints = Kpoints.automatic(100)
        self.assertEqual(kpoints.style, Kpoints.supported_modes.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, Kpoints.supported_modes.Monkhorst)
        kpoints = Kpoints.automatic_density(poscar.structure, 500, True)
        self.assertEqual(kpoints.style, Kpoints.supported_modes.Gamma)
        kpoints = Kpoints.automatic_density_by_vol(poscar.structure, 1000)
        self.assertEqual(kpoints.kpts, [[6, 11, 13]])
        self.assertEqual(kpoints.style, Kpoints.supported_modes.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, Kpoints.supported_modes.Gamma)
Exemple #4
0
    def test_static_constructors(self):
        kpoints = Kpoints.gamma_automatic([3, 3, 3], [0, 0, 0])
        self.assertEqual(kpoints.style, Kpoints.supported_modes.Gamma)
        self.assertEqual(kpoints.kpts, [[3, 3, 3]])
        kpoints = Kpoints.monkhorst_automatic([2, 2, 2], [0, 0, 0])
        self.assertEqual(kpoints.style, Kpoints.supported_modes.Monkhorst)
        self.assertEqual(kpoints.kpts, [[2, 2, 2]])
        kpoints = Kpoints.automatic(100)
        self.assertEqual(kpoints.style, Kpoints.supported_modes.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, [[1, 3, 3]])
        self.assertEqual(kpoints.style, Kpoints.supported_modes.Gamma)
        kpoints = Kpoints.automatic_density(poscar.structure, 500, True)
        self.assertEqual(kpoints.style, Kpoints.supported_modes.Gamma)
        kpoints = Kpoints.automatic_density_by_vol(poscar.structure, 1000)
        self.assertEqual(kpoints.kpts, [[6, 10, 13]])
        self.assertEqual(kpoints.style, Kpoints.supported_modes.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, Kpoints.supported_modes.Gamma)
        kpoints = Kpoints.from_string("""k-point mesh 
0
G
10 10 10
0.5 0.5 0.5
""")
        self.assertArrayAlmostEqual(kpoints.kpts_shift, [0.5, 0.5, 0.5])
Exemple #5
0
    def test_static_constructors(self):
        kpoints = Kpoints.gamma_automatic([3, 3, 3], [0, 0, 0])
        self.assertEqual(kpoints.style, Kpoints.supported_modes.Gamma)
        self.assertEqual(kpoints.kpts, [[3, 3, 3]])
        kpoints = Kpoints.monkhorst_automatic([2, 2, 2], [0, 0, 0])
        self.assertEqual(kpoints.style, Kpoints.supported_modes.Monkhorst)
        self.assertEqual(kpoints.kpts, [[2, 2, 2]])
        kpoints = Kpoints.automatic(100)
        self.assertEqual(kpoints.style, Kpoints.supported_modes.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, Kpoints.supported_modes.Monkhorst)
        kpoints = Kpoints.automatic_density(poscar.structure, 500, True)
        self.assertEqual(kpoints.style, Kpoints.supported_modes.Gamma)
        kpoints = Kpoints.automatic_density_by_vol(poscar.structure, 1000)
        self.assertEqual(kpoints.kpts, [[6, 11, 13]])
        self.assertEqual(kpoints.style, Kpoints.supported_modes.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, Kpoints.supported_modes.Gamma)
    def get_kpoints_object(self, step, structure):
        try:
            kpoints_tags = self.kpoints[step]
        except KeyError:
            return None

        if kpoints_tags['Type'] == 'automatic_density':
            K = Kpoints.automatic_density(structure,
                                          kpoints_tags['Grid Density'],
                                          kpoints_tags['Force Gamma'])
        elif kpoints_tags['Type'] == 'automatic_density_by_vol':
            K = Kpoints.automatic_density_by_vol(
                structure,
                kpoints_tags['Grid Density per A^(-3) of Reciprocal Cell'],
                kpoints_tags['Force Gamma'])
        elif kpoints_tags['Type'] == 'automatic_gamma_density':
            K = Kpoints.automatic_gamma_density(structure,
                                                kpoints_tags['Grid Density'])
        elif kpoints_tags['Type'] == 'gamma_automatic':
            K = Kpoints.gamma_automatic(kpoints_tags["KPTS"],
                                        kpoints_tags["Shift"])
        elif kpoints_tags['Type'] == 'monkhorst_automatic':
            K = Kpoints.monkhorst_automatic(kpoints_tags["KPTS"],
                                            kpoints_tags["Shift"])
        else:
            print('Invalid kpoints generation type %s; fatal error' %
                  kpoints_tags['Type'])
            sys.exit(1)
        return K
Exemple #7
0
 def set_kpoints(self, kpoint):
     """
     set the kpoint
     """
     if self.Grid_type == 'M':
         self.kpoints = Kpoints.monkhorst_automatic(kpts=kpoint)
     elif self.Grid_type == 'A':
         self.kpoints = Kpoints.automatic(subdivisions=kpoint)
     elif self.Grid_type == 'G':
         self.kpoints = Kpoints.gamma_automatic(kpts=kpoint)
     elif self.Grid_type == '3DD':
         self.kpoints = Kpoints.automatic_density_by_vol(structure= \
                                                             self.poscar.structure, kppvol=kpoint)
     elif self.Grid_type == 'band':
         self.kpoints = Kpoints.automatic_linemode(divisions=kpoint, \
                                                   ibz=HighSymmKpath(self.poscar.structure))
Exemple #8
0
 def set_kpoints(self, kpoint):
     """
     set the kpoint
     """
     if self.Grid_type == 'M':
         self.kpoints = Kpoints.monkhorst_automatic(kpts=kpoint)
     elif self.Grid_type == 'A':
         self.kpoints = Kpoints.automatic(subdivisions=kpoint)
     elif self.Grid_type == 'G':
         self.kpoints = Kpoints.gamma_automatic(kpts=kpoint)
     elif self.Grid_type == '3DD':
         self.kpoints = Kpoints.automatic_density_by_vol(structure= \
                                                             self.poscar.structure,
                                                         kppvol=kpoint)
     elif self.Grid_type == 'band':
         self.kpoints = Kpoints.automatic_linemode(divisions=kpoint, \
                                                   ibz=HighSymmKpath(
                                                       self.poscar.structure))
Exemple #9
0
 def set_kpoints(self, kpoint):
     """
     set the kpoint
     """
     if self.Grid_type == 'M':
         self.kpoints = Kpoints.monkhorst_automatic(kpts = kpoint)
     elif self.Grid_type == 'A':
         self.kpoints = Kpoints.automatic(subdivisions = kpoint)
     elif self.Grid_type == 'G': 
         self.kpoints = Kpoints.gamma_automatic(kpts = kpoint)
     elif self.Grid_type == '3DD':
         self.kpoints = Kpoints.automatic_density_by_vol(structure=\
                        self.poscar.structure, kppvol=kpoint)
     elif self.Grid_type == 'band':
         self.kpoints = Kpoints.automatic_linemode(divisions=kpoint,\
                        ibz=HighSymmKpath(self.poscar.structure))
     name = self.kpoint_to_name(kpoint, self.Grid_type)
     job_dir = self.job_dir +os.sep+ self.key_to_name('KPOINTS') \
       + os.sep + name
     return job_dir
Exemple #10
0
 def set_kpoints(self, kpoint):
     """
     set the kpoint
     """
     if self.Grid_type == 'M':
         self.kpoints = Kpoints.monkhorst_automatic(kpts=kpoint)
     elif self.Grid_type == 'A':
         self.kpoints = Kpoints.automatic(subdivisions=kpoint)
     elif self.Grid_type == 'G':
         self.kpoints = Kpoints.gamma_automatic(kpts=kpoint)
     elif self.Grid_type == '3DD':
         self.kpoints = Kpoints.automatic_density_by_vol(structure= \
                                                             self.poscar.structure, kppvol=kpoint)
     elif self.Grid_type == 'band':
         self.kpoints = Kpoints.automatic_linemode(divisions=kpoint, \
                                                   ibz=HighSymmKpath(self.poscar.structure))
     name = self.kpoint_to_name(kpoint, self.Grid_type)
     job_dir = self.job_dir + os.sep + self.key_to_name('KPOINTS') \
               + os.sep + name
     return job_dir
Exemple #11
0
    def write_KPOINTS(
        POSCAR_input: str = "POSCAR",
        KPOINTS_output="KPOINTS.lobster",
        reciprocal_density: int = 100,
        isym: int = -1,
        from_grid: bool = False,
        input_grid: list = [5, 5, 5],
        line_mode: bool = True,
        kpoints_line_density: int = 20,
        symprec: float = 0.01,
    ):
        """
        writes a KPOINT file for lobster (only ISYM=-1 and ISYM=0 are possible), grids are gamma centered
        Args:
            POSCAR_input (str): path to POSCAR
            KPOINTS_output (str): path to output KPOINTS
            reciprocal_density (int): Grid density
            isym (int): either -1 or 0. Current Lobster versions only allow -1.
            from_grid (bool): If True KPOINTS will be generated with the help of a grid given in input_grid. Otherwise,
                they will be generated from the reciprocal_density
            input_grid (list): grid to generate the KPOINTS file
            line_mode (bool): If True, band structure will be generated
            kpoints_line_density (int): density of the lines in the band structure
            symprec (float): precision to determine symmetry
        """
        structure = Structure.from_file(POSCAR_input)
        if not from_grid:
            kpointgrid = Kpoints.automatic_density_by_vol(
                structure, reciprocal_density).kpts
            mesh = kpointgrid[0]
        else:
            mesh = input_grid

        # The following code is taken from: SpacegroupAnalyzer
        # we need to switch off symmetry here
        latt = structure.lattice.matrix
        positions = structure.frac_coords
        unique_species = []  # type: List[Any]
        zs = []
        magmoms = []

        for species, g in itertools.groupby(structure,
                                            key=lambda s: s.species):
            if species in unique_species:
                ind = unique_species.index(species)
                zs.extend([ind + 1] * len(tuple(g)))
            else:
                unique_species.append(species)
                zs.extend([len(unique_species)] * len(tuple(g)))

        for site in structure:
            if hasattr(site, "magmom"):
                magmoms.append(site.magmom)
            elif site.is_ordered and hasattr(site.specie, "spin"):
                magmoms.append(site.specie.spin)
            else:
                magmoms.append(0)

        # For now, we are setting magmom to zero. (Taken from INCAR class)
        cell = latt, positions, zs, magmoms
        # TODO: what about this shift?
        mapping, grid = spglib.get_ir_reciprocal_mesh(mesh,
                                                      cell,
                                                      is_shift=[0, 0, 0])

        # exit()
        # get the kpoints for the grid
        if isym == -1:
            kpts = []
            weights = []
            all_labels = []
            for gp in grid:
                kpts.append(gp.astype(float) / mesh)
                weights.append(float(1))
                all_labels.append("")
        elif isym == 0:
            # time reversal symmetry: k and -k are equivalent
            kpts = []
            weights = []
            all_labels = []
            newlist = [list(gp) for gp in list(grid)]
            mapping = []
            for gp in newlist:
                minus_gp = [-k for k in gp]
                if minus_gp in newlist and minus_gp not in [[0, 0, 0]]:
                    mapping.append(newlist.index(minus_gp))
                else:
                    mapping.append(newlist.index(gp))

            for igp, gp in enumerate(newlist):
                if mapping[igp] > igp:
                    kpts.append(np.array(gp).astype(float) / mesh)
                    weights.append(float(2))
                    all_labels.append("")
                elif mapping[igp] == igp:
                    kpts.append(np.array(gp).astype(float) / mesh)
                    weights.append(float(1))
                    all_labels.append("")

        else:
            ValueError("Only isym=-1 and isym=0 are allowed.")
        # line mode
        if line_mode:
            kpath = HighSymmKpath(structure, symprec=symprec)
            if not np.allclose(kpath.prim.lattice.matrix,
                               structure.lattice.matrix):
                raise ValueError(
                    "You are not using the standard primitive cell. The k-path is not correct. Please generate a "
                    "standard primitive cell first.")

            frac_k_points, labels = kpath.get_kpoints(
                line_density=kpoints_line_density, coords_are_cartesian=False)

            for k, f in enumerate(frac_k_points):
                kpts.append(f)
                weights.append(0.0)
                all_labels.append(labels[k])
        if isym == -1:
            comment = ("ISYM=-1, grid: " +
                       str(mesh) if not line_mode else "ISYM=-1, grid: " +
                       str(mesh) + " plus kpoint path")
        elif isym == 0:
            comment = ("ISYM=0, grid: " +
                       str(mesh) if not line_mode else "ISYM=0, grid: " +
                       str(mesh) + " plus kpoint path")

        KpointObject = Kpoints(
            comment=comment,
            style=Kpoints.supported_modes.Reciprocal,
            num_kpts=len(kpts),
            kpts=kpts,
            kpts_weights=weights,
            labels=all_labels,
        )

        KpointObject.write_file(filename=KPOINTS_output)
#!/usr/bin/env python3
from pymatgen import Structure
from pymatgen.io.vasp.inputs import Kpoints

density = 150

structure = Structure.from_file("POSCAR")
kmesh = Kpoints.automatic_density_by_vol(structure, density)
kmesh.write_file("KPOINTS")
Exemple #13
0
    def set_kpoints(self, kpoint=None, poscar=None, ibzkpth=None):
        """
        set the kpoint
        """
        # useful to check if a poscar is supplied from setup_poscar_jobs (most often the case)
        # or this is a single poscar use case
        if not poscar:
            poscar = self.poscar

        # splitting into two if elif branches means fewer if statements to check on
        # a run

        # Most general method of setting the k-points for
        # different grid types
        # NOTE: requires that at least one k-points value be passed
        # as a turn - knobs list value
        # this is not true for values that may be caculated out of
        # a database
        # use this part only if this is a non-database run for example
        # for k-points calibration

        if not self.database:

            if self.Grid_type == 'M':
                self.kpoints = Kpoints.monkhorst_automatic(kpts=kpoint)
            elif self.Grid_type == 'A':
                self.kpoints = Kpoints.automatic(subdivisions=kpoint)
            elif self.Grid_type == 'G':
                self.kpoints = Kpoints.gamma_automatic(kpts=kpoint)
            elif self.Grid_type == '3D_vol':
                self.kpoints = Kpoints.automatic_density_by_vol(structure=poscar.structure,
                                                                kppvol=kpoint)
            elif self.Grid_type == 'bulk_bands_pbe':
                self.kpoints = Kpoints.automatic_linemode(divisions=kpoint,
                                                          ibz=HighSymmKpath(
                                                              poscar.structure))

            elif self.Grid_type == 'D':
                self.kpoints = Kpoints.automatic_density(structure=poscar.structure,kppa=kpoint)

            elif self.Grid_type == 'Finer_G_Mesh':
                # kpoint is the scaling factor and self.kpoints is the old kpoint mesh
                self.logger.info('Setting Finer G Mesh for {0} by scale {1}'.format(kpoint, self.finer_kpoint))
                self.kpoints = Kpoints.gamma_automatic(kpts = \
                   [i * self.finer_kpoint for i in kpoint])
                self.logger.info('Finished scaling operation of k-mesh')

        # applicable for database runs
        # future constructs or settinsg can be activated via a yaml file
        # database yaml file or better still the input deck from its speification
        # decides what combination of input calibrate constructor settings to use
        # one of them being the grid_type tag

        elif self.database == 'twod':

            # set of kpoints settings according to the 2D database profile
            # the actual settings of k-points density
            # will in future come from any database input file set

            if self.Grid_type == 'hse_bands_2D_prep':
                kpoint_dict = Kpoints.automatic_gamma_density(poscar.structure,
                                                              200).as_dict()
                kpoint_dict['kpoints'][0][2] = 1  # remove z kpoints
                self.kpoints = Kpoints.from_dict(kpoint_dict)

            elif self.Grid_type == 'hse_bands_2D':
                # can at most return the path to the correct kpoints file
                # needs kpoints to be written out in instrument in a different way
                # not using the Kpoints object
                self.kpoints = get_2D_hse_kpoints(poscar.structure, ibzkpth)

            elif self.Grid_type == 'bands_2D':
                kpoint_dict = Kpoints.automatic_linemode(divisions=20,
                                                         ibz=HighSymmKpath(poscar.structure)).as_dict()
                self.kpoints = Kpoints.from_dict(kpoint_dict)

            elif self.Grid_type == 'relax_2D':
                # general relaxation settings for 2D
                kpoint_dict = Kpoints.automatic_gamma_density(poscar.structure,
                                                              1000).as_dict()
                kpoint_dict['kpoints'][0][2] = 1
                self.kpoints = Kpoints.from_dict(kpoint_dict)

            elif self.Grid_type == 'relax_3D':
                # general relaxation settings for 3D
                kpoint_dict = Kpoints.automatic_gamma_density(
                    poscar.structure, 1000)
                self.kpoints = Kpoints.from_dict(kpoint_dict)