How would I calculate the work function of a metal?

You can't just get it from the atomic properties, the electronic properties of a metal are dominated by "solid state"-type considerations, for instance, the fact that electrons live in a band structure rather than something more akin to the usual discrete levels that one learns about in QM 1.

Thankfully, Ashcroft and Mermin's classic book has a long discussion on the work function in chapter 18.

Their formula is $W=-\epsilon_F+W_s$, where $\epsilon_F$ is the Fermi energy, a quantity determined by the density of electrons and the properties of the crystal lattice of the metal; you can work out reasonable approximations to this for alkali metals by using the free electron approximation. $W_s$ is a quantity related to surface effects; for this term Ashcroft and Mermin give a model with a dipole moment per unit area of $P$, so that $W_s=-4\pi e P$.

I'm not sure whether you can really get "within a few percent" with such crude techniques, but it's certainly something that's calculable. In particular, getting a good approximation comes down to two things, 1) getting a handle on the band structure of the metal so that you can calculate $\epsilon_F$ accurately 2) having a good model for the surface of the metal.

There's a wrinkle here about how $\epsilon_F$ is defined. One can't just use the usual expression $\epsilon_F=\hbar^2k_F^2/2m$ as one needs to add in a term corresponding to the electrostatic energy of the ions, something like the Madelung constants.

Again, I recommend the book of Ashcroft and Mermin for this (and any other just-beyond-basic questions you might have about thinking about electrons in metals and semiconductors).

Just out of curiosity, I dug into the literature a little bit to see what researchers have done.

In 1971, Lang and Kohn were able to get work functions of simple metals to about 5% and noble metals to 15%. I think it would be possible to reproduce these calculations today quite easily.

A more recent paper (2005) by Da Silva, Stampfl, and Scheffler uses all-electron first principles calculations, as opposed to the more empirical fitted pseudopotential calculation that Lang and Kohn used. My impression from skimming the data is that they only get marginal agreement with experiment; in particular, I noticed that the experimental values seem to have quite a bit of variance in them, consistent with the fact that work function is strongly dependent on surface properties, which are hard to get consistent.

For example, for Aluminum along the 1 1 1 crystal plane, their calculations yield 4.21eV, compared to experimental values of 4.48, 4.24 and 4.33.

By comparison, Lang and Kohn's 1979 calculation gave 4.05 eV and they quoted an experimental value of 4.19 eV.

Apparently the last big review on calculating work functions of metals is this one by Hözl et al from 1979. I didn't read it though.