Deductions & credits

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