# [Kwant] 回复： About MoS2 ribbon

```
Dear Professor,```
```
I use the follow code to calculate the LDOS of MoS2 ribbon with armchair edge,
however the error occur as

LinAlgError: QZ iteration failed to converge in zgges

Regards,
Qiao Chen
HNIE

from __future__ import division  # so that 1/2 == 0.5, and not 0
import kwant
import numpy as np
from matplotlib import pyplot as plt
import math
from math import pi
import tinyarray

e0, e2, ep, ez = -1.094, -1.512, -3.560, -6.886
V_pdd, V_pdp = 3.689, -1.241
V_ddd, V_ddp, V_ddde = -0.895, 0.252, 0.228
V_ppd, V_ppp = 1.225, -0.467
a0=0.316
sqrt_3=math.sqrt(3)

# Define the MoS2 lattice
lat=kwant.lattice.general([(0.5472, 0), (0.0, a0)],
[(0.0, 0.0),(0.0912, 0.15796),(0.2736,
0.1576),(0.3648,0.0)])

M1,S1,M2,S2=lat.sublattices

sz = 1.0 #
s=1j

E_M=tinyarray.array([[e0,    0,                         0,0,0,0],
[0,0,0,e0,0,0],

[0,                  0,             ez-V_ppd,0,0,0],
[0,0,0,0,                  0,             ez-V_ppd]]);

# hoppings between Mo-Mo
t1_MM=1/4*tinyarray.array([[3*V_ddde+V_ddd,
sqrt_3/2*(-V_ddde+V_ddd),          -3/2*(V_ddde-V_ddd),0,0,0],
[sqrt_3/2*(-V_ddde+V_ddd),
1/4*(V_ddde+12*V_ddp+3*V_ddd),      sqrt_3/4*(V_ddde-4*V_ddp+3*V_ddd),0,0,0],
[-3/2*(V_ddde-V_ddd),
sqrt_3/4*(V_ddde-4*V_ddp+3*V_ddd),  1/4*(3*V_ddde+4*V_ddp+9*V_ddd),0,0,0],
[0,0,0,3*V_ddde+V_ddd,
sqrt_3/2*(-V_ddde+V_ddd),          -3/2*(V_ddde-V_ddd)],
[0,0,0,sqrt_3/2*(-V_ddde+V_ddd),
1/4*(V_ddde+12*V_ddp+3*V_ddd),      sqrt_3/4*(V_ddde-4*V_ddp+3*V_ddd)],
[0,0,0,-3/2*(V_ddde-V_ddd),
sqrt_3/4*(V_ddde-4*V_ddp+3*V_ddd),  1/4*(3*V_ddde+4*V_ddp+9*V_ddd)]])

t2_MM=1/4*tinyarray.array([[3*V_ddde+V_ddd,          sqrt_3*(V_ddde-V_ddd),
0,0,0,0],
[sqrt_3*(V_ddde-V_ddd),    V_ddde+3*V_ddd,
0,0,0,0],
[0,                        0,
4*V_ddp,0,0,0],
[0,0,0,3*V_ddde+V_ddd,
sqrt_3*(V_ddde-V_ddd),0],
[0,0,0,sqrt_3*(V_ddde-V_ddd),    V_ddde+3*V_ddd,0],
[0,0,0,0,                        0,
4*V_ddp]])

t3_MM=1/4*tinyarray.array([[3*V_ddde+V_ddd,
sqrt_3/2*(-V_ddde+V_ddd),            3/2*(V_ddde-V_ddd),0,0,0],
[sqrt_3/2*(-V_ddde+V_ddd),
1/4*(V_ddde+12*V_ddp+3*V_ddd),      -sqrt_3/4*(V_ddde-4*V_ddp+3*V_ddd),0,0,0],
[3/2*(V_ddde-V_ddd),
-sqrt_3/4*(V_ddde-4*V_ddp+3*V_ddd),  1/4*(3*V_ddde+4*V_ddp+9*V_ddd),0,0,0],
[0,0,0,3*V_ddde+V_ddd,
sqrt_3/2*(-V_ddde+V_ddd),            3/2*(V_ddde-V_ddd)],
[0,0,0,sqrt_3/2*(-V_ddde+V_ddd),
1/4*(V_ddde+12*V_ddp+3*V_ddd),      -sqrt_3/4*(V_ddde-4*V_ddp+3*V_ddd)],
[0,0,0,3/2*(V_ddde-V_ddd),
-sqrt_3/4*(V_ddde-4*V_ddp+3*V_ddd),  1/4*(3*V_ddde+4*V_ddp+9*V_ddd)]])

# hoppings between S-S
t1_XX=1/4*tinyarray.array([[3*V_ppp+V_ppd,           sqrt_3*(V_ppp-V_ppd),
0,0,0,0],
[sqrt_3*(V_ppp-V_ppd),    V_ppp+3*V_ppd,
0,0,0,0],
[0,                       0,
4*V_ppp,0,0,0],
[0,0,0,3*V_ppp+V_ppd,
sqrt_3*(V_ppp-V_ppd),           0],
[0,0,0,sqrt_3*(V_ppp-V_ppd),    V_ppp+3*V_ppd,
0],
[0,0,0,0,                       0,
4*V_ppp]])

t2_XX=tinyarray.array([[V_ppd,  0,       0,0,0,0],
[0    ,  V_ppp,   0,0,0,0],
[0,  0,       V_ppp,0,0,0],
[0,0,0,V_ppd,  0,       0],
[0,0,0,0    ,  V_ppp,   0],
[0,0,0,0,  0,       V_ppp]])

t3_XX=1/4*tinyarray.array([[3*V_ppp+V_ppd,            -sqrt_3*(V_ppp-V_ppd),
0,0,0,0],
[-sqrt_3*(V_ppp-V_ppd),     V_ppp+3*V_ppd,
0,0,0,0],
[0,                         0,
4*V_ppp,0,0,0],
[0,0,0,3*V_ppp+V_ppd,
-sqrt_3*(V_ppp-V_ppd),       0],
[0,0,0,-sqrt_3*(V_ppp-V_ppd),     V_ppp+3*V_ppd,
0],
[0,0,0,0,                         0,
4*V_ppp]])

t1_MX=1/7*math.sqrt(2/7)*tinyarray.array([[-9*V_pdp+sqrt_3*V_pdd,
3*sqrt_3*V_pdp-V_pdd,     12*V_pdp+sqrt_3*V_pdd,0,0,0],
[5*sqrt_3*V_pdp+3*V_pdd,
9*V_pdp-sqrt_3*V_pdd,   -2*sqrt_3*V_pdp+3*V_pdd,0,0,0],
[-V_pdp-3*sqrt_3*V_pdd,
5*sqrt_3*V_pdp+3*V_pdd,  6*V_pdp-3*sqrt_3*V_pdd,0,0,0],
[0,0,0,-9*V_pdp+sqrt_3*V_pdd,
3*sqrt_3*V_pdp-V_pdd,     12*V_pdp+sqrt_3*V_pdd],
[0,0,0,5*sqrt_3*V_pdp+3*V_pdd,
9*V_pdp-sqrt_3*V_pdd,   -2*sqrt_3*V_pdp+3*V_pdd],
[0,0,0,-V_pdp-3*sqrt_3*V_pdd,
5*sqrt_3*V_pdp+3*V_pdd,  6*V_pdp-3*sqrt_3*V_pdd]])

t2_MX=1/7*math.sqrt(2/7)*tinyarray.array([[0,         -6*sqrt_3*V_pdp+2*V_pdd,
12*V_pdp+sqrt_3*V_pdd,0,0,0 ],
[0,         -6*V_pdp-4*sqrt_3*V_pdd,
4*sqrt_3*V_pdp-6*V_pdd,0,0,0],
[14*V_pdp,   0,
0,0,0,0],
[0,0,0,0,
-6*sqrt_3*V_pdp+2*V_pdd,   12*V_pdp+sqrt_3*V_pdd],
[0,0,0,0,
-6*V_pdp-4*sqrt_3*V_pdd,   4*sqrt_3*V_pdp-6*V_pdd],
[0,0,0,14*V_pdp,   0,
0]])

t3_MX=1/7*math.sqrt(2/7)*tinyarray.array([[9*V_pdp-sqrt_3*V_pdd,
3*sqrt_3*V_pdp-V_pdd,     12*V_pdp+sqrt_3*V_pdd,0,0,0],
[-5*sqrt_3*V_pdp-3*V_pdd,
9*V_pdp-sqrt_3*V_pdd,   -2*sqrt_3*V_pdp+3*V_pdd,0,0,0],
[-V_pdp-3*sqrt_3*V_pdd,
-5*sqrt_3*V_pdp-3*V_pdd, -6*V_pdp+3*sqrt_3*V_pdd,0,0,0],
[0,0,0,9*V_pdp-sqrt_3*V_pdd,
3*sqrt_3*V_pdp-V_pdd,     12*V_pdp+sqrt_3*V_pdd],
[0,0,0,-5*sqrt_3*V_pdp-3*V_pdd,
9*V_pdp-sqrt_3*V_pdd,   -2*sqrt_3*V_pdp+3*V_pdd],
[0,0,0,-V_pdp-3*sqrt_3*V_pdd,
-5*sqrt_3*V_pdp-3*V_pdd, -6*V_pdp+3*sqrt_3*V_pdd]])

# Define the scattering region
# Rectangle scattering region -Ribbon
def system_shape(pos):
x,y = pos
scatter_region = -s_length/2 <= x <= s_length/2 and -s_width/2 <= y <=
s_width/2
return scatter_region

def onsite(site):
return E_M if (site.family == M1 or site.family == M2) else E_X

sys = kwant.Builder()
sys[lat.shape(system_shape, (0,-1.0))] = onsite

sys[kwant.builder.HoppingKind(( 0,  0), M2, M1)] = t1_MM
sys[kwant.builder.HoppingKind(( 0,  0), S1, S2)] = t3_XX
sys[kwant.builder.HoppingKind(( 0,  0), M1, S1)] = t1_MX
sys[kwant.builder.HoppingKind(( 0,  0), M2, S1)] = t2_MX
sys[kwant.builder.HoppingKind(( 0,  0), M2, S2)] = t3_MX

sys[kwant.builder.HoppingKind((  1,  0), M1, S2)] = t2_MX
sys[kwant.builder.HoppingKind((  1,  0), S1, S2)] = t1_XX
sys[kwant.builder.HoppingKind(( -1,  0), M2, M1)] = t3_MM

#
sys[kwant.builder.HoppingKind(( 1,   1), M1, M2)] = t1_MM

sys[kwant.builder.HoppingKind(( 0,   -1), S1, S1)] = t2_XX
sys[kwant.builder.HoppingKind(( 0,   -1), S2, S2)] = t2_XX
sys[kwant.builder.HoppingKind(( 0,   -1), M1, M1)] = t2_MM
sys[kwant.builder.HoppingKind(( 0,   -1), M2, M2)] = t2_MM
sys[kwant.builder.HoppingKind(( 0,    1), M1, M2)] = t3_MM
sys[kwant.builder.HoppingKind(( 0,    1), S2, S1)] = t3_MM
sys[kwant.builder.HoppingKind(( 0,    1), M1, S1)] = t3_MX
sys[kwant.builder.HoppingKind(( 0,   -1), M2, S2)] = t1_MX

sys[kwant.builder.HoppingKind((-1,    1), S2, S1)] = t3_XX

left_symmetry=kwant.TranslationalSymmetry(lat.vec((-1,0)))

x,y = pos

# Specify the hoppings in lead0

lead0[kwant.builder.HoppingKind(( 0,  0), M2, M1)] = t1_MM
lead0[kwant.builder.HoppingKind(( 0,  0), S1, S2)] = t3_XX
lead0[kwant.builder.HoppingKind(( 0,  0), M1, S1)] = t1_MX
lead0[kwant.builder.HoppingKind(( 0,  0), M2, S1)] = t2_MX
lead0[kwant.builder.HoppingKind(( 0,  0), M2, S2)] = t3_MX

lead0[kwant.builder.HoppingKind((  1,  0), M1, S2)] = t2_MX
lead0[kwant.builder.HoppingKind((  1,  0), S1, S2)] = t1_XX
lead0[kwant.builder.HoppingKind(( -1,  0), M2, M1)] = t3_MM

#
lead0[kwant.builder.HoppingKind(( 1,   1), M1, M2)] = t1_MM

lead0[kwant.builder.HoppingKind(( 0,   -1), S1, S1)] = t2_XX
lead0[kwant.builder.HoppingKind(( 0,   -1), S2, S2)] = t2_XX
lead0[kwant.builder.HoppingKind(( 0,   -1), M1, M1)] = t2_MM
lead0[kwant.builder.HoppingKind(( 0,   -1), M2, M2)] = t2_MM
lead0[kwant.builder.HoppingKind(( 0,    1), M1, M2)] = t3_MM
lead0[kwant.builder.HoppingKind(( 0,    1), S2, S1)] = t1_XX
lead0[kwant.builder.HoppingKind(( 0,    1), M1, S1)] = t3_MX
lead0[kwant.builder.HoppingKind(( 0,   -1), M2, S2)] = t1_MX

lead0[kwant.builder.HoppingKind((-1,    1), S2, S1)] = t3_XX

#
#
right_symmetry=kwant.TranslationalSymmetry(lat.vec((1,0)))

x,y = pos

# Specify the hoppings in lead1
lead1[kwant.builder.HoppingKind(( 0,  0), M2, M1)] = t1_MM
lead1[kwant.builder.HoppingKind(( 0,  0), S1, S2)] = t3_XX
lead1[kwant.builder.HoppingKind(( 0,  0), M1, S1)] = t1_MX
lead1[kwant.builder.HoppingKind(( 0,  0), M2, S1)] = t2_MX
lead1[kwant.builder.HoppingKind(( 0,  0), M2, S2)] = t3_MX

lead1[kwant.builder.HoppingKind((  1,  0), M1, S2)] = t2_MX
lead1[kwant.builder.HoppingKind((  1,  0), S1, S2)] = t1_XX
lead1[kwant.builder.HoppingKind(( -1,  0), M2, M1)] = t3_MM

#
lead1[kwant.builder.HoppingKind(( 1,   1), M1, M2)] = t1_MM

lead1[kwant.builder.HoppingKind(( 0,   -1), S1, S1)] = t2_XX
lead1[kwant.builder.HoppingKind(( 0,   -1), S2, S2)] = t2_XX
lead1[kwant.builder.HoppingKind(( 0,   -1), M1, M1)] = t2_MM
lead1[kwant.builder.HoppingKind(( 0,   -1), M2, M2)] = t2_MM
lead1[kwant.builder.HoppingKind(( 0,    1), M1, M2)] = t3_MM
lead1[kwant.builder.HoppingKind(( 0,    1), S2, S1)] = t3_MM
lead1[kwant.builder.HoppingKind(( 0,    1), M1, S1)] = t3_MX
lead1[kwant.builder.HoppingKind(( 0,   -1), M2, S2)] = t1_MX

lead0[kwant.builder.HoppingKind((-1,    1), S2, S1)] = t3_XX

# attach the leads to the scattering region

# calculate the LDOS
def plot_ldos(sys,energy):
ldos = kwant.ldos(sys, energy)
ldos_site  = np.sum(ldos.reshape(-1, 6), axis=1)
0,hop_lw = 0.0,
hop_color = 'orange',site_color = 'r',cmap='Reds')

def main():
s_width = 5.6
s_length = 12.0

def family_color(site):
return 'blue' if site.family == M1 or site.family == M2 else 'red'

def hopping_lw(site1,site2):
return 0.1 if ((site1.family == M1 and site2.family == S2) or
(site1.family == M2 and site2.family==S1) or (site1.family == M2 and
site2.family==S2) or (site2.family==M2 and site1.family == S2) or
(site2.family==S1 and site1.family == M1)) else 0.0
= 0)
# calculate the LDOS
sys = sys.finalized()
plot_ldos(sys,0.0)

if __name__ == '__main__':
main()

------------------------------------------------------------------

<kwant-discuss@kwant-project.org>

Hi,
When I use kwant to calculate the conductance for MoS2 ribbon, zigzag edge is
right, however, for armchair edge ribbon, errors occure as follows,

LinAlgError: QZ iteration failed to converge in zgges.

Thanks for the report, other people have already reported a similar problem:

https://gitlab.kwant-project.org/kwant/kwant/issues/176

Can you post a minimal example that demonstrates the error?

Happy Kwanting,

Joe

```