  We present detailed thermal and gas-phase chemical models for the envelope of
the massive star-forming region AFGL 2591. Time- and space-dependent chemistry
are used to study the physical structure proposed by van der Tak et al. (1999;
2000), and the chemical evolution of this region. The model is compared with
observations for 29 species covering a wide range of conditions within the
source. Taking appropriate care when comparing models with both emission and
absorption measurements, we find that the majority of the chemical structure
can be well-explained. In particular, we find that the nitrogen and hydrocarbon
chemistry can be significantly affected by temperature, with the possibility of
high-temperature pathways to HCN. While we cannot determine the sulphur
reservoir, the observations can be explained by models with the majority of the
sulphur in CS in the cold gas, SO$_{2}$ in the warm gas, and atomic sulphur in
the warmest gas. The observed abundances of ions such as HCO$^+$ and N$_2$H$^+$
and the cold gas-phase production of HCN constrain the cosmic-ray ionization
rate to $\sim 5.6 \times 10^{-17}$ s$^{-1}$, to within a factor of three.
Finally, we find that the model and observations can simultaneously agree at a
reasonable level and often to within a factor of three for $7 \times 10^{3}
\leq t(\mathrm{yrs}) \leq 5 \times 10^{4}$, with a strong preference for $t
\sim 3 \times 10^{4}$ yrs since the collapse and formation of the central
luminosity source.
