Octonacci[k_]:=Module[{octo,i},
octo=Table[0,{i,1,k}];
octo[[1]]=1;
octo[[2]]=2;
Do[ octo[[i]]=octo[[i-2]]+2*octo[[i-1]],{i,3,k}];
octo];
locto=Octonacci[12];

locto

ClearAll[Mat,RawHamBloch,k,test,liens,cparmodcom]

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

cut=0.5;


RawHamBloch=Reap[Do[{rat=N[locto[[8]]*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]}];

sp7xv2=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,10]]}]/.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];

Transpose[sp7xv2][[2]]

{-4.22 1683175317801`,-4.221684198099277`,-4.221684734314314`,-4.221684762482884`,-4.2216842675011375`,-4.221683243857906`,-4.221681699563048`,-4.221679660613797`,-4.221677221357731`}

{{-0.0013611773707593031`,-4. 221683175317801`,-4.221445927179283`,-4.220931120683804`,-4.220113051196303`,-4.218891433787276`,4.219413606134628`,4.2203727145600505`,4.220871021754882`,4.221322040865022`,4.221625140861062`},{-0.0010208830280694773`,-4.221684198099277`,-4.221451203426509`,-4.22092785611768`,-4.220112169202931`,-4.218885799578562`,4.219407077903875`,4.220360831225868`,4.220853773733536`,4.221314529618845`,4.221621930663415`},{-0.0006805886853796516`,-4.221684734314314`,-4.221455927222991`,-4.220923962798419`,-4.220112326392382`,-4.218881451874217`,4.219403393384602`,4.220351442534631`,4.220842113268853`,4.221309170978988`,4.22161876083622`},{-0.0003402943426898258`,-4.221684762482884`,-4.2214600155357935`,-4.220919579584745`,-4.22011366536776`,-4.218878563428799`,4.219405080655395`,4.220348224348963`,4.220840480714185`,4.2213067376306945`,4.221615697371341`},{0.`,-4.2216842675011375`,-4.221463387787947`,-4.220914828296513`,-4.220116287450518`,-4.218877197708895`,4.219413881258516`,4.2203533162151485`,4.220852265862449`,4.221308028095586`,4.221612817318782`},{0.0003402943426898258`,-4.221683243857906`,-4.221465962510329`,-4.220909810785053`,-4.22012024254579`,-4.218877296662075`,4.219429241771813`,4.220365182301476`,4.220877973490417`,4.221313876554085`,4.221610216864297`},{0.0006805886853796516`,-4.221681699563048`,-4.221467655104783`,-4.220904606292383`,-4.2201255187303675`,-4.218878680348159`,4.2194484251196975`,4.22037935858405`,4.220913725452076`,4.221324996209139`,4.221608020575651`},{0.0010208830280694773`,-4.221679660613797`,-4.221468377458786`,-4.22089926888839`,-4.220132032701703`,-4.218881059637972`,4.219468276044384`,4.220391616485315`,4.220952103970604`,4.221341501010336`,4.2216063888768725`},{0.0013611773707593031`,-4.221677221357731`,-4.221468190519697`,-4.220894174782623`,-4.220140587802106`,-4.2188861374308715`,4.2189466051017375`,4.220103046712401`,4.220770515305935`,4.221316720561073`,4.221603065435424`}}

rulef={kx->0.,ky->0.};
ham=SparseArray[RawHamBloch/.rulef];

Sort[Eigenvalues[ham,10]]

{-4.2216842675011375` ,-4.221463387787947`,-4.220914828296513`,-4.220116287450518`,-4.218877197708895`,4.219413881258516`,4.2203533162151485`,4.220852265862449`,4.221308028095586`,4.221612817318782`}

Sort[Eigenvalues[ham,10,Method->{"Arnoldi","MaxIterations"->4000}]]

{-4.221697255291593`,-4.2215 33529137269`,-4.22148302232151`,-4.221308953278913`,-4.220948107685116`,4.220868575087995`,4.22123210637479`,4.221323687301066`,4.221597847606031`,4.22162261829266`}

