示例#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)
示例#2
0
def test_spin1():
    for val in ['unpolarized', '', Spin.UNPOLARIZED,
                'polarized', 'p', Spin.POLARIZED,
                'non-collinear', 'nc', Spin.NONCOLINEAR,
                'spin-orbit', 'so', Spin.SPINORBIT]:
        s = Spin(val)
        str(s)
        s1 = s.copy()
        assert s == s1
示例#3
0
 def test_spin1(self):
     for val in ['unpolarized', '',
                 'polarized', 'p',
                 'non-colinear', 'nc',
                 'spin-orbit', 'so']:
         s = Spin(val)
         repr(s)
         s1 = s.copy()
         assert_equal(s, s1)
示例#4
0
def test_sparse_orbital_bz_spin_orbit_warns_hermitian():
    M = SparseOrbitalBZSpin(geom.graphene(), spin=Spin('SO'))

    with pytest.warns(SislWarning, match='Hermitian'):
        M.construct(([0.1, 1.44],
                     [[0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8],
                      [0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]]))
示例#5
0
def test_pickle():
    import pickle as p

    S = Spin('nc')
    n = p.dumps(S)
    s = p.loads(n)
    assert S == s
示例#6
0
def test_sparse_orbital_bz_spin_orbit():
    M = SparseOrbitalBZSpin(geom.graphene(), spin=Spin('SO'))

    M.construct(([0.1, 1.44], [[0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8],
                               [0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]]))
    new = (M + M.transpose(True)) / 2
    assert np.abs((M - new)._csr._D).sum() == 0
示例#7
0
    def test_rho2(self, setup):
        bond = 1.42
        sq3h = 3.**.5 * 0.5
        sc = SuperCell(np.array(
            [[1.5, sq3h, 0.], [1.5, -sq3h, 0.], [0., 0., 10.]], np.float64) *
                       bond,
                       nsc=[3, 3, 1])

        n = 60
        rf = np.linspace(0, bond * 1.01, n)
        rf = (rf, rf)
        orb = SphericalOrbital(1, rf, 2.)
        C = Atom(6, orb)
        g = Geometry(np.array([[0., 0., 0.], [1., 0., 0.]], np.float64) * bond,
                     atom=C,
                     sc=sc)
        D = DensityMatrix(g)
        D.construct([[0.1, bond + 0.01], [1., 0.1]])
        grid = Grid(0.2, geometry=D.geom)
        D.density(grid)

        D = DensityMatrix(g, spin=Spin('P'))
        D.construct([[0.1, bond + 0.01], [(1., 0.5), (0.1, 0.1)]])
        grid = Grid(0.2, geometry=D.geom)
        D.density(grid)
        D.density(grid, [1., -1])
        D.density(grid, 0)
        D.density(grid, 1)

        D = DensityMatrix(g, spin=Spin('NC'))
        D.construct([[0.1, bond + 0.01],
                     [(1., 0.5, 0.01, 0.01), (0.1, 0.1, 0.1, 0.1)]])
        grid = Grid(0.2, geometry=D.geom)
        D.density(grid)
        D.density(grid, [[1., 0.], [0., -1]])

        D = DensityMatrix(g, spin=Spin('SO'))
        D.construct([[0.1, bond + 0.01],
                     [(1., 0.5, 0.01, 0.01, 0.01, 0.01, 0., 0.),
                      (0.1, 0.1, 0.1, 0.1, 0., 0., 0., 0.)]])
        grid = Grid(0.2, geometry=D.geom)
        D.density(grid)
        D.density(grid, [[1., 0.], [0., -1]])
        D.density(grid, Spin.X)
        D.density(grid, Spin.Y)
        D.density(grid, Spin.Z)
示例#8
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)
示例#9
0
 def test_fermi_level_spin(self, setup):
     R, param = [0.1, 1.5], [(1., 1.), (2.1, 0.1)]
     H = Hamiltonian(setup.g.copy(), spin=Spin('P'))
     H.construct([R, param])
     bz = MonkhorstPack(H, [10, 10, 1])
     q = 1.1
     Ef = H.fermi_level(bz, q=q)
     assert np.asarray(Ef).ndim == 0
     H.shift(-Ef)
     assert H.fermi_level(bz, q=q) == pytest.approx(0., abs=1e-6)
示例#10
0
 def test_fermi_level_spin_separate(self, setup):
     R, param = [0.1, 1.5], [(1., 1.), (2.1, 0.1)]
     H = Hamiltonian(setup.g.copy(), spin=Spin('P'))
     H.construct([R, param])
     bz = MonkhorstPack(H, [10, 10, 1])
     q = [0.5, 0.3]
     Ef = H.fermi_level(bz, q=q)
     assert len(Ef) == 2
     H.shift(-Ef)
     assert np.allclose(H.fermi_level(bz, q=q), 0.)
