This is an example: Attaching π clouds. For lone pairs it is done similarly, see the subroutines in other Mathematica programs, e.g. CoenzymeA.

Attach π clouds to the C atoms of the cyclopentadienyl ligands, perpendicular to the C5 planes of Ferrocene. Here is how:

In order to find the coordinates of the π clouds within the molecular coordinate system we use the following routine. We assume arbitrary orientation of the molecule and do not make use of planarity of the rings nor of any other symmetry element of the molecule (to render this routine general). Every C atom (in a nonlinear molecule) forms a triangle with two next neighbors. The coordinates are in the t array. We make a copy of every such triangle. The first statements in the routine below translate the target atom 2  into the origin x=y=z=0 by the 4x4 translation matrix Q, dragging the other atoms with it. p holds the 3x3 coordinates of the translated triangle. The next three 3x3 rotationmatrices move the other two atoms into the xy-plane without deformation of the triangle. The first rotation around the x axis puts one neighbor into the xy-plane. The second rotation around the z-axis moves this atom onto the x-axis. The third rotation is around the x axis again, which leaves the first two atoms untouched, but drops the remaining atom also into the xy-plane. Now, we know how to attach the two π clouds to the target atom 2: exactly in the z-direction above and below the xy-plane - equations πo[[2,3]]=+rpo, πi[[2,3]]=-rpi - with their radii rpo, rpi, thus determining their coordinates in the transformed triangle. The rest of the routine is easy: It transforms the coordinates of the π clouds (only!) into the molecular skeleton by reversing the three rotations and the translation we have done to the triangle. The translated triangle, a copy of the original, is discarded. Repeat this procedure nj times. At exit of this routine we have the coordinates of all π clouds in the arrays tpo, tpi, which later are added to the molecular coordinates of the σ clouds and used for plotting and computing interaction energies with other clouds and nuclei.- This routine is extremely fast!  

Created with the Wolfram Language