Ejemplo n.º 1
0
def trans_cal():
    from mpi4py import MPI
    from aces.App import App
    m = App().m
    comm = MPI.COMM_WORLD
    rank = comm.Get_rank()
    size = comm.Get_size()
    print("my rank is: %d" % rank)
    if rank == 0:
        print("Reading force constants from cache")
    d = np.load('fcbin.npz')
    fccenter, fcleft, fcright = d['fccenter'], d['fcleft'], d['fcright']

    #fccenter,fcleft,fcright = comm.bcast((fccenter,fcleft,fcright) if rank == 0 else None, root=0)
    print rank, len(fccenter)
    total = 400.0
    fmax = m.fmax
    dm = fmax / total
    intval = dm * size

    omega = np.arange(dm * rank, fmax, intval)  # THz
    factor = 1e12**2 * 1e-20 * 1e-3 / 1.6e-19 / 6.23e23
    energies = (omega * 2.0 * np.pi)**2 * factor
    mkdir('tmp')
    from ase.transport.calculators import TransportCalculator
    # important trick!
    # if eta is too small , there would be infinite value in transmission
    # while if eta is too large, the transmission will be curve.
    #
    if m.eta is None:
        eta = np.abs(fccenter).max() * 1e-5
        eta1 = np.abs(fcleft).max() * 1e-4
        eta2 = np.abs(fcright).max() * 1e-4
    else:
        if hasattr(m.eta, 'extend'):
            eta, eta1, eta2 = m.eta
        else:
            eta, eta1, eta2 = m.eta, m.eta, m.eta
    tcalc = TransportCalculator(
        h=fccenter,
        h1=fcleft,
        h2=fcright,
        energies=energies,
        dos=True,
        logfile='tmp/negf.log' +
        str(rank),
        eta=eta,
        eta1=eta1,
        eta2=eta2)
    if rank == 0:
        print('Calculate Transmission')
    trans = tcalc.get_transmission()
    if rank == 0:
        print('Calculate Dos')
    dos = tcalc.get_dos() * omega
    # np.savez('tmp/result%s.npz'%(rank),x=omega,trans=trans,dos=dos)

    to_txt(['omega', 'trans', 'dos'], np.c_[
           omega, trans, dos], 'tmp/result.txt' + str(rank))
Ejemplo n.º 2
0
def trans_cal():
    from mpi4py import MPI
    from aces.App import App
    m = App().m
    comm = MPI.COMM_WORLD
    rank = comm.Get_rank()
    size = comm.Get_size()
    print("my rank is: %d" % rank)
    if rank == 0:
        print("Reading force constants from cache")
    d = np.load('fcbin.npz')
    fccenter, fcleft, fcright = d['fccenter'], d['fcleft'], d['fcright']

    #fccenter,fcleft,fcright = comm.bcast((fccenter,fcleft,fcright) if rank == 0 else None, root=0)
    print rank, len(fccenter)
    total = 400.0
    fmax = m.fmax
    dm = fmax / total
    intval = dm * size

    omega = np.arange(dm * rank, fmax, intval)  # THz
    factor = 1e12**2 * 1e-20 * 1e-3 / 1.6e-19 / 6.23e23
    energies = (omega * 2.0 * np.pi)**2 * factor
    mkdir('tmp')
    from ase.transport.calculators import TransportCalculator
    # important trick!
    # if eta is too small , there would be infinite value in transmission
    # while if eta is too large, the transmission will be curve.
    #
    if m.eta is None:
        eta = np.abs(fccenter).max() * 1e-5
        eta1 = np.abs(fcleft).max() * 1e-4
        eta2 = np.abs(fcright).max() * 1e-4
    else:
        if hasattr(m.eta, 'extend'):
            eta, eta1, eta2 = m.eta
        else:
            eta, eta1, eta2 = m.eta, m.eta, m.eta
    tcalc = TransportCalculator(h=fccenter,
                                h1=fcleft,
                                h2=fcright,
                                energies=energies,
                                dos=True,
                                logfile='tmp/negf.log' + str(rank),
                                eta=eta,
                                eta1=eta1,
                                eta2=eta2)
    if rank == 0:
        print('Calculate Transmission')
    trans = tcalc.get_transmission()
    if rank == 0:
        print('Calculate Dos')
    dos = tcalc.get_dos() * omega
    # np.savez('tmp/result%s.npz'%(rank),x=omega,trans=trans,dos=dos)

    to_txt(['omega', 'trans', 'dos'], np.c_[omega, trans, dos],
           'tmp/result.txt' + str(rank))
