Discussion:
[Kwant] seeking help
shyam lochan bora
2018-08-28 04:53:12 UTC
Permalink
dear sir,
I am working on the assignment problem " tweaking the nanowire" from the
online course in topology in condensed matter
I am trying to apply the magnetic filed in the nanowire using the following
code but I am unable to plot the graph.Please help me in this regard.The
code is given below..
import kwant
import matplotlib
from matplotlib import pyplot
import numpy as np


def nanowire_chain():
lat = kwant.lattice.chain()
sys = kwant.Builder(kwant.TranslationalSymmetry(*lat.prim_vecs))

def onsite(onsite, p):
return (2 * p.t - p.mu) * pauli.szs0 + p.B *
(np.cos(p.phi)*pauli.s0sz+
np.sin(p.phi)*np.sin(p.theta)*pauli.s0sy+np.sin(p.phi)*np.sin(p.theta)*pauli.s0sx)+
p.delta * pauli.sxs0

sys[lat(0)] = onsite

def hop(site1, site2, p):
return -p.t * pauli.szs0 - .5j * p.alpha * pauli.szsx

sys[kwant.HoppingKind((1,), lat)] = hop

return sys


def spinful_kitaev_chain():
lat = kwant.lattice.chain()
sys = kwant.Builder(kwant.TranslationalSymmetry(*lat.prim_vecs))

def onsite(site, p):
return (2 * p.t - p.mu) * pauli.szs0 + p.B * pauli.szsz

sys[lat(0)] = onsite

def hop(site1, site2, p):
return -p.t * pauli.szs0 - 1j * p.delta * pauli.sys0

sys[kwant.HoppingKind((1,), lat)] = hop

return sys


def find_gap(sys, p, resolution=1e-4):
"""Find gap in a system by doing a binary search in energy."""

# This tells us if there are modes at a certain energy.
if len(sys.modes(energy=0, args=[p])[0].momenta):
return 0

gap = step = min(abs(kwant.physics.Bands(sys, args=[p])(k=0))) / 2
while step > resolution:
step /= 2
if len(sys.modes(gap, args=[p])[0].momenta):
gap -= step
else:
gap += step

return gap


def spinorbit_band_gap(sys, mu, t, delta, Bs):
sys = sys.finalized()
alphas = [0.0, 0.1, 0.2, 0.3]
p = SimpleNamespace(mu=mu, t=t, delta=delta,theta=theta,phi=phi)

def gap(sys, p, alpha, B):
p.alpha = alpha
p.B = B
return find_gap(sys, p)

gaps = [gap(sys, p, alpha, B) for alpha in alphas for B in Bs]
gaps = np.reshape(gaps, (len(alphas), -1))
dims = {'kdims': [r'$B$'], 'vdims': ['Band gap']}
B_crit = holoviews.VLine(np.sqrt(p.delta**2 + p.mu**2))
plot = [holoviews.Curve((Bs, gaps[i]), label=r'$\alpha={}$'.format(
alphas[i]), **dims) * B_crit for i, alpha in enumerate(alphas)]
title = r'$\Delta={delta}$, $\mu={mu}$'.format(delta=np.round(p.delta,
2), mu=np.round(p.mu, 2))
style = {'xticks': [0, 0.1, 0.2, 0.3], 'yticks': [0, 0.05, 0.1],
'fig_size': 150}
plot = holoviews.Overlay(plot)
return plot(plot=style)


def title(p):
try:
title = r"$\alpha={alpha}$, $\mu={mu}$, $B={B}$, $\Delta={delta}$"
title = title.format(alpha=np.round(p.alpha, 2),
mu=np.round(p.mu, 2),
B=np.round(p.B, 2),
delta=np.round(p.delta, 2))
except AttributeError:
title = r"$\mu={mu}$, $B={B}$, $\Delta={delta}$"
title = title.format(mu=np.round(p.mu, 2),
B=np.round(p.B, 2),
delta=np.round(p.delta, 2))
return title

style = {'k_x': np.linspace(-1, 1, 101),
'xdim': r'$k$',
'ydim': r'$E/t$',
'xticks': [-1, 0, 1],
'yticks': [-1, 0, 1],
'xlims': [-1, 1],
'ylims': [-1.5, 1.5],
'title': title}


Regards
Shyam Lochan Bora
shyam lochan bora
2018-08-29 06:31:35 UTC
Permalink
Dear sir,
Please help me with the following error in the program
from __future__ import print_function
from ipywidgets import interact, interactive, fixed, interact_manual
import ipywidgets as widgets
import kwant
from matplotlib import pyplot
import numpy as np
from holoviews.core.options import Cycle
from types import SimpleNamespace

