Riboswitches are RNA structured elements that modulate fundamental pathways in bacteria and plants. Depending on the availability of their sensed metabolite they undergo a conformational change that turns on or off gene expression. In the add adenine riboswitch from Vibrio Vulnificus there are three crucial spots for the switch between the two conformations: the P1 stem, the kissing-loops and the binding site for adenine. Our work is based on advanced in silico techniques, including atomistic molecular simulations, steered molecular dynamics, umbrella sampling, metadynamics and Hamiltonian replica exchange. First we investigated the P1-ligand dependent stabilization quantifying this effect in terms of free energy (Di Palma et al doi:10.1261/rna.040493.113). Then we evaluated the different contributions that Mg2+ and adenine give to the formation of the tertiary interactions between the two loops and we analysed the influence of these interactions on the binding site. The obtained data are in quantitative agreement with experiments. The atomistic description of metabolite binding, RNA-Mg2+ interaction, and tertiary-contact formation clarifies the details of the ligand-aptamer interactions and of the role of divalent cations in the global aptamer folding.