  We present a model aimed to reproduce the observed spectral energy
distribution (SED) as well as the ammonia line emission of the G31.41+0.31 hot
core. The core is modeled as an infalling envelope onto a massive star that is
undergoing an intense accretion phase. We assume an envelope with a density and
velocity structure resulting from the dynamical collapse of a singular
logatropic sphere. The stellar and envelope physical properties are determined
by fitting the SED. From these physical conditions, the ammonia line emission
is calculated and compared with subarcsecond resolution VLA data of the (4,4)
transition. The only free parameter in this line fitting is the ammonia
abundance. The observed properties of the NH3(4,4) lines and their spatial
distribution can be well reproduced provided it is taken into account the steep
increase of the abundance in the hotter (> 100 K), inner regions of the core
produced by the sublimation of icy mantles where ammonia molecules are trapped.
The model predictions for the (2,2), (4,4), and (5,5) transitions are also in
reasonably agreement with the single-dish spectra available in the literature.
The best fit is obtained for a model with a star of 25 Msun, a mass accretion
rate of 0.003 Msun/yr, and a total luminosity of 200,000 Lsun. The gas-phase
ammonia abundance ranges from 2 \times 10^{-8} in the outer region to 3 \times
10^{-6} in the inner region. To our knowledge, this is the first time that the
dust and molecular line data of a hot molecular core, including subarcsecond
resolution data that spatially resolve the structure of the core, have been
simultaneously explained by a physically self-consistent model. This modeling
shows that massive protostars are able to excite high excitation ammonia
transitions up to the outer edge (30,000 AU) of the large scale envelope.