def nanowire_chain():
lat = kwant.lattice.chain()
sys = kwant.Builder(kwant.TranslationalSymmetry(*lat.prim_vecs))

def onsite(onsite, p):
return (2 * p.t - p.mu) * pauli.szs0 + p.B *
(np.cos(p.phi)*pauli.s0sz+
np.sin(p.phi)*np.sin(p.theta)*pauli.s0sy+np.sin(p.phi)*np.sin(p.theta)*pauli.s0sx)+
p.delta * pauli.sxs0

sys[lat(0)] = onsite

def hop(site1, site2, p):
return -p.t * pauli.szs0 - .5j * p.alpha * pauli.szsx

sys[kwant.HoppingKind((1,), lat)] = hop

return sys


def spinful_kitaev_chain():
lat = kwant.lattice.chain()
sys = kwant.Builder(kwant.TranslationalSymmetry(*lat.prim_vecs))

def onsite(site, p):
return (2 * p.t - p.mu) * pauli.szs0 + p.B * pauli.szsz

sys[lat(0)] = onsite

def hop(site1, site2, p):
return -p.t * pauli.szs0 - 1j * p.delta * pauli.sys0

sys[kwant.HoppingKind((1,), lat)] = hop

return sys


def find_gap(sys, p, resolution=1e-4):
"""Find gap in a system by doing a binary search in energy."""

# This tells us if there are modes at a certain energy.
if len(sys.modes(energy=0, args=[p])[0].momenta):
return 0

gap = step = min(abs(kwant.physics.Bands(sys, args=[p])(k=0))) / 2
while step > resolution:
step /= 2
if len(sys.modes(gap, args=[p])[0].momenta):
gap -= step
else:
gap += step

return gap


def spinorbit_band_gap(sys, mu, t, delta, Bs):
sys = sys.finalized()
alphas = [0.0, 0.1, 0.2, 0.3]
p = SimpleNamespace(mu=mu, t=t, delta=delta,theta=theta,phi=phi)

def gap(sys, p, alpha, B):
p.alpha = alpha
p.B = B
return find_gap(sys, p)

gaps = [gap(sys, p, alpha, B) for alpha in alphas for B in Bs]
gaps = np.reshape(gaps, (len(alphas), -1))
dims = {'kdims': [r'$B$'], 'vdims': ['Band gap']}
B_crit = holoviews.VLine(np.sqrt(p.delta**2 + p.mu**2))
plot = [holoviews.Curve((Bs, gaps[i]), label=r'$\alpha={}$'.format(
alphas[i]), **dims) * B_crit for i, alpha in enumerate(alphas)]
title = r'$\Delta={delta}$, $\mu={mu}$'.format(delta=np.round(p.delta,
2), mu=np.round(p.mu, 2))
style = {'xticks': [0, 0.1, 0.2, 0.3], 'yticks': [0, 0.05, 0.1],
'fig_size': 150}
plot = holoviews.Overlay(plot)
return plot(plot=style)


def title(p):
try:
title = r"$\alpha={alpha}$, $\mu={mu}$, $B={B}$, $\Delta={delta}$"
title = title.format(alpha=np.round(p.alpha, 2),
mu=np.round(p.mu, 2),
B=np.round(p.B, 2),
delta=np.round(p.delta, 2))
except AttributeError:
title = r"$\mu={mu}$, $B={B}$, $\Delta={delta}$"
title = title.format(mu=np.round(p.mu, 2),
B=np.round(p.B, 2),
delta=np.round(p.delta, 2))
return title

style = {'k_x': np.linspace(-1, 1, 101),
'xdim': r'$k$',
'ydim': r'$E/t$',
'xticks': [-1, 0, 1],
'yticks': [-1, 0, 1],
'xlims': [-1, 1],
'ylims': [-1.5, 1.5],
'title': title}
sys = nanowire_chain()
p = SimpleNamespace(t=1, mu=0.1, delta=0.1, B=0.3,theta=np.pi/2,phi=np.pi/2)
alphas = np.linspace(0, 0.4, 10)
holoviews.HoloMap({alpha: spectrum(sys, p.update(alpha=alpha), **style) for
alpha in alphas}, kdims=[r'$\alpha$'])

