def _swap_pars(pars, a, b):
    """
    Swap polydispersity and magnetism when swapping parameters.

    Assume the parameters are of the same basic type (volume, sld, or other),
    so that if, for example, radius_pd is in pars but radius_bell_pd is not,
    then after the swap radius_bell_pd will be the old radius_pd and radius_pd
    will be removed.
    """
    for ext in ('', '_pd', '_pd_n', '_pd_nsigma', '_pd_type', '_M0',
        '_mphi', '_mtheta'):
        ax, bx = a + ext, b + ext
        if ax in pars and bx in pars:
            pars[ax], pars[bx] = pars[bx], pars[ax]
        elif ax in pars:
            pars[bx] = pars[ax]
            del pars[ax]
        elif bx in pars:
            pars[ax] = pars[bx]
            del pars[bx]
