We combine molecular simulations and ab initio calculations to investigate the permeation and separation of CO2/N2 in polymers of intrinsic microporosity (PIMs) with different functional groups (cyano, trifluoromethyl, phenylsulfone, and carboxyl). A robust equilibration protocol is proposed to construct model membranes with predicted densities very close to experimental data. The fractional free volumes (FFVs) in PIM-1 (with cyano), TFMPS-PIM (with both trifluoromethyl and phenylsulfone), and CX-PIM (with carboxyl) are 45.2%, 42.1%, and 38.7%, respectively. Hydrogen bonding is observed to form among carboxyl groups and contributes to the lowest FFV in CX-PIM. From wide-angle X-ray diffractions, the estimated d-spacing distances agree well with available experimental results, and the chain-to-chain distance in CX-PIM is the shortest among the three membranes. Ab initio calculations reveal that the interaction energies between the functional groups and CO2 decrease as carboxyl > phenylsulfone > cyano > tri...