c:\python36\lib\site-packages\kwant\linalg\lll.py:103: FutureWarning:
`rcond` parameter will change to the default of machine precision
times ``max(M, N)`` where M and N are the input matrix dimensions.
To use the future default and silence this warning we advise to pass
`rcond=None`, to keep using the old, explicitly pass `rcond=-1`.
coefs = np.linalg.lstsq(vecs_orig.T, vecs.T)[0]
c:\python36\lib\site-packages\kwant\linalg\lll.py:144: FutureWarning:
`rcond` parameter will change to the default of machine precision
times ``max(M, N)`` where M and N are the input matrix dimensions.
To use the future default and silence this warning we advise to pass
`rcond=None`, to keep using the old, explicitly pass `rcond=-1`.
center_coords = np.array(np.round(np.linalg.lstsq(basis.T, vec)[0]), int)

---------------------------------------------------------------------------NameError
Traceback (most recent call
last)<ipython-input-3-9ff9219a759e> in <module>() 2 p =
SimpleNamespace(t=1, mu=0.1, delta=0.1,
B=0.3,theta=np.pi/2,phi=np.pi/2) 3 alphas = np.linspace(0, 0.4,
10)----> 4 holoviews.HoloMap({alpha: spectrum(sys,
p.update(alpha=alpha), **style) for alpha in alphas},
kdims=[r'$\alpha$'])
NameError: name 'holoviews' is not defined
Anton Akhmerov
2018-08-31 15:18:22 UTC
Permalink
Dear Shyam Lochan Bora,

Right now your question is rather poorly formulated, and not suitable
for this mailing list. Please read this instruction on how to ask good
questions: https://stackoverflow.com/help/how-to-ask
Additionally, it appears that your problem is due the lack of the
Python knowledge, I recommend you to follow a Python course, or
otherwise learn the language more systematically.

