Ejemplo n.º 1
0
    def test_spin2(self, setup):
        g = Geometry([[i, 0, 0] for i in range(10)],
                     Atom(6, R=1.01),
                     sc=SuperCell(100, nsc=[3, 3, 1]))
        H = Hamiltonian(g, dtype=np.int32, spin=Spin.POLARIZED)
        for i in range(10):
            j = range(i * 2, i * 2 + 3)
            H[0, j] = (i, i * 2)

        H2 = Hamiltonian(g, 2, dtype=np.int32)
        for i in range(10):
            j = range(i * 2, i * 2 + 3)
            H2[0, j] = (i, i * 2)
        assert H.spsame(H2)

        H2 = Hamiltonian(g, Spin(Spin.POLARIZED), dtype=np.int32)
        for i in range(10):
            j = range(i * 2, i * 2 + 3)
            H2[0, j] = (i, i * 2)
        assert H.spsame(H2)

        H2 = Hamiltonian(g, Spin('polarized'), dtype=np.int32)
        for i in range(10):
            j = range(i * 2, i * 2 + 3)
            H2[0, j] = (i, i * 2)
        assert H.spsame(H2)
Ejemplo n.º 2
0
    def test_non_colinear_non_orthogonal(self, setup):
        g = Geometry([[i, 0, 0] for i in range(10)], Atom(6, R=1.01), sc=[100])
        H = Hamiltonian(g,
                        dtype=np.float64,
                        orthogonal=False,
                        spin=Spin.NONCOLINEAR)
        for i in range(10):
            j = range(i * 4, i * 4 + 3)
            H[i, i, 0] = 0.
            H[i, i, 1] = 0.
            H[i, i, 2] = 0.1
            H[i, i, 3] = 0.1
            if i > 0:
                H[i, i - 1, 0] = 1.
                H[i, i - 1, 1] = 1.
            if i < 9:
                H[i, i + 1, 0] = 1.
                H[i, i + 1, 1] = 1.
            H.S[i, i] = 1.
        eig1 = H.eigh()
        # Check TimeSelector
        for i in range(4):
            assert np.allclose(H.eigh(), eig1)
        assert len(eig1) == len(H)

        H1 = Hamiltonian(g,
                         dtype=np.float64,
                         orthogonal=False,
                         spin=Spin('non-collinear'))
        for i in range(10):
            j = range(i * 4, i * 4 + 3)
            H1[i, i, 0] = 0.
            H1[i, i, 1] = 0.
            H1[i, i, 2] = 0.1
            H1[i, i, 3] = 0.1
            if i > 0:
                H1[i, i - 1, 0] = 1.
                H1[i, i - 1, 1] = 1.
            if i < 9:
                H1[i, i + 1, 0] = 1.
                H1[i, i + 1, 1] = 1.
            H1.S[i, i] = 1.
        assert H1.spsame(H)
        eig1 = H1.eigh()
        # Check TimeSelector
        for i in range(4):
            assert np.allclose(H1.eigh(), eig1)
        assert np.allclose(H.eigh(), H1.eigh())

        es = H1.eigenstate()
        assert np.allclose(es.eig, eig1)
        es.spin_moment()

        PDOS = es.PDOS(np.linspace(-1, 1, 100))
        DOS = es.DOS(np.linspace(-1, 1, 100))
        assert np.allclose(PDOS.sum(1)[0, :], DOS)
Ejemplo n.º 3
0
    def test_repeat2(self):
        R, param = [0.1, 1.5], [1., 0.1]

        # Create reference
        Hg = Hamiltonian(self.g.repeat(2, 0).repeat(2, 1).repeat(2, 2))
        Hg.construct([R, param])
        Hg.finalize()
        H = Hamiltonian(self.g)
        H.construct([R, param])
        H = H.repeat(2, 0).repeat(2, 1).repeat(2, 2, eta=True)
        assert_true(Hg.spsame(H))
Ejemplo n.º 4
0
    def test_tile2(self):
        R, param = [0.1, 1.5], [1., 0.1]

        # Create reference
        Hg = Hamiltonian(self.g.tile(2, 0))
        Hg.construct([R, param])
        Hg.finalize()
        H = Hamiltonian(self.g)
        H.construct([R, param])
        H = H.tile(2, 0)
        assert_true(Hg.spsame(H))
