Simulating the structures of crystals and their surfaces