(* Kimball model and energy derived from B3LYP/6-31G(d) opt 13/14 July 2013 *) 
Clear[tw,n2,n,nb,bc,bh,u,u1,u2,Vee,Vne,Vnn]; rad=57.2957795;

t1=1.889726*{{2.8449449586,-1.1156236964,0.0233945780},{4.2519593102,-0.7235028782,0.0354342570},{4.2661194248,0.6329939647,0.0378072836},{2.8676557557,1.0542689656,0.0276819780},{2.4668940017,2.3959780179,0.0276425610},{1.1608611869,2.8840153995,0.0194907205},{0.7310874012,4.2535186215,0.0202168731},{-0.6412305950,4.2682887134,0.0107061435},{-1.1001030451,2.9085549193,0.0033443344},{-2.4162793415,2.4484230272,-0.0090331807},{-2.8450406426,1.1155691673,-0.0191094585},{-4.2520624806,0.7234970412,-0.0350424280},{-4.2661466063,-0.6329421018,-0.0427706637},{-2.8676514998,-1.0541450894,-0.0309066783},{-2.4667511138,-2.3957921796,-0.0333320958},{-1.1608161853,-2.8839823216,-0.0216154382},{-0.7310587681,-4.2534458668,-0.0225640068},{0.6411758504,-4.2683505522,-0.0076663419},{1.1000551440,-2.9086126976,0.0023035003},{2.4162386123,-2.4485780573,0.0165339545},{3.1868536155,-3.2145331076,0.0216793074},{-0.0219421873,-2.1175817455,-0.0064131496},{-0.0103673497,-1.1020334834,-0.0024690685},{1.2935255868,-5.1320081026,-0.0040948811},{-1.4018241942,-5.1029090735,-0.0333859181},{-3.2532175332,-3.1454482848,-0.0450892409},{-2.0303239965,0.0219985256,-0.0168702077},{-5.1214664602,-1.2981848018,-0.0552189415},{-5.0934578112,1.4063662130,-0.0397779572},{-3.1868607512,3.2144602561,-0.0121516324},{0.0219305927,2.1175701223,0.0093007500},{0.0104336302,1.1019413611,0.0060636045},{-1.2933685024,5.1321454479,0.0084537519},{1.4018520212,5.1029661103,0.0271294848},{3.2533512387,3.1456244824,0.0348660588},{2.0303631680,-0.0220257589,0.0190786174},{5.1215335656,1.2981638975,0.0455910995},{5.0931336913,-1.4066433141,0.0407918411}};

u={"C","C","C","C","C","C","C","C","C","C","C","C","C","C","C","C","C","C","C","C","H","N","H","H","H","H","N","H","H","H","N","H","H","H","H","N","H","H"};

n=Length[t1]

DeleteFile[ "C:\\Kimb_Mathem\\tmp3"];
For[i=1,i≤n,i++,
{u[[i]],Extract[t1,{i}]}>>> "C:\\Kimb_Mathem\\tmp3"]

un=Table[If[u[[i]]=="H","Z",u[[i]]],{i,1,n}]

num1=Table[i,{i,1,n}];

um=Table[{un[[i]],num1[[i]]},{i,1,n}];

us=Sort[um]

num=Table[us[[i,2]],{i,1,n}]

For[i=1,i<n+1,i++,If[us[[i,1]]=="Z",us[[i,1]]="H"]];

u1=Table[If[us[[i,1]]=="C",0.255,If[us[[i,1]]=="H",0.12,If[us[[i,1]]=="N",0.24,If[us[[i,1]]=="O",0.178,If[us[[i,1]]=="Cl",0.5]]]]],{i,1,n}]
u2=Table[If[us[[i,1]]=="C",0.255,If[us[[i,1]]=="H",0.6,If[us[[i,1]]=="N",0.21522,If[us[[i,1]]=="O",0.178,If[us[[i,1]]=="Cl",0.4507]]]]],{i,1,n}]

