Optimization of core–valence states of molecules