Ejemplo n.º 5
0
    def test_spin1(self, setup):
        g = Geometry([[i, 0, 0] for i in range(10)], Atom(6, R=1.01), sc=[100])
        H = Hamiltonian(g, dtype=np.int32, spin=Spin.POLARIZED)
        for i in range(10):
            j = range(i * 4, i * 4 + 3)
            H[0, j] = (i, i * 2)

        H2 = Hamiltonian(g, 2, dtype=np.int32)
        for i in range(10):
            j = range(i * 4, i * 4 + 3)
            H2[0, j] = (i, i * 2)
        assert H.spsame(H2)
Ejemplo n.º 6
0
    def test_so1(self, setup):
        g = Geometry([[i, 0, 0] for i in range(10)], Atom(6, R=1.01), sc=[100])
        H = Hamiltonian(g, dtype=np.float64, spin=Spin.SPINORBIT)
        for i in range(10):
            j = range(i * 4, i * 4 + 3)
            H[i, i, 0] = 0.
            H[i, i, 1] = 0.
            H[i, i, 2] = 0.1
            H[i, i, 3] = 0.1
            H[i, i, 4] = 0.1
            H[i, i, 5] = 0.1
            H[i, i, 6] = 0.1
            H[i, i, 7] = 0.1
            if i > 0:
                H[i, i - 1, 0] = 1.
                H[i, i - 1, 1] = 1.
            if i < 9:
                H[i, i + 1, 0] = 1.
                H[i, i + 1, 1] = 1.
        eig1 = H.eigh()
        # Check TimeSelector
        for i in range(2):
            assert np.allclose(H.eigh(), eig1)
        assert len(H.eigh()) == len(H)

        H1 = Hamiltonian(g, dtype=np.float64, spin=Spin('spin-orbit'))
        for i in range(10):
            j = range(i * 4, i * 4 + 3)
            H1[i, i, 0] = 0.
            H1[i, i, 1] = 0.
            H1[i, i, 2] = 0.1
            H1[i, i, 3] = 0.1
            if i > 0:
                H1[i, i - 1, 0] = 1.
                H1[i, i - 1, 1] = 1.
            if i < 9:
                H1[i, i + 1, 0] = 1.
                H1[i, i + 1, 1] = 1.
        assert H1.spsame(H)
        eig1 = H1.eigh()
        # Check TimeSelector
        for i in range(2):
            assert np.allclose(H1.eigh(), eig1)
        assert np.allclose(H.eigh(), H1.eigh())

        es = H.eigenstate()
        assert np.allclose(es.eig, eig1)
        es.spin_moment()

        PDOS = es.PDOS(np.linspace(-1, 1, 100))
        DOS = es.DOS(np.linspace(-1, 1, 100))
        assert np.allclose(PDOS.sum(1)[0, :], DOS)
Ejemplo n.º 7
0
    def test_so1(self, setup):
        g = Geometry([[i, 0, 0] for i in range(10)], Atom(6, R=1.01), sc=SuperCell(100, nsc=[3, 3, 1]))
        H = Hamiltonian(g, dtype=np.float64, spin=Spin.SPINORBIT)
        for i in range(10):
            j = range(i*2, i*2+3)
            H[i, i, 0] = 0.
            H[i, i, 1] = 0.
            H[i, i, 2] = 0.1
            H[i, i, 3] = 0.1
            H[i, i, 4] = 0.1
            H[i, i, 5] = 0.1
            H[i, i, 6] = 0.1
            H[i, i, 7] = 0.1
            if i > 0:
                H[i, i-1, 0] = 1.
                H[i, i-1, 1] = 1.
            if i < 9:
                H[i, i+1, 0] = 1.
                H[i, i+1, 1] = 1.
        eig1 = H.eigh(dtype=np.complex64)
        assert np.allclose(H.eigh(dtype=np.complex128), eig1)
        assert len(H.eigh()) == len(H)

        H1 = Hamiltonian(g, dtype=np.float64, spin=Spin('spin-orbit'))
        for i in range(10):
            j = range(i*2, i*2+3)
            H1[i, i, 0] = 0.
            H1[i, i, 1] = 0.
            H1[i, i, 2] = 0.1
            H1[i, i, 3] = 0.1
            if i > 0:
                H1[i, i-1, 0] = 1.
                H1[i, i-1, 1] = 1.
            if i < 9:
                H1[i, i+1, 0] = 1.
                H1[i, i+1, 1] = 1.
        assert H1.spsame(H)
        eig1 = H1.eigh(dtype=np.complex64)
        assert np.allclose(H1.eigh(dtype=np.complex128), eig1)
        assert np.allclose(H.eigh(dtype=np.complex64), H1.eigh(dtype=np.complex128))

        es = H.eigenstate(dtype=np.complex128)
        assert np.allclose(es.eig, eig1)

        sm = es.spin_moment()
        om = es.spin_orbital_moment()
        assert np.allclose(sm, om.sum(1))

        PDOS = es.PDOS(np.linspace(-1, 1, 100))
        DOS = es.DOS(np.linspace(-1, 1, 100))
        assert np.allclose(PDOS.sum(1)[0, :], DOS)
