Yes. The profit is based on the difference between the purchase price and sales price, which in your case is the mortgage loan price. A mortgage would typically have nothing to do with profit on the sale.
There are other factors. You can add the cost of improvements (as long as they have not already been taken on Schedule E, settlement cost at purchase and closing costs at sale to the basis to reduce your gain. You will also have to recapture any depreciation taken.