예제 #1
0
    def read_geometry(self, primary=False, **kwargs):
        """ Reads a geometry from the Sile """
        # 1st line is number of supercells
        nsc = _a.fromiteri(map(int, self.readline().split()[:3]))
        na, ns = map(int, self.readline().split()[:2])
        # Convert species to atom objects
        try:
            species = get_sile(self.file.rsplit('REF', 1)[0] + 'orbocc').read_atom()
        except:
            species = [Atom(s) for s in self.readline().split()[:ns]]

        # Total number of super-cells
        if primary:
            # Only read in the primary unit-cell
            ns = 1
        else:
            ns = np.prod(nsc)

        cell = _a.fromiterd(map(float, self.readline().split()))
        try:
            cell.shape = (3, 3)
            if primary:
                cell[0, :] /= nsc[0]
                cell[1, :] /= nsc[1]
                cell[2, :] /= nsc[2]
        except:
            c = np.empty([3, 3], np.float64)
            c[0, 0] = 1. + cell[0]
            c[0, 1] = cell[5] / 2.
            c[0, 2] = cell[4] / 2.
            c[1, 0] = cell[5] / 2.
            c[1, 1] = 1. + cell[1]
            c[1, 2] = cell[3] / 2.
            c[2, 0] = cell[4] / 2.
            c[2, 1] = cell[3] / 2.
            c[2, 2] = 1. + cell[2]
            cell = c * Ang2Bohr
        sc = SuperCell(cell * Bohr2Ang, nsc=nsc)

        # Create list of coordinates and atoms
        xyz = np.empty([na * ns, 3], np.float64)
        atoms = [None] * na * ns

        # Read the geometry
        for ia in range(na * ns):

            # Retrieve line
            #   ix  iy  iz  ia  is   x  y  z
            line = self.readline().split()

            atoms[ia] = species[int(line[4]) - 1]
            xyz[ia, :] = _a.fromiterd(map(float, line[5:8]))

        return Geometry(xyz * Bohr2Ang, atoms, sc=sc)
예제 #2
0
def test_struct_reorder(sisl_tmp, sisl_system):
    f = sisl_tmp('gr.STRUCT_IN', _dir)
    g = sisl_system.g.copy()
    g.atoms[0] = Atom(1)
    g.write(structSileSiesta(f, 'w'))
    g2 = structSileSiesta(f).read_geometry()

    # Assert they are the same
    assert np.allclose(g.cell, g2.cell)
    assert np.allclose(g.xyz, g2.xyz)
    assert g.atoms.equal(g2.atoms, R=False)
 def test_set_nsc2(self, setup):
     g = graphene(atom=Atom(6, R=1.43))
     s = SparseAtom(g)
     s.construct([[0.1, 1.43], [1, 2]])
     s.finalize()
     assert s.nnz == 8
     s.set_nsc(a=1)
     assert s.nnz == 6
     s.set_nsc([None, 1, 1])
     assert s.nnz == 4
     assert s[0, 0] == 1
예제 #4
0
def test_sparse_atom_transpose_single(i):
    """ This is problematic when the sparsity pattern is not *filled* """
    g = fcc(1., Atom(1, R=1.5)) * 3
    s = SparseAtom(g)
    s[i, 2] = 1.
    s[i, 0] = 2.
    t = s.transpose()

    assert t.nnz == s.nnz
    assert t[2, i] == pytest.approx(1.)
    assert t[0, i] == pytest.approx(2.)
예제 #5
0
def test_geom_category():
    hBN = honeycomb(1.42, [Atom(5, R=1.43), Atom(7, R=1.43)]) * (10, 11, 1)

    B = AtomZ([5, 6])
    B2 = AtomNeighbours(2, neighbour=B)
    N = AtomZ(7)
    N2 = AtomNeighbours(2, neighbour=N)
    B3 = AtomNeighbours(3, neighbour=B)
    N3 = AtomNeighbours(3, neighbour=N)

    assert B != N

    n2 = AtomNeighbours(2)
    n3 = AtomNeighbours(3)
    n3n2 = AtomNeighbours(1, 3, neighbour=n2) & n3
    n3n3n2 = AtomNeighbours(1, 3, neighbour=n3n2) & n3

    category = (B & B2) ^ (N & N2) ^ (B & B3) ^ (N & N3) ^ n2

    cat = category.categorize(hBN)
        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]*2)
            self.g = Geometry(np.array([[0., 0., 0.],
                                        [1., 0., 0.]], np.float64) * bond,
                              atom=C, sc=self.sc)

            self.mol = Geometry([[i, 0, 0] for i in range(10)], sc=[50])
