Beispiel #1
0
    def HS_and_eigen(self, kpts=None, convention=2):
        if kpts is not None:
            self.calc.set(kpts=kpts)
            self.atoms.calc=self.calc
            self.atoms.get_total_energy()

        self.calc.set(symmetry='off', fixdensity=True)
        self.atoms.get_total_energy()
        #self.kpt_u = self.wfs.kpt_u
        H, S= get_lcao_hamiltonian(self.calc)
        np.save('kpts.npy', kpts)
        np.save('H.npy', H)
        np.save('S.npy', S)

        nspin, nkpt, norb, _ = H.shape
        nbasis=nspin*norb
        evals=np.zeros((nkpt, nbasis), dtype=float)
        evecs=np.zeros((nkpt, nbasis, nbasis),dtype=complex)
        if self.calc.get_spin_polarized():
            H2=np.zeros((nkpt, nbasis, nbasis),dtype=complex)
            # spin up
            H2[:, :nbasis, :nbasis]=H[0]
            # spin down
            H2[:, nbasis:, nbasis:]=H[1]
            S2=np.zeros((nkpt, nbasis, nbasis),dtype=complex)
            S2[:, :norb, :orb]=S
            S2[:, norb:, norb:]=S

            for ikpt, k in enumerate(self.calc.get_ibz_k_points()):
                evals0, evecs0 = eigh(H[0, ikpt,:,:], S[ikpt,:,:])
                evals1, evecs1 = eigh(H[1, ikpt,:,:], S[ikpt,:,:])
                evals[ikpt, :nbasis]=evals0
                evals[ikpt, nbasis:]=evals1
                evecs[ikpt, :nbasis, :nbasis]=evecs0
                evecs[ikpt, nbasis:, nbasis:]=evecs1
        else:
            H2=H[0]
            for ikpt, k in self.kpt_u:
                evals[ikpt], evecs[ikpt]= eigh(H[0, ikpt], S[ikpt])
        np.save('kpts.npy', kpts)
        np.save('H2.npy', H2)
        np.save('S2.npy', S2)
        np.save('evals.npy', evals)
        np.save('evecs.npy', evecs)
        return H2, S2, evals, evecs
Beispiel #2
0
    def __init__(self, calc, spin=0):
        assert calc.wfs.gd.comm.size == 1
        assert calc.wfs.kd.comm.size == 1
        assert calc.wfs.bd.comm.size == 1

        from gpaw.lcao.tools import get_lcao_hamiltonian
        H_skMM, S_kMM = get_lcao_hamiltonian(calc)

        self.calc = calc
        self.dtype = calc.wfs.dtype
        self.spin = spin
        self.H_qww = H_skMM[spin]
        self.S_qww = S_kMM
        self.P_aqwi = calc.wfs.P_aqMi
        self.Nw = self.S_qww.shape[-1]

        for S in self.S_qww:
            print('Condition number: %0.1e' % condition_number(S))
    def __init__(self, calc, spin=0):
        assert calc.wfs.gd.comm.size == 1
        assert calc.wfs.kd.comm.size == 1
        assert calc.wfs.band_comm.size == 1
        
        from gpaw.lcao.tools import get_lcao_hamiltonian
        H_skMM, S_kMM = get_lcao_hamiltonian(calc)

        self.calc = calc
        self.dtype = calc.wfs.dtype
        self.spin = spin
        self.H_qww = H_skMM[spin]
        self.S_qww = S_kMM
        self.P_aqwi = calc.wfs.P_aqMi
        self.Nw = self.S_qww.shape[-1]
        
        for S in self.S_qww:
            print('Condition number: %0.1e' % condition_number(S))
Beispiel #4
0
def get_h_and_s(calc, direction='x'):
    '''
        The function below performs
            1. tri2full
            2. *= Hartree
    '''
    h_skmm, s_kmm = get_lcao_hamiltonian(calc)
    '''
        The code below performs
            1. remove_pbc
            2. align_fermi
    '''
    d = 'xyz'.index(direction)
    nspins, nkpts = h_skmm.shape[:2]
    for s in range(nspins):
        for k in range(nkpts):
            if s == 0:
                remove_pbc(atoms, h_skmm[s, k], s_kmm[k], d)
            else:
                remove_pbc(atoms, h_skmm[s, k], None, d)
            h_skmm[s, k] -= s_kmm[k] * calc.occupations.get_fermi_level()
    return h_skmm, s_kmm
Beispiel #5
0
            basis='szp(dzp)',
            occupations=FermiDirac(width=0.1),
            kpts=(1, 1, 1),
            mode='lcao',
            txt='pt_h2_lcao_scat.txt',
            mixer=Mixer(0.1, 5, weight=100.0),
            symmetry={
                'point_group': False,
                'time_reversal': False
            })
atoms.set_calculator(calc)

atoms.get_potential_energy()  # Converge everything!
Ef = atoms.calc.get_fermi_level()

H_skMM, S_kMM = get_lcao_hamiltonian(calc)
# Only use first kpt, spin, as there are no more
H, S = H_skMM[0, 0], S_kMM[0]
H -= Ef * S
remove_pbc(atoms, H, S, 0)

# Dump the Hamiltonian and Scattering matrix to a pickle file
pickle.dump((H, S), open('scat_hs.pickle', 'wb'), 2)

########################
# Left principal layer #
########################

# Use four Pt atoms in the lead, so only take those from before
atoms = atoms[:4].copy()
atoms.set_cell([4 * a, L, L])
Beispiel #6
0
if world.rank == 0:
    basis = BasisMaker('Li', 'szp').generate(1, 1)
    basis.write_xml()
world.barrier()
if setup_paths[0] != '.':
    setup_paths.insert(0, '.')

if 1:
    a = 2.7
    bulk = Atoms('Li', pbc=True, cell=[a, a, a])
    calc = GPAW(gpts=(8, 8, 8), kpts=(4, 4, 4), mode='lcao', basis='szp')
    bulk.set_calculator(calc)
    e = bulk.get_potential_energy()
    niter = calc.get_number_of_iterations()
    calc.write('temp.gpw')

atoms, calc = restart('temp.gpw')
H_skMM, S_kMM = get_lcao_hamiltonian(calc)
eigs = calc.get_eigenvalues(kpt=2)

if world.rank == 0:
    eigs2 = np.linalg.eigvals(np.linalg.solve(S_kMM[2], H_skMM[0, 2])).real
    eigs2.sort()
    assert abs(sum(eigs - eigs2)) < 1e-8

    energy_tolerance = 0.00003
    niter_tolerance = 0
    equal(e, -1.82847, energy_tolerance)
    equal(niter, 5, niter_tolerance)