If I am long a future and opt to take physical delivery, do I need to pay only the difference between the futures price and total margin posted? E.g. If I buy a long contract worth 50000, and by expiry I have posted 2000 in initial margin and an additional 3000 in variation margin, do I need to pay only 45000 in order to take physical delivery?
The first thing to note here is that initial margin and variation margin are not accounting items. In other words, your cash account with your broker has not been debited with these margin amounts. Rather, your broker will segregate (within your account) any required margin moneys so that these amounts cannot be used to fund other trading or be withdrawn from the account. At the time of the expiry of the contract these amounts are released from segregation. When taking delivery, the only debits that will have been posted in your cash account will be any commissions charged by your broker. (Futures commissions are normally paid on settlement.)
An odd thing about the example you are giving is that you are treating both the initial margin and the variation margin as being netted off the contract value. This implies that you are showing a loss (negative variation) and therefore begs the question as to why you would wish to take delivery by paying a higher price than is available in the cash market. Regardless, let's ignore this peculiarity.
Assuming your agreement with your broker allows you to exercise your right to take delivery, your broker will then facilitate your delivery. As noted above, your account will not have be debited/credited with any margin requirements related to your previously open position but these margin amounts will now be released from segregation. You will be required to pay the contracted amount (50,000), as well as a delivery fee, insurance, and warehousing fees. You will be required to continue to pay insurance and warehousing fees so long as your holding of the underlying commodity is held in the exchanges designated warehouse. If you wish to take delivery yourself by having the commodity removed from the warehouse and delivered to you personally, then you will need to arrange this delivery yourself. Warehouse/delivery points obviously vary according the contract being exercised. For example, the NYMEX Crude Oil contract has a single delivery point in Cushing Oklahoma, while the LME metal contracts have warehouses dotted around the world.