Simultaneous calculation of the equilibrium atomic structure and its electronic ground state using density-functional theory