A chemical model for the interstellar medium in galaxies