liens=Import["liensPBC6v2.dat"];
ppts=Import["PtsPBC6v2.dat"];
l=Length[liens];
ll=Length[ppts];

cut=0.5;


RawHamFlux=Reap[Do[{rat=N[169*Sqrt[2]];
dx=ppts[[liens[[m,1]],1]]-ppts[[liens[[m,2]],1]];
dy=ppts[[liens[[m,1]],2]]-ppts[[liens[[m,2]],2]];

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

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

ll

sp6fluxTot=Reap[
For[n=1,n≤50,n++,
Print[n];
rulef={Phi->n/20000};
ham=SparseArray[RawHamFlux/.rulef];
eig=Sort[Eigenvalues[ham]];
eig>>>"Pap7backup";
Sow[Flatten[{n/20000,eig}]/.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]];

tb6=Table[ListPlot[Transpose[{Transpose[sp6fluxTot][[1]],Transpose[sp6fluxTot][[i]]}],PlotStyle->{Blue,Thickness[0.0003]},PlotRange->{{0,0.005},{-4.3,-3.8}},Joined->True],{i,2,47321}];

Length[tb6]

Export["sp6fluxTot.dat",N[sp6fluxTot]];

Export["sp6fluxTot1.dat",N[sp6fluxTot]];

sp6p3=Import["sp6fluxTot3.dat"];

sp6p2=Import["sp6fluxTot2v2.dat"];

sp6=Join[sp6fluxTot,sp6p2];

sp6tot=Join[sp6,sp6p3];

tb6tot=Table[ListPlot[Transpose[{Transpose[sp6tot][[1]],Transpose[sp6tot][[i]]}],PlotStyle->{Blue,Thickness[0.0003]},PlotRange->{{0,0.005},{-4.3,-3.8}},Joined->True],{i,2,47321}];

Export["tb6tot.dat",tb6tot];

Show[Table[Plot[x*2*Pi*2.8529*(n+0.5)-4.222,{x,0,0.01},PlotStyle->{Red,Thickness[0.005]},PlotRange->{{0.,0.005},{-4.23,-4.0}}],{n,0,4}],Table[Plot[x*2*Pi*2.789*(n+0.5)-4.222,{x,0,0.01},PlotStyle->{Green,Thickness[0.005]},PlotRange->{{0.,0.005},{-4.23,-4.0}}],{n,0,4}],tb6tot,ImageSize->800]

Show[Table[Plot[x*2*Pi*2.789*(n+0.5)-4.222,{x,0,0.01},PlotStyle->{Red,Thickness[0.003]},PlotRange->{{0.,0.005},{-4.23,-4.15}}],{n,0,4}],tb6tot,AxesLabel->{"φ","E"},ImageSize->800]

Show[Table[Plot[x*2*Pi*2.789*(n+0.5)-4.222,{x,0,0.01},PlotStyle->{Red,Thickness[0.003]},PlotRange->{{0.,0.005},{-4.23,-4.20}}],{n,0,4}],tb6tot,AxesLabel->{"φ","E"},ImageSize->800]