Exemple #1
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,
                atom=C,
                sc=self.sc)
            self.D = DensityMatrix(self.g)
            self.DS = DensityMatrix(self.g, orthogonal=False)

            def func(D, ia, idxs, idxs_xyz):
                idx = D.geometry.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
Exemple #2
0
def make_dev(ori='zz',
             cell_num=(1, 1),
             stripe_len=1,
             scaling=1,
             nsc=[1, 1, 1],
             is_finite=False):
    """
    Make the device by giving sisl.Geometry an initial orthogonal supercell and
    then tiling it

    """
    a = 2.46 * scaling
    a_z = 3.35
    d = a / (2 * np.sqrt(3))

    #shift_to_cell = np.array([.5 * d, .75 * a, 0])

    carbon_a = Atom(6, R=a / np.sqrt(3) + 0.01, tag='A')
    carbon_b = Atom(6, R=a / np.sqrt(3) + 0.01, tag='B')
    atom_list = [carbon_a, carbon_b] * 4

    xyz = np.array([[0, 0, 0], [d, -a / 2, 0], [3 * d, -a / 2, 0], [
        4 * d, 0, 0
    ], [d, -a / 2, a_z], [2 * d, 0, a_z], [4 * d, 0, a_z],
                    [5 * d, -a / 2, a_z]]) + np.array([.5 * d, .75 * a, 0])

    lat_vecs = np.array([[6 * d, 0, 0], [0, a, 0], [0, 0, 2 * a_z]])

    if ori == 'ac':

        xyz = np.array([xyz[:, 1], xyz[:, 0], xyz[:, 2]]).T

        lat_vecs = np.array([lat_vecs[:, 1], lat_vecs[:, 0], lat_vecs[:, 2]]).T

    print('a', a)

    # Repeat in the direction of the stripe
    xyz = np.concatenate([xyz + i * lat_vecs[0] for i in range(stripe_len)
                          ]) - (stripe_len / 2) * lat_vecs[0]
    atom_list = np.concatenate([atom_list for i in range(stripe_len)])

    # Repeat in the direction of transport to the left and right of the origin
    xyz = np.concatenate([xyz + i * lat_vecs[1] for i in range(sum(cell_num))
                          ]) - cell_num[0] * lat_vecs[1]
    atom_list = np.concatenate([atom_list for i in range(sum(cell_num))])

    # Generate the supercell lattice vectors
    lat_vecs_sc = np.copy(lat_vecs)
    lat_vecs_sc[0] *= stripe_len
    lat_vecs_sc[1] *= np.sum(cell_num)
    print(np.sum(lat_vecs_sc, axis=1))

    # Create the geometry and tile it in the non-transport direction
    blg = Geometry(xyz, atom_list, sc=SuperCell(list(lat_vecs_sc), nsc=nsc))

    return blg
Exemple #3
0
    def read_geometry(self, geometry=None):
        """ Returns Geometry object from a TranSiesta file """

        # Read supercell
        sc = self.read_supercell()

        na = _siesta.read_tshs_sizes(self.file)[1]
        _bin_check(self, 'read_geometry', 'could not read sizes.')
        arr = _siesta.read_tshs_geom(self.file, na)
        _bin_check(self, 'read_geometry', 'could not read geometry.')
        xyz = np.array(arr[0].T, np.float64)
        xyz.shape = (-1, 3)
        lasto = np.array(arr[1], np.int32)

        # Since the TSHS file does not contain species information
        # and/or other stuff we *can* reuse an existing
        # geometry which contains the correct atomic numbers etc.
        orbs = np.diff(lasto)
        if geometry is None:
            # Create all different atoms...
            # The TSHS file does not contain the
            # atomic numbers, so we will just
            # create them individually

            # Get unique orbitals
            uorb = np.unique(orbs)
            # Create atoms
            atoms = []
            for Z, orb in enumerate(uorb):
                atoms.append(Atom(Z + 1, [-1] * orb))

            def get_atom(atoms, orbs):
                for atom in atoms:
                    if atom.no == orbs:
                        return atom

            atom = []
            for orb in orbs:
                atom.append(get_atom(atoms, orb))

        else:
            # Create a new geometry with the correct atomic numbers
            atom = []
            for ia, no in zip(geometry, orbs):
                a = geometry.atoms[ia]
                if a.no == no:
                    atom.append(a)
                else:
                    # correct atom
                    atom.append(
                        Atom(a.Z, [-1. for io in range(no)],
                             mass=a.mass,
                             tag=a.tag))

        # Create and return geometry object
        return Geometry(xyz, atom, sc=sc)