Ejemplo n.º 8
0
    def test_repeat2(self, setup):
        R, param = [0.1, 1.5], [1., 0.1]

        # Create reference
        Hg = Hamiltonian(setup.g.repeat(2, 0).repeat(2, 1).repeat(2, 2))
        Hg.construct([R, param])
        Hg.finalize()
        H = Hamiltonian(setup.g)
        H.construct([R, param])
        H = H.repeat(2, 0).repeat(2, 1).repeat(2, 2)
        assert Hg.spsame(H)
        H.finalize()
        Hg.finalize()
        assert np.allclose(H._csr._D, Hg._csr._D)
Ejemplo n.º 9
0
    def test_non_colinear_non_orthogonal(self, setup):
        g = Geometry([[i, 0, 0] for i in range(10)], Atom(6, R=1.01), sc=SuperCell(100, nsc=[3, 3, 1]))
        H = Hamiltonian(g, dtype=np.float64, orthogonal=False, spin=Spin.NONCOLINEAR)
        for i in range(10):
            j = range(i*2, i*2+3)
            H[i, i, 0] = 0.
            H[i, i, 1] = 0.
            H[i, i, 2] = 0.1
            H[i, i, 3] = 0.1
            if i > 0:
                H[i, i-1, 0] = 1.
                H[i, i-1, 1] = 1.
            if i < 9:
                H[i, i+1, 0] = 1.
                H[i, i+1, 1] = 1.
            H.S[i, i] = 1.
        eig1 = H.eigh(dtype=np.complex64)
        assert np.allclose(H.eigh(dtype=np.complex128), eig1)
        assert len(eig1) == len(H)

        H1 = Hamiltonian(g, dtype=np.float64, orthogonal=False, spin=Spin('non-collinear'))
        for i in range(10):
            j = range(i*2, i*2+3)
            H1[i, i, 0] = 0.
            H1[i, i, 1] = 0.
            H1[i, i, 2] = 0.1
            H1[i, i, 3] = 0.1
            if i > 0:
                H1[i, i-1, 0] = 1.
                H1[i, i-1, 1] = 1.
            if i < 9:
                H1[i, i+1, 0] = 1.
                H1[i, i+1, 1] = 1.
            H1.S[i, i] = 1.
        assert H1.spsame(H)
        eig1 = H1.eigh(dtype=np.complex64)
        assert np.allclose(H1.eigh(dtype=np.complex128), eig1)
        assert np.allclose(H.eigh(dtype=np.complex64), H1.eigh(dtype=np.complex128))

        es = H1.eigenstate(dtype=np.complex128)
        assert np.allclose(es.eig, eig1)

        sm = es.spin_moment()
        om = es.spin_orbital_moment()
        assert np.allclose(sm, om.sum(1))

        PDOS = es.PDOS(np.linspace(-1, 1, 100))
        DOS = es.DOS(np.linspace(-1, 1, 100))
        assert np.allclose(PDOS.sum(1)[0, :], DOS)
Ejemplo n.º 10
0
    def test_op4(self, setup):
        g = Geometry([[i, 0, 0] for i in range(100)], Atom(6, R=1.01), sc=[100])
        H = Hamiltonian(g, dtype=np.int32)
        # Create initial stuff
        for i in range(10):
            j = range(i*4, i*4+3)
            H[0, j] = i

        h = 1 + H
        assert h.dtype == np.int32
        h = 1. + H
        assert h.dtype == np.float64
        h = 1.j + H
        assert h.dtype == np.complex128

        h = 1 - H
        assert h.dtype == np.int32
        h = 1. - H
        assert h.dtype == np.float64
        h = 1.j - H
        assert h.dtype == np.complex128

        h = 1 * H
        assert h.dtype == np.int32
        h = 1. * H
        assert h.dtype == np.float64
        h = 1.j * H
        assert h.dtype == np.complex128

        h = 1 ** H
        assert h.dtype == np.int32
        h = 1. ** H
        assert h.dtype == np.float64
        h = 1.j ** H
        assert h.dtype == np.complex128
