Deductions & credits

You CANNOT spend down the gains by using the proceeds on the new home ... that is NOT allowed.