Exemple #1
0
    def read_sc(self):
        """ Returns a SuperCell object from a siesta.TSHS file
        """

        n_s = _siesta.read_tshs_sizes(self.file)[3]
        arr = _siesta.read_tshs_cell(self.file, n_s)
        nsc = np.array(arr[0], np.int32)
        cell = np.array(arr[1], np.float64)
        cell.shape = (3, 3)
        isc = np.array(arr[2], np.int32)
        sc = np.array(arr[2], np.float64)

        SC = SuperCell(cell, nsc=nsc)
        SC.sc_off = np.dot(sc.T, cell.T)
        return SC
Exemple #2
0
 def setUp(self):
     alat = 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) * alat, nsc=[3, 3, 1])
     self.g = Grid([10, 10, 100], sc=self.sc)
Exemple #3
0
    def read_sc(self, *args, **kwargs):
        """ Returns `SuperCell` object from the FDF file """
        f, lc = self._read('LatticeConstant')

        s = float(lc.split()[1])
        if 'ang' in lc.lower():
            pass
        elif 'bohr' in lc.lower():
            s *= Bohr2Ang

        # Read in cell
        cell = np.empty([3, 3], np.float64)

        f, lc = self._read_block('LatticeVectors')
        if f:
            for i in range(3):
                cell[i, :] = [float(k) for k in lc[i].split()[:3]]
        else:
            f, lc = self._read_block('LatticeParameters')
            if f:
                tmp = [float(k) for k in lc[0].split()[:6]]
                cell = SuperCell.tocell(*tmp)
        if not f:
            # the fdf file contains neither the latticevectors or parameters
            raise SileError(
                'Could not find Vectors or Parameters block in file')
        cell *= s

        return SuperCell(cell)
Exemple #4
0
    def read_sc(self):
        """ Returns `SuperCell` object from a .TBT.nc file """
        cell = np.array(np.copy(self.cell), dtype=np.float64)
        cell.shape = (3, 3)

        try:
            nsc = self._value('nsc')
        except:
            nsc = None

        sc = SuperCell(cell, nsc=nsc)
        try:
            sc.sc_off = self._value('isc_off')
        except:
            pass

        return sc
Exemple #5
0
 def __init__(self):
     alat = 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) * alat, nsc=[3, 3, 1])
     self.g = Grid([10, 10, 100], sc=self.sc)
     self.g.fill(2.)
Exemple #6
0
 def test_param_circle(self, n):
     bz = BrillouinZone.param_circle(1, 10, 0.1, n, [1 / 2] * 3)
     assert len(bz) == 10
     sc = SuperCell(1)
     bz_loop = BrillouinZone.param_circle(sc, 10, 0.1, n, [1 / 2] * 3, True)
     assert len(bz_loop) == 10
     assert not np.allclose(bz.k, bz_loop.k)
     assert np.allclose(bz_loop.k[0, :], bz_loop.k[-1, :])
Exemple #7
0
def test_sparse_orbital_add_axis(setup):
    g = setup.g.copy()
    s = SparseOrbital(g)
    s.construct([[0.1, 1.5], [1, 2]])
    s1 = s.add(s, axis=2)
    s2 = SparseOrbital(g.append(SuperCell([0, 0, 10]), 2).add(g, offset=[0, 0, 5]))
    s2.construct([[0.1, 1.5], [1, 2]])
    assert s1.spsame(s2)
Exemple #8
0
 def test_pickle(self):
     import pickle as p
     s = p.dumps(self.sc)
     n = p.loads(s)
     assert_true(self.sc == n)
     assert_false(self.sc != n)
     s = SuperCell([1, 1, 1])
     assert_false(self.sc == s)
Exemple #9
0
    def read_supercell(self, *args, **kwargs):

        cell = _siesta.read_grid_cell(self.file)
        _bin_check(self, 'read_supercell', 'could not read cell.')
        cell = np.array(cell.T, np.float64)
        cell.shape = (3, 3)

        return SuperCell(cell)
Exemple #10
0
    def _r_geometry_sisl(self, na, header, sp, xyz):
        """ Read the geometry as though it was created with sisl """
        # Default version of the header is 1
        v = header.get("sisl-version", 1)
        nsc = list(map(int, header.pop("nsc").split()))
        cell = _a.fromiterd(header.pop("cell").split()).reshape(3, 3)

        return Geometry(xyz, atoms=sp, sc=SuperCell(cell, nsc=nsc))