예제 #7
0
def test_bilayer():
    a = bilayer(1.42)
    a = bilayer(1.42, stacking='AA')
    a = bilayer(1.42, stacking='BA')
    a = bilayer(1.42, stacking='AB')
    for m in range(7):
        a = bilayer(1.42, twist=(m, m + 1))
    a = bilayer(1.42, twist=(6, 7), layer='bottom')
    a = bilayer(1.42, twist=(6, 7), layer='TOP')
    a = bilayer(1.42, bottom_atoms=(Atom['B'], Atom['N']), twist=(6, 7))
    a = bilayer(1.42, top_atoms=(Atom(5), Atom(7)), twist=(6, 7))
    a, th = bilayer(1.42, twist=(6, 7), ret_angle=True)

    with pytest.raises(ValueError):
        bilayer(1.42, twist=(6, 7), layer='undefined')

    with pytest.raises(ValueError):
        bilayer(1.42, twist=(6, 7), stacking='undefined')

    with pytest.raises(ValueError):
        bilayer(1.42, twist=('str', 7), stacking='undefined')
예제 #8
0
def test_wavefunction1():
    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)
    R, param = [0.1, 1.5], [1., 0.1]
    H.construct([R, param])
    ES = H.eigenstate(dtype=np.float64)
    # Plot in the full thing
    grid = Grid(0.1, geometry=H.geom)
    grid.fill(0.)
    ES.sub(0).wavefunction(grid)
예제 #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=[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(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 * 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(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)
        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)
예제 #10
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)
예제 #11
0
def test_get1():
    atoms = Atoms(['C', 'C', 'Au'])
    assert atoms[2] == Atom('Au')
    assert atoms[0] == Atom('C')
    assert atoms[1] == Atom('C')
    assert atoms[0:2] == [Atom('C')]*2
    assert atoms[1:] == [Atom('C'), Atom('Au')]
예제 #12
0
def test_sparse_orbital_replace_hole_norbs():
    """ Create a big graphene flake remove a hole (multiple orbitals) """
    a1 = Atom(5, R=(1.44, 1.44))
    a2 = Atom(7, R=(1.44, 1.44, 1.44))
    g = graphene(atoms=[a1, a2], orthogonal=True)
    spo = SparseOrbital(g)
    def func(self, ia, atoms, atoms_xyz=None):
        geom = self.geometry
        def a2o(idx):
            return geom.a2o(idx, True)
        io = a2o(ia)
        idx = self.geometry.close(ia, R=[0.1, 1.44], atoms=atoms, atoms_xyz=atoms_xyz)
        idx = list(map(a2o, idx))
        self[io, idx[0]] = 0
        for i in io:
            self[i, idx[1]] = 2.7
    # create the sparse-orbital
    spo.construct(func)

    # create 10x10 geoemetry
    nx, ny = 10, 10
    big = spo.tile(10, 0).tile(10, 1)
    hole = spo.tile(6, 0).tile(6, 1)
    hole = hole.remove(hole.close(hole.center(), R=3))

    def create_sp(geom):
        spo = SparseOrbital(geom)
        # create the sparse-orbital
        spo.construct(func)
        return spo

    # now replace every position that can be replaced
    for y in [0, 3]:
        for x in [1, 3]:
            cube = Cuboid(hole.sc.cell, origin=g.sc.offset([x, y, 0]) - 0.1)
            atoms = big.within(cube)
            assert len(atoms) == 4 * 6 * 6
            new = big.replace(atoms, hole)
            new_copy = create_sp(new.geometry)
            assert np.fabs((new - new_copy)._csr._D).sum() == 0.
예제 #13
0
 def test_get1(self):
     atoms = Atoms(['C', 'C', 'Au'])
     assert_true(atoms[2] == Atom('Au'))
     assert_true(atoms[0] == Atom('C'))
     assert_true(atoms[1] == Atom('C'))
     assert_true(atoms[0:2] == [Atom('C')] * 2)
     assert_true(atoms[1:] == [Atom('C'), Atom('Au')])
