Total energy and stress of metal and semiconductor surfaces