Ejemplo n.º 11
0
    def test_wrap_kwargs(arg):
        from sisl import geom, Hamiltonian
        g = geom.graphene()
        H = Hamiltonian(g)
        H.construct([[0.1, 1.44], [0, -2.7]])

        bz = MonkhorstPack(H, [2, 2, 2], trs=False)
        assert len(bz) == 2 ** 3

        def wrap_none(arg):
            return arg
        def wrap_kwargs(arg, parent, k, weight):
            return arg * weight

        E = np.linspace(-2, 2, 100)
        asarray1 = (bz.asarray().DOS(E, wrap=wrap_none) * bz.weight.reshape(-1, 1)).sum(0)
        asarray2 = bz.asarray().DOS(E, wrap=wrap_kwargs).sum(0)
        aslist1 = (np.array(bz.aslist().DOS(E, wrap=wrap_none)) * bz.weight.reshape(-1, 1)).sum(0)
        aslist2 = np.array(bz.aslist().DOS(E, wrap=wrap_kwargs)).sum(0)
        asyield1 = (np.array([a for a in bz.asyield().DOS(E, wrap=wrap_none)]) * bz.weight.reshape(-1, 1)).sum(0)
        asyield2 = np.array([a for a in bz.asyield().DOS(E, wrap=wrap_kwargs)]).sum(0)
        asaverage = bz.asaverage().DOS(E, wrap=wrap_none)
        assum = bz.assum().DOS(E, wrap=wrap_kwargs)

        assert np.allclose(asarray1, asaverage)
        assert np.allclose(asarray2, asaverage)
        assert np.allclose(aslist1, asaverage)
        assert np.allclose(aslist2, asaverage)
        assert np.allclose(asyield1, asaverage)
        assert np.allclose(asyield2, asaverage)
        assert np.allclose(assum, asaverage)
Ejemplo n.º 12
0
    def test_pathos(self):
        try:
            import pathos
        except ImportError:
            pytest.skip("pathos not available")

        from sisl import geom, Hamiltonian
        g = geom.graphene()
        H = Hamiltonian(g)
        H.construct([[0.1, 1.44], [0, -2.7]])

        bz = MonkhorstPack(H, [2, 2, 2], trs=False)

        # We need to ensure that all functions does the same
        apply = bz.apply
        papply = bz.papply

        for method in ["iter", "average", "sum", "array", "list", "oplist"]:
            # TODO One should be careful with zip
            # zip will stop when it hits the final element in the first
            # list.
            # So if a generator has some clean-up code one has to use zip_longest
            # regardless of method
            for v1, v2 in zip(papply[method].eigh(), apply[method].eigh()):
                assert np.allclose(v1, v2)
Ejemplo n.º 13
0
    def test_sub1(self):
        R, param = [0.1, 1.5], [1., 0.1]

        # Create reference
        H = Hamiltonian(self.g)
        H.construct([R, param])
        H.finalize()
        # Tiling in this direction will not introduce
        # any new connections.
        # So tiling and removing is a no-op (but
        # increases vacuum in 3rd lattice vector)
        Hg = Hamiltonian(self.g.tile(2, 2))
        Hg.construct([R, param])
        Hg = Hg.sub(range(len(self.g)))
        Hg.finalize()
        assert_true(Hg.spsame(H))
Ejemplo n.º 14
0
def test_real_space_SE_fail_nsc_semi():
    sq = Geometry([0] * 3, Atom(1, 1.01), [1])
    sq.set_nsc([3, 5, 3])
    H = Hamiltonian(sq)
    H.construct([(0.1, 1.1), (4, -1)])

    RSE = RealSpaceSE(H, 1, 0, (3, 4, 1), dk=100)
