subroutine ps_destroy(ps)
!! Cleans the ps object
type(ps_t), intent(inout) :: ps
integer :: i
call ps_clean_annotation(ps%annotation)
call destroy_provenance(ps%provenance)
call ps_clean_annotation(ps%header%annotation)
call ps_clean_annotation(ps%config_val%annotation)
call ps_clean_annotation(ps%config_core%annotation)
call destroy_xc(ps%xc_info)
!
! Note that freshly declared objects must have
! npots = 0 and npswfs = 0 !
!
call destroy_semilocal(ps%semilocal)
call destroy_nonlocal(ps%nonlocal)
!
call destroy_local(ps%local)
!
call destroy_wavefunctions(ps%wavefunctions)
!
call destroy_radfunc(ps%valence_charge%rho_val)
call ps_clean_annotation(ps%valence_charge%annotation)
!
call destroy_radfunc(ps%core_charge%rho_core)
call ps_clean_annotation(ps%core_charge%annotation)
call destroy_radfunc(ps%valence_kinetic_energy_density%kin_edens_val)
call ps_clean_annotation(ps%valence_kinetic_energy_density%annotation)
!
call destroy_radfunc(ps%core_kinetic_energy_density%kin_edens_core)
call ps_clean_annotation(ps%core_kinetic_energy_density%annotation)
!
call delete(ps%global_grid)
end subroutine ps_destroy