Statistical mechanics of weakly nonlinear optical multimode gases.