Exemple #4
0
def sc(alat, atom):
    """
    Returns a Simple cubic lattice (1 atom)
    """
    sc = SuperCell(np.array([[1, 0, 0],
                             [0, 1, 0],
                             [0, 0, 1]], np.float64) * alat,
                   nsc=[3, 3, 3])
    g = Geometry([0, 0, 0], atom, sc=sc)
    return g
Exemple #5
0
def fcc(alat, atom, orthogonal=False):
    """
    Returns a geometry with the FCC crystal structure (1 atom)
    """
    if orthogonal:
        sc = SuperCell(np.array([[1, 0, 0],
                                 [0, 1, 0],
                                 [0, 0, 1]], np.float64) * alat,
                       nsc=[3, 3, 3])
        ah = alat / 2
        g = Geometry([[0, 0, 0], [ah, ah, 0],
                      [ah, 0, ah], [0, ah, ah]], atom, sc=sc)
    else:
        sc = SuperCell(np.array([[0, 1, 1],
                                 [1, 0, 1],
                                 [1, 1, 0]], np.float64) * alat / 2,
                       nsc=[3, 3, 3])
        g = Geometry([0, 0, 0], atom, sc=sc)
    return g
Exemple #6
0
def test_geometry_car_mixed(sisl_tmp):
    f = sisl_tmp('test_read_write.POSCAR', _dir)

    atoms = [Atom[1], Atom[2], Atom[2], Atom[1], Atom[1], Atom[2], Atom[3]]
    xyz = np.random.rand(len(atoms), 3)
    geom = Geometry(xyz, atoms, 100)

    geom.write(carSileVASP(f, 'w'))

    assert carSileVASP(f).read_geometry() == geom
Exemple #7
0
def test_geometry_car_allsame(sisl_tmp):
    f = sisl_tmp('test_read_write.POSCAR', _dir)

    atoms = Atom[1]
    xyz = np.random.rand(10, 3)
    geom = Geometry(xyz, atoms, 100)

    geom.write(carSileVASP(f, 'w'))

    assert carSileVASP(f).read_geometry() == geom
Exemple #8
0
    def read_hamiltonian(self, **kwargs):
        """ Returns the electronic structure from the siesta.TSHS file """

        # Now read the sizes used...
        Gamma, spin, no, no_s, nnz = _siesta.read_hsx_sizes(self.file)
        _bin_check(self, 'read_hamiltonian',
                   'could not read Hamiltonian sizes.')
        ncol, col, dH, dS, dxij = _siesta.read_hsx_hsx(self.file, Gamma, spin,
                                                       no, no_s, nnz)
        _bin_check(self, 'read_hamiltonian', 'could not read Hamiltonian.')

        # Try and immediately attach a geometry
        geom = kwargs.get('geometry', kwargs.get('geom', None))
        if geom is None:
            # We have *no* clue about the
            if np.allclose(dxij, 0.):
                # We truly, have no clue,
                # Just generate a boxed system
                xyz = [[x, 0, 0] for x in range(no)]
                geom = Geometry(xyz, Atom(1), sc=[no, 1, 1])
            else:
                # Try to figure out the supercell
                warn(
                    self.__class__.__name__ + '.read_hamiltonian '
                    '(currently we can not calculate atomic positions from xij array)'
                )
        if geom.no != no:
            raise SileError(
                str(self) + '.read_hamiltonian could not use the '
                'passed geometry as the number of atoms or orbitals is '
                'inconsistent with HSX file.')

        # Create the Hamiltonian container
        H = Hamiltonian(geom,
                        spin,
                        nnzpr=1,
                        dtype=np.float32,
                        orthogonal=False)

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

        H._csr._D = np.empty([nnz, spin + 1], np.float32)
        H._csr._D[:, :spin] = dH[:, :]
        H._csr._D[:, spin] = dS[:]

        # Convert the supercells to sisl supercells
        if no_s // no == np.product(geom.nsc):
            _csr_from_siesta(geom, H._csr)

        return H