예제 #14
0
파일: test_atom.py 프로젝트: cationly/sisl
 def test6(self):
     assert_true(Atom(Z=1, orbs=3).orbs == 3)
     assert_true(len(Atom(Z=1, orbs=3)) == 3)
     assert_true(Atom(Z=1, R=1.4).R == 1.4)
     assert_true(Atom(Z=1, R=1.4).maxR() == 1.4)
     assert_true(Atom(Z=1, R=[1.4, 1.8]).orbs == 2)
     assert_true(Atom(Z=1, R=[1.4, 1.8]).maxR() == 1.8)
예제 #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 __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] * 3)
            self.g = Geometry(
                np.array([[0., 0., 0.], [1., 0., 0.]], np.float64) * bond,
                atoms=C,
                sc=self.sc)
            self.E = EnergyDensityMatrix(self.g)
            self.ES = EnergyDensityMatrix(self.g, orthogonal=False)

            def func(E, ia, idxs, idxs_xyz):
                idx = E.geometry.close(ia,
                                       R=(0.1, 1.44),
                                       atoms=idxs,
                                       atoms_xyz=idxs_xyz)
                ia = ia * 3

                i0 = idx[0] * 3
                i1 = idx[1] * 3
                # on-site
                p = 1.
                E.E[ia, i0] = p
                E.E[ia + 1, i0 + 1] = p
                E.E[ia + 2, i0 + 2] = p

                # nn
                p = 0.1

                # on-site directions
                E.E[ia, ia + 1] = p
                E.E[ia, ia + 2] = p
                E.E[ia + 1, ia] = p
                E.E[ia + 1, ia + 2] = p
                E.E[ia + 2, ia] = p
                E.E[ia + 2, ia + 1] = p

                E.E[ia, i1 + 1] = p
                E.E[ia, i1 + 2] = p

                E.E[ia + 1, i1] = p
                E.E[ia + 1, i1 + 2] = p

                E.E[ia + 2, i1] = p
                E.E[ia + 2, i1 + 1] = p

            self.func = func
예제 #17
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]))
예제 #18
0
def test_geometry_sort_func_sort():
    bi = sisl_geom.bilayer().tile(2, 0).repeat(2, 1)

    # Sort according to another cell fractional coordinates
    fcc = sisl_geom.fcc(2.4, Atom(6))

    def fcc_fracs(axis):
        def _(geometry):
            return np.dot(geometry.xyz, fcc.icell.T)[:, axis]

        return _

    out = bi.sort(func_sort=(fcc_fracs(0), fcc_fracs(2)))
예제 #19
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')
예제 #20
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)
예제 #21
0
def test_wavefunction2():
    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)
    R, param = [0.1, 1.5], [1., 0.1]
    H.construct([R, param])
    ES = H.eigenstate(dtype=np.float64)
    # This is effectively plotting outside where no atoms exists
    # (there could however still be psi weight).
    grid = Grid(0.1, sc=SuperCell([2, 2, 2], origo=[2] * 3))
    grid.fill(0.)
    ES.sub(0).wavefunction(grid)
예제 #22
0
    def read_geometry(self):
        """ Read geometry from the contained file """

        # First we read in the geometry
        sc = self.read_supercell()

        # Try and go to the first model record
        in_model, l = self._step_record('MODEL')

        idx = []
        tags = []
        xyz = []
        Z = []
        if in_model:
            l = self.readline()

            def is_atom(line):
                return l.startswith('ATOM') or l.startswith('HETATM')

            def is_end_model(line):
                return l.startswith('ENDMDL') or l == ''

            while not is_end_model(l):
                if is_atom(l):
                    idx.append(int(l[6:11]))
                    tags.append(l[12:16].strip())
                    xyz.append(
                        [float(l[30:38]),
                         float(l[38:46]),
                         float(l[46:54])])
                    Z.append(l[76:78].strip())
                l = self.readline()

        # First sort all atoms according to the idx array
        idx = np.array(idx)
        idx = np.argsort(idx)
        xyz = np.array(xyz)[idx, :]
        tags = [tags[i] for i in idx]
        Z = [Z[i] for i in idx]

        # Create the atom list
        atoms = Atoms(Atom(Z[0], tag=tags[0]), na=len(Z))
        for i, a in enumerate(map(Atom, Z, tags)):
            try:
                s = atoms.specie_index(a)
            except:
                s = len(atoms.atom)
                atoms._atom.append(a)
            atoms._specie[i] = s

        return Geometry(xyz, atoms, sc=sc)