u=Table[us[[i,1]],{i,1,n}]

ChemicalData["Porphine","MolecularFormulaString"]

cn=Table[If[u[[i]]=="C",6.0,If[u[[i]]=="H",1.0,If[u[[i]]=="N",7.0,If[u[[i]]=="O",8.0,If[u[[i]]=="Cl",17.0]]]]],{i,1,n}]

bc=0;
For[i=1, i<n+1,i++,If[u[[i]]≠"H", bc=bc+1]];
bc
bh=n-bc

t=Table[t1[[num[[i]]]],{i,1,n}];
Plot1o=Table[Graphics3D[{Opacity[0.8],If[u[[i]]=="N",Lighter[Blue],If[u[[i]]=="H",Lighter[White],If[u[[i]]=="O",Lighter[Red],If[u[[i]]=="Cl",Lighter[Green],If[u[[i]]=="B",Lighter[Orange],Darker[Brown]]]]]],Sphere[{t[[i,1]],t[[i,2]],t[[i,3]]},u1[[i]]]}],{i,1,n}];
Plot2=Table[Graphics3D[Text[i,{t[[i,1]]-0.6,t[[i,2]],t[[i,3]]} ,{1,0}]],{i,1,n}];
Show[Plot1o,Plot2,{AspectRatio->Automatic,Boxed->True, Axes->Automatic,AxesLabel->{xl,yl,zl},SphericalRegion->True}]

(* Distance Matrix Bohr *)
dc=Table[Norm[t[[i]]-t[[j]]],{i,1,n},{j,1,n}];
MatrixForm[Prepend[dc,num1]]

x=Table[t[[i,1]],{i,1,n}];
y=Table[t[[i,2]],{i,1,n}];
z=Table[t[[i,3]],{i,1,n}];