Ejemplo n.º 3
0
 def test(self):
     dm = .1
     omega = np.arange(dm, 60, dm)  #THz
     factor = 1e12**2 * 1e-20 * 1e-3 / 1.6e-19 / 6.23e23
     energies = (omega * 2.0 * np.pi)**2 * factor
     #energies=np.arange(0,10,.01)
     h = -np.array((-2, 1, 0, 1, -2, 1, 0, 1, -2)).reshape((3, 3))
     h1 = -np.array((-2, 1, 1, -2)).reshape((2, 2))
     #x=1.0/np.sqrt(2)
     #h1=h=-np.array((-2,x,0,0,x,-1,x,0,0,x,-2,x,0,0,x,-1)).reshape((4,4))
     #energies = np.arange(-3, 3, 0.1)
     calc = TransportCalculator(h=h, h1=h1, energies=energies, dos=True)
     T = calc.get_transmission()
     #print T
     dos = calc.get_dos() * omega
     plot([omega, 'Frequency (THz)'], [T, 'Transmission'],
          'test_green_transmission.png')
     plot([omega, 'Frequency (THz)'], [dos, 'Phonon Density of State'],
          'test_green_dos.png')
Ejemplo n.º 4
0
    def ase_et(self, scatter_hamil):

        # Set up options if we want to call ASE with special cases
        if self.input.dict['orthonormal_overlap'] != 'False':
            scatter_hamil['s'] = None
            scatter_hamil['s1'] = None
            scatter_hamil['s2'] = None
        # initialize the calculator
        ETran = TCalc(h=scatter_hamil['h'],
                      h1=scatter_hamil['h1'],
                      h2=scatter_hamil['h2'],
                      s=scatter_hamil['s'],
                      s1=scatter_hamil['s1'],
                      s2=scatter_hamil['s2'])

        # Disable reading in the off diagonal matrices
        if (self.input.dict['exclude_coupling'] == 'False'):
            ETran.set(hc1=scatter_hamil['hc1'],
                      hc2=scatter_hamil['hc2'],
                      sc1=scatter_hamil['sc1'],
                      sc2=scatter_hamil['sc2'])
        # either calculate the electron transport at the Fermi level or a
        # range of values relative to the Fermi level
        if (self.input.dict['energy_levels_ET'] is None):
            temp_form = [(0.0)]
            ETran.set(energies=[(0.0)])
        else:
            temp_form = self.input.dict['energy_levels_ET']
            ETran.set(
                energies=np.arange(temp_form[0], temp_form[1], temp_form[2]))

        # ase has some warnings that we can't do anything about,
        # so suppress the warnings
        with warnings.catch_warnings():
            warnings.filterwarnings("ignore", category=FutureWarning)
            T = ETran.get_transmission()
        # print results
        if (self.input.dict['energy_levels_ET'] is not None):
            j = 0
            for i in np.arange(temp_form[0], temp_form[1], temp_form[2]):
                printx("Energy = {0:.3f} Transmission = {1}".format(i, T[j]),
                       self.file)
                j += 1
            self.print_conductance(T, temp_form[2], temp_form[0], temp_form[1])
        else:
            printx("Energy = 0.0  Transmission = {0}".format(T[0]), self.file)
        printx("\n", self.file)

        return
