Re: [Kwant] Plotting energy as a function of magnetic field in 3D.

2019-09-11 Thread Anton Akhmerov
Dear Naveen,

If you are dealing with a continuum Hamiltonian (so a polynomial in
k-space), then there is a recent addition to Kwant, that allows to
compute Landau levels. Please check out if this tutorial is what you
are looking for:
https://kwant-project.org/doc/dev/tutorial/magnetic_field#adding-magnetic-field
(if you click the "activate thebelab" button, you can also play around
with the code in your browser).

If that suits your needs, you'd need to either install a development
version of Kwant or just get this file:
https://gitlab.kwant-project.org/kwant/kwant/blob/master/kwant/continuum/landau_levels.py

Let me know if that answers your question,
Anton

On Wed, 11 Sep 2019 at 18:39, Naveen Yadav  wrote:
>
> Dear sir,
>
> I understood that this code is off no use. The leads are useless here.
> Actually, I want to plot the Landau fan. Can KWANT  do the job here?
>
>
>
>
>
>
>
>
>
>
>
> Naveen
> Department of Physics & Astrophysics
> University of Delhi
> New Delhi-110007
>
> On Mon, Sep 9, 2019, 00:50 Abbout Adel  wrote:
>>
>> Dear Naveen,
>>
>> If your concern is the program which is slow, that is not an issue since it 
>> takes just few minutes.
>> Now, if you are talking about the result, I want to be sure that you notice 
>> that your system is not infinite as you claim in your email.
>> You can check that by adding extra cells from the lead" 
>> syst.attach_lead(lead, add_cells=10)
>> Actually, in your case, the presence of the leads is useless since at the 
>> end, you are just diagonalizing the Hamiltonian of the central system.
>> If you want to study an infinite system in x and y, you need to look at the 
>> module "wraparound" and the example of graphene that is in the archive of 
>> kwant.
>> For the magnetic field, you can use the Pierls substitution. check for 
>> example this paper [1]
>>
>> You can also think about the use of continuous Hamiltonian in kwant. You may 
>> find it very useful [2]
>> I hope this helps.
>>
>> Regards,
>> Adel
>>
>>
>> [1]  https://arxiv.org/pdf/1601.06507.pdf
>> [2] https://kwant-project.org/doc/1/tutorial/discretize
>>
>> On Sun, Sep 8, 2019 at 6:16 PM Naveen Yadav  wrote:
>>>
>>> Dear Sir,
>>> Thanks for the tips. As you told, I have tried in other way also but I am 
>>> getting the same result which are very tedious. I don't know where is fault.
>>> Now the code looks like
>>>
>>> import kwant
>>> import scipy.sparse.linalg as sla
>>> import matplotlib.pyplot as plt
>>> import tinyarray
>>> import numpy as np
>>> from numpy import cos, sin, pi
>>> import cmath
>>> from cmath import exp
>>>
>>> sigma_0 = tinyarray.array([[1, 0], [0, 1]])
>>> sigma_x = tinyarray.array([[0, 1], [1, 0]])
>>> sigma_y = tinyarray.array([[0, -1j], [1j, 0]])
>>> sigma_z = tinyarray.array([[1, 0], [0, -1]])
>>>
>>>
>>> def make_system(a=1, L=30, W=10, H=10, t=1.0, t_x=1.0, t_y=1.0, t_z=1.0, 
>>> lamda=0.1, beta=1.05):
>>> def onsite(site):
>>> return (t_z * cos(beta) + 2 * t) * sigma_z
>>>
>>> def hoppingx(site0, site1):
>>> return (-0.5 * t * sigma_z - 0.5 * 1j * t_x * sigma_x)
>>>
>>> def hoppingy(site0, site1):
>>> return -0.5 * t * sigma_z - 0.5 * 1j * t_y * sigma_y
>>>
>>> def hoppingz(site0, site1, B):
>>> y = site1.pos[1]
>>> return (-0.5 * t_z * sigma_z - 0.5 * 1j * lamda * sigma_0) * exp(2 
>>> * pi * 1j * B * a * (y-40))
>>>
>>>
>>> syst = kwant.Builder()
>>> lat = kwant.lattice.cubic(a)
>>> syst[(lat(z, y, x) for z in range(H) for y in range(W) for x in 
>>> range(L))] = onsite
>>> syst[kwant.builder.HoppingKind((1, 0, 0), lat, lat)] = hoppingz
>>> syst[kwant.builder.HoppingKind((0, 1, 0), lat, lat)] = hoppingy
>>> syst[kwant.builder.HoppingKind((0, 0, 1), lat, lat)] = hoppingx
>>>
>>> lead1=kwant.Builder(kwant.TranslationalSymmetry((0,-a,0)))
>>> lead1[(lat(z,y,x)  for z in range(H)for y in range(W)for x in 
>>> range(L))]=onsite
>>> lead1[kwant.builder.HoppingKind((1, 0, 0), lat, lat)] = hoppingz
>>> lead1[kwant.builder.HoppingKind((0, 1, 0), lat, lat)] = hoppingy
>>> lead1[kwant.builder.HoppingKind((0, 0, 1), lat, lat)] = hoppingx
>>>
>>> syst.attach_lead(lead1)
>>> syst.attach_lead(lead1.reversed())
>>>
>>> lead2=kwant.Builder(kwant.TranslationalSymmetry((-a,0,0)))
>>> lead2[(lat(z,y,x)  for z in range(H)for y in range(W)for x in 
>>> range(L))]=onsite
>>> lead2[kwant.builder.HoppingKind((1, 0, 0), lat, lat)] = hoppingz
>>> lead2[kwant.builder.HoppingKind((0, 1, 0), lat, lat)] = hoppingy
>>> lead2[kwant.builder.HoppingKind((0, 0, 1), lat, lat)] = hoppingx
>>>
>>> syst.attach_lead(lead2)
>>> syst.attach_lead(lead2.reversed())
>>> syst = syst.finalized()
>>> return syst
>>>
>>> def analyze_system(syst, Bfields):
>>> syst = make_system()
>>> kwant.plot(syst)
>>> energies = []
>>> for B in Bfields:
>>> #print(B)
>>> ham_mat = syst.hamiltonian_submatrix(params=dict(B=B), sparse=True)
>>> 