Ejemplo n.º 15
0
 def test_read_write_hamiltonian(self):
     G = self.g.rotatec(-30)
     H = Hamiltonian(G)
     H.construct([[0.1, 1.45], [0.1, -2.7]])
     print(H)
     f = mkstemp(dir=self.d)[1]
     read_hamiltonian = get_siles(['read_hamiltonian'])
     for sile in get_siles(['write_hamiltonian']):
         if not sile in read_hamiltonian:
             continue
         # Write
         sile(f, mode='w').write_hamiltonian(H)
         # Read 1
         try:
             h = sile(f, mode='r').read_hamiltonian()
             assert_true(H.spsame(h))
         except UnicodeDecodeError as e:
             pass
         # Read 2
         try:
             h = Hamiltonian.read(sile(f, mode='r'))
             assert_true(H.spsame(h))
         except UnicodeDecodeError as e:
             pass
         # Clean-up file
         os.remove(f)
Ejemplo n.º 16
0
    def test_read_write_hamiltonian_overlap(self, sisl_tmp, sisl_system, sile):
        if issubclass(sile, _gfSileSiesta):
            return

        G = sisl_system.g.rotate(-30, sisl_system.g.cell[2, :])
        H = Hamiltonian(G, orthogonal=False)
        H.construct([[0.1, 1.45], [(0.1, 1), (-2.7, 0.1)]])
        f = sisl_tmp("test_read_write_hamiltonian_overlap.win", _dir)
        # Write
        with sile(f, mode='w') as s:
            s.write_hamiltonian(H)
        # Read 1
        try:
            with sile(f, mode='r') as s:
                h = s.read_hamiltonian()
            assert H.spsame(h)
        except UnicodeDecodeError as e:
            pass
        # Read 2
        try:
            with sile(f, mode='r') as s:
                h = Hamiltonian.read(s)
            assert H.spsame(h)
        except UnicodeDecodeError as e:
            pass
Ejemplo n.º 17
0
def test_real_space_SE_fail_k_semi_same():
    sq = Geometry([0] * 3, Atom(1, 1.01), [1])
    sq.set_nsc([3] * 3)
    H = Hamiltonian(sq)
    H.construct([(0.1, 1.1), (4, -1)])

    RSE = RealSpaceSE(H, 0, 0, (3, 4, 1))
Ejemplo n.º 18
0
def sisl_system():
    """ A preset list of geometries/Hamiltonians. """
    class System:
        pass

    d = System()

    alat = 1.42
    sq3h = 3.**.5 * 0.5
    C = Atom(Z=6, R=1.42)
    sc = SuperCell(np.array([[1.5, sq3h, 0.],
                             [1.5, -sq3h, 0.],
                             [0., 0., 10.]], np.float64) * alat,
                   nsc=[3, 3, 1])
    d.g = Geometry(np.array([[0., 0., 0.],
                             [1., 0., 0.]], np.float64) * alat,
                   atom=C, sc=sc)

    d.R = np.array([0.1, 1.5])
    d.t = np.array([0., 2.7])
    d.tS = np.array([(0., 1.0),
                     (2.7, 0.)])
    d.C = Atom(Z=6, R=max(d.R))
    d.sc = SuperCell(np.array([[1.5, sq3h, 0.],
                               [1.5, -sq3h, 0.],
                               [0., 0., 10.]], np.float64) * alat,
                     nsc=[3, 3, 1])
    d.gtb = Geometry(np.array([[0., 0., 0.],
                               [1., 0., 0.]], np.float64) * alat,
                     atom=C, sc=sc)

    d.ham = Hamiltonian(d.gtb)
    d.ham.construct([(0.1, 1.5), (0.1, 2.7)])
    return d
Ejemplo n.º 19
0
    def test_as_wrap(self):
        from sisl import geom, Hamiltonian
        g = geom.graphene()
        H = Hamiltonian(g)
        H.construct([[0.1, 1.44], [0, -2.7]])

        bz = MonkhorstPack(H, [2, 2, 2], trs=False)
        assert len(bz) == 2**3

        # Check with a wrap function
        def wrap(arg):
            return arg[::-1]

        # Assert that as* all does the same
        asarray = bz.apply.array.eigh(wrap=wrap)
        aslist = np.array(bz.apply.list.eigh(wrap=wrap))
        asyield = np.array([a for a in bz.apply.iter.eigh(wrap=wrap)])
        asaverage = bz.apply.average.eigh(wrap=wrap)
        assert np.allclose(asarray, aslist)
        assert np.allclose(asarray, asyield)
        assert np.allclose((asarray / len(bz)).sum(0), asaverage)

        # Now we should check whether the reverse is doing its magic!
        mylist = [wrap(H.eigh(k=k)) for k in bz]
        assert np.allclose(aslist, mylist)
