Dear Naveen,

As suggested by Christoph,  MayaVi  may be the best choice you can adopt.
If you give it a try let us know about the result  please.

For your program, you have some mistakes:
1) Since you have spin, norbs=2.
2) In building sys2, you need to choose a specific slice. To do so, you can
add the if condition: if site.pos[2]==z0 for example.
3) The same for the density you want to plot: from your array of the 3D
results you need to choose the elements representing the density on the
sites belonging to your slice. Again, you can achieve this with a simple if
condition.

Another remark: your potential is uniform in the z direction. The density
will be the same for all z0.
I added a small potential in "onsite0'' to make the result different as an
illustration.
Check please if the following is what you are expecting.

I hope this helps
Adel



#######################################################
import kwant
from numpy import *
from matplotlib import pyplot as plt
sigma_z=array([[1,0],[0,-1]])
sigma_x=array([[0,1],[1,0]])
sigma_y=array([[0,1j],[-1j,0]])
sigma_0=array([[1,0],[0,1]])
def make_system(a=1, L=10, W=20, H=10, t=1.0, t_x=1.0, t_y=1.0, t_z=1.0,
lamda=0.2, beta=1.05, phi=0.007):
    def onsite(site):
        return (t_z * cos(beta) + 2 * t) * sigma_z

    def onsite0(site):
        return .3+(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):
        y = site0.pos[1]
        return (-0.5 * t_z * sigma_z - 0.5 * 1j * lamda * sigma_0) * exp(2
* pi * 1j * phi * a * y)


    syst = kwant.Builder()
    lat = kwant.lattice.cubic(a, norbs=2)
    syst[(lat(x, y, z) for x in range(L) for y in range(W) for z in
range(H))] = onsite0
    syst[kwant.builder.HoppingKind((0, 0, 1), lat, lat)] = hoppingz
    syst[kwant.builder.HoppingKind((0, 1, 0), lat, lat)] = hoppingy
    syst[kwant.builder.HoppingKind((1, 0, 0), lat, lat)] = hoppingx

    lead = kwant.Builder(kwant.TranslationalSymmetry((0, 0, -a)))
    lead[(lat(x, y, z) for x in range(L) for y in range(W) for z in
range(H))] = onsite
    lead[kwant.builder.HoppingKind((0, 0, 1), lat, lat)] = hoppingz
    lead[kwant.builder.HoppingKind((0, 1, 0), lat, lat)] = hoppingy
    lead[kwant.builder.HoppingKind((1, 0, 0), lat, lat)] = hoppingx

    syst.attach_lead(lead)
    syst.attach_lead(lead.reversed())
    return syst


syst = make_system()
kwant.plot(syst)
kwant.plot(syst, pos_transform=lambda p: (p[0] , p[1]))

sysf=syst.finalized()
wf=kwant.wave_function(sysf, energy=0)
psi=wf(0)[0]
Sites=list(sysf.sites)
def analyze_system(z0=0,t=1.0, t_x=1.0, t_y=1.0, t_z=1.0, lamda=0.2,
beta=1.05):




    rho = kwant.operator.Density(sysf)
    density = rho(psi)
    wf_sqr = sum(rho(psi) for psi in wf(0))

    lat2=kwant.lattice.square(norbs=2)
    sys2=kwant.Builder()
    #Sites2=[lat2(site.pos[0],site.pos[0]) for site in Sites if
site.pos[2]=0]
    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

    #sys2[(lat2(site.pos[0],site.pos[1]) for site in Sites)]=onsite
    sys2[(lat2(site.pos[0],site.pos[1]) for site in Sites if
site.pos[2]==z0)]=onsite
    sys2[kwant.builder.HoppingKind((0, 1), lat2, lat2)] = hoppingy
    sys2[kwant.builder.HoppingKind((1, 0), lat2, lat2)] = hoppingx

    sys2f=sys2.finalized()

    plotted_wf=[elem for i,elem in enumerate(wf_sqr) if Sites[i].pos[2]==z0]
    kwant.plotter.map(sys2f, plotted_wf)
    plt.show()

def main():
    syst = make_system()
    analyze_system(z0=0)
    analyze_system(z0=5)
main()

On Tue, Jun 11, 2019 at 3:15 PM Naveen Yadav <naveengunwa...@gmail.com>
wrote:

> Dear Sir,
>
> I want to plot like the figure attached with this mail. The 2D
> visualization of probability density (abs(\psi(x, y))^2) of a 3D system in
> which density is translationally invarient in the z- direction. The code
> for making the system is given below. I tried it as you suggested, but it
> shows an error message
>
> ValueError: vector is incorrect shape.
>
> The 3D system in the code below is correct. I don't know how to proceed
> further to make another 2D system with the same onsite and hopping
> parameters. Please help me in this regard.
>
> Best regards,
> Naveen
>
> *#########################################*
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> *def make_system(a=1, L=10, W=20, H=10, t=1.0, t_x=1.0, t_y=1.0, t_z=1.0,
> lamda=0.2, beta=1.05, phi=0.007):    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):        y = site0.pos[1]        return (-0.5 * t_z *
> sigma_z - 0.5 * 1j * lamda * sigma_0) * exp(2 * pi * 1j * phi * a * y)
>       syst = kwant.Builder()    lat = kwant.lattice.cubic(a, norbs=1)
> syst[(lat(x, y, z) for x in range(L) for y in range(W) for z in range(H))]
> = onsite    syst[kwant.builder.HoppingKind((0, 0, 1), lat, lat)] =
> hoppingz    syst[kwant.builder.HoppingKind((0, 1, 0), lat, lat)] =
> hoppingy    syst[kwant.builder.HoppingKind((1, 0, 0), lat, lat)] =
> hoppingx       lead = kwant.Builder(kwant.TranslationalSymmetry((0, 0,
> -a)))    lead[(lat(x, y, z) for x in range(L) for y in range(W) for z in
> range(H))] = onsite    lead[kwant.builder.HoppingKind((0, 0, 1), lat, lat)]
> = hoppingz    lead[kwant.builder.HoppingKind((0, 1, 0), lat, lat)] =
> hoppingy    lead[kwant.builder.HoppingKind((1, 0, 0), lat, lat)] =
> hoppingx        syst.attach_lead(lead)
> syst.attach_lead(lead.reversed())    return systdef analyze_system(t=1.0,
> t_x=1.0, t_y=1.0, t_z=1.0, lamda=0.2, beta=1.05):    syst = make_system()
>   kwant.plot(syst)    kwant.plot(syst, pos_transform=lambda p: (p[0] ,
> p[1]))        sysf=syst.finalized()    wf=kwant.wave_function(sysf,
> energy=0)    Sites=list(sysf.sites)    psi=wf(0)[0]        rho =
> kwant.operator.Density(sysf)    density = rho(psi)    wf_sqr = sum(rho(psi)
> for psi in wf(0))        lat2=kwant.lattice.square(norbs=1)
> sys2=kwant.Builder()        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
> sys2[(lat2(site.pos[0],site.pos[1]) for site in Sites)]=onsite
> sys2[kwant.builder.HoppingKind((0, 1), lat2, lat2)] = hoppingy
> sys2[kwant.builder.HoppingKind((1, 0), lat2, lat2)] = hoppingx
> sys2f=sys2.finalized()        kwant.plotter.map(sys2f, wf_sqr)
> plt.show()def main():    syst = make_system()    analyze_system()*
> *main()*
>
> On Tue, Jun 11, 2019 at 1:16 PM Christoph Groth <christoph.gr...@cea.fr>
> wrote:
>
>> Naveen Yadav wrote:
>>
>> > Following the Kwant documentation, it is easy to plot probability
>> > density for 2D systems. But on following the same procedure for the 3D
>> > systems it shows an *ValueError: Only 2D systems can be plotted this
>> > way.* Please suggest me if there is a way to plot probability density
>> > for 3D system having only an orbital degree of freedom per site.
>>
>> Kwant's plotting submodule is based on matplotlib, whose 3D features are
>> very rudimentary and slow.  And anyway, what kind of plot do you have in
>> mind?  There are many different ways to plot 3D densities, appropriate
>> for different situations/data.
>>
>> For serious 3D plotting, I suggest using a separate library.  For
>> example, you could give MayaVi a try.
>>
>
>
> --
>
>
> With Best Regards
> NAVEEN YADAV
> Ph.D Research Scholar
> Deptt. Of Physics & Astrophysics
> University Of Delhi.
>


-- 
Abbout Adel

Reply via email to