The initial step for silicate and aluminosilicate condensation is studied in water in the presence of a realistic tetrapropylammonium template under basic conditions. The model corresponds to the synthesis conditions of ZSM5. The free energy profile for the dimer formation ((OH) 3Si-O-Si-(OH) 2O - or [(OH) 3Al-O-Si-(OH) 3] -) is calculated with ab initio molecular dynamics and thermodynamic integration. The Si-O-Si dimer formation occurs in a two-step manner with an overall free energy barrier of 75 kJ mol -1. The first step is associated with the Si-O bond formation and results in an intermediate with a five-coordinated Si, and the second one concerns the removal of the water molecule. The template is displaced away from the Si centres upon dimer formation, and a shell of water molecules is inserted between the silicate and the template. The main effect of the template is to slow down the backward hydrolysis reaction with respect to the condensation one. The Al-O-Si dimer formation first requires the formation of a metastable precursor state by proton transfer from Si(OH) 4 to Al(OH) 4 - mediated by a solvent molecule. It then proceeds through a single step with an overall barrier of 70 kJ mol -1. The model with water molecules explicitly included is then compared to a simple calculation using an implicit continuum model for the solvent. The results underline the importance of an explicit and dynamical treatment of the water solvent, which plays a key role in assisting the reaction. © the Owner Societies 2012.