Esempio n. 1
0
    def test_castep_cell_null_init(self):
        null_cell = CastepCell()
        self.assertEqual(null_cell.blocks, {})
        self.assertEqual(null_cell.tags, {})

        with self.assertRaises(ValueError):
            structure = null_cell.structure
Esempio n. 2
0
 def test_castep_cell_from_structure(self):
     cell = CastepCell.from_structure(self.si_structure)
     self.assertEqual(cell.blocks['lattice_cart'].values,
                      [['ang'], ['5.43', '0.0', '0.0'],
                       ['0.0', '5.43', '0.0'], ['0.0', '0.0', '5.43']])
     self.assertEqual(cell.blocks['positions_frac'].values[0],
                      ['Si', '0.0', '0.0', '0.0'])
     self.assertEqual(cell.blocks['positions_frac'].values[7],
                      ['Si', '0.75', '0.75', '0.25'])
Esempio n. 3
0
 def test_castep_cell_from_structure(self):
     cell = CastepCell.from_structure(self.si_structure)
     self.assertEqual(
         cell.blocks["lattice_cart"].values,
         [
             ["ang"],
             ["5.43", "0.0", "0.0"],
             ["0.0", "5.43", "0.0"],
             ["0.0", "0.0", "5.43"],
         ],
     )
     self.assertEqual(cell.blocks["positions_frac"].values[0],
                      ["Si", "0.0", "0.0", "0.0"])
     self.assertEqual(cell.blocks["positions_frac"].values[7],
                      ["Si", "0.75", "0.75", "0.25"])
Esempio n. 4
0
    def test_castep_cell_from_singlepoint_file(self):
        cc = CastepCell.from_file(self.zns_singlepoint_cell)
        self.assertEqual(set(cc.blocks.keys()),
                         set(('lattice_cart', 'positions_abs', 'species_pot')))
        self.assertEqual({k: v.value
                          for k, v in cc.tags.items()}, {
                              'fix_all_cell': ['true'],
                              'fix_all_ions': ['true'],
                              'symmetry_generate': ['true'],
                              'kpoint_mp_grid': ['4', '4', '4'],
                              'snap_to_symmetry': ['true']
                          })
        self.assertEqual(cc.blocks['species_pot'].values[1], ['S', 'NCP'])
        self.assertEqual(cc.blocks['species_pot'].comments, ['', ''])

        structure = cc.structure
        self.assertIsInstance(structure, Structure)
        assert_array_almost_equal(
            structure.lattice.matrix,
            [[0., 2.71, 2.71], [2.71, 0., 2.71], [2.71, 2.71, 0.]])
Esempio n. 5
0
    def test_castep_cell_from_singlepoint_file(self):
        cc = CastepCell.from_file(self.zns_singlepoint_cell)
        self.assertEqual(set(cc.blocks.keys()),
                         {"lattice_cart", "positions_abs", "species_pot"})
        self.assertEqual(
            {k: v.value
             for k, v in cc.tags.items()},
            {
                "fix_all_cell": ["true"],
                "fix_all_ions": ["true"],
                "symmetry_generate": ["true"],
                "kpoint_mp_grid": ["4", "4", "4"],
                "snap_to_symmetry": ["true"],
            },
        )
        self.assertEqual(cc.blocks["species_pot"].values[1], ["S", "NCP"])
        self.assertEqual(cc.blocks["species_pot"].comments, ["", ""])

        structure = cc.structure
        self.assertIsInstance(structure, Structure)
        assert_array_almost_equal(
            structure.lattice.matrix,
            [[0.0, 2.71, 2.71], [2.71, 0.0, 2.71], [2.71, 2.71, 0.0]],
        )
