In modern-day simulations of many-body systems, much of the computational complexity is shifted to the identification of slowly changing molecular order parameters called collective variables (CVs) or reaction coordinates. A vast array of enhanced-sampling methods are based on the identification and biasing of these lowdimensional order parameters, whose fluctuations are important in driving rare events of interest. Here, we describe a new algorithm for finding optimal low-dimensional CVs for use in enhancedsampling biasing methods like umbrella sampling, metadynamics, and related methods, when limited prior static and dynamic information is known about the system, and a much larger set of candidate CVs is specified. The algorithm involves estimating the best combination of these candidate CVs, as quantified by a maximum path entropy estimate of the spectral gap for dynamics viewed as a function of that CV. The algorithm is called spectral gap optimization of order parameters (SGOOP). Through multiple practical examples, we show how this postprocessing procedure can lead to optimization of CV and several orders of magnitude improvement in the convergence of the free energy calculated through metadynamics, essentially giving the ability to extract useful information even from unsuccessful metadynamics runs.collective variables | timescale separation | spectral gap | caliber | enhanced sampling W ith the advent of increasingly accurate force fields and powerful computers, molecular-dynamics (MD) simulations have become a ubiquitous tool for studying the static and dynamic properties of systems across disciplines. However, most realistic systems of interest are characterized by deep, multiple free-energy basins separated by high barriers. The timescales associated with escaping such barriers can be formidably high compared with what is accessible with straightforward MD even with the most powerful computing resources. Thus, to accurately characterize such landscapes with atomistic simulations, a large number of enhanced-sampling schemes have become popular, starting with the pioneering works of Torrie, Valleau, Bennett, and others (1-13). Many of these schemes involve probing the probability distribution along selected low-dimensional collective variables (CVs), either through a static preexisting bias or through a bias constructed on-the-fly, that enhances the sampling of hardto-access but important regions in the configuration space.The quality, reliability, and usefulness of the sampled distribution is in the end deeply dependent on the quality of the chosen CV. Specifically, one key assumption inherent in several enhanced-sampling methods is that of timescale separation (14): for efficient and accurate sampling, the chosen CV should encode all of the relevant slow dynamics in the system, and any dynamics not captured by the CV should be relatively fast. For most practical applications, there are a large number of possible CVs that could be chosen, and it is not at all obvious how to construct the best low-dimen...