Ejemplo n.º 5
0
    def generate(self):
        self.m.xp = 1
        leadm = self.preLead()
        self.phonopy('lead', leadm)
        centerm = self.preCenter()
        self.phonopy('center', centerm)

        fccenter, fclead = self.collect()
        dm = .5
        omega = np.arange(dm, 60, dm)  #THz
        factor = 1e12**2 * 1e-20 * 1e-3 / 1.6e-19 / 6.23e23
        energies = (omega * 2.0 * np.pi)**2 * factor
        tcalc = TransportCalculator(h=fccenter,
                                    h1=fclead,
                                    h2=fclead,
                                    energies=energies,
                                    logfile='negf.log',
                                    dos=True)
        print 'Calculate Transmission'
        trans = tcalc.get_transmission()
        print 'Calculate Dos'
        dos = tcalc.get_dos() * omega
        print 'Calculate Thermal Conductance'
        self.post()
Ejemplo n.º 6
0
def test_transport_calculator():
    H_lead = np.zeros([4, 4])

    # On-site energies are zero
    for i in range(4):
        H_lead[i, i] = 0.0

    # Nearest neighbor hopping is -1.0
    for i in range(3):
        H_lead[i, i + 1] = -1.0
        H_lead[i + 1, i] = -1.0

    # Next-nearest neighbor hopping is 0.2
    for i in range(2):
        H_lead[i, i + 2] = 0.2
        H_lead[i + 2, i] = 0.2

    H_scat = np.zeros([6, 6])
    # Principal layers on either side of S
    H_scat[:2, :2] = H_lead[:2, :2]
    H_scat[-2:, -2:] = H_lead[:2, :2]

    # Scattering region
    H_scat[2, 2] = 0.0
    H_scat[3, 3] = 0.0
    H_scat[2, 3] = -0.8
    H_scat[3, 2] = -0.8

    # External coupling
    H_scat[1, 2] = 0.2
    H_scat[2, 1] = 0.2
    H_scat[3, 4] = 0.2
    H_scat[4, 3] = 0.2

    energies = np.arange(-3, 3, 0.02)
    tcalc = TransportCalculator(h=H_scat,
                                h1=H_lead,
                                eta=0.02,
                                energies=energies)

    T = tcalc.get_transmission()
    tcalc.set(pdos=[2, 3])
    pdos = tcalc.get_pdos()

    tcalc.set(dos=True)
    dos = tcalc.get_dos()

    write('T.dat', tcalc.energies, T)
    write('pdos0.dat', tcalc.energies, pdos[0])
    write('pdos1.dat', tcalc.energies, pdos[1])

    #subdiagonalize
    h_rot, s_rot, eps, u = tcalc.subdiagonalize_bfs([2, 3], apply=True)
    T_rot = tcalc.get_transmission()
    dos_rot = tcalc.get_dos()
    pdos_rot = tcalc.get_pdos()

    write('T_rot.dat', tcalc.energies, T_rot)
    write('pdos0_rot.dat', tcalc.energies, pdos_rot[0])
    write('pdos1_rot.dat', tcalc.energies, pdos_rot[1])

    print('Subspace eigenvalues:', eps)
    assert sum(abs(eps - (-0.8, 0.8))) < 2.0e-15, 'Subdiagonalization. error'
    print('Max deviation of T after the rotation:', np.abs(T - T_rot).max())
    assert max(abs(T - T_rot)) < 2.0e-15, 'Subdiagonalization. error'

    #remove coupling
    h_cut, s_cut = tcalc.cutcoupling_bfs([2], apply=True)
    T_cut = tcalc.get_transmission()
    dos_cut = tcalc.get_dos()
    pdos_cut = tcalc.get_pdos()

    write('T_cut.dat', tcalc.energies, T_cut)
    write('pdos0_cut.dat', tcalc.energies, pdos_cut[0])
    write('pdos1_cut.dat', tcalc.energies, pdos_cut[1])
Ejemplo n.º 7
0
stm = reload(stm)
stm_calc = stm.STM(h1, s1, h2, s2, h10, s10, h20, s20, eta1, eta2)
energies = np.arange(-3.0, 3.0, 0.01)
stm_calc.initialize(energies)

T_stm = stm_calc.get_transmission(V_ts)