(* connected pairs: distance criteria < 3.0 bohr *)
Dij=Table[If[(dc[[i,j]]<2.9&&(dc[[i,j]]≠2.770063479875957`)),dc[[i,j]],0],{i,1,n},{j,1,n}];
MatrixForm[Prepend[Dij,num1]]

(* count C atoms *)
nc=0;  
For[i=1,i<bc+1,i++,If[u[[i]]=="C",nc=nc+1,nc]]
cnt=Table[0,{nc}];
pri=cnt; sec=cnt;ter=cnt; qua=cnt;
nc

(* count H atoms bonded to each C atom *)
For[j=1,j≤nc,j++,
For[i=bc+1,i≤n,i++,If[ Dij[[i,j]]≠0 ,cnt[[j]]=cnt[[j]]+1,0]]];
cnt

(* parse into prim, sec, tert, and quart C cores with different radii *)
n1=0; n2=0; n3=0; n4=0;
For[i=1,i≤nc,i++,
If[cnt[[i]]==3,n1=n1+1;pri[[n1]]=i,
If[cnt[[i]]==2,n2=n2+1;sec[[n2]]=i,
If[cnt[[i]]==1,n3=n3+1;ter[[n3]]=i,
If[cnt[[i]]=0,n4=n4+1;qua[[n4]]=i]]]]];
For [i=1, i≤nc,i++,If[pri[[i]]≠0,u2[[pri[[i]]]]=0.2572]]
For [i=1, i≤nc,i++,If[sec[[i]]≠0,u2[[sec[[i]]]]=0.2556]]
For [i=1, i≤nc,i++,If[ter[[i]]≠0,u2[[ter[[i]]]]=0.257]]
For [i=1, i≤nc,i++,If[qua[[i]]≠0,u2[[qua[[i]]]]=0.257]]

Eij=Table[If[i≥j,Dij[[i,j]],0],{i,1,nc},{j,1,nc}];
CD=Select[Flatten[Eij],(#≥2.4 &&#≤2.73) &]
Mean[CD] ± StandardDeviation[CD]

CC=Select[Flatten[Eij],(#≥2.73) &]
Mean[CC] ± StandardDeviation[CC]

Eij=Table[If[i≥j,Dij[[i,j]],0],{i,bc+1,n},{j,1,nc}];
CH=Select[Flatten[Eij],(#>0 &&#≤2.1) &]
Mean[CH] ± StandardDeviation[CH]

For[i=1 ,i<n+1,i++,
For[j=1, j<bc+1,j++,
If[(Dij[[i,j]]≠0  && u[[i]]== "H"),If[u[[j]]=="C",u2[[i]]=0.5693,If[u[[j]]=="F",u2[[i]]=0.5,If[u[[j]]=="N",u2[[i]]=0.5541,If[u[[j]]=="O",u2[[i]]=0.5241]]]]]]]
u2

(* subtract core radii from pair distances *)
Fij=Dij-u2;
(*MatrixForm[Fij];*)
Gij=Table[If[i≥j,If[Fij[[i,j]]>0,Fij[[i,j]],0]," "],{i,1,n},{j,1,n}];
(*MatrixForm[Gij];*)

Hij=Transpose[Gij];
(*MatrixForm[Hij];*)

Kij=Hij-u2;
(*MatrixForm[Kij];*)
Lij=Table[If[i≤j,If[Kij[[i,j]]>0,Kij[[i,j]],0]," "],{i,1,n},{j,1,n}];
(*MatrixForm[Lij];*)

(* determine bond cloud radii *)
Lij=Table[If[i≤j,If[Lij[[i,j]]>0,If[u[[j]]≠"H",0.5*Lij[[i,j]],Lij[[i,j]]],0]," "],{i,1,n},{j,1,n}];  
Qij=Lij;
(*MatrixForm[Lij];*)

(* determine kinetic energy *)
Nij=Table[If[i≤j,If[Lij[[i,j]]>0,2.25/Lij[[i,j]]^2,0]," "],{i,1,n},{j,1,n}];
(*MatrixForm[Nij]*)

Tval=Sum[If[i≤j,Nij[[i,j]],0],{i,1,n},{j,1,n}]

Tcor=Sum[If[u[[i]]≠"H",2.25/u2[[i]]^2,0],{i,1,n}]

Ttot=Tval+Tcor  (* plus π and lone pairs: + 8.7616 *)

TvalH=Sum[If[(i≤j && u[[j]]== "H"),Nij[[i,j]],0],{i,1,n},{j,1,n}]

TvalC=Tval-TvalH

MatrixForm[Table[Join[{i},{u[[i]]},t[[i]]],{i,1,n}]]

Mij=Prepend[Qij,u];
Oij=Transpose[Mij];
Pij=Prepend[Oij,Prepend[u," "]];

con=Table[{i},{i,1,n}]; conj=Table[0,{nc}];
For[i=1,i≤n,i++,
For[j=1,j≤n,j++,If[ Dij[[i,j]]≠0 ,con[[i]]={con[[i]],j}]]];
conn=Table[Flatten[con[[i]]],{i,1,n}];
(* identify C atoms at double bonds *)
j=0;
For[i=1,i≤nc,i++,If[Length[conn[[i]]]==4,j=j+1;conj[[j]]=i]];
conj=Take[conj,{1,j}]
nj=Length[conj]
MatrixForm[conn, TableAlignments->Left]

Clear[c,v,p,Q,P,v1,v2,nk,nl]; (*c1=20; c2=21; c3=51;*) 
rpo=1.4;
rpi=1.4;
tpo=Table[{0,0,0},{nj+4}];
tpu=Table[{0,0,0},{nj+4}];
P=3; c={0,0,0,0,0}; 
(*--------------------------------------------------------------------------*)
(* construct the π clouds for C atoms *)

Do[(c=conn[[conj[[k]]]];
c=Take[c,P];
v=Table[Join[t[[c[[i]]]],{1}],{i,1,P}];
x2=t[[c[[2]],1]];
y2=t[[c[[2]],2]]; 
z2=t[[c[[2]],3]];
Q={{1,0,0,0},
{0,1,0,0},
{0,0,1,0},
{-x2,-y2,-z2,1}};
p=v.Q;
p=Table[Take[p[[i]],3],{i,1,P}];
T1=ArcTan[p[[1,3]]/p[[1,2]]];
U=p;
T=RotationMatrix[T1,{1,0,0}];
p=U.T;
T2=ArcTan[p[[1,2]]/p[[1,1]]];
U=p;
T=RotationMatrix[T2,{0,0,1}];
p=U.T;
T3=ArcTan[p[[3,3]]/p[[3,2]]];
U=p;
T=RotationMatrix[T3,{1,0,0}];
p=Chop[U.T];
mk=p;
ml=p;
mk[[1,3]]=rpo;
ml[[1,3]]=-rpi;
U=p;
U1=mk;
U2=ml;
T=RotationMatrix[-T3,{1,0,0}];
p=U.T;
mk=U1.T;
ml=U2.T;
U=p;
U1=mk;
U2=ml;
T=RotationMatrix[-T2,{0,0,1}];
p=U.T;
mk=U1.T;
ml=U2.T;
U=p;
U1=mk;
U2=ml;
T=RotationMatrix[-T1,{1,0,0}];
p=U.T;
mk=U1.T;
ml=U2.T;
Clear[v,v1,v2];
v  =Table[Join[p[[i]],{1}],{i,1,P}];
v1=Table[Join[mk[[i]],{1}],{i,1,P}];
v2=Table[Join[ml[[i]],{1}],{i,1,P}];
Q={{1,0,0,0},
{0,1,0,0},
{0,0,1,0},
{x2,y2,z2,1}};
p=v.Q;
mk=v1.Q;
ml=v2.Q;
p=Table[Take[p[[i]],3],{i,1,P}];
mk=Table[Take[mk[[i]],3],{i,1,P}];
ml=Table[Take[ml[[i]],3],{i,1,P}];
tpo[[k]]=mk[[1]];
tpu[[k]]=ml[[1]]),{k,nj}];

(*-------------------------------------------------------------------------*)
(* construct the π clouds for four N atom *)

k=1;
Clear[conn];
conn={{21,16,19},{22,11,14},{23,6,9},{24,1,4}};
rln=1.246;

Do[(c=conn[[k]];
v=Table[Join[t[[c[[i]]]],{1}],{i,1,P}];
x2=t[[c[[2]],1]];
y2=t[[c[[2]],2]]; 
z2=t[[c[[2]],3]];
Q={{1,0,0,0},
{0,1,0,0},
{0,0,1,0},
{-x2,-y2,-z2,1}};
p=v.Q;
p=Table[Take[p[[i]],3],{i,1,P}];
T1=ArcTan[p[[1,3]]/p[[1,2]]];
U=p;
T=RotationMatrix[T1,{1,0,0}];
p=U.T;
T2=ArcTan[p[[1,2]]/p[[1,1]]];
U=p;
T=RotationMatrix[T2,{0,0,1}];
p=U.T;
T3=ArcTan[p[[3,3]]/p[[3,2]]];
U=p;
T=RotationMatrix[T3,{1,0,0}];
p=Chop[U.T];
nk=p;
nl=p;
nk[[1,3]]=rln;
nl[[1,3]]=-rln;
U=p;
U1=nk;
U2=nl;
T=RotationMatrix[-T3,{1,0,0}];
p=U.T;
nk=U1.T;
nl=U2.T;
U=p;
U1=nk;
U2=nl;
T=RotationMatrix[-T2,{0,0,1}];
p=U.T;
nk=U1.T;
nl=U2.T;
U=p;
U1=nk;
U2=nl;
T=RotationMatrix[-T1,{1,0,0}];
p=U.T;
nk=U1.T;
nl=U2.T;
Clear[v,v1,v2];
v  =Table[Join[p[[i]],{1}],{i,1,P}];
v1=Table[Join[nk[[i]],{1}],{i,1,P}];
v2=Table[Join[nl[[i]],{1}],{i,1,P}];
Q={{1,0,0,0},
{0,1,0,0},
{0,0,1,0},
{x2,y2,z2,1}};
p=v.Q;
nk=v1.Q;
nl=v2.Q;
p=Table[Take[p[[i]],3],{i,1,P}];
nk=Table[Take[nk[[i]],3],{i,1,P}];
nl=Table[Take[nl[[i]],3],{i,1,P}];
tpo[[nj+k]]=nk[[1]];
tpu[[nj+k]]=nl[[1]]),{k,4}];

(*-------------------------------------------------------------------------*)
(* next: N21 ,22,23,24,four doubly occ LP as sp2 ligand *)

k=1;
Clear[conn,α,β,γ,gamm];
tpln=Table[{0.0,0.0,0.0},{i,1,2}];
conn={{11,22,14},{1,24,4}};
Plota= Table[{0}, {i, 1, 2}]; 
Plotc= Plota;
Plotd =Plota; 
Plotb0 =Plota; 
Ok={{1,-1,1},{-1,1,1}};
gamm={{0,0,0},{0,0,0}};

Do[(c=conn[[k]];
a1=dc[[c[[2]],c[[1]]]]; a2=dc[[c[[2]],c[[3]]]]; d1=dc[[c[[1]],c[[3]]]];
α=ArcCos[(a1^2+a2^2-d1^2)/(2*a1*a2)];
L=u2[[c[[2]]]]+rln;
β=ArcSin[rln/L];
γ=π/2-α/2; gamm[[k]]=γ;
(*If[(k==1 || k==3),γ=π-α/4,γ=3*π/2+α/2];*)
v=Table[Join[t[[c[[i]]]],{1}],{i,1,P}];
x2=t[[c[[2]],1]];
y2=t[[c[[2]],2]]; 
z2=t[[c[[2]],3]];
Q={{1,0,0,0},
{0,1,0,0},
{0,0,1,0},
{-x2,-y2,-z2,1}};
p=v.Q;
p=Table[Take[p[[i]],3],{i,1,P}];
(*Plota[[k]] = Table[Graphics3D[{Opacity[0.5],Sphere[p[[i]],u2[[c[[i]]]]]}],{i,1,P}];
Plotc[[k]] = Table[Graphics3D[{Tube[{p[[i]],p[[j]]},0.02]}],{i,1,P-1},{j,i+1,P}];*)
T1=ArcTan[p[[1,3]]/p[[1,2]]];
U=p;
T=RotationMatrix[T1,{1,0,0}];
p=U.T;
T2=ArcTan[p[[1,2]]/p[[1,1]]];
U=p;
T=RotationMatrix[T2,{0,0,1}];
p=U.T;
T3=ArcTan[p[[3,3]]/p[[3,2]]];
U=p;
T=RotationMatrix[T3,{1,0,0}];
p=Chop[U.T];
nk=p;
 nk[[2,1]]=L*Sin[γ]; nk[[2,2]]=-L*Cos[γ];  nk[[2,3]]=0; 
nk[[2]]=Ok[[k]]*nk[[2]];
Plota[[k]] = Table[Graphics3D[{Opacity[0.5],Sphere[p[[i]],u2[[c[[i]]]]]}],{i,1,P}];
Plotc[[k]] = Table[Graphics3D[{Tube[{p[[i]],p[[j]]},0.02]}],{i,1,P-1},{j,i+1,P}];
Plotd[[k]]=Graphics3D[{Opacity[0.5],Lighter[Blue],Sphere[nk[[2]],rln]}];
Plotb0[[k]]=Table[Graphics3D[Text[c[[i]],p[[i]],{1,0}]],{i,1,P}];
U=p;
U1=nk;
T=RotationMatrix[-T3,{1,0,0}];
p=U.T;
nk=U1.T;
U=p;
U1=nk;
T=RotationMatrix[-T2,{0,0,1}];
p=U.T;
nk=U1.T;
U=p;
U1=nk;
T=RotationMatrix[-T1,{1,0,0}];
p=U.T;
nk=U1.T;
Clear[v,v1,v2];
v  =Table[Join[p[[i]],{1}],{i,1,P}];
v1=Table[Join[nk[[i]],{1}],{i,1,P}];
Q={{1,0,0,0},
{0,1,0,0},
{0,0,1,0},
{x2,y2,z2,1}};
p=v.Q;
nk=v1.Q;
p=Table[Take[p[[i]],3],{i,1,P}];
nk=Table[Take[nk[[i]],3],{i,1,P}];
tpln[[k]]=nk[[2]]),{k,2}];

Table[Show[Plotd[[i]], Plota[[i]], Plotb0[[i]], Plotc[[i]], {Axes -> Automatic, AxesLabel -> {xl, yl, zl}, 
        AspectRatio -> Automatic, Boxed -> False, PlotRange -> Automatic, SphericalRegion -> True}],{i,1,2}]

k = 1;
Clear[conn,P];
P = 4;rln=1.246;pn=0;
tpyrn = {{0.0, 0.0, 0.0}};
conn = {{2,6,7,20}};

<< "C:\\Kimb_Mathem\\LpyrNtrans.m"

DeleteFile[ "C:\\Kimb_Mathem\\tmp4"];
For[i=2,i<n+2,i++,
For[j=2,j≤i,j++,
If[Pij[[i,j]]>0,{i-1,j-1,Extract[Pij,{i,j}]}>>> "C:\\Kimb_Mathem\\tmp4"]]]

a=ReadList["C:\\Kimb_Mathem\\tmp4"]
nb=Length[a]
cw=nb-bh

wxc=Table[(a[[i,3]]+u2[[a[[i,1]]]])/(u2[[a[[i,1]]]]+2*a[[i,3]]+u2[[a[[i,2]]]])*(x[[a[[i,2]]]]-x[[a[[i,1]]]])+x[[a[[i,1]]]],{i,1,cw}];
wyc=Table[(a[[i,3]]+u2[[a[[i,1]]]])/(u2[[a[[i,1]]]]+2*a[[i,3]]+u2[[a[[i,2]]]])*(y[[a[[i,2]]]]-y[[a[[i,1]]]])+y[[a[[i,1]]]],{i,1,cw}];   
wzc=Table[(a[[i,3]]+u2[[a[[i,1]]]])/(u2[[a[[i,1]]]]+2*a[[i,3]]+u2[[a[[i,2]]]])*(z[[a[[i,2]]]]-z[[a[[i,1]]]])+z[[a[[i,1]]]],{i,1,cw}];

Plot7=Table[Graphics3D[{Darker[Brown,0.4],Opacity[0.5],If[wxc[[i]]≠0,Sphere[{wxc[[i]],wyc[[i]],wzc[[i]]},a[[i,3]]]]}],{i,1,cw}];

wxh=Table[(a[[i,3]]+u2[[a[[i,2]]]])/(u2[[a[[i,1]]]]+a[[i,3]]+u2[[a[[i,2]]]])*(x[[a[[i,1]]]]-x[[a[[i,2]]]])+x[[a[[i,2]]]],{i,cw+1,nb}];
wyh=Table[(a[[i,3]]+u2[[a[[i,2]]]])/(u2[[a[[i,1]]]]+a[[i,3]]+u2[[a[[i,2]]]])*(y[[a[[i,1]]]]-y[[a[[i,2]]]])+y[[a[[i,2]]]],{i,cw+1,nb}];
wzh=Table[(a[[i,3]]+u2[[a[[i,2]]]])/(u2[[a[[i,1]]]]+a[[i,3]]+u2[[a[[i,2]]]])*(z[[a[[i,1]]]]-z[[a[[i,2]]]])+z[[a[[i,2]]]],{i,cw+1,nb}];

Plot8=Table[Graphics3D[{Opacity[0.5],Sphere[{wxh[[i]],wyh[[i]],wzh[[i]]},a[[i+cw,3]]]}],{i,1,bh}];

Plot8a=Table[Graphics3D[{Opacity[0.3],Lighter[Yellow],Sphere[tpo[[i]],rpo]}],{i,1,nj}];
Plot8b=Table[Graphics3D[{Opacity[0.3],Lighter[Cyan],Sphere[tpu[[i]],rpi]}],{i,1,nj}];
Plot8c=Table[Graphics3D[{Opacity[0.3],Lighter[Yellow],Sphere[tpo[[i]],rln]}],{i,nj+1,nj+4}];
Plot8d=Table[Graphics3D[{Opacity[0.3],Lighter[Cyan],Sphere[tpu[[i]],rln]}],{i,nj+1,nj+4}];
Plot8e=Table[Graphics3D[{Opacity[0.4],Lighter[Blue],Sphere[tpln[[i]],rln]}],{i,1,2}];

Plot9= Table[Graphics3D[{Lighter[Orange,0.5],Tube[{{x[[a[[i,1]]]],y[[a[[i,1]]]],z[[a[[i,1]]]]},{x[[a[[i,2]]]],y[[a[[i,2]]]],z[[a[[i,2]]]]}},0.1]}],{i,1,nb}];
(*Plot9a= Graphics3D[Tube[{{x[[21]],y[[21]],z[[21]]},{nk[[2,1]],nk[[2,2]],nk[[2,3]]}},0.06]];
Plot9b= Graphics3D[Tube[{{x[[21]],y[[21]],z[[21]]},{nl[[2,1]],nl[[2,2]],nl[[2,3]]}},0.06]];*)

Show[Plot1o,(*Plot2,*)Plot7,Plot8,Plot8a,Plot8b,Plot8c,Plot8d,Plot8e,Plot9,{AspectRatio->Automatic,Boxed->False,(* Axes->Automatic,AxesLabel->{xl,yl,zl},*)SphericalRegion->True}]

Show[Plot1o,(*Plot2,*)(*Plot7,Plot8,*)Plot8a,Plot8b,Plot8c,Plot8d,Plot8e,Plot9,{AspectRatio->Automatic,Boxed->False,(* Axes->Automatic,AxesLabel->{xl,yl,zl},*)SphericalRegion->True}]

Show[Plot1o,Plot2,Plot9,(*Plot9a,Plot9b,*){Axes->Automatic,AxesLabel->{xl,yl,zl},AspectRatio->Automatic,Boxed->True, SphericalRegion->True}]

tc=Table[{x[[i]],y[[i]],z[[i]]},{i,1,bc}];   (* core clouds *)
twc=Table[{wxc[[i]],wyc[[i]],wzc[[i]]},{i,1,cw}];  (* Bond cöouds between cores *)
twh=Table[{wxh[[i]],wyh[[i]],wzh[[i]]},{i,1,bh}]; (* H-bonding clouds *) 
ttlo=Table[tlo[[i]],{i,1,0}];
ttlu=Table[tlu[[i]],{i,1,0}];
ttpln=Table[tpln[[i]],{i,1,2}];
ttpyrn=Table[tpyrn[[i]],{i,1,0}];
tw=Join[tc,twc,twh,tpo,tpu,ttlo,ttlu,ttpln,ttpyrn];
bt=Length[tw]
MatrixForm[tw]
(* coordinates of clouds *)

(* cloud-cloud distances *)
dw=Table[Norm[tw[[i]]-tw[[j]]],{i,1,bt},{j,1,bt}];
(*MatrixForm[dw]*)
Length[dw]

(* nucleus-nucleus distances *)
(*MatrixForm[dc] *)

tv1=Table[t[[i]],{i,1,bc}];
tv2=Table[{0,0,0},{i,1,cw}];
tv3= Table[t[[i]],{i,bc+1,n}];
tv4 =Table[{0,0,0},{i,1,nj+4}]; 
tv5 =Table[{0,0,0},{i,1,nj+4}]; 
tv6 =Table[{0,0,0},{i,1,2}]; 
tv  = Join[tv1,tv2,tv3,tv4,tv5,tv6];
MatrixForm[tv]
Length[tv]

ow=Join[Table[-2.0,{i,1,bc+nb}],Table[-0.5,{i,1,2*nj}],Table[-1.0,{i,1,2}],Table[-0.5,{i,1,2}],Table[-1.0,{i,1,2}],Table[-0.5,{i,1,2}],Table[-2.0,{i,1,2}]]
lw=Length[ow]
cnv=Join[Table[cn[[i]],{i,1,bc}],Table[0.0,{i,1,cw}],Table[cn[[i]],{i,bc+1,n}],Table[0.0,{i,1,2*(nj+4)}],Table[0.0,{i,1,2}]]
lc=Length[cnv]

echarg=Sum[ow[[i]],{i,1,lw}]
pcharg=Sum[cnv[[i]],{i,1,lc}]

(* nucleus-cloud distances *)
dcw=Table[sq=Norm[tw[[i]]-tv[[j]]];If[(sq> 0.1 && i≠j),1/sq,0],{i,1,bt},{j,1,bt}];
Length[dcw]
(*MatrixForm[dcw]*)

Vee=0.0; Vnn=0.0;

(* all clouds repulsion *)
For[i=1,i<bt,i++,
For[j=i+1,j≤bt,j++,
Vee=Vee+ow[[i]]*ow[[j]]/dw[[i,j]]]]
Vee

(* half cloud with other common halfcloud: subtract WW *)
Vee=Vee-(nj+2)*0.25/(rpo+rpi); (* nj C + 2 N *)
Vee

sc=0.3767;   (* core clouds *)
For[i=1 ,i≤bc,i++,Vee=Vee+3*sc/u2[[i]]]
sw=0.3767;  (* bonding clouds *)
For[i=1 ,i≤nb,i++,Vee=Vee+3*sw/a[[i,3]]]
For[i=1 ,i≤2,i++,Vee=Vee+3*sw/rln]
Vee

(* all nuclei with all clouds, except i = j *)
Vne=cnv.(ow.dcw)

(* core nuclei in their cloud centers *)

For[i=1,i≤bc,i++,Vne=Vne-3*cn[[i]]/u2[[i]]]
Vne

(* protons in their bonding cloud, distance u2[[a[[i,1]]]] to cloud center *)
For[i=cw+1,i≤nb,i++,Vne=Vne-(3-(u2[[a[[i,1]]]]/a[[i,3]])^2)/a[[i,3]]]
Vne

(* nucleus-nucleus *)
For[i=1,i<n,i++,
For[j=i+1,j≤n,j++,Vnn=Vnn+cn[[i]]*cn[[j]]/dc[[i,j]]]]
Vnn

ratio=-(Vne+2*Vnn)/(Vee-Vnn)

ratioB3=-(-6000.651246+2*1852.5179838)/(2179.0522804-1852.5179838)

Vee
Vnn
Vne
Tpi   =1.67*(nj+2)*0.5*1.125*(1/rpo^2+1/rpi^2) +1.67*2*1.125*(2/rln^2)(* pi kin e added *)
Tln   =1.67*2*2.25*(1/rln^2) (* lp kin e of 2 N added *)
Vtot=Vne+Vee+Vnn
Ttot=Ttot+Tpi+Tln
Vir   =-Vtot/Ttot
Etot =Ttot+Vtot