Evolution of the GaAs(001) surface structure during the transition from the As-rich (2×4) to the Ga-rich (4×2) reconstruction