예제 #23
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])

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

            def func(D, ia, atoms, atoms_xyz):
                idx = D.geometry.close(ia, R=(0.1, 1.44), atoms=atoms, atoms_xyz=atoms_xyz)
                ia = ia * 3

                i0 = idx[0] * 3
                i1 = idx[1] * 3
                # on-site
                p = 1.
                D.D[ia, i0] = p
                D.D[ia+1, i0+1] = p
                D.D[ia+2, i0+2] = p

                # nn
                p = 0.1

                # on-site directions
                D.D[ia, ia+1] = p
                D.D[ia, ia+2] = p
                D.D[ia+1, ia] = p
                D.D[ia+1, ia+2] = p
                D.D[ia+2, ia] = p
                D.D[ia+2, ia+1] = p

                D.D[ia, i1+1] = p
                D.D[ia, i1+2] = p

                D.D[ia+1, i1] = p
                D.D[ia+1, i1+2] = p

                D.D[ia+2, i1] = p
                D.D[ia+2, i1+1] = p

            self.func = func
예제 #24
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] * 3)
            self.g = Geometry(
                np.array([[0., 0., 0.], [1., 0., 0.]], np.float64) * bond,
                atom=C,
                sc=self.sc)
            self.D = DynamicalMatrix(self.g)

            def func(D, ia, idxs, idxs_xyz):
                idx = D.geom.close(ia,
                                   R=(0.1, 1.44),
                                   idx=idxs,
                                   idx_xyz=idxs_xyz)
                ia = ia * 3

                i0 = idx[0] * 3
                i1 = idx[1] * 3
                # on-site
                p = 1.
                D.D[ia, i0] = p
                D.D[ia + 1, i0 + 1] = p
                D.D[ia + 2, i0 + 2] = p

                # nn
                p = 0.1

                # on-site directions
                D.D[ia, ia + 1] = p
                D.D[ia, ia + 2] = p
                D.D[ia + 1, ia] = p
                D.D[ia + 1, ia + 2] = p
                D.D[ia + 2, ia] = p
                D.D[ia + 2, ia + 1] = p

                D.D[ia, i1 + 1] = p
                D.D[ia, i1 + 2] = p

                D.D[ia + 1, i1] = p
                D.D[ia + 1, i1 + 2] = p

                D.D[ia + 2, i1] = p
                D.D[ia + 2, i1 + 1] = p

            self.func = func
예제 #25
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)
예제 #26
0
def test_sparse_orbital_transpose_more(i):
    g = fcc(1., Atom(1, R=(1.5, 2.1))) * 3
    s = SparseOrbital(g)
    s[i, 2] = 1.
    s[i, 0] = 2.
    s[i + 3, 4] = 1.
    s[i + 2, 4] = 2.
    t = s.transpose()

    assert t.nnz == s.nnz
    assert t[2, i] == pytest.approx(1.)
    assert t[0, i] == pytest.approx(2.)
    assert t[4, i + 3] == pytest.approx(1.)
    assert t[4, i + 2] == pytest.approx(2.)
예제 #27
0
    def test_op_numpy_scalar(self, setup):
        g = graphene(atoms=Atom(6, R=1.43))
        S = SparseAtom(g)
        I = np.ones(1, dtype=np.complex128)[0]
        # Create initial stuff
        for i in range(10):
            j = range(i, i * 2)
            S[0, j] = i
        S.finalize()

        Ssum = S._csr._D.sum()

        s = S + I
        assert isinstance(s, SparseAtom)
        assert s.dtype == np.complex128
        assert s._csr._D.sum() == Ssum + S.nnz

        s = S - I
        assert isinstance(s, SparseAtom)
        assert s.dtype == np.complex128
        assert s._csr._D.sum() == Ssum - S.nnz

        s = I + S
        assert isinstance(s, SparseAtom)
        assert s.dtype == np.complex128
        assert s._csr._D.sum() == Ssum + S.nnz

        s = S * I
        assert isinstance(s, SparseAtom)
        assert s.dtype == np.complex128
        assert s._csr._D.sum() == Ssum

        s = I * S
        assert isinstance(s, SparseAtom)
        assert s.dtype == np.complex128
        assert s._csr._D.sum() == Ssum

        s = S / I
        assert isinstance(s, SparseAtom)
        assert s.dtype == np.complex128
        assert s._csr._D.sum() == Ssum

        s = S**I
        assert isinstance(s, SparseAtom)
        assert s.dtype == np.complex128
        assert s._csr._D.sum() == Ssum

        s = I**S
        assert isinstance(s, SparseAtom)
        assert s.dtype == np.complex128
