ClearAll[liens,cparmodcom,l,ll,RawHamBloch,sp7xv5]

liens=Import["liensPBC7.dat"];
cparmodcom=Import["PtsPBC7.dat"];
l=Length[liens];
ll=Length[cparmodcom];

cut=0.5;


RawHamBloch=Reap[Do[{rat=N[408*Sqrt[2]];dx=cparmodcom[[liens[[m,1]],1]]-cparmodcom[[liens[[m,2]],1]];dy=cparmodcom[[liens[[m,1]],2]]-cparmodcom[[liens[[m,2]],2]];

If[(liens[[m,1]]<liens[[m,2]])&&(Abs[dx]>cut)&&(Abs[dy]>cut),(*Print["Cond 1 "," ",dx," ",dy," ",liens[[m,1]]," ",liens[[m,2]]];*)
Sow[{{liens[[m,1]],liens[[m,2]]},- Exp[I*rat*(kx*(dx-Sign[dx])+ky*(dy-Sign[dy]))]}];Sow[{{liens[[m,2]],liens[[m,1]]},-Exp[-I*rat*(kx*(dx-Sign[dx])+ky*(dy-Sign[dy]))]}];];

If[(liens[[m,1]]<liens[[m,2]])&&(Abs[dx]>cut)&&(Abs[dy]<cut),(*Print["Cond 2 "," ",dx," ",dy," ",liens[[m,1]]," ",liens[[m,2]]];*)
Sow[{{liens[[m,1]],liens[[m,2]]},-Exp[I*rat*(kx*(dx-Sign[dx])+ky*(dy))]}];
Sow[{{liens[[m,2]],liens[[m,1]]},-Exp[-I*rat*(kx*(dx-Sign[dx])+ky*(dy))]}];];

If[(liens[[m,1]]<liens[[m,2]])&&(Abs[dy]>cut)&&(Abs[dx]<cut),(*Print["Cond 3 "," ",dx," ",dy," ",liens[[m,1]]," ",liens[[m,2]]];*)
Sow[{{liens[[m,1]],liens[[m,2]]},-Exp[I*rat*(kx*(dx)+ky*(dy-Sign[dy]))]}];
Sow[{{liens[[m,2]],liens[[m,1]]},-Exp[-I*rat*(kx*(dx)+ky*(dy-Sign[dy]))]}];];

If[(liens[[m,1]]<liens[[m,2]])&&(Abs[dy]<cut)&&(Abs[dx]<cut),(*Print["Cond 4 "," ",dx," ",dy," ",liens[[m,1]]," ",liens[[m,2]]];*)
Sow[{{liens[[m,1]],liens[[m,2]]},-Exp[I*rat*(kx*(dx)+ky*(dy))]}];
Sow[{{liens[[m,2]],liens[[m,1]]},-Exp[-I*rat*(kx*(dx)+ky*(dy))]}];]
},{m,1,l}]][[2,1]];

tmp=Split[Sort[RawHamBloch],#1[[1]]==#2[[1]]&];
RawHamBloch=Table[tmp[[i,1,1]]->Tr[Transpose[tmp[[i]]][[2]]],{i,1,Length[tmp]}];

sp7xv5=Monitor[Reap[
For[n=1,n≤9,n++,
rulef={kx->(n-5)*N[Pi/(16*408*Sqrt[2])],ky->0.};
ham=SparseArray[RawHamBloch/.rulef];
Sow[Flatten[{(n-5)*N[Pi/(16*408*Sqrt[2])],Sort[Eigenvalues[ham,20,Method->{"Arnoldi","MaxIterations"->4000}]]}]/.rulef]
(*,Method->{"Arnoldi","MaxIterations"->4000}]
res=Eigensystem[ham];
For[j=1,j≤ntot,j++,
If[Tr[((Abs[res[[2,j]]])^4)]<ϵ,Sow[Flatten[{f,Chop[res[[1,j]]]}]/.rulef]];
];*)

]][[2,1]],n];

Export["sp7x9pts.dat",N[sp7xv5]];

sp7yv5=Monitor[Reap[
For[n=1,n≤9,n++,
rulef={ky->(n-5)*N[Pi/(16*408*Sqrt[2])],kx->0.};
ham=SparseArray[RawHamBloch/.rulef];
Sow[Flatten[{(n-5)*N[Pi/(16*408*Sqrt[2])],Sort[Eigenvalues[ham,20,Method->{"Arnoldi","MaxIterations"->4000}]]}]/.rulef]
(*,Method->{"Arnoldi","MaxIterations"->4000}]
res=Eigensystem[ham];
For[j=1,j≤ntot,j++,
If[Tr[((Abs[res[[2,j]]])^4)]<ϵ,Sow[Flatten[{f,Chop[res[[1,j]]]}]/.rulef]];
];*)

]][[2,1]],n];
sp7xyv5=Monitor[Reap[
For[n=1,n≤9,n++,
rulef={kx->(n-5)*N[Pi/(16*408*Sqrt[2])],ky->(n-5)*N[Pi/(16*408*Sqrt[2])]};
ham=SparseArray[RawHamBloch/.rulef];
Sow[Flatten[{(n-5)*N[Pi/(16*408*Sqrt[2])],Sort[Eigenvalues[ham,20,Method->{"Arnoldi","MaxIterations"->4000}]]}]/.rulef]
(*,Method->{"Arnoldi","MaxIterations"->4000}]
res=Eigensystem[ham];
For[j=1,j≤ntot,j++,
If[Tr[((Abs[res[[2,j]]])^4)]<ϵ,Sow[Flatten[{f,Chop[res[[1,j]]]}]/.rulef]];
];*)

]][[2,1]],n];

ListPlot[Transpose[{Transpose[sp7xv5][[1]],Transpose[sp7xv5][[2]]}],PlotRange->{{-0.0015,0.0015},{-4.22170,-4.22169}}]

Fit[Transpose[{Transpose[sp7yv5][[1]],Transpose[sp7yv5][[2]]}],{1,x,x^2,x^3},x]

Fit[Transpose[{Transpose[sp7xyv5][[1]],Transpose[sp7xyv5][[2]]}],{1,x,x^2,x^3},x]

-4.221697257857193`+2.3803340129869337`*^-11 x+2.821662405942648` ((x )^2)-4.837928647623429`*^-7 (x^3)

Fit[Transpose[{Transpose[sp7xv5][[1]],Transpose[sp7xv5][[2]]}],{1,x,x^2,x^3},x]

-4.221697258242795`+5.952757618324414`*^-11 x +1.4112499193581576` (x^2)-0.00004773426330725552` (x^3)

Fit[Transpose[{Transpose[sp7xyv5][[1]],Transpose[sp7xyv5][[2]]}],{1,x^2},x]

-4.221697257857194`+ 2.821662405780352` (x^2)

alpha7x=2*1.4112499193581576`;
alpha7y=2*1.4112499227153497`;

alpha7xy=2.821662405942648`-1.4112499193581576`-1.4112499227153497`;

minv7=Sqrt[alpha7x*alpha7y-alpha7xy*alpha7xy]

alpha7xy