Exemple #11
0
    def read_energy_density_matrix(self, **kwargs):
        """ Returns the energy density matrix from the siesta.DM file """

        # Now read the sizes used...
        spin, no, nsc, nnz = _siesta.read_tsde_sizes(self.file)
        _bin_check(self, 'read_energy_density_matrix',
                   'could not read energy density matrix sizes.')
        ncol, col, dEDM = _siesta.read_tsde_edm(self.file, spin, no, nsc, nnz)
        _bin_check(self, 'read_energy_density_matrix',
                   'could not read energy 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_energy_density_matrix could '
                'not use the passed geometry as the number of atoms or orbitals '
                'is inconsistent with DM file.')

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

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

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

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

        return EDM
Exemple #12
0
    def read_supercell(self):
        """ Returns `SuperCell` object from this file """
        cell = _a.arrayd(np.copy(self.cell))
        cell.shape = (3, 3)

        try:
            nsc = self._value('nsc')
        except:
            nsc = None

        sc = SuperCell(cell, nsc=nsc)
        try:
            sc.sc_off = self._value('isc_off')
        except:
            # This is ok, we simply do not have the supercell offsets
            pass

        return sc
Exemple #13
0
    def read_supercell(self):
        """ Returns `SuperCell` object from the XV file """

        cell = np.empty([3, 3], np.float64)
        for i in range(3):
            cell[i, :] = list(map(float, self.readline().split()[:3]))
        cell *= Bohr2Ang

        return SuperCell(cell)
Exemple #14
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 #15
0
    def read_supercell(self):
        """ Returns a SuperCell object from a SIESTA.grid.nc file
        """
        cell = np.array(self._value('cell'), np.float64)
        # Yes, this is ugly, I really should implement my unit-conversion tool
        cell *= Bohr2Ang
        cell.shape = (3, 3)

        return SuperCell(cell)