Esempio n. 6
0
def kgen(
    filename="POSCAR",
    code="vasp",
    directory=None,
    make_folders=False,
    symprec=0.01,
    kpts_per_split=None,
    ibzkpt=None,
    spg=None,
    density=60,
    phonon=False,
    mode="bradcrack",
    cart_coords=False,
    kpt_list=None,
    labels=None,
):
    """Generate KPOINTS files for VASP band structure calculations.

    This script provides a wrapper around several frameworks used to generate
    k-points along a high-symmetry path. The paths found in Bradley and
    Cracknell, SeeK-path, and pymatgen are all supported.

    It is important to note that the standard primitive cell symmetry is
    different between SeeK-path and pymatgen. If the correct the structure
    is not used, the high-symmetry points (and band path) may be invalid.

    Args:
        filename (:obj:`str`, optional): Path to VASP structure file. Default
            is ``POSCAR``.
        code (:obj:`str`, optional): Calculation type. Default is 'vasp';
            'questaal' also supported.
        directory (:obj:`str`, optional): The output file directory.
        make_folders (:obj:`bool`, optional): Generate folders and copy in
            required files (INCAR, POTCAR, POSCAR, and possibly CHGCAR) from
            the current directory.
        symprec (:obj:`float`, optional): The precision used for determining
            the cell symmetry.
        kpts_per_split (:obj:`int`, optional): If set, the k-points are split
            into separate k-point files (or folders) each containing the number
            of k-points specified. This is useful for hybrid band structure
            calculations where it is often intractable to calculate all
            k-points in the same calculation.
        ibzkpt (:obj:`str`, optional): Path to IBZKPT file. If set, the
            generated k-points will be appended to the k-points in this file
            and given a weight of 0. This is necessary for hybrid band
            structure calculations.
        spg (:obj:`str` or :obj:`int`, optional): The space group international
            number or symbol to override the symmetry determined by spglib.
            This is not recommended and only provided for testing purposes.
            This option will only take effect when ``mode = 'bradcrack'``.
        line_density (:obj:`int`, optional): Density of k-points along the
            path.
        phonon (:obj:`bool`, optional): Write phonon q-point path instead of
            k-points. (Not appropriate for most codes.)
        mode (:obj:`str`, optional): Method used for calculating the
            high-symmetry path. The options are:

            bradcrack
                Use the paths from Bradley and Cracknell. See [brad]_.

            pymatgen
                Use the paths from pymatgen. See [curt]_.

            latimer-munro
                Use the paths from Latimer & Munro. See [lm]_.

            seekpath
                Use the paths from SeeK-path. See [seek]_.

        cart_coords (:obj:`bool`, optional): Whether the k-points are returned
            in cartesian or reciprocal coordinates. Defaults to ``False``
            (fractional coordinates).
        kpt_list (:obj:`list`, optional): List of k-points to use, formatted as
            a list of subpaths, each containing a list of fractional k-points.
            For example::

                [ [[0., 0., 0.], [0., 0., 0.5]],
                  [[0.5, 0., 0.], [0.5, 0.5, 0.]] ]

            Will return points along ``0 0 0 -> 0 0 1/2 | 1/2 0 0
            -> 1/2 1/2 0``
        path_labels (:obj:`list`, optional): The k-point labels. These should
            be provided as a :obj:`list` of :obj:`str` for each subpath of the
            overall path. For example::

                [ ['Gamma', 'Z'], ['X', 'M'] ]

            combined with the above example for ``kpt_list`` would indicate the
            path: Gamma -> Z | X -> M. If no labels are provided, letters from
            A -> Z will be used instead. If a label begins with '@' it will be
            concealed when plotting with sumo-bandplot.
    """
    if code.lower() == "vasp":
        structure = Poscar.from_file(filename).structure
    elif code.lower() == "questaal":
        if filename.split(".")[0] == "site":
            site = QuestaalSite.from_file(filename)
            structure = site.structure
            alat = site.alat
        else:
            structure = QuestaalInit.from_file(filename).structure
            alat = None
    elif code.lower() == "castep":
        if cart_coords:
            logging.warning("Ignoring request for Cartesian coordinates: "
                            "not applicable to CASTEP band structure format.")
            cart_coords = False
        if ibzkpt:
            logging.warning('Ignoring request to use IBZKPT ("hybrid mode"), '
                            "for CASTEP workflow the SCF mesh should already "
                            "be set in input .cell file.")
        structure = CastepCell.from_file(filename).structure
    else:
        raise ValueError(f'Code "{code}" not recognized.')

    if phonon and (code.lower() not in phonon_supported_codes):
        logging.error("Cannot write phonon path for {code}. "
                      "Supported codes: {supported}".format(
                          code=code,
                          supported=", ".join(phonon_supported_codes)))
        sys.exit()

    kpath, kpoints, labels = get_path_data(
        structure,
        mode=mode,
        symprec=symprec,
        kpt_list=kpt_list,
        labels=labels,
        spg=spg,
        line_density=density,
        cart_coords=cart_coords,
    )

    logging.info("\nk-point label indices:")
    for i, label in enumerate(labels):
        if label:
            logging.info(f"\t{label}: {i + 1}")

    if not kpt_list and not np.allclose(structure.lattice.matrix,
                                        kpath.prim.lattice.matrix):
        prim_filename = f"{os.path.basename(filename)}_prim"
        if code.lower() == "questaal":
            QuestaalInit.from_structure(kpath.prim).to_file(prim_filename)
        elif code.lower() == "castep":
            CastepCell.from_structure(kpath.prim).to_file(prim_filename)

        else:
            kpath.prim.to(filename=prim_filename)

        logging.error(
            "\nWARNING: The input structure does not match the "
            "expected standard\nprimitive symmetry, the path may be "
            "incorrect! Use at your own risk.\n\nThe correct "
            "symmetry primitive structure has been saved as {}.".format(
                prim_filename))

    ibz = _parse_ibzkpt(ibzkpt)

    if ibz and kpts_per_split is None:
        logging.info("\nFound {} total kpoints in path, do you want to "
                     "split them up? (y/n)".format(len(kpoints)))
        if input()[0].lower() == "y":
            logging.info("How many kpoints per file?")
            kpts_per_split = int(input())

    if code.lower() == "vasp":
        sumo.io.vasp.write_kpoint_files(
            filename,
            kpoints,
            labels,
            make_folders=make_folders,
            ibzkpt=ibz,
            kpts_per_split=kpts_per_split,
            directory=directory,
            cart_coords=cart_coords,
        )

    elif code.lower() == "castep":
        sumo.io.castep.write_kpoint_files(
            filename,
            kpoints,
            labels,
            make_folders=make_folders,
            kpts_per_split=kpts_per_split,
            phonon=phonon,
            directory=directory,
        )

    elif code.lower() == "questaal":
        if cart_coords:
            kpoints = [kpoint / (2 * np.pi) for kpoint in kpoints]
            if alat is not None:
                logging.info(
                    f"Multiplying kpoint values by ALAT = {alat} Bohr")
                _bohr_to_angstrom = 0.5291772
                kpoints = [
                    kpoint * alat * _bohr_to_angstrom for kpoint in kpoints
                ]
        sumo.io.questaal.write_kpoint_files(
            filename,
            kpoints,
            labels,
            make_folders=make_folders,
            directory=directory,
            cart_coords=cart_coords,
        )