#Perform the full calculation and compare
from ase.transport.calculators import TransportCalculator as TC

h = np.zeros([4, 4])
h[:2, :2] = h1
h[-2:, -2:] = h2
h[:2, -2:] = V_ts
h[-2:, :2] = V_ts.T

tc = TC(energies=energies, h=h, h1=h10, h2=h20, eta=eta1, eta1=eta1, eta2=eta2)

T_full = tc.get_transmission()

pylab.plot(stm_calc.energies, T_stm, 'b')
pylab.plot(tc.energies, T_full, 'r--')
pylab.show()

#bias stuff
biass = np.arange(-2.0, 2.0, 0.2)
Is = [stm_calc.get_current(bias, V_ts) for bias in biass]
pylab.plot(biass, Is, '+')
pylab.show()
Ejemplo n.º 8
0
                   [0.2, -1., 0., -1.], [0., 0.2, -1., 0.]])

H_scat = np.zeros((6, 6))

# Principal layers on either side of S
H_scat[:2, :2] = H_scat[-2:, -2:] = H_lead[:2, :2]

# Scattering region (hydrogen molecule) - onsite 0.0 and hopping -0.8
H_scat[2:4, 2:4] = [[0.0, -0.8], [-0.8, 0.0]]

# coupling to the leads - nearest neighbor only
H_scat[1, 2] = H_scat[2, 1] = H_scat[3, 4] = H_scat[4, 3] = 0.2

tcalc = TransportCalculator(
    h=H_scat,  # Scattering Hamiltonian
    h1=H_lead,  # Lead 1 (left)
    h2=H_lead,  # Lead 2  (right)
    energies=np.arange(-3, 3, 0.02))

T_e = tcalc.get_transmission()
pylab.plot(tcalc.energies, T_e)
pylab.title('Transmission function')
pylab.show()

tcalc.set(pdos=[2, 3])
pdos_ne = tcalc.get_pdos()
pylab.plot(tcalc.energies, pdos_ne[0], ':')
pylab.plot(tcalc.energies, pdos_ne[1], '--')
pylab.title('Projected density of states')
pylab.show()
Ejemplo n.º 9
0
H_scat[-2:, -2:] = H_lead[:2, :2]

# Scattering region
H_scat[2, 2] = 0.0
H_scat[3, 3] = 0.0
H_scat[2, 3] = -0.8
H_scat[3, 2] = -0.8

# External coupling
H_scat[1, 2] = 0.2
H_scat[2, 1] = 0.2
H_scat[3, 4] = 0.2
H_scat[4, 3] = 0.2

energies = np.arange(-3, 3, 0.02)
tcalc = TransportCalculator(h=H_scat, h1=H_lead, eta=0.02, energies=energies)

T = tcalc.get_transmission()
tcalc.set(pdos=[2, 3])
pdos = tcalc.get_pdos()

tcalc.set(dos=True)
dos = tcalc.get_dos()

write('T.dat', tcalc.energies, T)
write('pdos0.dat', tcalc.energies, pdos[0])
write('pdos1.dat', tcalc.energies, pdos[1])

#subdiagonalize
h_rot, s_rot, eps, u = tcalc.subdiagonalize_bfs([2, 3], apply=True)
T_rot = tcalc.get_transmission()
Ejemplo n.º 10
0
stm_calc.initialize(energies)


T_stm = stm_calc.get_transmission(V_ts)


# Perform the full calculation and compare
from ase.transport.calculators import TransportCalculator as TC

h = np.zeros([4, 4])
h[:2, :2] = h1
h[-2:, -2:] = h2
h[:2, -2:] = V_ts
h[-2:, :2] = V_ts.T


tc = TC(energies=energies, h=h, h1=h10, h2=h20, eta=eta1, eta1=eta1, eta2=eta2)

T_full = tc.get_transmission()

pylab.plot(stm_calc.energies, T_stm, "b")
pylab.plot(tc.energies, T_full, "r--")
pylab.show()