示例#11
0
def test_sparse_orbital_bz_non_colinear():
    M = SparseOrbitalBZSpin(geom.graphene(), spin=Spin('NC'))
    M.construct(([0.1, 1.44], [[0.1, 0.2, 0.3, 0.4], [0.2, 0.3, 0.4, 0.5]]))

    MT = M.transpose()
    MH = M.transpose(True)

    assert np.abs((M - MT)._csr._D).sum() != 0
    assert np.abs((M - MH)._csr._D).sum() != 0
    assert np.abs((MT - MH)._csr._D).sum() != 0
示例#12
0
 def test_shift3(self, setup):
     R, param = [0.1, 1.5], [(1., -1., 1.), (0.1, 0.1, 0.1)]
     H = Hamiltonian(setup.g.copy(), spin=Spin('P'), orthogonal=False)
     H.construct([R, param])
     eig0_0 = H.eigh(spin=0)[0]
     eig1_0 = H.eigh(spin=1)[0]
     H.shift(0.2)
     assert H.eigh(spin=0)[0] == pytest.approx(eig0_0 + 0.2)
     assert H.eigh(spin=1)[0] == pytest.approx(eig1_0 + 0.2)
     H.shift([0, -0.2])
     assert H.eigh(spin=0)[0] == pytest.approx(eig0_0 + 0.2)
     assert H.eigh(spin=1)[0] == pytest.approx(eig1_0)
示例#13
0
def test_pickle_non_orthogonal_spin():
    import pickle as p
    gr = _get()
    sp = SparseOrbitalBZSpin(gr, spin=Spin('p'), orthogonal=False)
    sp[0, 0, :] = 0.5
    sp[1, 1, :] = 0.5
    sp.S[0, 0] = 1.
    sp.S[1, 1] = 1.
    s = p.dumps(sp)
    SP = p.loads(s)
    assert sp.spsame(SP)
    assert np.allclose(sp.eigh(), SP.eigh())
示例#14
0
def test_sparse_orbital_bz_spin_orbit():
    M = SparseOrbitalBZSpin(geom.graphene(), spin=Spin('SO'))

    M.construct(([0.1, 1.44], [[0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8],
                               [0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]]))

    MT = M.transpose()
    MH = M.transpose(True)

    assert np.abs((M - MT)._csr._D).sum() != 0
    assert np.abs((M - MH)._csr._D).sum() != 0
    assert np.abs((MT - MH)._csr._D).sum() != 0
示例#15
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)
示例#16
0
def test_wavefunction_eta():
    N = 50
    o1 = SphericalOrbital(0, (np.linspace(0, 2, N), np.exp(-np.linspace(0, 100, N))))
    G = Geometry([[1] * 3, [2] * 3], Atom(6, o1), sc=[4, 4, 4])
    H = Hamiltonian(G, spin=Spin('nc'))
    R, param = [0.1, 1.5], [[0., 0., 0.1, -0.1],
                            [1., 1., 0.1, -0.1]]
    H.construct([R, param])
    ES = H.eigenstate()
    # Plot in the full thing
    grid = Grid(0.1, dtype=np.complex128, sc=SuperCell([2, 2, 2], origo=[-1] * 3))
    grid.fill(0.)
    ES.sub(0).wavefunction(grid, eta=True)
示例#17
0
def test_sparse_orbital_bz_non_colinear():
    M = SparseOrbitalBZSpin(geom.graphene(), spin=Spin('NC'))
    M.construct(([0.1, 1.44], [[0.1, 0.2, 0.3, 0.4], [0.2, 0.3, 0.4, 0.5]]))

    MT = M.transpose()
    MH = M.transpose(True)

    assert np.abs((M - MT)._csr._D).sum() != 0
    # For a non-collinear with construct we don't take
    # into account the imaginary parts... :(
    # This should be fixed
    assert np.abs((M - MH)._csr._D).sum() == 0
    assert np.abs((MT - MH)._csr._D).sum() != 0
示例#18
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)
示例#19
0
def test_sparse_orbital_bz_non_colinear_trs_kramers_theorem():
    M = SparseOrbitalBZSpin(geom.graphene(), spin=Spin('NC'))

    M.construct(([0.1, 1.44], [[0.1, 0.2, 0.3, 0.4], [0.2, 0.3, 0.4, 0.5]]))

    M = (M + M.transpose(True)) * 0.5
    MTRS = (M + M.trs()) * 0.5

    # This will in principle also work for M since the above parameters preserve
    # TRS
    k = np.array([0.1, 0.1, 0])
    eig1 = MTRS.eigh(k=k)
    eig2 = MTRS.eigh(k=-k)
    assert np.allclose(eig1, eig2)
