The production of ATP is defined by chemiosmotic theory.
Each thylakoid in the grana is an enclosed chamber in which protons (H+) are pumped from the stroma using proton pumps (protein carriers) located in the thylakoid membranes. The energy for this process comes from the photolysis of water.
Photolysis also produces protons, further increasing their concentration inside the thylakoid space.
Due to the high concentration of protons in the thylakoid space and the low concentration of protons in the stroma, protons cross the thylakoid membranes through ATPsynthase channel proteins.
As protons pass through the ATPsynthase channel proteins, the structure of the enzyme is altered, allowing ADP + Pi to be catalysed to form ATP.