Python Forum
How should i read H_T function in below program?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How should i read H_T function in below program?
#1
My code is plotting eigenvalues of different H_T functions as E_c and E_v. For E_c i expect to have all E_c's for all Hamiltonians curved upward like for H_0. I can't find the mistake which cause it to go in wrong way for others. Belowe is my code

################################################################################
import math
import numpy as np
import matplotlib.pyplot as plt
import csv
n=150
alpha_up, alpha_down, beta_up, beta_down, kapa_up, kapa_down, Eta_up, Eta_down=-5.34, -5.71, -0.95, -0.52, -1.31, -1.23, 15.11, 17.10 #DFT
#alpha_up, alpha_down, beta_up, beta_down, kapa_up, kapa_down, Eta_up, Eta_down=-5.76, -6.2,-0.54, -0.03, -1.49, -1.4, 18.28, 20.93 #GW
#################################################################################################################################################################
f1, f2, a=1.4, 2.53/3.319, 3.319 #DFT
#f1, f2, a=2.26, 2.22/3.319, 3.319 #GW
##################################################################################################################################################################
Mp=0.25
K_p=0
Gamma=0.22
n=100
t=1
Qx=np.linspace(-Gamma/t,Mp/t,int(n))
Qy=0
###############################################################################################################################################################
#Pauli spin matricies
sx = np.array([[0, 1],[1, 0]], dtype=complex)
sy = np.array([[0, -1j],[1j, 0]], dtype=complex)
sz = np.array([[1, 0],[0, -1]], dtype=complex)
s1= np.array([[1,0],[0,1]], dtype=complex)
sg1=np.array([[1, 0], [0, 0]], dtype=complex)
sg2=np.array([[0, 0], [0, 1]], dtype=complex)
###############################################################################################################################################################
def H_T(k1,Alpha,Beta,Kapa,eta):
H_0=(0.5*f1*sz)+((f2*a)*((Qx[k1]*sx)+(Qy*sy)))
H_as=(Qx[k1]**2+Qy**2)*(Alpha*sg1+Beta*sg2)
H_3w=Kapa*(((Qx[k1]*sx)-(Qy*sy))**2)
H_cub=-(0.5*eta*(Qx[k1]**2+Qy**2))*((Qx[k1]*sx)+(Qy*sy))
H=H_0+H_as
if R==0: # H_0
H=H_0
elif R==1: #H_0+H_as
H=H_0+H_as
elif R==2: #H_0+H_as+H_3w
H=H_0+H_as+H_3w
elif R==3: #H_0+H_as+H_3w+H_cub
H=H_0+H_as+H_3w+H_cub
return H
#+H_as
#################################################################################################################################################################################################################################################################################################################
#Calculate eigenvalues of hamiltonian (E_c and E_v)
E_v=np.zeros(shape=(4,int(n)))
E_c=np.zeros(shape=(4,int(n)))
for R in range(4):
for j in range(n):
H1=H_T(j,alpha_up,beta_up,kapa_up,Eta_up)
e1=np.linalg.eigvals(H1).real
E_c[R,j]=e1[0]
H2=H_T(j,alpha_down,beta_down,kapa_down,Eta_down)
e2=np.linalg.eigvals(H2).real
E_v[R,j]=e2[1]
#Plot dispersion curve
fig1 = plt.figure()
plt.plot(Qx,E_c[0,:],'r',label=r'H$_0$', lw='3')
plt.plot(Qx,E_v[0,:], 'r--', lw='3')
plt.plot(Qx,E_c[1,:],'c',label=r'H$_0+$H$_{as}$', lw='3')
plt.plot(Qx,E_v[1,:], 'c--',lw='3')
plt.plot(Qx,E_c[2,:],'m',label=r'H$_0+$H$_{as}$+H$_{3w}$', lw='3')
plt.plot(Qx,E_v[2,:], 'm--',lw='3')
plt.plot(Qx,E_c[3,:],'k',label=r'H$_0$+H$_{as}$+H$_{3w}$+H$_{cub}$', lw='3')
plt.plot(Qx,E_v[3,:], 'k--', lw='3')
size=16
plt.legend(loc='best',fontsize=12)
plt.ylabel('Energy (eV)',fontsize=size)
plt.tick_params(axis = 'both', which = 'major', labelsize = 10)
fig1.savefig("Dispersion_MoSe2_Kormanyos15_DFT.pdf", bbox_inches='tight')
plt.show()
################################################################################
Reply
#2
This post is so ugly.
reformat using BBcode (see buran's mod note for link to instructions) and repost.

if you call function H_T, it returns H,
so:
print('{}'.format(H_T(...))
will show results (note you supply arguments in place of ...
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Noob here. Random quiz program. Using a while loop function and alot of conditionals. monkeydesu 6 1,378 Sep-07-2022, 02:01 AM
Last Post: kaega2
  I am writing a car rental program on python. In this function I am trying to modify aboo 2 2,722 Aug-05-2021, 06:00 PM
Last Post: deanhystad
  read terminal text from running program AArdvark_UK 2 1,878 Aug-27-2020, 12:43 PM
Last Post: AArdvark_UK
  How to call/read function for all elements in my list in python johnny_sav1992 1 2,065 Jul-27-2020, 04:19 PM
Last Post: buran
  python read function FlyingPig 2 4,237 Jul-07-2020, 07:27 AM
Last Post: bowlofred
  I can't read data from the clipboard in an external program AlekseyPython 1 2,595 Mar-19-2019, 07:56 AM
Last Post: buran
  Setting Byte Count in pyVisa Read Function mike505 0 5,053 Nov-17-2016, 07:43 PM
Last Post: mike505

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020