sp7xv3=Monitor[Reap[
For[n=1,n≤2,n++,
rulef={kx->(2*n-3)*N[Pi/(5*408*Sqrt[2])],ky->0.};
ham=SparseArray[RawHamBloch/.rulef];
Sow[Flatten[{(2*n-3)*N[Pi/(5*408*Sqrt[2])],Sort[Eigenvalues[ham,10,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];

sp7xv3

{{-0.0010889418966074425`,-4.221695578641333` ,-4.221542204723886`,-4.221480412091291`,-4.221286626500178`,-4.220976273647939`,4.220895340532252`,4.221283305055906`,4.221366065677161`,4.221597093899707`,4.2216289367547075`},{0.0010889418966074425`,-4.221695577653806`,-4.221556527116998`,-4.221497809803076`,-4.22131330872619`,-4.220930946189801`,4.220926816717779`,4.221238968071321`,4.221344250148281`,4.221586317511463`,4.221632510778895`}}

{-4.221697255291593`,-4.2215 33529137269`,-4.22148302232151`,-4.221308953278913`,-4.220948107685116`,4.220868575087995`,4.22123210637479`,4.221323687301066`,4.221597847606031`,4.22162261829266`}

sp7x={{-0.0010889418966074425`,-4.221695578641333`},{0.,-4.221697255291593`},{0.0010889418966074425`,-4.221695577653806`}};

Transpose[sp7xv4][[2]]

{-4.221695584574613`,-4.221697258442472`,-4.22 16955845745`}

ListPlot[Transpose[{Transpose[sp7x][[1]],Transpose[sp7x][[2]]}],PlotRange->{{-0.0015,0.0015},{-4.2217,-4.22169}}]

sp7xv4=Monitor[Reap[
For[n=1,n≤3,n++,
rulef={kx->(n-2)*N[Pi/(5*408*Sqrt[2])],ky->0.};
ham=SparseArray[RawHamBloch/.rulef];
Sow[Flatten[{(n-2)*N[Pi/(5*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[sp7xv4][[1]],Transpose[sp7xv4][[2]]}],PlotRange->{{-0.0015,0.0015},{-4.2217,-4.22169}}]

Clear[x]

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

sp7yv4=Monitor[Reap[
For[n=1,n≤3,n++,
rulef={ky->(n-2)*N[Pi/(5*408*Sqrt[2])],kx->0.};
ham=SparseArray[RawHamBloch/.rulef];
Sow[Flatten[{(n-2)*N[Pi/(5*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];

sp7xyv4=Monitor[Reap[
For[n=1,n≤3,n++,
rulef={kx->(n-2)*N[Pi/(5*408*Sqrt[2])],ky->(n-2)*N[Pi/(5*408*Sqrt[2])]};
ham=SparseArray[RawHamBloch/.rulef];
Sow[Flatten[{(n-2)*N[Pi/(5*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[sp7yv4][[1]],Transpose[sp7yv4][[2]]}],PlotRange->{{-0.0015,0.0015},{-4.2217,-4.22169}}]

ListPlot[Transpose[{Transpose[sp7xyv4][[1]],Transpose[sp7xyv4][[2]]}],PlotRange->{{-0.0015,0.0015},{-4.2217,-4.22169}}]

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

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

-4.221697258442472`+6.090313234255051`*^-13 x+ 2.8226900085527586` (x^2)+2.7231314055121035`*^-8 (x^3)

alpha7x=2*1.4116003941573594`;
alpha7y=2*1.4116004492797516`;
alpha7xy=2.8226900085527586`-1.4116003941573594`-1.4116004492797516`

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

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

-4.221697258442471`+2. 8226900041609655` (x^2)

ll

rulef={kx->N[Pi/(5*408*Sqrt[2])],ky->0.};
ham=SparseArray[RawHamBloch/.rulef];

eig6000=Eigenvalues[ham,20,Method->{"Arnoldi","MaxIterations"->8000}]

{-4.221695584575206`,4.221634061795508`,4.221625797950372`,4.221596769093936`, 4.221584828070166`,-4.221563993609491`,-4.221533828861761`,-4.221518793218892`,-4.221486864431096`,-4.221409110296553`,-4.221395427119406`,4.221345465163712`,4.221339958031615`,4.2213281390004855`,-4.221311418351195`,-4.221299746850471`,4.221268315613105`,4.221264096271132`,4.221203159520499`,4.221191099701177`}

-4.22 16955845745`