The semipermeability of clay aggregates in mudstones, shales, and marine sediments gives rise to geological ultrafiltration of ions and water. This behavior has been numerically analyzed based on the theory of the electric double layer (EDL). The model of EDL is suited for describing ionic partitions in clay pore with a width of a few nanometers. However, the interlayer space of smectite might be hardly described by the EDL model. An explicit atomic-scale description is more appropriate for the interlayer space. Besides, clay swelling or collapse corresponding to a variation of environmental conditions, and its impact on partitions of water and ions between interlayers and environment, have not been taken into account numerically. With atomic-scale molecular dynamics simulations and thermodynamic integrations based on them, the coupling between montmorillonite swelling/collapse and partitions of water and cations under different aqueous activity conditions is systematically disclosed here. With the combination of the Horinek’s force field to describe cations and ClayFF force field for atoms in solid layers, consistent swelling/collapse of Na- and K-montmorillonite with experimental observations as a function of water activity is shown. The swelling/collapse is connected to the transition between monolayer and bilayer hydration states. Decomposition of the swelling/collapse free energy shows both energy and entropy contributions are important in determining the thermodynamically stable hydration state. Taking environmental water activity and Na+/K+ ionic activity ratio as variables, a picture of cationic partition in response to those variables is established. It shows, under all circumstances, K+ ions are enriched in montmorillonite, which might explain K+ depletion in pore fluids of sediments. A low water activity improves K+ enrichment in montmorillonite. In addition, cationic partition accompanies variations of hydration states and alters the ionic concentration of the aqueous environment. These results can be applied to explain water and ionic partitions during subsurface water flow and the diagenesis processes of sediments.