def cij(i,j): # correlation between sites i,j pairs = [(2*i,2*j),(2*i+1,2*j),(2*i,2*j+1),(2*i+1,2*j+1)] # pairs = [(2*i,2*j),(2*i+1,2*j+1)] y1 = densitymatrix.restricted_dm(h,mode="KPM",pairs=pairs,npol=500) # y1 = densitymatrix.restricted_dm(h,mode="full",pairs=pairs,npol=500) # y1 = np.array(y1).reshape(2,2) # y1 = np.linalg.det(y1) # determinant # print(y1) # print(np.linalg.svd(y1,compute_uv=False)) # y2 = np.linalg.svd(y1,compute_uv=False) # print(np.sum(y2),np.sum(y1)) return np.sum(y1) # return correlation
def cij(i, j): # correlation between sites i,j pairs = [(2 * i, 2 * j), (2 * i + 1, 2 * j), (2 * i, 2 * j + 1), (2 * i + 1, 2 * j + 1)] # pairs = [(2*i,2*j),(2*i+1,2*j+1)] y1 = densitymatrix.restricted_dm(h, mode="KPM", pairs=pairs, npol=500) # y1 = densitymatrix.restricted_dm(h,mode="full",pairs=pairs,npol=500) # y1 = np.array(y1).reshape(2,2) # y1 = np.linalg.det(y1) # determinant # print(y1) # print(np.linalg.svd(y1,compute_uv=False)) # y2 = np.linalg.svd(y1,compute_uv=False) # print(np.sum(y2),np.sum(y1)) return np.sum(y1) # return correlation
g = geometry.chain() g = g.supercell(100) g.dimensionality = 0 h = g.get_hamiltonian() #h.remove_spin() #h.add_sublattice_imbalance(.5) #h.shift_fermi(.5) h.add_rashba(.5) h.add_zeeman([0.,1.,0.]) #h.intra += np.diag(np.random.random(h.intra.shape[0])) i = 20 j = 9 x = range(0,30) pairs = [(i,i+k) for k in x] # create pairs t1 = time.clock() y1 = densitymatrix.restricted_dm(h,mode="KPM",pairs=pairs,npol=1000) t2 = time.clock() y2 = densitymatrix.restricted_dm(h,mode="full",pairs=pairs) t3 = time.clock() print(y1-y2) print("Time KPM = ",t2-t1) print("Time in inversion = ",t3-t2) #print(np.trapz(y,x=x,dx=x[1]-x[0])) plt.subplot(1,2,1) plt.plot(x,y1.real,marker="o",label="KPM") plt.plot(x,y2.real,marker="o",label="Green") plt.legend() plt.subplot(1,2,2) plt.plot(x,y1.imag,marker="o",label="KPM") plt.plot(x,y2.imag,marker="o",label="Green") plt.legend()
# Add the root path of the pygra library import os import sys sys.path.append(os.path.dirname(os.path.realpath(__file__)) + "/../../../src") from pygra import geometry # library to create crystal geometries from pygra import hamiltonians # library to work with hamiltonians from pygra import sculpt # to modify the geometry from pygra import correlator from pygra import kpm from pygra import densitymatrix import numpy as np import matplotlib.pyplot as plt import time g = geometry.bichain() g = g.supercell(100) g.dimensionality = 0 h = g.get_hamiltonian(has_spin=False) h.add_sublattice_imbalance(.03) #h.add_rashba(.5) #h.add_zeeman([0.,1.,0.]) #h.intra += np.diag(np.random.random(h.intra.shape[0])) pairs = [(0, i) for i in range(20)] y1 = densitymatrix.restricted_dm(h, mode="KPM", pairs=pairs) y2 = densitymatrix.restricted_dm(h, mode="full", pairs=pairs) plt.scatter(range(20), y1, label="KPM", c="red", s=90, marker="o") plt.scatter(range(20), y2, label="Exact", c="blue", s=20, marker="o") plt.legend() plt.show()
import numpy as np import matplotlib.pyplot as plt import time g = geometry.chain() g = g.supercell(100) g.dimensionality = 0 h = g.get_hamiltonian() h.add_rashba(.5) h.add_zeeman([0.,1.,0.]) h.intra += np.diag(np.random.random(h.intra.shape[0])) i = 0 j = 9 t1 = time.clock() rand = lambda : np.random.randint(0,40) pairs = [(i,i+np.random.randint(1,8)) for i in range(10,20)] y = densitymatrix.restricted_dm(h,mode="KPM",pairs=pairs) t2 = time.clock() y2 = densitymatrix.restricted_dm(h,mode="full",pairs=pairs) t3 = time.clock() print("Time KPM mode = ",t2-t1) print("Time in full mode = ",t3-t2) #print(np.trapz(y,x=x,dx=x[1]-x[0])) plt.subplot(1,2,1) x = range(len(y)) plt.plot(x,y.real,marker="o",label="KPM") plt.plot(x,y2.real,marker="o",label="Green") plt.legend() plt.subplot(1,2,2) plt.plot(x,y.imag,marker="o",label="KPM") plt.plot(x,y2.imag,marker="o",label="Green") plt.legend()
# Add the root path of the pygra library import os import sys sys.path.append(os.path.dirname(os.path.realpath(__file__)) + "/../../../src") from pygra import geometry from pygra import densitymatrix import numpy as np n = 400 g = geometry.chain(n) # chain g.dimensionality = 0 h = g.get_hamiltonian(has_spin=False) h.add_onsite(lambda r: 2.3 * np.cos(np.sqrt(2) / 2. * r[0])) pairs = [(n // 2, n // 2 + i) for i in range(n // 3)] y = densitymatrix.restricted_dm(h, mode="full", pairs=pairs).real import matplotlib.pyplot as plt x = np.array(range(len(y))) plt.plot(x, y * x) plt.show()
# Add the root path of the pygra library import os ; import sys ; sys.path.append(os.environ['PYGRAROOT']) from pygra import geometry from pygra import densitymatrix import numpy as np n = 400 g = geometry.chain(n) # chain g.dimensionality = 0 h = g.get_hamiltonian(has_spin=False) h.add_onsite(lambda r: 2.3*np.cos(np.sqrt(2)/2.*r[0])) pairs = [(n//2,n//2+i) for i in range(n//3)] y = densitymatrix.restricted_dm(h,mode="full",pairs=pairs).real import matplotlib.pyplot as plt x = np.array(range(len(y))) plt.plot(x,y*x) plt.show()