Ejemplo n.º 20
0
    def test_wrap_unzip(self):
        from sisl import geom, Hamiltonian
        g = geom.graphene()
        H = Hamiltonian(g)
        H.construct([[0.1, 1.44], [0, -2.7]])

        bz = MonkhorstPack(H, [2, 2, 2], trs=False)

        # Check with a wrap function
        E = np.linspace(-2, 2, 20)

        def wrap(es):
            return es.eig, es.DOS(E)

        eig0, DOS0 = zip(*bz.apply.list.eigenstate(wrap=wrap))
        with bz.apply.renew(unzip=True) as k_unzip:
            eig1, DOS1 = k_unzip.list.eigenstate(wrap=wrap)
            eig2, DOS2 = k_unzip.array.eigenstate(wrap=wrap)

        #eig0 and DOS0 are generators, and not list's
        #eig1 and DOS1 are generators, and not list's
        assert isinstance(eig2, np.ndarray)
        assert isinstance(DOS2, np.ndarray)

        assert np.allclose(eig0, eig1)
        assert np.allclose(DOS0, DOS1)
        assert np.allclose(eig0, eig2)
        assert np.allclose(DOS0, DOS2)
Ejemplo n.º 21
0
 def test_shift2(self, setup):
     R, param = [0.1, 1.5], [(1., 1.), (0.1, 0.1)]
     H = Hamiltonian(setup.g.copy(), orthogonal=False)
     H.construct([R, param])
     eig0 = H.eigh()[0]
     H.shift(0.2)
     assert H.eigh()[0] == pytest.approx(eig0 + 0.2)
Ejemplo n.º 22
0
    def test_repeat4(self, setup):
        def func(self, ia, idxs, idxs_xyz=None):
            idx = self.geom.close(ia, R=[0.1, 1.43], idx=idxs)
            io = self.geom.a2o(ia)
            # Set on-site on first and second orbital
            odx = self.geom.a2o(idx[0])
            self[io, odx] = -1.
            self[io + 1, odx + 1] = 1.

            # Set connecting
            odx = self.geom.a2o(idx[1])
            self[io, odx] = 0.2
            self[io, odx + 1] = 0.01
            self[io + 1, odx] = 0.01
            self[io + 1, odx + 1] = 0.3

        setup.H2.construct(func)
        Hbig = setup.H2.repeat(3, 0).repeat(3, 1)

        gbig = setup.H2.geom.repeat(3, 0).repeat(3, 1)
        H = Hamiltonian(gbig)
        H.construct(func)

        assert H.spsame(Hbig)
        H.finalize()
        Hbig.finalize()
        assert np.allclose(H._csr._D, Hbig._csr._D)
        setup.H2.empty()
Ejemplo n.º 23
0
 def test_shift1(self, setup):
     R, param = [0.1, 1.5], [1., 0.1]
     H = Hamiltonian(setup.g.copy())
     H.construct([R, param])
     eig0 = H.eigh()[0]
     H.shift(0.2)
     assert H.eigh()[0] == pytest.approx(eig0 + 0.2)
Ejemplo n.º 24
0
def get_H(orthogonal=True, *args):
    gr = geom.graphene(orthogonal=orthogonal)
    H = Hamiltonian(gr)
    H.construct([(0.1, 1.44), (0, -2.7)])
    for axis, rep in zip(args[::2], args[1::2]):
        H = H.tile(rep, axis)
    return H
Ejemplo n.º 25
0
        def __init__(self):
            bond = 1.42
            sq3h = 3.**.5 * 0.5
            self.sc = SuperCell(np.array([[1.5, sq3h, 0.],
                                          [1.5, -sq3h, 0.],
                                          [0., 0., 10.]], np.float64) * bond, nsc=[3, 3, 1])

            C = Atom(Z=6, R=[bond * 1.01])
            self.g = Geometry(np.array([[0., 0., 0.],
                                        [1., 0., 0.]], np.float64) * bond,
                            atom=C, sc=self.sc)
            self.H = Hamiltonian(self.g)
            func = self.H.create_construct([0.1, bond+0.1], [0., -2.7])
            self.H.construct(func)
            self.HS = Hamiltonian(self.g, orthogonal=False)
            func = self.HS.create_construct([0.1, bond+0.1], [(0., 1.), (-2.7, 0.)])
            self.HS.construct(func)