Exemple #16
0
def bcc(alat, atom, orthogonal=False):
    """
    Returns a BCC lattice (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, ah]], atom, sc=sc)
    else:
        sc = SuperCell(np.array([[1, 1, 1],
                                 [1, -1, 1],
                                 [1, 1, -1]], np.float64) * alat / 2,
                       nsc=[3, 3, 3])
        g = Geometry([0, 0, 0], atom, sc=sc)
    return g
def test_sparse_orbital_add_no_axis():
    from sisl.geom import sc
    g = (sc(1., Atom(1, R=1.5)) * 2).add(SuperCell([0, 0, 5]))
    s = SparseOrbital(g)
    s.construct([[0.1, 1.5], [1, 2]])
    s1 = s.add(s, offset=[0, 0, 3])
    s2 = SparseOrbital(g.add(g, offset=[0, 0, 3]))
    s2.construct([[0.1, 1.5], [1, 2]])
    assert s1.spsame(s2)
Exemple #18
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 #19
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.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 #20
0
 def read_supercell(self):
     """ Reads a supercell from the Sile """
     # 1st line is number of supercells
     nsc = _a.fromiteri(map(int, self.readline().split()[:3]))
     self.readline()  # natoms, nspecies
     self.readline()  # species
     cell = _a.fromiterd(map(float, self.readline().split()[:9]))
     # Typically ScaleUp uses very large unit-cells
     # so supercells will typically be restricted to [3, 3, 3]
     return SuperCell(cell * Bohr2Ang, nsc=nsc)
Exemple #21
0
    def read_sc(self):
        """ Returns `SuperCell` object from the XV file """

        cell = np.empty([3, 3], np.float64)
        for i in range(3):
            cell[i, :] = np.fromstring(self.readline(),
                                       dtype=float, sep=' ')[0:3]
        cell *= Bohr2Ang

        return SuperCell(cell)
Exemple #22
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 #23
0
 def read_supercell(self):
     """ Returns a SuperCell object from a TranSiesta file """
     n_s = _siesta.read_tshs_sizes(self.file)[3]
     _bin_check(self, 'read_supercell', 'could not read sizes.')
     arr = _siesta.read_tshs_cell(self.file, n_s)
     _bin_check(self, 'read_supercell', 'could not read cell.')
     nsc = np.array(arr[0], np.int32)
     cell = np.array(arr[1].T, np.float64)
     cell.shape = (3, 3)
     return SuperCell(cell, nsc=nsc)
Exemple #24
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 #25
0
 def read_supercell(self):
     """ Reads a supercell from the Sile """
     # 1st line is number of supercells
     nsc = ensure_array(map(int, self.readline().split()[:3]), np.int32)
     self.readline() # natoms, nspecies
     self.readline() # species
     cell = ensure_array(map(float, self.readline().split()[:9]), np.float64)
     # Typically ScaleUp uses very large unit-cells
     # so supercells will typically be restricted to [3, 3, 3]
     return SuperCell(cell * Bohr2Ang)
Exemple #26
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 #27
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 #28
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 #29
0
    def read_supercell(self):
        """ Reads supercell object from the file """
        self.fh.seek(0)

        # read until "lattice_vector" is found
        cell = []
        for line in self:
            if line.startswith("lattice_vector"):
                cell.append([float(f) for f in line.split()[1:]])

        return SuperCell(cell)
Exemple #30
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
        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])
Exemple #32
0
    def test_spin1(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)
        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 #34
0
    def _read_sc(self):
        """ Defered routine """

        f, l = self.step_to('unit_cell_cart', case=False)
        if not f:
            raise ValueError("The unit-cell vectors could not be found in the seed-file.")

        # Create the cell
        cell = np.empty([3, 3], np.float64)
        for i in [0, 1, 2]:
            cell[i, :] = [float(x) for x in self.readline().split()]

        return SuperCell(cell)
Exemple #35
0
class TestGrid(object):

    def setUp(self):
        alat = 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) * alat, nsc=[3, 3, 1])
        self.g = Grid([10, 10, 100], sc=self.sc)

    def tearDown(self):
        del self.sc
        del self.g

    def test_append(self):
        g = self.g.append(self.g, 0)
        assert_true(np.allclose(g.grid.shape, [20, 10, 100]))
        g = self.g.append(self.g, 1)
        assert_true(np.allclose(g.grid.shape, [10, 20, 100]))
        g = self.g.append(self.g, 2)
        assert_true(np.allclose(g.grid.shape, [10, 10, 200]))

    def test_size(self):
        assert_true(np.allclose(self.g.grid.shape, [10, 10, 100]))
        
    def test_item(self):
        assert_true(np.allclose(self.g[1:2, 1:2, 2:3], self.g.grid[1:2, 1:2, 2:3]))

    def test_dcell(self):
        assert_true(np.all(self.g.dcell*self.g.cell >= 0))

    def test_dvol(self):
        assert_true(self.g.dvol > 0)

    def test_shape(self):
        assert_true(np.all(self.g.shape == self.g.grid.shape))

    def test_dtype(self):
        assert_true(self.g.dtype == self.g.grid.dtype)

    def test_copy(self):
        assert_true(self.g.copy() == self.g)

    def test_swapaxes(self):
        g = self.g.swapaxes(0, 1)
        assert_true(np.allclose(self.g.cell[0,:], g.cell[1,:]))
        assert_true(np.allclose(self.g.cell[1,:], g.cell[0,:]))

    def test_interp(self):
        shape = np.array(self.g.shape, np.int32)
        g = self.g.interp(shape * 2)
        g1 = g.interp(shape)
        assert_true(np.allclose(self.g.grid, g1.grid))

    def test_index1(self):
        mid = np.array(self.g.shape, np.int32) // 2
        idx = self.g.index(self.sc.center())
        print(mid, idx)
        assert_true(np.all(mid == idx))

    def test_sum(self):
        for i in range(3):
            assert_true(self.g.sum(i).shape[i] == 1)

    def test_mean(self):
        for i in range(3):
            assert_true(self.g.mean(i).shape[i] == 1)

    def test_cross_section(self):
        for i in range(3):
            assert_true(self.g.cross_section(1, i).shape[i] == 1)

    def test_remove_part(self):
        for i in range(3):
            assert_true(self.g.remove_part(1, i, above=True).shape[i] == 1)

    def test_sub_part(self):
        for i in range(3):
            assert_true(self.g.sub_part(1, i, above=False).shape[i] == 1)

    def test_sub(self):
        for i in range(3):
            assert_true(self.g.sub(1, i).shape[i] == 1)
        for i in range(3):
            assert_true(self.g.sub([1,2], i).shape[i] == 2)

    def test_remove(self):
        for i in range(3):
            assert_true(self.g.remove(1, i).shape[i] == self.g.shape[i]-1)
        for i in range(3):
            assert_true(self.g.remove([1,2], i).shape[i] == self.g.shape[i]-2)

    def test_argumentparser(self):
        self.g.ArgumentParser()