Second-order coupled perturbed hartree—fock equations for closed-shell and open-shell self-consistent-field wavefunctions