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 hot 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 observed SED . From these physical conditions , the emerging ammonia line emission is calculated and compared with subarcsecond resolution VLA data of the ( 4,4 ) transition taken from the literature . The only free parameter in this line fitting is the ammonia abundance . The observed intensities of the main and satellite ammonia ( 4,4 ) lines and their spatial distribution can be well reproduced provided it is taken into account the steep increase of the gas-phase ammonia 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 , obtained with the same set of parameters , are also in reasonably agreement , given the observational uncertainties , with the single-dish spectra of the region available in the literature . The best fit is obtained for a model with a central star of \sim 25 ~ { } M _ { \odot } , a mass accretion rate of \sim 3 \times 10 ^ { -3 } ~ { } M _ { \odot } yr ^ { -1 } , and a total luminosity of \sim 2 \times 10 ^ { 5 } ~ { } L _ { \odot } . The outer radius of the envelope is 30,000 AU , where kinetic temperatures as high as \sim 40 K are reached . The gas-phase ammonia abundance ranges from \sim 2 \times 10 ^ { -8 } in the outer region to \sim 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 detailed , physically self-consistent model . This modeling shows that hot , massive protostars are able to excite high excitation ammonia transitions up to the outer edge ( \sim 30,000 AU ) of the large scale infalling envelopes .