The engineered spin structures recently built and measured in scanning tunneling microscope experiments are calculated using density functional theory. By determining the precise local structure around the surface impurities, we find that the Mn atoms can form molecular structures with the binding surface, behaving like surface molecular magnets. The spin structures are confirmed to be antiferromagnetic, and the exchange couplings are calculated within 8% of the experimental values simply by collinear-spin generalized gradient approximation +U calculations. We can also explain why the exchange couplings significantly change with different impurity binding sites from the determined local structure. The bond polarity is studied by calculating the atomic charges with and without the Mn adatoms. In addition, we study a second adatom, Co. We study the surface Kondo effect of Co by calculating the surrounding local density of states and the on-site Coulomb Uand compare and contrast the behavior of Co and Mn. Finally, our calculations confirm that the Mn and Co spins of these structures are 5/2 and 3/2, respectively, as also measured indirectly by scanning tunneling microscope. © 2011 American Physical Society.