def inf_rashba_integrand(k,energy,layers=20,so_strength=0.0, theta=0.0, randomize=False,rando_strength=0.0, collector=[]):
	"""
	Integrand function for infinite Rashba plane k-integration.
	"""
	sigma_0 = 1.e-4+1.e-4j
	sites = 1
	mag = 100
	ener = energy
	delt = 0.1
	on_site = -0.067+0.j
	rashba_sys = build_rashba(on_site,1,1,so_strength,sigma_0, 500, 0.5, sites, 1,ener+0.j)
	ras = rashba_sys[0]
	if randomize:
		ras = gd.randomize_hamil(ras,rando_strength,orbitals=1)
	t_x = rashba_sys[1]
	hamil_new = ras.hamil + ras.t_y * np.exp((k)*1.j) + calc.hermitian(ras.t_y) * np.exp((-k)*1.j)
	hamil_se = sparse.kron(on_site,np.identity(2)) + ras.t_y * np.exp((k)*1.j) + calc.hermitian(ras.t_y) * np.exp((-k)*1.j)
	hamil_new = calc.build_fm_island(calc.make_hamil_layers(hamil_new, layers, t_x,sites),theta,0,delt+0.j,sites,layers,padding=False,topo=False)
	off_diag = np.diag(hamil_new,1)
	print(off_diag)
	ras.update_hamil_2(hamil_new, sites, layers,no_mag_leads = True, hamil_sub = hamil_se)
	gb = gd.find_gb_local(theta,0,ras,fm_width=layers,n_orbitals=1,topo=False,delta=delt)
	gil = gb[0]
	s = 0
	for i in range(gil.shape[0]):
		s+=gil[i]
	print("k = " + str(k))
	print("s = " + str(s))
	if randomize:
		collector.append(s)	
	return s	
def test_rashba_local():
	"""
	Compute and plot the local Gilbert Damping and LDOS of finite Rashba plane.
	"""	
	process = psutil.Process(os.getpid())
	sigma_0 = 1.e-4+1.e-4j
	layers = 100
	sites = 20
	so_strength = 0.01
	mag = 100
	ener = -0.2
	delt = 0.1
	rashba_sys = build_rashba(-0.067+0.j,1,1,so_strength,sigma_0, 500, 0.5, sites, 1,ener+0.j)
	ras = rashba_sys[0]
	t_x = rashba_sys[1]
	ras.update_hamil_2(calc.build_fm_island(calc.make_hamil_layers(ras.hamil, layers, t_x,sites),0,0,delt+0.j,sites,layers,padding=False,topo=False),sites,layers)
	ras.greens_ret = gd.mod_greens(ras,1e-2,magmom=mag,delta=delt)
	gb = gd.find_gb_local(0,0,ras,fm_width=layers,n_orbitals=1,topo=False,delta=delt)
	
	maj = gb[1]
	print(maj.size)
	grid = maj.reshape((layers,sites))
	fig, ax = plt.subplots()
	cax = ax.imshow(grid, extent=(0, sites, 0, layers), interpolation='spline16', cmap=cm.OrRd)
	cbar = fig.colorbar(cax)
	fig.savefig('rashba_majority'+str(sites)+'x'+str(layers)+'SO'+str(so_strength)+'magmom'+str(mag)+'E'+str(ener)+'.png')
	plt.close(fig)
	
	mino = gb[2]
	grid = mino.reshape((layers,sites))
	fig, ax = plt.subplots()
	cax = ax.imshow(grid, extent=(0, sites, 0, layers), interpolation='spline16', cmap=cm.OrRd)
	cbar = fig.colorbar(cax)
	fig.savefig('rashba_minority'+str(sites)+'x'+str(layers)+'SO'+str(so_strength)+'magmom'+str(mag)+'E'+str(ener)+'.png')
	plt.close(fig)
	gil = gb[0]
	s = 0
	for i in range(gil.shape[0]):
		s+=gil[i]
	grid = gil.reshape((layers,sites))
	fig, ax = plt.subplots()
	cax = ax.imshow(grid, extent=(0, sites, 0, layers), interpolation='spline16', cmap=cm.OrRd)
	cbar = fig.colorbar(cax)
	fig.savefig('rashba_gilbert'+str(sites)+'x'+str(layers)+'SO'+str(so_strength)+'magmom'+str(mag)+'E'+str(ener)+'.png')
	plt.close(fig)
	print("gilbert = " + str(s))
	print(process.memory_info().rss)