Ejemplo n.º 26
0
    def test_cut1(self):
        # Test of eigenvalues using a cut
        # Hamiltonian
        dR, param = [0.1, 1.5], [1., 0.1]

        # Create reference
        Hg = Hamiltonian(self.g)
        Hg.construct([dR, param])
        g = self.g.tile(2, 0).tile(2, 1)
        H = Hamiltonian(g)
        H.construct([dR, param])
        # Create cut Hamiltonian
        Hc = H.cut(2, 1).cut(2, 0)
        eigc = Hc.eigh()
        eigg = Hg.eigh()
        assert_true(np.allclose(Hg.eigh(), Hc.eigh()))
        del Hc, H
Ejemplo n.º 27
0
 def test_berry_phase_fail_loop(self, setup):
     g = setup.g.tile(2, 0).tile(2, 1).tile(2, 2)
     H = Hamiltonian(g)
     bz = BandStructure.param_circle(H,
                                     20,
                                     0.01, [0, 0, 1], [1 / 3] * 3,
                                     loop=True)
     elec.berry_phase(bz)
Ejemplo n.º 28
0
 def test_fermi_level(self, setup):
     R, param = [0.1, 1.5], [(1., 1.), (2.1, 0.1)]
     H = Hamiltonian(setup.g.copy(), orthogonal=False)
     H.construct([R, param])
     bz = MonkhorstPack(H, [10, 10, 1])
     Ef = H.fermi_level(bz, q=1)
     H.shift(-Ef)
     assert H.fermi_level(bz, q=1) == pytest.approx(0., abs=1e-6)
Ejemplo n.º 29
0
def test_real_space_SE_fail_nsc_semi_fully_periodic():
    sq = Geometry([0] * 3, Atom(1, 1.01), [1])
    sq.set_nsc([3, 5, 3])
    H = Hamiltonian(sq)
    H.construct([(0.1, 1.1), (4, -1)])

    with pytest.raises(ValueError):
        RSE = RealSpaceSE(H, 1, 0, (3, 4, 1), dk=100)
Ejemplo n.º 30
0
    def test_pathos(self):
        pytest.skip(
            "BrillouinZone.apply(pool=True|int) scales extremely bad and may cause stall"
        )
        pytest.importorskip("pathos", reason="pathos not available")

        from sisl import geom, Hamiltonian
        g = geom.graphene()
        H = Hamiltonian(g)
        H.construct([[0.1, 1.44], [0, -2.7]])

        bz = MonkhorstPack(H, [2, 2, 2], trs=False)

        # try and determine a sensible
        import os
        try:
            import psutil
            nprocs = len(psutil.Process().cpu_affinity()) // 2
        except Exception:
            nprocs = os.cpu_count() // 2
        omp_num_threads = os.environ.get("OMP_NUM_THREADS")

        # Check that the ObjectDispatcher works
        apply = bz.apply

        papply = bz.apply.renew(pool=nprocs)
        assert str(apply) != str(papply)

        for method in ["iter", "average", "sum", "array", "list", "oplist"]:
            # TODO One should be careful with zip
            # zip will stop when it hits the final element in the first
            # list.
            # So if a generator has some clean-up code one has to use zip_longest
            # regardless of method
            os.environ["OMP_NUM_THREADS"] = "1"
            V1 = papply[method].eigh()
            if omp_num_threads is None:
                del os.environ["OMP_NUM_THREADS"]
            else:
                os.environ["OMP_NUM_THREADS"] = omp_num_threads
            V2 = apply[method].eigh()

            for v1, v2 in zip(V1, V2):
                assert np.allclose(v1, v2)

        # Check that the MethodDispatcher works
        apply = bz.apply.eigh
        papply = bz.apply.renew(pool=True).eigh
        assert str(apply) != str(papply)

        for method in ["iter", "average", "sum", "array", "list", "oplist"]:
            # TODO One should be careful with zip
            # zip will stop when it hits the final element in the first
            # list.
            # So if a generator has some clean-up code one has to use zip_longest
            # regardless of method
            for v1, v2 in zip(papply[method](), apply[method]()):
                assert np.allclose(v1, v2)