  We present the use of the recently developed Square Gradient Minimization
(SGM) algorithm for excited state orbital optimization, to obtain spin-pure
Restricted Open-Shell Kohn-Sham (ROKS) energies for core excited states of
molecules. The SGM algorithm is robust against variational collapse, and offers
a reliable route to converging orbitals for target excited states at only 2-3
times the cost of ground state orbital optimization (per iteration). ROKS/SGM
with the modern SCAN/$\omega$B97X-V functionals is found to predict the K edge
of C,N,O and F to a root mean squared error of $\sim$0.3 eV. ROKS/SGM is
equally effective at predicting L edge spectra of third period elements,
provided a perturbative spin-orbit correction is employed. This high accuracy
can be contrasted with traditional TDDFT, which typically has greater than 10
eV error and requires translation of computed spectra to align with experiment.
ROKS is computationally affordable (having the same scaling as ground state
DFT, and a slightly larger prefactor) and can be applied to geometry
optimizations/ab-initio molecular dynamics of core excited states, as well as
condensed phase simulations. ROKS can also model doubly excited/ionized states
with one broken electron pair, which are beyond the ability of linear response
based methods.
