A powerful way to deal with a complex system is to build a coarsegrained model capable of catching its main physical features, while being computationally affordable. Inevitably, such coarsegrained models introduce a set of phenomenological parameters, which are often not easily deducible from the underlying atomistic system. We present a unique approach to the calculation of these parameters, based on the recently introduced variationally enhanced sampling method. It allows us to obtain the parameters from atomistic simulations, providing thus a direct connection between the microscopic and the mesoscopic scale. The coarsegrained model we consider is that of Ginzburg-Landau, valid around a second-order critical point. In particular, we use it to describe a Lennard-Jones fluid in the region close to the liquidvapor critical point. The procedure is general and can be adapted to other coarse-grained models.coarse graining | enhanced sampling | Ginzburg-Landau free energy | second-order phase transitions | Lennard-Jones C omputer simulations of condensed systems based on an atomistic description of matter are playing an everincreasing role in many fields of science. However, as the complexity of the systems studied increases, so does the awareness that a less detailed, but nevertheless accurate, description of the system is necessary.This has been long since recognized, and branches of physics like elasticity or hydrodynamics can be classified in modern terms as coarse-grained (CG) models of matter. In more recent times, a field theoretical model suitable to describe second-order phase transitions has been introduced by Landau (1) and later perfected by Ginzburg (2). In recent decades a number of coarsegrained models that aim at describing polymers or biomolecules have also been proposed (3,4). In all these approaches some degrees of freedom, deemed not essential to study the phenomenon at hand, are integrated out and the resulting reduced description contains a number of parameters that are not easily determined.Here we use the recently developed variationally enhanced sampling (VES) method (5) to suggest a procedure that allows the determination of such parameters, starting from the microscopic Hamiltonian. This illuminates a somewhat unexpected application of VES, which has been introduced as an enhanced sampling method. We show that it also provides a powerful framework for the optimization of CG models, due to the combination of its enhanced sampling capabilities and its variational flexibility. Moreover, VES takes advantage of its deep connection with relative entropy, a quantity that has been shown to play a key role in multiscale problems (6, 7).As a first test case for our procedure we consider the Ginzburg-Landau (GL) model for continuous phase transitions. An advantage of using this model is that its strengths and limits are well known and that other researchers have already attempted to perform such a calculation (8)(9)(10)(11)(12)(13)(14). A system that undergoes a second-order phase transition is desc...