Propagation of flare protons in the solar atmosphere