Exemplo n.º 1
0
    def basic_test(self,
                   cell,
                   positions,
                   atomic_numbers,
                   check_bravais_lattice,
                   symprec=None):
        """
        Given a cell, the positions and the atomic numbers, checks
        that the bravais lattice is the expected one.

        :param cell: 3x3 list of lattice vectors
        :param positions: Nx3 list of (scaled) positions
        :param atomic_number: list of length N with the atomic numbers
        :param check_bravais_lattice: a string with the expected Bravais lattice 
            (e.g., 'tI', 'oF', ...)
        :param symprec: if specified, pass also the symprec to the code
        """
        import warnings

        from seekpath import hpkot

        system = (cell, positions, atomic_numbers)

        if symprec is None:
            res = hpkot.get_path(system, with_time_reversal=False)
        else:
            res = hpkot.get_path(system,
                                 with_time_reversal=False,
                                 symprec=symprec)
        # Checks
        self.assertEqual(res['bravais_lattice'], check_bravais_lattice)
Exemplo n.º 2
0
    def basic_test(
        self,
        cell,
        positions,
        atomic_numbers,
        check_bravais_lattice,
        check_string=None,
        symprec=None,
    ):
        """
        Given a cell, the positions and the atomic numbers, checks that
        (only one) warning is issued, of type hpkot.EdgeCaseWarning,
        that the bravais lattice is the expected one,
        and that (optionally, if specified) the warning message contains
        the given string 'check_string'.

        :param cell: 3x3 list of lattice vectors
        :param positions: Nx3 list of (scaled) positions
        :param atomic_number: list of length N with the atomic numbers
        :param check_bravais_lattice: a string with the expected Bravais lattice
            (e.g., 'tI', 'oF', ...)
        :param check_string: if specified, this should be contained in the warning
            message
        :param symprec: if specified, pass also the symprec to the code
        """
        import warnings

        from seekpath import hpkot

        system = (cell, positions, atomic_numbers)

        with warnings.catch_warnings(record=True) as w:
            if symprec is None:
                res = hpkot.get_path(system, with_time_reversal=False)
            else:
                res = hpkot.get_path(system,
                                     with_time_reversal=False,
                                     symprec=symprec)
            # Checks
            self.assertEqual(res["bravais_lattice"], check_bravais_lattice)
            # Checks on issued warnings
            relevant_w = [
                _ for _ in w if issubclass(_.category, hpkot.EdgeCaseWarning)
            ]
            self.assertEqual(
                len(relevant_w),
                1,
                "Wrong number of warnings issued! "
                "({} instead of 1)".format(len(relevant_w)),
            )
            if check_string is not None:
                self.assertIn(check_string, str(relevant_w[0].message))
Exemplo n.º 3
0
def kpath(atoms):
    """Returns a list of the special k-points in the BZ at which the
    phonons should be sampled.

    Args:
        atoms (matdb.atoms.Atoms): structure to get the path for.

    Returns:

        tuple: `(path, points)`, where `path` is a list of *names* of the special points
        and `points` is a dict with the same names as keys and :class:`numpy.ndarray` as
        values.
    """
    from seekpath.hpkot import get_path
    s = (atoms.cell, atoms.get_scaled_positions(), atoms.get_atomic_numbers())
    kdict = get_path(s)

    names = [kdict["path"][0][0]]
    for ki in range(len(kdict["path"]))[1:]:
        s0, e0 = kdict["path"][ki - 1]
        s1, e1 = kdict["path"][ki]

        if e0 == s1:
            names.append(s1)
        else:
            names.append((e0, s1))
    names.append(kdict["path"][-1][1])

    pts = {k: np.array(v) for k, v in kdict["point_coords"].items()}
    return (names, pts)
Exemplo n.º 4
0
    def test_supercell(self):
        """
        Test a supercell (BCC).
        This is just a very basic test.
        """
        from seekpath import hpkot

        cell = [[4., 0., 0.], [0., 10., 0.], [0., 0., 4.]]
        positions = [[0., 0., 0.], [0.5, 0.25, 0.5], [0., 0.5, 0.],
                     [0.5, 0.75, 0.5]]
        atomic_numbers = [6, 6, 6, 6]

        system = (cell, positions, atomic_numbers)
        res = hpkot.get_path(system, with_time_reversal=False)

        # Just some basic checks...
        self.assertEqual(res['volume_original_wrt_conv'], 2)
        self.assertEqual(res['volume_original_wrt_prim'], 4)
Exemplo n.º 5
0
    def base_test(self, ext_bravais, with_inv):
        """
        Test a specific extended Bravais symol, 
        with or without inversion (uses the cell whose
        POSCAR is stored in the directories - they have been obtained by 
        Y. Hinuma from the Materials Project).

        :param ext_bravais: a string with the extended Bravais Lattice symbol 
           (like 'cF1', for instance)
        :param with_inv: if True, consider a system with inversion symmetry,
            otherwise one without (in which case, the get_path function is
            called with the kwarg 'with_time_reversal = False')
        """
        import os

        from seekpath import hpkot

        # Get the POSCAR with the example structure
        this_folder = os.path.split(os.path.abspath(hpkot.__file__))[0]
        folder = os.path.join(this_folder, "band_path_data", ext_bravais)
        poscar_with_inv = os.path.join(folder, 'POSCAR_inversion')
        poscar_no_inv = os.path.join(folder, 'POSCAR_noinversion')

        poscar = poscar_with_inv if with_inv else poscar_no_inv
        #asecell = ase.io.read(poscar)
        # system = (asecell.get_cell(), asecell.get_scaled_positions(),
        #    asecell.get_atomic_numbers())
        system = simple_read_poscar(poscar)

        res = hpkot.get_path(system, with_time_reversal=False)

        self.assertEqual(res['bravais_lattice_extended'], ext_bravais)
        self.assertEqual(res['has_inversion_symmetry'], with_inv)

        if self.verbose_tests:
            print("*** {} (inv={})".format(ext_bravais, with_inv))
            for p1, p2 in res['path']:
                print("   {} -- {}: {} -- {}".format(p1, p2,
                                                     res['point_coords'][p1],
                                                     res['point_coords'][p2]))