liens=Import["liensPBC5.dat"];
ppts=Import["PtsPBC5.dat"];
l=Length[liens];
ll=Length[ppts];

cut=0.5;


RawHamFlux=Reap[Do[{rat=N[70*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]}];

sp5flux=Monitor[Reap[
For[n=1,n≤100,n++,
rulef={Phi->(0.0005+(100+n)/21000)};
ham=SparseArray[RawHamFlux/.rulef];
eig=Sort[Eigenvalues[ham]];
eig>>>"Pap5backup2";
Sow[Flatten[{(0.0005+(100+n)/21000),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]],n];

Export["Pap5backup2fin.dat",N[sp5flux]];

Clear[tb5p2]

tb5p2=Table[ListPlot[Transpose[{Transpose[sp5flux][[1]],Transpose[sp5flux][[i]]}],PlotStyle->{Blue,Thickness[0.0003]},Joined->True],{i,2,4000}];

Show[tb5p2,PlotRange->{{0.005,0.01},{-4.2,-3.8}},ImageSize->800]

tb5p2tot=Table[ListPlot[Transpose[{Transpose[sp5flux][[1]],Transpose[sp5flux][[i]]}],PlotStyle->{Blue,Thickness[0.0003]},Joined->True],{i,2,8120}];

sp5p1=Import["pap5backup1fin.dat"];

Dimensions[sp5p1]

tb5p1=Table[ListPlot[Transpose[{Transpose[sp5p1][[1]],Transpose[sp5p1][[i]]}],PlotStyle->{Blue,Thickness[0.0003]},Joined->True],{i,2,4000}];

Show[tb5p1,tb5p2,PlotRange->{{0.,0.01},{-4.2,-3.8}},ImageSize->800]

sp5=Join[sp5p1,sp5flux];

Dimensions[sp5]

tb5=Table[ListPlot[Transpose[{Transpose[sp5][[1]],Transpose[sp5][[i]]}],PlotStyle->{Blue,Thickness[0.0003]},Joined->True],{i,2,4000}];

Show[Table[Plot[x*2*Pi*2.823*(n+0.5)-4.222,{x,0,0.01},PlotStyle->Red,PlotRange->{{0.,0.01},{-4.23,-3.8}}],{n,0,4}],Table[Plot[x*2*Pi*2.75*(n+0.5)-4.222,{x,0,0.01},PlotStyle->Green],{n,0,4}],tb5,Frame->True,ImageSize->800]

sp5flux0=Monitor[Reap[
For[n=1,n≤11,n++,
rulef={Phi->n/21000};
ham=SparseArray[RawHamFlux/.rulef];
eig=Sort[Eigenvalues[ham]];
Sow[Flatten[{n/21000,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]],n];

0.0005*21000

sp5v2=Join[sp5flux0,sp5];

tb5v2=Table[ListPlot[Transpose[{Transpose[sp5v2][[1]],Transpose[sp5v2][[i]]}],PlotStyle->{Blue,Thickness[0.0003]},Joined->True],{i,2,400}];

Show[Table[Plot[x*2*Pi*2.8225*(n+0.5)-4.222,{x,0,0.01},PlotStyle->Red,PlotRange->{{0.,0.01},{-4.23,-3.8}}],{n,0,4}],Table[Plot[x*2*Pi*2.8*(n+0.5)-4.222,{x,0,0.01},PlotStyle->Green],{n,0,4}],tb5v2,Frame->True,ImageSize->800]

Export["pap5flux0to001.dat",N[sp5v2]];

p6=Import["Pap7backup","Table"];

Dimensions[p6]

tb6=Table[ListPlot[Transpose[Transpose[p6][[i]]],PlotStyle->{Blue,Thickness[0.0003]},Joined->True],{i,2,400}];

ListPlot[p6]

p6[[200]]

p6

Show[tb4,tb5v2,PlotRange->{{0.,0.01},{-4.23,-3.8}}]

sp5flux[[-1]][[100]]