(* Kimball model and energy derived from Wolfram source, ES 21 March 2013 *) 
Clear[tw,n2,n,nb,bc,bh,u,u1,u2,Vee,Vne,Vnn];

t1=1.889726*{{-0.702,3.336,0.616},{0.718,3.537,-1.821},{1.392,3.114,-0.610},{0.734,3.330,0.616},{1.431,4.076,-2.949},{2.552,2.264,-0.610},{1.528,3.270,1.828},{1.275,4.127,2.955},{0.023,4.715,3.329},{-1.237,4.137,2.956},{-1.496,3.282,1.828},{3.157,1.748,-1.822},{2.788,3.803,-3.323},{3.456,2.591,-2.950},{-3.388,0.362,0.616},{-3.138,1.776,-1.821},{-2.528,2.287,-0.609},{-2.938,1.727,0.616},{-3.432,2.620,-2.949},{-1.363,3.126,-0.609},{-2.635,2.462,1.828},{-3.529,2.487,2.955},{-4.476,1.477,3.328},{-4.315,0.102,2.955},{-3.581,-0.409,1.828},{-0.686,3.542,-1.821},{-2.753,3.827,-3.322},{-1.394,4.088,-2.949},{-1.389,-3.110,0.616},{-2.656,-2.437,-1.821},{-2.952,-1.698,-0.609},{-2.547,-2.261,0.616},{-3.551,-2.454,-2.948},{-3.391,-0.330,-0.609},{-3.154,-1.745,1.828},{-3.454,-2.588,2.955},{-2.786,-3.800,3.328},{-1.429,-4.073,2.955},{-0.715,-3.533,1.828},{-3.578,0.442,-1.821},{-4.488,-1.436,-3.321},{-4.316,-0.063,-2.948},{2.532,-2.283,0.615},{1.499,-3.280,-1.821},{0.706,-3.334,-0.609},{1.366,-3.123,0.616},{1.239,-4.137,-2.948},{-0.731,-3.328,-0.609},{0.688,-3.539,1.828},{1.396,-4.085,2.956},{2.756,-3.824,3.329},{3.435,-2.618,2.955},{3.142,-1.773,1.827},{-1.525,-3.266,-1.821},{-0.020,-4.714,-3.321},{-1.272,-4.125,-2.948},{2.957,1.702,0.615},{3.584,0.411,-1.822},{3.391,-0.360,-0.610},{3.395,0.333,0.615},{4.317,-0.100,-2.950},{2.942,-1.724,-0.610},{3.581,-0.440,1.827},{4.320,0.065,2.955},{4.492,1.438,3.328},{3.554,2.456,2.955},{2.659,2.439,1.827},{2.638,-2.460,-1.821},{4.477,-1.476,-3.323},{3.531,-2.486,-2.950},{0.732,4.969,-3.777},{2.368,4.430,3.783},{0.026,5.767,4.262},{-2.326,4.449,3.784},{3.409,4.651,-4.257},{4.517,2.193,-3.779},{-4.497,2.233,-3.776},{-3.479,3.619,3.784},{-5.476,1.806,4.259},{-4.950,-0.838,3.782},{-3.369,4.681,-4.254},{-0.689,4.975,-3.777},{-3.512,-3.587,-3.775},{-4.517,-2.191,3.782},{-3.408,-4.650,4.259},{-0.731,-4.966,3.783},{-5.491,-1.757,-4.252},{-4.942,0.883,-3.776},{2.328,-4.449,-3.776},{0.690,-4.973,3.783},{3.370,-4.679,4.261},{4.500,-2.230,3.783},{-0.024,-5.766,-4.253},{-2.365,-4.428,-3.775},{4.950,0.839,-3.779},{4.945,-0.881,3.783},{5.494,1.759,4.261},{3.514,3.589,3.783},{5.476,-1.806,-4.257},{3.481,-3.618,-3.777},{6.073,0.491,-4.600},{5.229,3.128,-4.600},{1.410,5.929,-4.598},{-1.359,5.941,-4.597},{-5.202,3.174,-4.595},{-6.069,0.543,-4.594},{-4.625,-3.967,-4.594},{-2.392,-5.604,-4.595},{2.344,-5.625,-4.596},{4.591,-4.007,-4.597},{1.360,-5.940,4.602},{-1.410,-5.927,4.601},{-5.230,-3.128,4.600},{-6.074,-0.490,4.600},{-4.590,4.007,4.602},{-2.342,5.625,4.604},{2.394,5.606,4.603},{4.628,3.968,4.602},{6.072,-0.542,4.602},{5.204,-3.173,4.602},{6.990,1.492,-5.048},{6.408,-0.844,-4.749},{4.732,-5.358,-5.044},{5.654,-3.133,-4.748},{7.717,-1.238,-5.178},{6.940,-3.596,-5.176},{3.580,-6.188,-5.044},{1.177,-6.357,-4.745},{-3.633,-6.156,-5.042},{1.208,-7.722,-5.173},{-1.275,-7.712,-5.172},{-5.681,-3.084,-4.744},{-4.779,-5.315,-5.041},{-6.416,-0.788,-4.744},{-6.978,1.553,-5.042},{-6.971,-3.535,-5.171},{-7.728,-1.171,-5.171},{-4.688,4.451,-4.746},{-6.533,2.902,-5.042},{-2.733,5.859,-4.747},{-0.679,7.116,-5.046},{-5.517,5.538,-5.174},{-3.502,6.988,-5.175},{0.741,7.110,-5.046},{2.784,5.835,-4.749},{4.726,4.410,-4.749},{6.557,2.845,-5.048},{3.561,6.958,-5.178},{5.564,5.491,-5.178},{-4.727,-4.410,4.749},{-6.559,-2.846,5.045},{-2.784,-5.834,4.750},{-0.741,-7.110,5.047},{-5.565,-5.490,5.175},{-3.562,-6.958,5.176},{0.680,-7.116,5.047},{2.734,-5.858,4.751},{4.690,-4.450,4.752},{6.535,-2.902,5.049},{3.502,-6.988,5.177},{5.518,-5.539,5.178},{6.980,-1.552,5.049},{6.418,0.790,4.752},{5.684,3.084,4.752},{4.781,5.318,5.049},{7.731,1.172,5.179},{6.974,3.536,5.179},{3.635,6.158,5.049},{1.234,6.347,4.753},{-1.176,6.357,4.753},{-3.580,6.188,5.049},{1.276,7.713,5.180},{-1.207,7.724,5.179},{-5.654,3.134,4.751},{-4.732,5.358,5.049},{-6.409,0.845,4.750},{-6.992,-1.493,5.046},{-6.942,3.596,5.177},{-7.719,1.238,5.176},{-1.481,-8.293,5.191},{1.409,-8.306,5.192},{7.432,-3.972,5.194},{8.337,-1.227,5.194},{6.075,5.841,5.194},{3.744,7.550,5.195},{-3.677,7.580,5.194},{-6.022,5.892,5.193},{-8.346,-1.155,5.191},{-7.465,-3.906,5.190},{-3.742,-7.547,-5.188},{-6.072,-5.838,-5.188},{-8.335,1.227,-5.188},{-7.431,3.971,-5.189},{-1.409,8.306,-5.192},{1.480,8.294,-5.193},{7.463,3.907,-5.194},{8.344,1.154,-5.194},{6.021,-5.892,-5.191},{3.677,-7.580,-5.190},{0.750,9.518,-4.975},{2.921,8.214,-5.197},{4.993,6.810,-5.215},{6.954,5.257,-5.197},{8.851,3.578,-4.976},{3.719,9.359,-4.863},{5.813,7.929,-5.005},{7.806,6.362,-4.864},{9.282,2.227,-4.976},{8.713,-0.241,-5.197},{8.020,-2.645,-5.214},{7.148,-4.990,-5.195},{6.137,-7.313,-4.974},{10.049,-0.646,-4.863},{9.336,-3.079,-5.004},{8.463,-5.459,-4.862},{4.987,-8.142,-4.973},{2.464,-8.363,-5.193},{-0.037,-8.445,-5.210},{-2.536,-8.340,-5.192},{-5.058,-8.097,-4.971},{2.491,-9.758,-4.861},{-0.043,-9.831,-5.001},{-2.576,-9.736,-4.859},{-7.192,-4.927,-5.191},{-6.201,-7.258,-4.970},{-8.043,-2.575,-5.208},{-8.716,-0.166,-5.191},{-9.265,2.308,-4.971},{-8.511,-5.385,-4.859},{-9.363,-2.997,-5.000},{-10.056,-0.559,-4.859},{-6.910,5.317,-5.193},{-8.820,3.654,-4.972},{-4.934,6.854,-5.212},{-2.851,8.238,-5.195},{-0.668,9.524,-4.975},{-7.752,6.430,-4.860},{-5.745,7.978,-5.002},{-3.639,9.390,-4.862},{-6.955,-5.257,5.193},{-8.852,-3.578,4.971},{-4.994,-6.811,5.211},{-2.922,-8.214,5.194},{-0.750,-9.517,4.972},{-7.807,-6.363,4.859},{-5.813,-7.928,5.001},{-3.720,-9.359,4.859},{0.668,-9.524,4.972},{2.852,-8.239,5.195},{4.935,-6.853,5.214},{6.910,-5.317,5.196},{8.821,-3.655,4.974},{3.639,-9.390,4.860},{5.745,-7.979,5.002},{7.752,-6.431,4.861},{9.266,-2.308,4.974},{8.719,0.165,5.197},{8.045,2.576,5.215},{7.194,4.929,5.197},{6.203,7.261,4.975},{10.057,0.559,4.861},{9.366,2.998,5.003},{8.512,5.385,4.862},{5.059,8.099,4.975},{2.538,8.343,5.197},{0.037,8.446,5.215},{-2.464,8.363,5.197},{-4.987,8.141,4.974},{2.577,9.737,4.862},{0.044,9.831,5.003},{-2.491,9.758,4.861},{-7.149,4.990,5.196},{-6.138,7.313,4.974},{-8.021,2.645,5.213},{-8.715,0.240,5.194},{-9.284,-2.228,4.971},{-8.464,5.458,4.861},{-9.337,3.079,5.002},{-10.051,0.646,4.860},{-1.521,-10.586,4.377},{1.429,-10.599,4.377},{9.600,-4.718,4.378},{10.524,-1.917,4.378},{7.455,7.672,4.378},{5.076,9.416,4.378},{-4.993,9.459,4.378},{-7.386,7.735,4.378},{-10.540,-1.825,4.377},{-9.640,-4.635,4.377},{-1.430,10.600,-4.380},{1.521,10.588,-4.381},{9.639,4.635,-4.381},{10.538,1.825,-4.381},{7.387,-7.736,-4.380},{4.992,-9.461,-4.379},{-5.075,-9.416,-4.377},{-7.454,-7.671,-4.377},{-10.524,1.916,-4.378},{-9.600,4.718,-4.378},{-1.232,-6.345,-4.744},{9.110,5.989,-4.320},{10.766,4.218,-3.624},{7.223,7.656,-4.737},{5.128,9.193,-4.737},{2.972,10.491,-4.320},{0.784,11.538,-3.623},{-2.881,10.516,-4.319},{-0.684,11.544,-3.623},{-5.050,9.236,-4.735},{-7.158,7.718,-4.734},{-9.059,6.069,-4.317},{-10.732,4.311,-3.621},{-10.892,0.510,-4.317},{-11.192,2.916,-3.621},{-10.345,-1.948,-4.733},{-9.553,-4.422,-4.732},{-8.571,-6.740,-4.316},{-7.417,-8.873,-3.621},{-6.232,-9.742,-3.621},{-3.851,-10.202,-4.316},{-1.345,-10.441,-4.733},{1.254,-10.452,-4.734},{3.762,-10.234,-4.318},{6.147,-9.797,-3.622},{7.339,-8.938,-3.623},{8.511,-6.814,-4.319},{9.513,-4.506,-4.736},{10.327,-2.038,-4.737},{10.895,0.414,-4.320},{11.214,2.819,-3.624},{7.417,8.873,3.620},{8.572,6.741,4.317},{9.554,4.423,4.734},{10.347,1.948,4.734},{10.893,-0.509,4.316},{11.191,-2.917,3.619},{10.730,-4.311,3.619},{9.059,-6.069,4.316},{7.158,-7.718,4.734},{5.049,-9.236,4.733},{2.881,-10.515,4.316},{0.684,-11.543,3.619},{-0.784,-11.537,3.619},{-2.972,-10.490,4.316},{-5.129,-9.192,4.733},{-7.224,-7.656,4.732},{-9.111,-5.989,4.315},{-10.768,-4.219,3.619},{-10.896,-0.415,4.316},{-11.216,-2.819,3.619},{-10.328,2.037,4.733},{-9.515,4.505,4.734},{-8.512,6.813,4.317},{-7.338,8.936,3.620},{-3.761,10.233,4.317},{-6.147,9.794,3.620},{-1.253,10.451,4.734},{1.345,10.441,4.735},{3.851,10.202,4.317},{6.232,9.742,3.620},{3.687,11.355,-3.463},{5.870,10.195,-4.019},{7.956,8.665,-4.019},{1.525,12.319,-2.664},{9.719,6.931,-3.464},{11.289,5.159,-2.665},{10.743,6.462,-2.555},{9.137,8.259,-3.334},{7.277,9.925,-3.737},{5.128,11.199,-3.334},{2.932,12.190,-2.554},{0.769,13.043,-1.645},{12.206,4.656,-1.647},{-9.660,7.016,-3.461},{-7.883,8.733,-4.017},{-5.782,10.245,-4.017},{-11.246,5.257,-2.662},{-3.590,11.386,-3.462},{-1.419,12.332,-2.663},{-2.827,12.215,-2.554},{-5.032,11.243,-3.332},{-7.191,9.988,-3.735},{-9.067,8.338,-3.332},{-10.689,6.555,-2.553},{-12.168,4.762,-1.644},{-0.657,13.049,-1.645},{-9.659,-7.020,-3.461},{-10.742,-4.797,-4.016},{-11.532,-2.333,-4.016},{-8.475,-9.071,-2.662},{-11.939,0.105,-3.461},{-12.168,2.462,-2.662},{-12.493,1.087,-2.553},{-12.249,-1.311,-3.332},{-11.722,-3.753,-3.734},{-10.733,-6.046,-3.332},{-9.538,-8.139,-2.553},{-8.290,-10.101,-1.644},{-12.615,3.409,-1.644},{3.691,-11.355,-3.462},{1.243,-11.699,-4.017},{-1.345,-11.688,-4.017},{6.008,-10.864,-2.663},{-3.789,-11.322,-3.461},{-6.102,-10.811,-2.662},{-4.895,-11.544,-2.553},{-2.539,-12.054,-3.332},{-0.054,-12.309,-3.735},{2.433,-12.076,-3.332},{4.793,-11.587,-2.554},{7.044,-11.005,-1.645},{-7.140,-10.944,-1.644},{11.937,0.001,-3.464},{11.509,-2.433,-4.019},{10.698,-4.891,-4.019},{12.187,2.356,-2.665},{9.596,-7.103,-3.463},{8.395,-9.144,-2.663},{9.466,-8.222,-2.554},{10.679,-6.139,-3.334},{11.688,-3.854,-3.737},{12.235,-1.417,-3.334},{12.498,0.978,-2.555},{12.641,3.298,-1.647},{8.200,-10.172,-1.645},{-9.720,-6.932,3.459},{-7.957,-8.665,4.015},{-5.870,-10.195,4.015},{-11.291,-5.160,2.660},{-3.687,-11.354,3.459},{-1.525,-12.318,2.660},{-2.932,-12.189,2.551},{-5.129,-11.199,3.330},{-7.277,-9.925,3.733},{-9.138,-8.260,3.330},{-10.744,-6.463,2.551},{-12.208,-4.657,1.642},{-0.770,-13.042,1.642},{-9.596,7.101,3.460},{-10.699,4.890,4.016},{-11.510,2.432,4.015},{-8.395,9.142,2.660},{-11.939,-0.002,3.459},{-12.187,-2.357,2.660},{-12.500,-0.978,2.551},{-12.236,1.416,3.330},{-11.689,3.854,3.733},{-10.679,6.138,3.330},{-9.466,8.220,2.551},{-8.201,10.170,1.642},{-12.643,-3.300,1.642},{3.789,11.320,3.459},{1.345,11.687,4.016},{-1.242,11.698,4.016},{6.101,10.809,2.660},{-3.690,11.352,3.460},{-6.007,10.861,2.660},{-4.792,11.584,2.551},{-2.433,12.073,3.330},{0.054,12.307,3.733},{2.538,12.053,3.330},{4.893,11.542,2.550},{7.138,10.941,1.641},{-7.044,11.002,1.642},{11.937,-0.105,3.459},{11.531,2.333,4.015},{10.742,4.797,4.015},{12.165,-2.462,2.659},{9.658,7.018,3.459},{8.474,9.070,2.659},{9.536,8.138,2.550},{10.731,6.046,3.329},{11.722,3.752,3.732},{12.247,1.311,3.329},{12.490,-1.087,2.550},{12.611,-3.408,1.641},{8.288,10.098,1.641},{3.589,-11.385,3.459},{5.782,-10.245,4.015},{7.882,-8.733,4.015},{1.418,-12.331,2.660},{9.659,-7.015,3.459},{11.244,-5.256,2.659},{10.686,-6.555,2.550},{9.066,-8.338,3.330},{7.190,-9.988,3.733},{5.031,-11.242,3.330},{2.827,-12.214,2.551},{0.656,-13.048,1.642},{12.165,-4.762,1.641},{5.765,11.865,-2.222},{7.887,10.757,-2.800},{9.581,9.066,-2.223},{3.610,12.621,-1.333},{10.950,7.238,-1.334},{12.397,5.462,-0.476},{11.614,6.653,-0.231},{10.270,8.452,-1.104},{8.992,10.291,-2.000},{7.110,11.672,-2.000},{4.972,12.337,-1.103},{2.853,13.078,-0.230},{13.036,4.916,0.639},{1.481,13.466,-0.475},{0.768,13.911,0.641},{-9.503,9.149,-2.221},{-7.795,10.825,-2.798},{-5.663,11.914,-2.221},{-10.889,7.333,-1.332},{-3.500,12.652,-1.333},{-1.364,13.478,-0.474},{-2.739,13.102,-0.230},{-4.866,12.379,-1.102},{-7.009,11.732,-1.998},{-8.904,10.369,-1.998},{-10.198,8.541,-1.102},{-11.558,6.755,-0.229},{-0.647,13.918,0.641},{-12.351,5.570,-0.474},{-12.994,5.030,0.642},{-11.640,-6.211,-2.221},{-12.705,-4.067,-2.798},{-13.083,-1.703,-2.221},{-10.341,-8.090,-1.332},{-13.116,0.581,-1.332},{-13.242,2.868,-0.474},{-13.310,1.444,-0.229},{-13.279,-0.801,-1.102},{-13.326,-3.041,-1.998},{-12.614,-5.264,-1.998},{-11.276,-7.059,-1.102},{-9.996,-8.905,-0.229},{-13.439,3.685,0.642},{-9.115,-10.025,-0.474},{-8.799,-10.805,0.642},{2.309,-12.988,-2.221},{-0.058,-13.340,-2.798},{-2.422,-12.968,-2.221},{4.499,-12.334,-1.333},{-4.606,-12.294,-1.332},{-6.820,-11.708,-0.474},{-5.486,-12.212,-0.229},{-3.341,-12.877,-1.102},{-1.226,-13.613,-1.998},{1.108,-13.623,-1.998},{3.229,-12.905,-1.102},{5.379,-12.258,-0.230},{-7.658,-11.642,0.642},{6.718,-11.766,-0.475},{7.556,-11.706,0.641},{13.064,-1.817,-2.223},{12.667,-4.177,-2.800},{11.583,-6.311,-2.222},{13.118,0.467,-1.334},{10.268,-8.178,-1.333},{9.026,-10.103,-0.475},{9.918,-8.990,-0.230},{11.212,-7.156,-1.103},{12.566,-5.373,-2.000},{13.297,-3.156,-2.000},{13.269,-0.917,-1.104},{13.319,1.328,-0.231},{8.704,-10.880,0.641},{13.264,2.752,-0.476},{13.467,3.567,0.639},{-9.582,-9.068,2.219},{-7.888,-10.757,2.797},{-5.765,-11.864,2.219},{-10.952,-7.238,1.330},{-3.610,-12.621,1.330},{-1.481,-13.467,0.472},{-2.854,-13.079,0.228},{-4.973,-12.337,1.100},{-7.111,-11.672,1.997},{-8.993,-10.292,1.997},{-10.271,-8.453,1.100},{-11.616,-6.655,0.228},{-0.769,-13.913,-0.643},{-12.398,-5.464,0.472},{-13.038,-4.918,-0.643},{-11.584,6.310,2.219},{-12.668,4.177,2.797},{-13.066,1.816,2.219},{-10.267,8.177,1.330},{-13.120,-0.467,1.330},{-13.266,-2.753,0.472},{-13.322,-1.329,0.227},{-13.271,0.916,1.100},{-13.298,3.155,1.997},{-12.567,5.373,1.997},{-11.213,7.154,1.100},{-9.918,8.989,0.228},{-13.470,-3.569,-0.643},{-9.026,10.102,0.472},{-8.705,10.879,-0.643},{2.422,12.966,2.218},{0.058,13.338,2.796},{-2.309,12.985,2.219},{4.605,12.291,1.329},{-4.498,12.331,1.330},{-6.717,11.764,0.472},{-5.380,12.257,0.227},{-3.228,12.902,1.100},{-1.108,13.621,1.996},{1.226,13.610,1.996},{3.340,12.873,1.099},{5.485,12.209,0.226},{-7.556,11.706,-0.643},{6.819,11.705,0.471},{7.656,11.640,-0.645},{13.079,1.703,2.217},{12.703,4.067,2.795},{11.637,6.209,2.217},{13.112,-0.581,1.328},{10.337,8.088,1.328},{9.113,10.023,0.470},{9.994,8.902,0.226},{11.273,7.057,1.098},{12.612,5.263,1.994},{13.324,3.039,1.994},{13.276,0.801,1.098},{13.307,-1.444,0.226},{8.798,10.802,-0.645},{13.239,-2.868,0.470},{13.435,-3.685,-0.645},{5.661,-11.913,2.219},{7.793,-10.824,2.796},{9.501,-9.149,2.218},{3.500,-12.652,1.330},{10.887,-7.332,1.329},{12.349,-5.570,0.471},{11.556,-6.755,0.226},{10.196,-8.541,1.099},{8.903,-10.369,1.996},{7.009,-11.733,1.996},{4.865,-12.380,1.100},{2.740,-13.103,0.227},{12.992,-5.030,-0.645},{1.365,-13.479,0.472},{0.647,-13.919,-0.643}};
MatrixForm[t1]