예제 #28
0
파일: out.py 프로젝트: tfrederiksen/sisl
    def read_basis(self):
        """ Reads the basis as found in the output file

        This parses 3 things:

        1. At the start of the file there are some initatom output
           specifying which species in the calculation.
        2. Reading the <basis_specs> entries for the masses
        3. Reading the PAO.Basis block output for orbital information
        """
        found, line = self.step_to("Species number:")
        if not found:
            return []

        atoms = {}
        order = []
        while 'Species number:' in line:
            ls = line.split()
            if ls[3] == 'Atomic':
                atoms[ls[7]] = {'Z': int(ls[5]), 'tag': ls[7]}
                order.append(ls[7])
            else:
                atoms[ls[4]] = {'Z': int(ls[7]), 'tag': ls[4]}
                order.append(ls[4])
            line = self.readline()

            # Now go down to basis_specs
        found, line = self.step_to("<basis_specs>")
        while found:
            # =====
            self.readline()
            # actual line
            line = self.readline().split("=")
            tag = line[0].split()[0]
            atoms[tag]["mass"] = float(line[2].split()[0])
            found, line = self.step_to("<basis_specs>", reread=False)

        block = []
        found, line = self.step_to("%block PAO.Basis")
        line = self.readline()
        while not line.startswith("%endblock PAO.Basis"):
            block.append(line)
            line = self.readline()

        from .fdf import fdfSileSiesta
        atom_orbs = fdfSileSiesta._parse_pao_basis(block)
        for atom, orbs in atom_orbs.items():
            atoms[atom]["orbitals"] = orbs

        return [Atom(**atoms[tag]) for tag in order]
예제 #29
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)
            self.HS = Hamiltonian(self.g, orthogonal=False)

            C = Atom(Z=6, R=[bond * 1.01] * 2)
            self.g2 = Geometry(
                np.array([[0., 0., 0.], [1., 0., 0.]], np.float64) * bond,
                atom=C,
                sc=self.sc)
            self.H2 = Hamiltonian(self.g2)
            self.HS2 = Hamiltonian(self.g2, orthogonal=False)
예제 #30
0
def test_rocksalt_slab():
    rocksalt_slab(5.64, [Atom(11, R=3), Atom(17, R=4)], 100)
    assert (rocksalt_slab(5.64, ['Na', 'Cl'], 100, layers=5).equal(
        rocksalt_slab(5.64, ['Na', 'Cl'], 100, layers="ABABA")))
    rocksalt_slab(5.64, ['Na', 'Cl'], 110, vacuum=None)
    rocksalt_slab(5.64, ['Na', 'Cl'], 111, orthogonal=False)
    rocksalt_slab(5.64, ['Na', 'Cl'], 111, orthogonal=True)
    rocksalt_slab(5.64, 'Na', 100)
    with pytest.raises(ValueError):
        rocksalt_slab(5.64, ['Na', 'Cl'], 100, start=0, end=0)
    with pytest.raises(ValueError):
        rocksalt_slab(5.64, ['Na', 'Cl'], 1000)
    with pytest.raises(NotImplementedError):
        rocksalt_slab(5.64, ['Na', 'Cl'], 200)
    with pytest.raises(ValueError):
        rocksalt_slab(5.64, ['Na', 'Cl'], 100, start=0, layers='BABAB')
    rocksalt_slab(5.64, ['Na', 'Cl'], 100, start=1, layers='BABAB')
    with pytest.raises(ValueError):
        rocksalt_slab(5.64, ['Na', 'Cl'], 100, end=0, layers='BABAB')
    rocksalt_slab(5.64, ['Na', 'Cl'], 100, end=1, layers='BABAB')
    assert not np.allclose(
        rocksalt_slab(5.64, ['Na', 'Cl'], 100, end=1, layers='BABAB').xyz,
        rocksalt_slab(5.64, ['Na', 'Cl'], 100, end=1, layers=' BABAB ').xyz)