Exemple #9
0
    def test_spin_squared(self, setup, k):
        g = Geometry([[i, 0, 0] for i in range(10)],
                     Atom(6, R=1.01),
                     sc=SuperCell(1, nsc=[3, 1, 1]))
        H = Hamiltonian(g, spin=Spin.POLARIZED)
        H.construct(([0.1, 1.1], [[0, 0.1], [1, 1.1]]))
        H[0, 0] = (0.1, 0.)
        H[0, 1] = (0.5, 0.4)
        es_alpha = H.eigenstate(k, spin=0)
        es_beta = H.eigenstate(k, spin=1)

        sup, sdn = spin_squared(es_alpha.state, es_beta.state)
        sup1, sdn1 = H.spin_squared(k)
        assert sup.sum() == pytest.approx(sdn.sum())
        assert np.all(sup1 == sup)
        assert np.all(sdn1 == sdn)
        assert len(sup) == es_alpha.shape[0]
        assert len(sdn) == es_beta.shape[0]

        sup, sdn = spin_squared(es_alpha.sub(range(2)).state, es_beta.state)
        assert sup.sum() == pytest.approx(sdn.sum())
        assert len(sup) == 2
        assert len(sdn) == es_beta.shape[0]

        sup, sdn = spin_squared(
            es_alpha.sub(range(3)).state,
            es_beta.sub(range(2)).state)
        sup1, sdn1 = H.spin_squared(k, 3, 2)
        assert sup.sum() == pytest.approx(sdn.sum())
        assert np.all(sup1 == sup)
        assert np.all(sdn1 == sdn)
        assert len(sup) == 3
        assert len(sdn) == 2

        sup, sdn = spin_squared(
            es_alpha.sub(0).state.ravel(),
            es_beta.sub(range(2)).state)
        assert sup.sum() == pytest.approx(sdn.sum())
        assert sup.ndim == 1
        assert len(sup) == 1
        assert len(sdn) == 2

        sup, sdn = spin_squared(
            es_alpha.sub(0).state.ravel(),
            es_beta.sub(0).state.ravel())
        assert sup.sum() == pytest.approx(sdn.sum())
        assert sup.ndim == 0
        assert sdn.ndim == 0

        sup, sdn = spin_squared(
            es_alpha.sub(range(2)).state,
            es_beta.sub(0).state.ravel())
        assert sup.sum() == pytest.approx(sdn.sum())
        assert len(sup) == 2
        assert len(sdn) == 1
Exemple #10
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)
Exemple #11
0
    def test_op2(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)
        for i in range(10):
            j = range(i*4, i*4+3)
            H[0, j] = i

            # +
            s = H + 1
            for jj in j:
                assert s[0, jj] == i+1
                assert H[0, jj] == i
                assert s[1, jj] == 0

            # -
            s = H - 1
            for jj in j:
                assert s[0, jj] == i-1
                assert H[0, jj] == i
                assert s[1, jj] == 0

            # -
            s = 1 - H
            for jj in j:
                assert s[0, jj] == 1-i
                assert H[0, jj] == i
                assert s[1, jj] == 0

            # *
            s = H * 2
            for jj in j:
                assert s[0, jj] == i*2
                assert H[0, jj] == i
                assert s[1, jj] == 0

            # //
            s = s // 2
            for jj in j:
                assert s[0, jj] == i
                assert H[0, jj] == i
                assert s[1, jj] == 0

            # **
            s = H ** 2
            for jj in j:
                assert s[0, jj] == i**2
                assert H[0, jj] == i
                assert s[1, jj] == 0

            # ** (r)
            s = 2 ** H
            for jj in j:
                assert s[0, jj], 2 ** H[0 == jj]
                assert H[0, jj] == i
                assert s[1, jj] == 0
Exemple #12
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)
        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)
Exemple #13
0
def test_geometry(sisl_tmp):
    f = sisl_tmp('GRID.cube', _dir)
    geom = Geometry(np.random.rand(10, 3), np.random.randint(1, 70, 10), sc=[10, 10, 10, 45, 60, 90])
    grid = Grid(0.2, geometry=geom)
    grid.grid = np.random.rand(*grid.shape)
    grid.write(f)
    read = grid.read(f)
    assert np.allclose(grid.grid, read.grid)
    assert not grid.geometry is None
    assert not read.geometry is None
    assert grid.geometry == read.geometry
Exemple #14
0
    def read_geometry(self, velocity=False, species_Z=False):
        """ Returns a `Geometry` object from the XV file

        Parameters
        ----------
        species_Z : bool, optional
           if ``True`` the atomic numbers are the species indices (useful when
           reading the ChemicalSpeciesLabel block simultaneously).
        velocity : bool, optional
           also return the velocities in the file

        Returns
        -------
        Geometry
        velocity : only if `velocity` is true.
        """
        sc = self.read_supercell()

        # Read number of atoms
        na = int(self.readline())
        xyz = np.empty([na, 3], np.float64)
        vel = np.empty([na, 3], np.float64)
        atms = [None] * na
        sp = np.empty([na], np.int32)
        for ia in range(na):
            line = list(map(float, self.readline().split()[:8]))
            sp[ia] = int(line[0])
            if species_Z:
                atms[ia] = Atom(sp[ia])
            else:
                atms[ia] = Atom(int(line[1]))
            xyz[ia, :] = line[2:5]
            vel[ia, :] = line[5:8]

        xyz *= Bohr2Ang
        vel *= Bohr2Ang

        # Ensure correct sorting
        max_s = sp.max()
        sp -= 1
        # Ensure we can remove the atom after having aligned them
        atms2 = Atoms(AtomUnknown(1000), na=na)
        for i in range(max_s):
            idx = (sp[:] == i).nonzero()[0]
            if len(idx) == 0:
                # Always ensure we have "something" for the unoccupied places
                atms2[idx] = AtomUnknown(1000 + i)
            else:
                atms2[idx] = atms[idx[0]]

        geom = Geometry(xyz, atms2.reduce(), sc=sc)
        if velocity:
            return geom, vel
        return geom
