A radiative transfer model to treat infrared molecular excitation in cometary atmospheres