Explain how chemiosmosis functions in the cell. Discuss the energy transfers and explain the role of ATP in this process.