# bias stuff
biass = np.arange(-2.0, 2.0, 0.2)
Is = [stm_calc.get_current(bias, V_ts) for bias in biass]
pylab.plot(biass, Is, "+")
pylab.show()
Ejemplo n.º 11
0
# Principal layer size
# Uncomment this line if going back to gpawtransport again
# pl = 4 * 9 # 9 is the number of bf per Pt atom (basis=szp), see below

# Read in the hamiltonians
h, s = pickle.load(open('scat_hs.pickle', 'rb'))
# Uncomment this line if going back to gpawtransport again
# h, s = h[pl:-pl, pl:-pl], s[pl:-pl, pl:-pl]
h1, s1 = pickle.load(open('lead1_hs.pickle', 'rb'))
h2, s2 = pickle.load(open('lead2_hs.pickle', 'rb'))

tcalc = TransportCalculator(
    h=h,
    h1=h1,
    h2=h2,  # hamiltonian matrices
    s=s,
    s1=s1,
    s2=s2,  # overlap matrices
    align_bf=1)  # align the Fermi levels

# Calculate the conductance (the energy zero corresponds to the Fermi level)
tcalc.set(energies=[0.0])
G = tcalc.get_transmission()[0]
print('Conductance: %.2f 2e^2/h' % G)

# Determine the basis functions of the two Hydrogen atoms and subdiagonalize
Pt_N = 5  # Number of Pt atoms on each side in the scattering region
Pt_nbf = 15  # number of bf per Pt atom (basis=szp)
H_nbf = 4  # number of bf per H atom (basis=szp)
bf_H1 = Pt_nbf * Pt_N
bfs = range(bf_H1, bf_H1 + 2 * H_nbf)
Ejemplo n.º 12
0
calc.set(kpts=kpts, usesymm=usesymm)
atoms.get_potential_energy()

efermi = calc.get_fermi_level()
ibzk2d_k, weight2d_k, h_skmm, s_kmm\
= get_lead_lcao_hamiltonian(calc, direction=direction)
h_kmm = h_skmm[0] - efermi * s_kmm

T_kpts = np.zeros_like(energies)

i = 0
for h_mm, s_mm, weight in zip(h_kmm, s_kmm, weight2d_k):
    print i
    tc = TC(energies=energies,
            h=h_mm, s=s_mm,
            h1=h_mm, s1=s_mm,
            h2=h_mm, s2=s_mm,
            align_bf=0)
    tc.initialize()
    T_kpts += tc.get_transmission() * weight
    i += 1

# repeat the system in the transverse directions
repeat = np.ones((3,))
repeat[transverse_dirs] = np.asarray(kpts)[transverse_dirs].astype(int)
atoms2 = atoms.repeat(repeat)

kpts2 = np.ones((3,))
kpts2[dir] = kpts[dir]
calc.set(kpts=tuple(kpts2.astype(int)), usesymm=usesymm)
atoms2.set_calculator(calc)
                   [0.2, -1.,  0., -1.],
                   [0.,  0.2, -1.,  0.]])

H_scat = np.zeros((6, 6))

# Principal layers on either side of S
H_scat[:2, :2] = H_scat[-2:, -2:] = H_lead[:2, :2]

# Scattering region (hydrogen molecule) - onsite 0.0 and hopping -0.8
H_scat[2:4, 2:4] = [[0.0, -0.8], [-0.8, 0.0]]

# coupling to the leads - nearest neighbor only
H_scat[1, 2] = H_scat[2, 1] = H_scat[3, 4] = H_scat[4, 3] = 0.2

tcalc = TransportCalculator(h=H_scat,  # Scattering Hamiltonian
                            h1=H_lead,  # Lead 1 (left)
                            h2=H_lead,  # Lead 2  (right)
                            energies=np.arange(-3, 3, 0.02))

T_e = tcalc.get_transmission()
pylab.plot(tcalc.energies, T_e)
pylab.title('Transmission function')
pylab.show()