Best regards,
Anton Akhmerov
On Fri, Aug 31, 2018 at 5:08 PM shyam lochan bora
Post by shyam lochan bora
Dear sir,
Please help me with the following error in the program
from __future__ import print_function
from ipywidgets import interact, interactive, fixed, interact_manual
import ipywidgets as widgets
import kwant
from matplotlib import pyplot
import numpy as np
from holoviews.core.options import Cycle
from types import SimpleNamespace
lat = kwant.lattice.chain()
sys = kwant.Builder(kwant.TranslationalSymmetry(*lat.prim_vecs))
return (2 * p.t - p.mu) * pauli.szs0 + p.B * (np.cos(p.phi)*pauli.s0sz+ np.sin(p.phi)*np.sin(p.theta)*pauli.s0sy+np.sin(p.phi)*np.sin(p.theta)*pauli.s0sx)+ p.delta * pauli.sxs0
sys[lat(0)] = onsite
return -p.t * pauli.szs0 - .5j * p.alpha * pauli.szsx
sys[kwant.HoppingKind((1,), lat)] = hop
return sys
lat = kwant.lattice.chain()
sys = kwant.Builder(kwant.TranslationalSymmetry(*lat.prim_vecs))
return (2 * p.t - p.mu) * pauli.szs0 + p.B * pauli.szsz
sys[lat(0)] = onsite
return -p.t * pauli.szs0 - 1j * p.delta * pauli.sys0
sys[kwant.HoppingKind((1,), lat)] = hop
return sys
"""Find gap in a system by doing a binary search in energy."""
# This tells us if there are modes at a certain energy.
return 0
gap = step = min(abs(kwant.physics.Bands(sys, args=[p])(k=0))) / 2
step /= 2
gap -= step
gap += step
return gap
sys = sys.finalized()
alphas = [0.0, 0.1, 0.2, 0.3]
p = SimpleNamespace(mu=mu, t=t, delta=delta,theta=theta,phi=phi)
p.alpha = alpha
p.B = B
return find_gap(sys, p)
gaps = [gap(sys, p, alpha, B) for alpha in alphas for B in Bs]
gaps = np.reshape(gaps, (len(alphas), -1))
dims = {'kdims': [r'$B$'], 'vdims': ['Band gap']}
B_crit = holoviews.VLine(np.sqrt(p.delta**2 + p.mu**2))
plot = [holoviews.Curve((Bs, gaps[i]), label=r'$\alpha={}$'.format(
alphas[i]), **dims) * B_crit for i, alpha in enumerate(alphas)]
title = r'$\Delta={delta}$, $\mu={mu}$'.format(delta=np.round(p.delta, 2), mu=np.round(p.mu, 2))
style = {'xticks': [0, 0.1, 0.2, 0.3], 'yticks': [0, 0.05, 0.1], 'fig_size': 150}
plot = holoviews.Overlay(plot)
return plot(plot=style)
title = r"$\alpha={alpha}$, $\mu={mu}$, $B={B}$, $\Delta={delta}$"
title = title.format(alpha=np.round(p.alpha, 2),
mu=np.round(p.mu, 2),
B=np.round(p.B, 2),
delta=np.round(p.delta, 2))
title = r"$\mu={mu}$, $B={B}$, $\Delta={delta}$"
title = title.format(mu=np.round(p.mu, 2),
B=np.round(p.B, 2),
delta=np.round(p.delta, 2))
return title
style = {'k_x': np.linspace(-1, 1, 101),
'xdim': r'$k$',
'ydim': r'$E/t$',
'xticks': [-1, 0, 1],
'yticks': [-1, 0, 1],
'xlims': [-1, 1],
'ylims': [-1.5, 1.5],
'title': title}
sys = nanowire_chain()
p = SimpleNamespace(t=1, mu=0.1, delta=0.1, B=0.3,theta=np.pi/2,phi=np.pi/2)
alphas = np.linspace(0, 0.4, 10)
holoviews.HoloMap({alpha: spectrum(sys, p.update(alpha=alpha), **style) for alpha in alphas}, kdims=[r'$\alpha$'])
c:\python36\lib\site-packages\kwant\linalg\lll.py:103: FutureWarning: `rcond` parameter will change to the default of machine precision times ``max(M, N)`` where M and N are the input matrix dimensions.
To use the future default and silence this warning we advise to pass `rcond=None`, to keep using the old, explicitly pass `rcond=-1`.
coefs = np.linalg.lstsq(vecs_orig.T, vecs.T)[0]
c:\python36\lib\site-packages\kwant\linalg\lll.py:144: FutureWarning: `rcond` parameter will change to the default of machine precision times ``max(M, N)`` where M and N are the input matrix dimensions.
To use the future default and silence this warning we advise to pass `rcond=None`, to keep using the old, explicitly pass `rcond=-1`.
center_coords = np.array(np.round(np.linalg.lstsq(basis.T, vec)[0]), int)
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-3-9ff9219a759e> in <module>()
2 p = SimpleNamespace(t=1, mu=0.1, delta=0.1, B=0.3,theta=np.pi/2,phi=np.pi/2)
3 alphas = np.linspace(0, 0.4, 10)
----> 4 holoviews.HoloMap({alpha: spectrum(sys, p.update(alpha=alpha), **style) for alpha in alphas}, kdims=[r'$\alpha$'])
NameError: name 'holoviews' is not defined
shyam lochan bora
2018-09-03 13:56:49 UTC
Permalink
Thank you so much sir for your advice.
Post by Anton Akhmerov
Dear Shyam Lochan Bora,
Right now your question is rather poorly formulated, and not suitable
for this mailing list. Please read this instruction on how to ask good
questions: https://stackoverflow.com/help/how-to-ask
Additionally, it appears that your problem is due the lack of the
Python knowledge, I recommend you to follow a Python course, or
otherwise learn the language more systematically.
Best regards,
Anton Akhmerov
On Fri, Aug 31, 2018 at 5:08 PM shyam lochan bora
Post by shyam lochan bora
Dear sir,
Please help me with the following error in the program
from __future__ import print_function
from ipywidgets import interact, interactive, fixed, interact_manual
import ipywidgets as widgets
import kwant
from matplotlib import pyplot
import numpy as np
from holoviews.core.options import Cycle
from types import SimpleNamespace
lat = kwant.lattice.chain()
sys = kwant.Builder(kwant.TranslationalSymmetry(*lat.prim_vecs))
return (2 * p.t - p.mu) * pauli.szs0 + p.B *
(np.cos(p.phi)*pauli.s0sz+
np.sin(p.phi)*np.sin(p.theta)*pauli.s0sy+np.sin(p.phi)*np.sin(p.theta)*pauli.s0sx)+
p.delta * pauli.sxs0
Post by shyam lochan bora
sys[lat(0)] = onsite
return -p.t * pauli.szs0 - .5j * p.alpha * pauli.szsx
sys[kwant.HoppingKind((1,), lat)] = hop
return sys
lat = kwant.lattice.chain()
sys = kwant.Builder(kwant.TranslationalSymmetry(*lat.prim_vecs))
return (2 * p.t - p.mu) * pauli.szs0 + p.B * pauli.szsz
sys[lat(0)] = onsite
return -p.t * pauli.szs0 - 1j * p.delta * pauli.sys0
sys[kwant.HoppingKind((1,), lat)] = hop
return sys
"""Find gap in a system by doing a binary search in energy."""
# This tells us if there are modes at a certain energy.
return 0
gap = step = min(abs(kwant.physics.Bands(sys, args=[p])(k=0))) / 2
step /= 2
gap -= step
gap += step
return gap
sys = sys.finalized()
alphas = [0.0, 0.1, 0.2, 0.3]
p = SimpleNamespace(mu=mu, t=t, delta=delta,theta=theta,phi=phi)
p.alpha = alpha
p.B = B
return find_gap(sys, p)
gaps = [gap(sys, p, alpha, B) for alpha in alphas for B in Bs]
gaps = np.reshape(gaps, (len(alphas), -1))
dims = {'kdims': [r'$B$'], 'vdims': ['Band gap']}
B_crit = holoviews.VLine(np.sqrt(p.delta**2 + p.mu**2))
plot = [holoviews.Curve((Bs, gaps[i]), label=r'$\alpha={}$'.format(
alphas[i]), **dims) * B_crit for i, alpha in enumerate(alphas)]
title = r'$\Delta={delta}$,
$\mu={mu}$'.format(delta=np.round(p.delta, 2), mu=np.round(p.mu, 2))
Post by shyam lochan bora
style = {'xticks': [0, 0.1, 0.2, 0.3], 'yticks': [0, 0.05, 0.1],
'fig_size': 150}
Post by shyam lochan bora
plot = holoviews.Overlay(plot)
return plot(plot=style)
title = r"$\alpha={alpha}$, $\mu={mu}$, $B={B}$,
$\Delta={delta}$"
Post by shyam lochan bora
title = title.format(alpha=np.round(p.alpha, 2),
mu=np.round(p.mu, 2),
B=np.round(p.B, 2),
delta=np.round(p.delta, 2))
title = r"$\mu={mu}$, $B={B}$, $\Delta={delta}$"
title = title.format(mu=np.round(p.mu, 2),
B=np.round(p.B, 2),
delta=np.round(p.delta, 2))
return title
style = {'k_x': np.linspace(-1, 1, 101),
'xdim': r'$k$',
'ydim': r'$E/t$',
'xticks': [-1, 0, 1],
'yticks': [-1, 0, 1],
'xlims': [-1, 1],
'ylims': [-1.5, 1.5],
'title': title}
sys = nanowire_chain()
p = SimpleNamespace(t=1, mu=0.1, delta=0.1,
B=0.3,theta=np.pi/2,phi=np.pi/2)
Post by shyam lochan bora
alphas = np.linspace(0, 0.4, 10)
holoviews.HoloMap({alpha: spectrum(sys, p.update(alpha=alpha), **style)
for alpha in alphas}, kdims=[r'$\alpha$'])
`rcond` parameter will change to the default of machine precision times
``max(M, N)`` where M and N are the input matrix dimensions.
Post by shyam lochan bora
To use the future default and silence this warning we advise to pass
`rcond=None`, to keep using the old, explicitly pass `rcond=-1`.
Post by shyam lochan bora
coefs = np.linalg.lstsq(vecs_orig.T, vecs.T)[0]
`rcond` parameter will change to the default of machine precision times
``max(M, N)`` where M and N are the input matrix dimensions.
Post by shyam lochan bora
To use the future default and silence this warning we advise to pass
`rcond=None`, to keep using the old, explicitly pass `rcond=-1`.
Post by shyam lochan bora
center_coords = np.array(np.round(np.linalg.lstsq(basis.T, vec)[0]),
int)
---------------------------------------------------------------------------
Post by shyam lochan bora
NameError Traceback (most recent call
last)
Post by shyam lochan bora
<ipython-input-3-9ff9219a759e> in <module>()
2 p = SimpleNamespace(t=1, mu=0.1, delta=0.1,
B=0.3,theta=np.pi/2,phi=np.pi/2)
Post by shyam lochan bora
3 alphas = np.linspace(0, 0.4, 10)
----> 4 holoviews.HoloMap({alpha: spectrum(sys, p.update(alpha=alpha),
**style) for alpha in alphas}, kdims=[r'$\alpha$'])
Post by shyam lochan bora
NameError: name 'holoviews' is not defined
Continue reading on narkive:
Loading...