(* ::Package:: *) NCNtrans::usage = "NCNtrans sets the lone pair at the end of a -CN group in arbitrary orientations, see EthylCyanoacetate.nb as example: Input: Table t of the atomic coordinates, connection table connc of, from the end, N-C-X, where X is a ligand not on the NC- axis. The transformation makes the NC axis the x axis with N at the origin of the triangle NCX. The target N atom is at first position, cnlj is the number of such CN groups, rln the radius of the LP at the end of the NC axis. The table tlno contains the coordinates of the LP clouds on exit. There is no plot of these LP's." P=3; c={0,0,0,0,0}; k=1; Do[(c = connc[[k]]; (* Target 1 *) 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 = U.T; mk = p; mk[[1,1]] = p[[1,1]]+u2[[c[[1]]]]+rln; U = p; U1 = mk; T = RotationMatrix[-T3, {1, 0, 0}]; p = U.T; mk = U1.T; U = p; U1 = mk; T = RotationMatrix[-T2, {0, 0, 1}]; p = U.T; mk = U1.T; U = p; U1 = mk; T = RotationMatrix[-T1, {1, 0, 0}]; p = U.T; mk = U1.T; v = Table[Join[p[[i]], {1}], {i, 1, P}]; v1 = Table[Join[mk[[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; p = Table[Take[p[[i]], 3], {i, 1, P}]; mk = Table[Take[mk[[i]], 3], {i, 1, P}]; tlno[[k]] = mk[[1]]),{k, cnlj}];