u=Table["C",{640}];

n=Length[t1]

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.2557,If[us[[i,1]]=="H",0.6,If[us[[i,1]]=="N",0.22522,If[us[[i,1]]=="O",0.178,If[us[[i,1]]=="Cl",0.5]]]]],{i,1,n}]

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

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

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

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]]<3.0||(u[[i]]=="Cl" && j==10 && i== 17)),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.2547]]
For [i=1, i≤nc,i++,If[sec[[i]]≠0,u2[[sec[[i]]]]=0.255]]
For [i=1, i≤nc,i++,If[ter[[i]]≠0,u2[[ter[[i]]]]=0.2557]]
For [i=1, i≤nc,i++,If[qua[[i]]≠0,u2[[qua[[i]]]]=0.2577]]

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

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

Eij=Table[If[i≥j,Dij[[i,j]],0],{i,bc+1,n},{j,1,bc-1}];
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

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}];
tpu=Table[{0,0,0},{nj}];
P=3; c={0,0,0,0,0};

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];
nk=p;
nl=p;
nk[[1,3]]=rpo;
nl[[1,3]]=-rpi;
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[[k]]=nk[[1]];
tpu[[k]]=nl[[1]]),{k,nj}];

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[Cyan],Sphere[tpo[[i]],rpo]}],{i,1,nj}];
Plot8b=Table[Graphics3D[{Opacity[0.3],Lighter[Yellow],Sphere[tpu[[i]],rpi]}],{i,1,nj}];

