Exemple #1
0
    def test_kpath_api(self):
        """Testing Kpath API."""
        structure = abilab.Structure.as_structure(abidata.cif_file("si.cif"))

        knames = ["G", "X", "L", "G"]
        kpath = Kpath.from_names(structure, knames, line_density=5)
        repr(kpath)
        str(kpath)
        assert kpath.to_string(verbose=2, title="Kpath")
        assert not kpath.is_ibz and kpath.is_path
        assert kpath[0].is_gamma and kpath[-1].is_gamma
        #assert len(kpath.ds) == len(self) - 1
        #assert kpath.ksampling.kptopt == 1
        #self.assert_equal(kpath.ksampling.mpdivs, [4, 4, 4])

        assert Kpoint.from_name_and_structure("Gamma", structure) == kpath[0]

        assert len(kpath.ds) == len(kpath) - 1
        assert len(kpath.versors) == len(kpath) - 1
        assert len(kpath.lines) == len(knames) - 1
        self.assert_almost_equal(kpath.frac_bounds,
                                 structure.get_kcoords_from_names(knames))
        self.assert_almost_equal(
            kpath.cart_bounds,
            structure.get_kcoords_from_names(knames, cart_coords=True))

        r = kpath.find_points_along_path(kpath.get_cart_coords())
        assert len(r.ikfound) == len(kpath)
        self.assert_equal(
            r.ikfound,
            [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0])

        #kpath = IrredZone.from_kppa(structure, kppa=1000, shiftk=[0.5, 0.5, 0.5], kptopt=1, verbose=1)
        #assert not kpath.is_ibz and kpath.is_path
        #assert len(kpath) == 60
        #self.assert_equal(kpath.ksampling.mpdivs, [8, 8, 8])

        segments = build_segments(
            k0_list=(0, 0, 0),
            npts=1,
            step=0.01,
            red_dirs=(1, 0, 0),
            reciprocal_lattice=structure.reciprocal_lattice)
        assert len(segments) == 1
        assert np.all(segments[0] == (0, 0, 0))

        step, npts = 0.1, 5
        red_dir = np.array((1, 1, 0))
        segments = build_segments(
            k0_list=(0, 0, 0, 0.5, 0, 0),
            npts=npts,
            step=step,
            red_dirs=red_dir,
            reciprocal_lattice=structure.reciprocal_lattice)

        #print("segments:\n", segments)
        # (nk0_list, len(red_dirs) * npts, 3)
        assert segments.shape == (2, npts, 3)
        self.assert_almost_equal(segments[0, 2], (0, 0, 0))
        self.assert_almost_equal(segments[1, 2], (0.5, 0.0, 0))

        def r2c(vec):
            return structure.reciprocal_lattice.get_cartesian_coords(vec)

        cart_vers = r2c(red_dir)
        cart_vers /= np.linalg.norm(cart_vers)
        self.assert_almost_equal(r2c(segments[1, 1] - segments[1, 0]),
                                 step * cart_vers)
        self.assert_almost_equal(r2c(segments[1, 3] - segments[1, 2]),
                                 step * cart_vers)