Exemple #15
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)
Exemple #16
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 #17
0
def hcp(a, atoms, coa=1.63333, orthogonal=False):
    """ Hexagonal closed packed lattice with 2 (non-orthogonal) or 4 atoms (orthogonal)

    Parameters
    ----------
    a : float
        lattice parameter for 1st and 2nd lattice vectors
    atoms : Atom
        the atom(s) in the HCP lattice
    coa : float, optional
        c over a parameter where c is the 3rd lattice vector length
    orthogonal : bool, optional
        whether the lattice is orthogonal (4 atoms)
    """
    # height of hcp structure
    c = a * coa
    a2sq = a / 2**.5
    if orthogonal:
        sc = SuperCell([[a + a * _c60 * 2, 0, 0], [0, a * _c30 * 2, 0],
                        [0, 0, c / 2]])
        gt = Geometry([[0, 0, 0], [a, 0, 0], [a * _s30, a * _c30, 0],
                       [a * (1 + _s30), a * _c30, 0]],
                      atoms,
                      sc=sc)
        # Create the rotated one on top
        gr = gt.copy()
        # mirror structure
        gr.xyz[0, 1] += sc.cell[1, 1]
        gr.xyz[1, 1] += sc.cell[1, 1]
        gr = gr.translate(-np.amin(gr.xyz, axis=0))
        # Now displace to get the correct offset
        gr = gr.translate([0, a * _s30 / 2, 0])
        g = gt.append(gr, 2)
    else:
        sc = SuperCell([a, a, c, 90, 90, 60])
        g = Geometry([[0, 0, 0], [a2sq * _c30, a2sq * _s30, c / 2]],
                     atoms,
                     sc=sc)
    if np.all(g.maxR(True) > 0.):
        g.optimize_nsc()
    return g
Exemple #18
0
def test_imaginary_fail_geometry(sisl_tmp):
    fr = sisl_tmp('GRID_real.cube', _dir)
    fi = sisl_tmp('GRID_imag.cube', _dir)
    geom = Geometry(np.random.rand(10, 3), np.random.randint(1, 70, 10), sc=[10, 10, 10, 45, 60, 90])
    grid = Grid(0.2, geometry=geom, dtype=np.complex128)
    grid.grid = np.random.rand(*grid.shape) + 1j*np.random.rand(*grid.shape)
    grid.write(fr)

    # Assert it fails on geometry
    grid2 = Grid(0.3, dtype=np.complex128)
    grid2.write(fi, imag=True)
    grid.read(fr, imag=fi)
Exemple #19
0
    def _r_geometry_ase(self, na, header, sp, xyz):
        """ Read the geometry as though it was created with ASE """
        # Convert F T to nsc
        #  F = 1
        #  T = 3
        nsc = list(
            map(lambda x: "FT".index(x) * 2 + 1,
                header.pop("pbc").strip('"').split()))
        cell = _a.fromiterd(header.pop("Lattice").strip('"').split()).reshape(
            3, 3)

        return Geometry(xyz, atom=sp, sc=SuperCell(cell, nsc=nsc))
Exemple #20
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)
Exemple #21
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)
Exemple #22
0
def test_geometry_car_group(sisl_tmp):
    f = sisl_tmp('test_sort.POSCAR', _dir)

    atoms = [Atom[1], Atom[2], Atom[2], Atom[1], Atom[1], Atom[2], Atom[3]]
    xyz = np.random.rand(len(atoms), 3)
    geom = Geometry(xyz, atoms, 100)

    geom.write(carSileVASP(f, 'w'), group_species=True)

    assert carSileVASP(f).read_geometry() != geom
    geom = carSileVASP(f).geometry_group(geom)
    assert carSileVASP(f).read_geometry() == geom
        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
Exemple #24
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)
Exemple #25
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)
Exemple #26
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 #27
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)
Exemple #28
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)
Exemple #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] * 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
Exemple #30
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)