示例#20
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)
示例#21
0
    def test_spin2(self):
        g = Geometry([[i, 0, 0] for i in range(10)], Atom(6, R=1.01), sc=[100])
        H = Hamiltonian(g, dtype=np.int32, spin=2)
        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_true(H.spsame(H2))

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

        H2 = Hamiltonian(g, Spin('polarized'), dtype=np.int32)
        for i in range(10):
            j = range(i * 4, i * 4 + 3)
            H2[0, j] = (i, i * 2)
        assert_true(H.spsame(H2))
示例#22
0
def test_sparse_orbital_bz_non_colinear():
    M = SparseOrbitalBZSpin(geom.graphene(), spin=Spin('NC'))
    M.construct(([0.1, 1.44], [[0.1, 0.2, 0.3, 0.4], [0.2, 0.3, 0.4, 0.5]]))
    M.finalize()

    MT = M.transpose()
    MH = M.transpose(True)

    assert np.abs((M - MT)._csr._D).sum() != 0
    # For a non-collinear with construct we don't take
    # into account the imaginary parts... :(
    # Transposing and Hermitian transpose are the same for NC
    # There are only 1 imaginary part which will change sign regardless
    assert np.abs((MT - MH)._csr._D).sum() != 0
    assert np.abs((M - MH)._csr._D).sum() == 0
示例#23
0
    def test_orbital_momentum(self, setup):
        bond = 1.42
        sq3h = 3.**.5 * 0.5
        sc = SuperCell(np.array([[1.5, sq3h, 0.],
                                      [1.5, -sq3h, 0.],
                                      [0., 0., 10.]], np.float64) * bond, nsc=[3, 3, 1])

        orb = AtomicOrbital('px', R=bond * 1.001)
        C = Atom(6, orb)
        g = Geometry(np.array([[0., 0., 0.],
                                    [1., 0., 0.]], np.float64) * bond,
                        atoms=C, sc=sc)
        D = DensityMatrix(g, spin=Spin('SO'))
        D.construct([[0.1, bond + 0.01], [(1., 0.5, 0.01, 0.01, 0.01, 0.01, 0., 0.), (0.1, 0.1, 0.1, 0.1, 0., 0., 0., 0.)]])
        D.orbital_momentum("atom")
        D.orbital_momentum("orbital")