Re: [Kwant] Plotting energy as a function of magnetic field in 3D.

2019-09-11 Thread Naveen Yadav
Dear sir,

I understood that this code is off no use. The leads are useless here.
Actually, I want to plot the Landau fan. Can KWANT  do the job here?











Naveen
Department of Physics & Astrophysics
University of Delhi
New Delhi-110007

On Mon, Sep 9, 2019, 00:50 Abbout Adel  wrote:

> Dear Naveen,
>
> If your concern is the program which is slow, that is not an issue since
> it takes just few minutes.
> Now, if you are talking about the result, I want to be sure that you
> notice that your system is not infinite as you claim in your email.
> You can check that by adding extra cells from the lead" syst.attach_lead(
> lead, add_cells=10)
> Actually, in your case, the presence of the leads is useless since at the
> end, you are just diagonalizing the Hamiltonian of the central system.
> If you want to study an infinite system in x and y, you need to look at
> the module "wraparound" and the example of graphene that is in the archive
> of kwant.
> For the magnetic field, you can use the Pierls substitution. check for
> example this paper [1]
>
> You can also think about the use of continuous Hamiltonian in kwant. You
> may find it very useful [2]
> I hope this helps.
>
> Regards,
> Adel
>
>
> [1]  https://arxiv.org/pdf/1601.06507.pdf
> [2] https://kwant-project.org/doc/1/tutorial/discretize
>
> On Sun, Sep 8, 2019 at 6:16 PM Naveen Yadav 
> wrote:
>
>> Dear Sir,
>> Thanks for the tips. As you told, I have tried in other way also but I am
>> getting the same result which are very tedious. I don't know where is fault.
>> Now the code looks like
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> *import kwantimport scipy.sparse.linalg as slaimport matplotlib.pyplot as
>> pltimport tinyarrayimport numpy as npfrom numpy import cos, sin, piimport
>> cmathfrom cmath import expsigma_0 = tinyarray.array([[1, 0], [0,
>> 1]])sigma_x = tinyarray.array([[0, 1], [1, 0]])sigma_y =
>> tinyarray.array([[0, -1j], [1j, 0]])sigma_z = tinyarray.array([[1, 0], [0,
>> -1]])def make_system(a=1, L=30, W=10, H=10, t=1.0, t_x=1.0, t_y=1.0,
>> t_z=1.0, lamda=0.1, beta=1.05):def onsite(site):return (t_z *
>> cos(beta) + 2 * t) * sigma_zdef hoppingx(site0, site1):
>> return (-0.5 * t * sigma_z - 0.5 * 1j * t_x * sigma_x)def
>> hoppingy(site0, site1):return -0.5 * t * sigma_z - 0.5 * 1j * t_y *
>> sigma_ydef hoppingz(site0, site1, B):y = site1.pos[1]
>> return (-0.5 * t_z * sigma_z - 0.5 * 1j * lamda * sigma_0) * exp(2 * pi *
>> 1j * B * a * (y-40))syst = kwant.Builder()lat =
>> kwant.lattice.cubic(a)syst[(lat(z, y, x) for z in range(H) for y in
>> range(W) for x in range(L))] = onsitesyst[kwant.builder.HoppingKind((1,
>> 0, 0), lat, lat)] = hoppingzsyst[kwant.builder.HoppingKind((0, 1, 0),
>> lat, lat)] = hoppingysyst[kwant.builder.HoppingKind((0, 0, 1), lat,
>> lat)] = hoppingx
>> lead1=kwant.Builder(kwant.TranslationalSymmetry((0,-a,0)))
>> lead1[(lat(z,y,x)  for z in range(H)for y in range(W)for x in
>> range(L))]=onsitelead1[kwant.builder.HoppingKind((1, 0, 0), lat, lat)]
>> = hoppingzlead1[kwant.builder.HoppingKind((0, 1, 0), lat, lat)] =
>> hoppingylead1[kwant.builder.HoppingKind((0, 0, 1), lat, lat)] =
>> hoppingxsyst.attach_lead(lead1)syst.attach_lead(lead1.reversed())
>>   lead2=kwant.Builder(kwant.TranslationalSymmetry((-a,0,0)))
>> lead2[(lat(z,y,x)  for z in range(H)for y in range(W)for x in
>> range(L))]=onsitelead2[kwant.builder.HoppingKind((1, 0, 0), lat, lat)]
>> = hoppingzlead2[kwant.builder.HoppingKind((0, 1, 0), lat, lat)] =
>> hoppingylead2[kwant.builder.HoppingKind((0, 0, 1), lat, lat)] =
>> hoppingxsyst.attach_lead(lead2)syst.attach_lead(lead2.reversed())
>>   syst = syst.finalized()return systdef analyze_system(syst, Bfields):
>>   syst = make_system()kwant.plot(syst)energies = []for B in
>> Bfields:#print(B)ham_mat =
>> syst.hamiltonian_submatrix(params=dict(B=B), sparse=True)ev, evec =
>> sla.eigsh(ham_mat.tocsc(), k=20, sigma=0)energies.append(ev)
>> #print (energies)plt.figure()plt.plot(Bfields, energies)
>> plt.xlabel("magnetic field [${10^-3 h/e}$]")plt.ylabel("energy [t]")
>> plt.ylim(0, 0.11)plt.show()def main():syst = make_system()
>> analyze_system(syst, [B * 0.2 for B in range(101)])main()*
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> Naveen
>> Department of Physics & Astrophysics
>> University of Delhi
>> New Delhi-110007
>>
>> On Sun, Sep 8, 2019, 17:37 Abbout Adel  wrote:
>>
>>> Dear Naveen,
>>>
>>> Your program works fine. You have just a small problem of plotting.  You
>>> can solve that by changing "plt.show"  by "plt.show()".
>>>
>>> Think about putting  print (B) inside the loop when you debug your
>>> program. That