Plot9= Table[Graphics3D[{If[(a[[i,3]]>0.98 && a[[i,3]]<1.05),({Lighter[Orange,0.5],Tube[{{x[[a[[i,1]]]],y[[a[[i,1]]]]+0.12,z[[a[[i,1]]]]},{x[[a[[i,2]]]],y[[a[[i,2]]]]+0.12,z[[a[[i,2]]]]}},0.06],Tube[{{x[[a[[i,1]]]],y[[a[[i,1]]]]-0.12,z[[a[[i,1]]]]},{x[[a[[i,2]]]],y[[a[[i,2]]]]-0.12,z[[a[[i,2]]]]}},0.06]}),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.06]]}],{i,1,nb}];

Show[Plot1o,(*Plot2,*)Plot7,(*Plot8,*)(*Plot8a,Plot8b,*)Plot9,{AspectRatio->Automatic,Boxed->False, (*Axes->Automatic,AxesLabel->{xl,yl,zl},*)SphericalRegion->True}]
Show[Plot1o,Plot2,Plot9,{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 *) 
tw=Join[tc,twc,twh,tpo,tpu];
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}]; 
tv5 =Table[{0,0,0},{i,1,nj}]; 
tv  = Join[tv1,tv2,tv3,tv4,tv5];
MatrixForm[tv]
Length[tv]

ow=Join[Table[-2.0,{i,1,bc+nb}],Table[-0.5,{i,1,2*nj}]]
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}]]

(* 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+1,j++,
Vee=Vee+ow[[i]]*ow[[j]]/dw[[i,j]]]]
Vee

(* half cloud with other common halfcloud: subtract WW *)
For [i=nb+bc+1,i<nb+bc+nj+1,i++,Vee=Vee-ow[[i]]*ow[[i+nj]]/(rpo+rpi)(*dw[[i,i+nj]]*)];
Vee

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

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

(* core nuclei in their cloud centers *)

For[i=1,i<bc+1,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+1,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+1,j++,Vnn=Vnn+cn[[i]]*cn[[j]]/dc[[i,j]]]]
Vnn

Vee
Vnn
Vne
Tpi = 2.296*nj*0.5*1.125*(1/rpo^2+1/rpi^2) (* pi kin e added *)
Vtot=Vne+Vee+Vnn
Ttot =Ttot+Tpi
Vir   =-Vtot/Ttot
Etot=Ttot+Vtot