  We present HOMERUN (Highly Optimized Multi-cloud Emission-line Ratios Using
photo-ionizatioN), a new approach to modelling emission lines from photoionized
gas that can simultaneously reproduce all observed line intensities from a wide
range of ionization levels and with high accuracy. Our approach is based on the
weighted combination of multiple single-cloud photoionization models and,
contrary to previous works, the novelty of our approach consists in using the
weights as free parameters of the fit and constraining them with the observed
data. One of the main applications of HOMERUN is the accurate determination of
gas-phase metallicities and we show that a critical point is to allow for a
variation of the N/O and S/O abundance ratios which can significantly improve
the quality of the fit and the accuracy of the results. Moreover, our approach
provides a major improvement compared to the single-cloud, constant-pressure
models commonly used in the literature. By using high-quality literature
spectra of H ii regions where 10 to 20 emission lines (including several
auroral lines) are detected with high signal-to-noise ratio, we show that all
lines are reproduced by the model with an accuracy better than 10%. In
particular, the model is able to simultaneously reproduce [O i]6300, 6363, [O
ii]3726, 3729, [O iii]4959, 5007, [S ii]6717, 6731, and [S iii]9069, 9532
emission lines which, to our knowledge, is an unprecedented result. Finally, we
show that the gas metallicities estimated with our models for HII regions in
the Milky Way are in agreement with the stellar metallicities than the
estimates based on the Te-method. Overall, our method provides a new accurate
tool to estimate the metallicity and the physical conditions of the ionized
gas. It can be applied to many different science cases from HII regions to AGN
and wherever there are emission lines from photoionized gas.