tcalc.set(pdos=[2, 3])
pdos_ne = tcalc.get_pdos()
pylab.plot(tcalc.energies, pdos_ne[0], ':')
pylab.plot(tcalc.energies, pdos_ne[1], '--')
pylab.title('Projected density of states')
pylab.show()

h_rot, s_rot, eps_n, vec_nn = tcalc.subdiagonalize_bfs([2, 3])
Ejemplo n.º 14
0
# Scattering region
H_scat[2,2] = 0.0
H_scat[3,3] = 0.0
H_scat[2,3] = -0.8
H_scat[3,2] = -0.8

# External coupling
H_scat[1,2] = 0.2
H_scat[2,1] = 0.2
H_scat[3,4] = 0.2
H_scat[4,3] = 0.2

energies = np.arange(-3,3,0.02)
tcalc = TransportCalculator(h=H_scat,
                            h1=H_lead,
                            h2=H_lead,
                            energies=energies)

T = tcalc.get_transmission()
tcalc.set(pdos=[2, 3])
pdos = tcalc.get_pdos()

tcalc.set(dos=True)
dos = tcalc.get_dos()

write('T.dat',tcalc.energies,T)
write('pdos0.dat', tcalc.energies,pdos[0])
write('pdos1.dat', tcalc.energies,pdos[1])

#subdiagonalize
h_rot, s_rot, eps, u = tcalc.subdiagonalize_bfs([2, 3])
Ejemplo n.º 15
0
atoms.get_potential_energy()

efermi = calc.get_fermi_level()
ibzk2d_k, weight2d_k, h_skmm, s_kmm\
= get_lead_lcao_hamiltonian(calc, direction=direction)
h_kmm = h_skmm[0] - efermi * s_kmm

T_kpts = np.zeros_like(energies)

i = 0
for h_mm, s_mm, weight in zip(h_kmm, s_kmm, weight2d_k):
    print i
    tc = TC(energies=energies,
            h=h_mm,
            s=s_mm,
            h1=h_mm,
            s1=s_mm,
            h2=h_mm,
            s2=s_mm,
            align_bf=0)
    tc.initialize()
    T_kpts += tc.get_transmission() * weight
    i += 1

# repeat the system in the transverse directions
repeat = np.ones((3, ))
repeat[transverse_dirs] = np.asarray(kpts)[transverse_dirs].astype(int)
atoms2 = atoms.repeat(repeat)

kpts2 = np.ones((3, ))
kpts2[dir] = kpts[dir]
calc.set(kpts=tuple(kpts2.astype(int)), usesymm=usesymm)
import pickle
import pylab

# Principal layer size
# Uncomment this line if going back to gpawtransport again
# pl = 4 * 9 # 9 is the number of bf per Pt atom (basis=szp), see below

# Read in the hamiltonians
h, s = pickle.load(file('scat_hs.pickle'))
# Uncomment this line if going back to gpawtransport again
# h, s = h[pl:-pl, pl:-pl], s[pl:-pl, pl:-pl]
h1, s1 = pickle.load(file('lead1_hs.pickle'))
h2, s2 = pickle.load(file('lead2_hs.pickle'))

tcalc = TransportCalculator(h=h, h1=h1, h2=h2,  # hamiltonian matrices
                            s=s, s1=s1, s2=s2,  # overlap matrices
                            align_bf=1)        # align the Fermi levels

# Calculate the conductance (the energy zero corresponds to the Fermi level)
tcalc.set(energies=[0.0])
G = tcalc.get_transmission()[0]
print('Conductance: %.2f 2e^2/h' % G)

# Determine the basis functions of the two Hydrogen atoms and subdiagonalize
Pt_N = 5    # Number of Pt atoms on each side in the scattering region
Pt_nbf = 9  # number of bf per Pt atom (basis=szp)
H_nbf = 4   # number of bf per H atom (basis=szp)
bf_H1 = Pt_nbf * Pt_N
bfs = range(bf_H1, bf_H1 + 2 * H_nbf)
h_rot, s_rot, eps_n, vec_jn = tcalc.subdiagonalize_bfs(bfs)
for n in range(len(eps_n)):