Exemple #1
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)
Exemple #2
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))
Exemple #3
0
    def read_density_matrix(self, **kwargs):
        """ Returns the density matrix from the siesta.DM file """

        # Now read the sizes used...
        spin, no, nsc, nnz = _siesta.read_dm_sizes(self.file)
        _bin_check(self, 'read_density_matrix',
                   'could not read density matrix sizes.')

        ncol, col, dDM = _siesta.read_dm(self.file, spin, no, nsc, nnz)
        _bin_check(self, 'read_density_matrix',
                   'could not read density matrix.')

        # Try and immediately attach a geometry
        geom = kwargs.get('geometry', kwargs.get('geom', None))
        if geom is None:
            # We truly, have no clue,
            # Just generate a boxed system
            xyz = [[x, 0, 0] for x in range(no)]
            sc = SuperCell([no, 1, 1], nsc=nsc)
            geom = Geometry(xyz, Atom(1), sc=sc)

        if nsc[0] != 0 and np.any(geom.nsc != nsc):
            # We have to update the number of supercells!
            geom.set_nsc(nsc)

        if geom.no != no:
            raise SileError(
                str(self) + '.read_density_matrix could not use the '
                'passed geometry as the number of atoms or orbitals is '
                'inconsistent with DM file.')

        # Create the density matrix container
        DM = DensityMatrix(geom,
                           spin,
                           nnzpr=1,
                           dtype=np.float64,
                           orthogonal=False)

        # Create the new sparse matrix
        DM._csr.ncol = ncol.astype(np.int32, copy=False)
        DM._csr.ptr = np.insert(np.cumsum(ncol, dtype=np.int32), 0, 0)
        # Correct fortran indices
        DM._csr.col = col.astype(np.int32, copy=False) - 1
        DM._csr._nnz = len(col)

        DM._csr._D = np.empty([nnz, spin + 1], np.float64)
        DM._csr._D[:, :spin] = dDM[:, :]
        # DM file does not contain overlap matrix... so neglect it for now.
        DM._csr._D[:, spin] = 0.

        # Convert the supercells to sisl supercells
        if nsc[0] != 0 or geom.no_s >= col.max():
            _csr_from_siesta(geom, DM._csr)
        else:
            warn(
                str(self) +
                '.read_density_matrix may result in a wrong sparse pattern!')

        return DM
Exemple #4
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)
Exemple #5
0
 def test_distance7(self):
     # Create a 1D chain
     geom = Geometry([0] * 3, Atom(1, R=1.), sc=1)
     geom.set_nsc([77, 1, 1])
     # Try with a short R and a long tolerance list
     d = geom.distance(R=1, tol=np.ones(10) * .5)
     assert_equal(len(d), 1)
     assert_true(np.allclose(d, [1.]))
 def test_distance8(self, setup):
     geom = Geometry([0]*3, Atom(1, R=1.), sc=1)
     geom.set_nsc([77, 1, 1])
     d = geom.distance(0, method='min')
     assert len(d) == 1
     d = geom.distance(0, method='median')
     assert len(d) == 1
     d = geom.distance(0, method='mode')
     assert len(d) == 1
 def test_distance7(self, setup):
     # Create a 1D chain
     geom = Geometry([0]*3, Atom(1, R=1.), sc=1)
     geom.set_nsc([77, 1, 1])
     # Try with a short R and a long tolerance list
     # We know that the tolerance list prevails, because
     d = geom.distance(R=1, tol=np.ones(10) * .5)
     assert len(d) == 1
     assert np.allclose(d, [1.])
Exemple #8
0
def test_real_space_SE_fail_k_trs():
    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, 1, (3, 4, 1))
    with pytest.raises(ValueError):
        RSE.green(0.1, [0, 0, 0.2])
Exemple #9
0
 def test_berry_phase_method_fail(self):
     g = Geometry([[-.6, 0, 0], [0.6, 0, 0]], Atom(1, 1.001), sc=[2, 10, 10])
     g.set_nsc([3, 1, 1])
     H = Hamiltonian(g)
     H.construct([(0.1, 1.0, 1.5), (0, 1., 0.5)])
     # Contour
     k = np.linspace(0.0, 1.0, 101)
     K = np.zeros([k.size, 3])
     K[:, 0] = k
     bz = BrillouinZone(H, K)
     berry_phase(bz, method='unknown')
Exemple #10
0
 def test_optimize_nsc1(self):
     # Create a 1D chain
     geom = Geometry([0] * 3, Atom(1, R=1.), sc=1)
     geom.set_nsc([77, 77, 77])
     assert_true(np.allclose(geom.optimize_nsc(), [3, 3, 3]))
     geom.set_nsc([77, 77, 77])
     assert_true(np.allclose(geom.optimize_nsc(1), [77, 3, 77]))
     geom.set_nsc([77, 77, 77])
     assert_true(np.allclose(geom.optimize_nsc([0, 2]), [3, 77, 3]))
     geom.set_nsc([77, 77, 77])
     assert_true(np.allclose(geom.optimize_nsc([0, 2], R=2), [5, 77, 5]))
     geom.set_nsc([1, 1, 1])
     assert_true(np.allclose(geom.optimize_nsc([0, 2], R=2), [5, 1, 5]))
