import matplotlib.pyplot as plt
import numpy as np
def read_file(filepath,L):
#L = 61
with open(filepath) as f1:
content = f1.readlines()
spin_sum = []
spin_up = []
spin_down = []
E = []
for i in content[1:L+1]:
spin_sum.append(float(i.split()[0]))
E.append(float(i.split()[1]))
for i in content[(L+3)*4+1:(L+3)*4+L+1]:
spin_up.append(float(i.split()[0]))
for i in content[(L+3)*5+1:(L+3)*5+L+1]:
spin_down.append(float(i.split()[0]))
return spin_sum, spin_up, spin_down, E
#print(read_file('Trans1_P.dat', L=61))
def plot(E,spin_up,spin_down,filepath):
plt.figure()
plt.plot(E,spin_up,'o-',label='$T_{up}$')
plt.plot(E,spin_down,'ro-',label='$T_{down}$')
plt.yscale('log')
plt.xlabel('$E-E_f(eV)$')
plt.ylabel('Transmission')
plt.xlim(-2,2)
plt.title('{}'.format(filepath))
plt.legend(loc=0)
#plt.show()
def plotTrans(E,P_spin_sum,AP_spin_sum):
plt.figure()
plt.plot(E,P_spin_sum,'o-',label='$T_{P}$')
plt.plot(E,AP_spin_sum,'ro-',label='$T_{AP}$')
plt.yscale('log')
plt.xlabel('$E-E_f(eV)$')
plt.ylabel('Transmission')
# plt.ylim(0,0.01)
plt.xlim(-2,2)
plt.legend(loc=0)
#plt.show()
def plotTMR(E,P_spin_sum,AP_spin_sum):
plt.figure()
TMR = []
for i in range(len(P_spin_sum)):
tmr = 100*(P_spin_sum[i]-AP_spin_sum[i])/AP_spin_sum[i]
TMR.append(tmr)
plt.plot(E,TMR,'o-',label='$TMR=(T_P-T_{AP})/T_{AP}$')
plt.xlabel('$E-E_f(eV)$')
plt.ylabel('TMR(%)')
# plt.xlim(-0.9,0.2)
plt.legend(loc=0)
#plt.show()
def main():
P_filepath = 'P'
P_spin_sum, P_spin_up, P_spin_down, P_E = read_file(P_filepath,L=121)
AP_filepath = 'AP'
AP_spin_sum, AP_spin_up, AP_spin_down, AP_E = read_file(AP_filepath,L=121)
plot(P_E,P_spin_up,P_spin_down,P_filepath)
plot(AP_E,AP_spin_up,AP_spin_down,AP_filepath)
if P_E == AP_E:
plotTMR(P_E,P_spin_sum,AP_spin_sum)
plotTrans(P_E,P_spin_sum,AP_spin_sum)
plt.show()
if __name__ == '__main__':
main()
import matplotlib.pyplot as plt
import numpy as np
with open('IV_PBE.dat','r') as f:
content = f.readlines()
V = []
Ip = []
Iap = []
TMR = []
for i in range(len(content)):
v = float(content[i].split()[0])
ip = float(content[i].split()[1])*1e9
iap = float(content[i].split()[2])*1e9
if iap != 0: tmr = 100*(ip-iap)/iap
# print(tmr)
V.append(v)
Ip.append(ip)
#print(-iap)
Iap.append(-iap)
TMR.append(tmr)
for i in range(len(TMR)-1,-1,-1):
print(TMR[i])
plt.figure()
plt.plot(V,Ip,'o-',label='$I_{P}$')
plt.plot(V,Iap,'ro-',label='$I_{AP}$')
#plt.yscale('log')
plt.xlabel('Voltage(V)')
plt.ylabel('I(nA)')
# plt.xlim(0,1)
plt.legend(loc=0)
#plt.show()
plt.figure()
plt.plot(V,TMR,'o-',label='$TMR=(I_P-I_{AP})/I_{AP}$')
plt.xlabel('Voltage(V)')
plt.ylabel('TMR(%)')
plt.legend(loc=0)
plt.show()