示例#24
0
    def test_non_colinear1(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.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.
        eig1 = H.eigh(dtype=np.complex64)
        assert np.allclose(H.eigh(dtype=np.complex128), eig1)
        assert np.allclose(H.eigh(gauge='r', dtype=np.complex128), eig1)
        assert len(eig1) == len(H)

        H1 = Hamiltonian(g, dtype=np.float64, 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.
        assert H1.spsame(H)
        eig1 = H1.eigh(dtype=np.complex64)
        assert np.allclose(H1.eigh(dtype=np.complex128), eig1)
        assert np.allclose(H.eigh(), H1.eigh())

        es = H1.eigenstate(dtype=np.complex128)
        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)
示例#25
0
    def test_so1(self):
        g = Geometry([[i, 0, 0] for i in range(10)], Atom(6, R=1.01), sc=[100])
        H = Hamiltonian(g, dtype=np.float64, spin=8)
        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_true(np.allclose(H.eigh(), eig1))
        assert_true(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_true(H1.spsame(H))
        eig1 = H1.eigh()
        # Check TimeSelector
        for i in range(2):
            assert_true(np.allclose(H1.eigh(), eig1))
        assert_true(np.allclose(H.eigh(), H1.eigh()))
示例#26
0
    def test_spin_rotate_so(self, setup):
        bond = 1.42
        sq3h = 3.**.5 * 0.5
        sc = SuperCell(np.array([[1.5, sq3h, 0.],
                                      [1.5, -sq3h, 0.],
                                      [0., 0., 10.]], np.float64) * bond, nsc=[3, 3, 1])

        orb = AtomicOrbital('px', R=bond * 1.001)
        C = Atom(6, orb)
        g = Geometry(np.array([[0., 0., 0.],
                                    [1., 0., 0.]], np.float64) * bond,
                        atoms=C, sc=sc)
        D = DensityMatrix(g, spin=Spin('SO'))
        D.construct([[0.1, bond + 0.01], [(1., 0.5, 0.01, 0.01, 0.01, 0.01, 0.2, 0.2), (0.1, 0.2, 0.1, 0.1, 0., 0.1, 0.2, 0.3)]])
        D_mull = D.mulliken()
        d = D.spin_rotate([45, 60, 90], rad=False)
        d_mull = d.mulliken()
        assert not np.allclose(D_mull, d_mull)
        assert np.allclose(D_mull[:, 0], d_mull[:, 0])
示例#27
0
    def update_options(self, spin, only_if_polarized=None):
        """
        Updates the options of the spin selector.

        It does so according to the type of spin that the plot is handling.

        Parameters
        -----------
        spin: sisl.Spin, str or int
            It is used to indicate the kind of spin.
        only_if_polarized: bool, optional
            If set to `True`, the options can only be either [UP, DOWN] or [].

            That is, no extra options for non collinear and spin orbit calculations.

            If not provided the initialization value of `only_if_polarized` will be used.

        See also
        ---------
        sisl.physics.Spin
        """
        if not isinstance(spin, Spin):
            spin = Spin(spin)

        # Use the default for this input field if only_if_polarized is not provided.
        if only_if_polarized is None:
            only_if_polarized = self._only_if_polarized

        # Determine what are the new options
        if only_if_polarized:
            if spin.is_polarized:
                options = self._options[Spin.POLARIZED]
            else:
                options = self._options[Spin.UNPOLARIZED]
        else:
            options = self._options[spin.kind]

        # Update them
        self.modify("inputField.params.options", options)

        return self
示例#28
0
    def test_rho_fail_nc(self, setup):
        bond = 1.42
        sq3h = 3.**.5 * 0.5
        sc = SuperCell(np.array([[1.5, sq3h, 0.],
                                      [1.5, -sq3h, 0.],
                                      [0., 0., 10.]], np.float64) * bond, nsc=[3, 3, 1])

        n = 60
        rf = np.linspace(0, bond * 1.01, n)
        rf = (rf, rf)
        orb = SphericalOrbital(1, rf, 2.)
        C = Atom(6, orb)
        g = Geometry(np.array([[0., 0., 0.],
                                    [1., 0., 0.]], np.float64) * bond,
                        atoms=C, sc=sc)

        D = DensityMatrix(g, spin=Spin('NC'))
        D.construct([[0.1, bond + 0.01], [(1., 0.5, 0.01, 0.01), (0.1, 0.1, 0.1, 0.1)]])
        grid = Grid(0.2, geometry=D.geometry)
        with pytest.raises(ValueError):
            D.density(grid, [1., 0.])
示例#29
0
    def test_spin_align_nc(self, setup):
        bond = 1.42
        sq3h = 3.**.5 * 0.5
        sc = SuperCell(np.array(
            [[1.5, sq3h, 0.], [1.5, -sq3h, 0.], [0., 0., 10.]], np.float64) *
                       bond,
                       nsc=[3, 3, 1])

        orb = AtomicOrbital('px', R=bond * 1.001)
        C = Atom(6, orb)
        g = Geometry(np.array([[0., 0., 0.], [1., 0., 0.]], np.float64) * bond,
                     atom=C,
                     sc=sc)
        D = DensityMatrix(g, spin=Spin('nc'))
        D.construct([[0.1, bond + 0.01],
                     [(1., 0.5, 0.01, 0.01), (0.1, 0.2, 0.1, 0.1)]])
        D_mull = D.mulliken()
        v = np.array([1, 2, 3])
        d = D.spin_align(v)
        d_mull = d.mulliken()
        assert not np.allclose(D_mull, d_mull)
        assert np.allclose(D_mull[:, 0], d_mull[:, 0])
示例#30
0
    def test_spin_align_pol(self, setup):
        bond = 1.42
        sq3h = 3.**.5 * 0.5
        sc = SuperCell(np.array([[1.5, sq3h, 0.],
                                      [1.5, -sq3h, 0.],
                                      [0., 0., 10.]], np.float64) * bond, nsc=[3, 3, 1])

        orb = AtomicOrbital('px', R=bond * 1.001)
        C = Atom(6, orb)
        g = Geometry(np.array([[0., 0., 0.],
                                    [1., 0., 0.]], np.float64) * bond,
                        atoms=C, sc=sc)
        D = DensityMatrix(g, spin=Spin('p'))
        D.construct([[0.1, bond + 0.01], [(1., 0.5), (0.1, 0.2)]])
        D_mull = D.mulliken()
        v = np.array([1, 2, 3])
        d = D.spin_align(v)
        d_mull = d.mulliken()
        assert D_mull.shape == (len(D), 2)
        assert d_mull.shape == (len(D), 4)
        assert not np.allclose(-np.diff(D_mull, axis=1), d_mull[:, 3])
        assert np.allclose(D_mull.sum(1), d_mull[:, 0])