Exemple #11
0
 def test_berry_phase_zak(self):
     # SSH model, topological cell
     g = Geometry([[-.6, 0, 0], [0.6, 0, 0]], Atom(1, 1.001), sc=[2, 10, 10])
     g.set_nsc([3, 1, 1])
     H = Hamiltonian(g)
     H.construct([(0.1, 1.0, 1.5), (0, 1., 0.5)])
     # Contour
     k = np.linspace(0.0, 1.0, 101)
     K = np.zeros([k.size, 3])
     K[:, 0] = k
     bz = BrillouinZone(H, K)
     assert np.allclose(np.abs(berry_phase(bz, sub=0, method='zak')), np.pi)
     # Just to do the other branch
     berry_phase(bz, method='zak')
Exemple #12
0
    def test_repeat3(self):
        R, param = [0.1, 1.1, 2.1, 3.1], [1., 2., 3., 4.]

        # Create reference
        g = Geometry([[0] * 3], Atom('H', R=[4.]), sc=[1.] * 3)
        g.set_nsc([7] * 3)

        # Now create bigger geometry
        G = g.repeat(2, 0).repeat(2, 1).repeat(2, 2)

        HG = Hamiltonian(G.repeat(2, 0).repeat(2, 1).repeat(2, 2))
        HG.construct([R, param])
        HG.finalize()
        H = Hamiltonian(G)
        H.construct([R, param])
        H.finalize()
        H = H.repeat(2, 0).repeat(2, 1).repeat(2, 2)
        assert_true(HG.spsame(H))
Exemple #13
0
def test_real_space_HS_SE_unfold_with_k():
    # check that calculating the real-space Green function is equivalent for two equivalent systems
    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, 1, (3, 4, 1), dk=100, trs=False)

    k1 = [0, 0, 0.2]
    k2 = [0, 0, 0.3]
    for E in [0.1, 1.5]:
        G1 = RSE.green(E, k1)
        G2 = RSE.green(E, k2)
        assert not np.allclose(G1, G2)

        SE1 = RSE.self_energy(E, k1)
        SE2 = RSE.self_energy(E, k2)
        assert not np.allclose(SE1, SE2)
Exemple #14
0
    def test_tile3(self, setup):
        R, param = [0.1, 1.1, 2.1, 3.1], [1., 2., 3., 4.]

        # Create reference
        g = Geometry([[0] * 3], Atom('H', R=[4.]), sc=[1.] * 3)
        g.set_nsc([7] * 3)

        # Now create bigger geometry
        G = g.tile(2, 0).tile(2, 1).tile(2, 2)

        HG = Hamiltonian(G.tile(2, 0).tile(2, 1).tile(2, 2))
        HG.construct([R, param])
        HG.finalize()
        H = Hamiltonian(G)
        H.construct([R, param])
        H.finalize()
        H = H.tile(2, 0).tile(2, 1).tile(2, 2)
        assert HG.spsame(H)
        H.finalize()
        HG.finalize()
        assert np.allclose(H._csr._D, HG._csr._D)
    def test_distance6(self, setup):
        # Create a 1D chain
        geom = Geometry([0]*3, Atom(1, R=1.), sc=1)
        geom.set_nsc([77, 1, 1])
        d = geom.distance(0)
        assert len(d) == 1
        assert np.allclose(d, [1.])

        # Do twice
        d = geom.distance(R=2)
        assert len(d) == 2
        assert np.allclose(d, [1., 2.])

        # Do all
        d = geom.distance(R=np.inf)
        assert len(d) == 77 // 2
        # Add one due arange not adding the last item
        assert np.allclose(d, range(1, 78 // 2))

        # Create a 2D grid
        geom.set_nsc([3, 3, 1])
        d = geom.distance(R=2, tol=[.4, .3, .2, .1])
        assert len(d) == 2 # 1, sqrt(2)
        # Add one due arange not adding the last item
        assert np.allclose(d, [1, 2 ** .5])

        # Create a 2D grid
        geom.set_nsc([5, 5, 1])
        d = geom.distance(R=2, tol=[.4, .3, .2, .1])
        assert len(d) == 3 # 1, sqrt(2), 2
        # Add one due arange not adding the last item
        assert np.allclose(d, [1, 2 ** .5, 2])
 def test_optimize_nsc1(self, setup):
     # Create a 1D chain
     geom = Geometry([0]*3, Atom(1, R=1.), sc=1)
     geom.set_nsc([77, 77, 77])
     assert np.allclose(geom.optimize_nsc(), [3, 3, 3])
     geom.set_nsc([77, 77, 77])
     assert np.allclose(geom.optimize_nsc(1), [77, 3, 77])
     geom.set_nsc([77, 77, 77])
     assert np.allclose(geom.optimize_nsc([0, 2]), [3, 77, 3])
     geom.set_nsc([77, 77, 77])
     assert np.allclose(geom.optimize_nsc([0, 2], R=2.00000001), [5, 77, 5])
     geom.set_nsc([1, 1, 1])
     assert np.allclose(geom.optimize_nsc([0, 2], R=2.0000001), [5, 1, 5])
     geom.set_nsc([5, 1, 5])
     assert np.allclose(geom.optimize_nsc([0, 2], R=0.9999), [1, 1, 1])