Grain opacity and the bulk composition of extrasolar planets. II. An analytical model for the grain opacity in protoplanetary atmospheres