betaFeedback

WorksPhysics and Astronomy

MDRefine: a Python package for refining Molecular Dynamics trajectories with experimental data

Abstract

Molecular dynamics (MD) simulations play a crucial role in resolving the underlying conformational dynamics of molecular systems. However, their capability to correctly reproduce and predict dynamics in agreement with experiments is limited by the accuracy of the force-field model. This capability can be improved by refining the structural ensembles or the force-field parameters. Furthermore, discrepancies with experimental data can be due to imprecise forward models, namely, functions mapping simulated structures to experimental observables. Here, we introduce MDRefine, a Python package aimed at implementing the refinement of the ensemble, the force-field and/or the forward model by comparing MD-generated trajectories with experimental data. The software consists of several tools that can be employed separately from each other or combined together in different ways, providing a seamless interpolation between these three different types of refinement. We use some benchmark cases to show that the combined approach is superior to separately applied refinements. Source code, documentation and examples are freely available at https://pypi.org/project/MDRefine and https://github.com/bussilab/MDRefine.

Introduction

Molecular dynamics (MD) simulations are a powerful tool to investigate the structure and dynamics of complex molecular systems[1]. MD simulations can be used in a predicting fashion. However, due to imperfect sampling and issues with the employed force fields, their predictions might be incorrect. Integration of experimental data is a widely recognized solution to this issue[2] and can be interpreted in two ways: on one hand, it makes simulations accurate, by forcing them to match experiments. On the other hand, it makes experiments interpretable, providing a microscopic picture corresponding to the macroscopic observations and, ultimately, allowing MD simulations to be used as a computational microscope[3]. Integration of experimental data and MD simulations has been widely exploited in the literature, in particular for complex molecular and biomolecular systems (see Refs.[4, 5, 6, 7] for recent reviews). Among integrative methods, ensemble refinement techniques where the experimental information is included a posteriori are particularly convenient because they can be used to analyze existing trajectories. Many methods of this class take advantage of the maximum entropy principle in order to minimally perturb the original ensemble while at the same time getting the best possible agreement with experimental values[8, 9].

Importantly, measurement devices are always affected by inescapable uncertainties. This uncertainty can be modeled in a Bayesian manner, leading in fact to a regularized version of the maximum entropy approach[10, 11, 12] [13, 14, 15], which allows to fine-tune the relative confidence of experiments and prior ensembles by means of a suitably chosen hyperparameter.

When ensemble corrections are only regularized by the requirement of maximizing the relative entropy to the initial prior, the result is system-specific and cannot be transferred to different molecular systems. To restore transferability, the refinement can be performed on the force-field parameters rather than on the ensemble16,17. This takes place at the expense of a reduced flexibility in the ensemble, which requires chemically motivated insights into the design of the force-field correction. In addition, transferability requires simultaneous analysis of multiple systems, which in turn complicates the implementation. Importantly, the maximum entropy principle can be used as a guideline also in force-field fitting strategies, namely by using the relative entropy to regularize the fitting18. Recently, the possibility to simultaneously perform ensemble and force-field refinement has been proposed19. With a similar formalism, the equations used to connect microscopic ensembles with experimental measurements, so-called forward models, can be refined simultaneously with ensemble refinement20. The generality of the process of adjusting force-field parameters including multiple systems, and the possibility to combine force-field, ensemble, and forward model refinement, result in a significant increase in complexity of these methods, which often require substantial amount of programming. As far as we know, general purpose scripts have been published to perform plain ensemble refinement (see, e.g., https://github.com/KULL-Centre/BME and https://github.com/bio-phys/BioEn). For all the other methods discussed above, a user is forced to write analysis scripts from scratch.

Here we present MDRefine, a Python toolkit to analyse and compare MD-generated trajectories with experimental data. The library contains routines to calculate various quantities (such as relative entropies and χ2\chi^2) and to reweight existing trajectories using different criteria. Importantly, it allows the generalizations discussed above to be used without the need to implement complex algorithms. Additionally, it includes an algorithm to determine optimal hyperparameters minimizing the cross-validation error by performing an optimization procedure rather than an exhaustive hyperparameter scan. The package is available at https://pypi.org/project/MDRefine.

MDRefine builds on powerful Python libraries such as Numpy21, Scipy22, and JAX23. It allows to define customized force-field corrections and/or forward models, which best suit for any specific case of interest. The seamless combination of ensembles, force-field and forward-model refinements enables the user both to preliminarily select the desired improvement and/or to determine the optimal one with the given input data. In this article, we first introduce the basic concept and design of MDRefine and then show how to use it in some benchmark cases. Source code, documentation and illustrative notebooks are provided at https://github.com/bussilab/MDRefine.

Materials and methods

MDRefine is implemented as a Python package. It requires Python ≥3.8\ge3.8, Numpy, JAX and Scipy libraries. Source code is freely available at https://github.com/bussilab/MDRefine.git. Tagged versions can be installed from PyPI. The GitHub repository contains documentation as well as a set of illustrative Jupyter notebooks. MDRefine is modular and treats data sets, including both experimental values and quantities from MD simulations, as objects. In the following, we describe the overall architecture of the package and some examples to enable users to make good use of the library.

Structure of data objects

A complete data set is represented as an object data, which, once defined, is devised to be immutable. Its exact structure is discussed in the Python documentation. The user can directly provide the data object or use the provided load_data function to read files saved using the standard Numpy format from a suitably organized hierarchy of directories. The data object has two main attributes: data.properties, which is a dictionary containing global properties of the data (such as the names of the systems sys_names and the original forward-model coefficients), and data.mol, which is a dictionary with one item for each molecular system.

For each system, the corresponding item data.mol[sys_name] (an instance of data_class) contains as attributes both the experimental values gexp (measured values gi,exp⁡g_{i,\exp} with estimated uncertainties σi,exp⁡\sigma_{i,\exp}) and some quantities evaluated for each frame xx of the MD trajectory. The latter includes: the weights w(x)w(x), the observables gg to be compared with gexpg_{\mathrm{exp}}, and the quantities f required to compute the force-field corrections through the method ff_correction, whose functional form is specified by the user. We include also the possibility to compute some (or all) of the observables gg through a user-defined function stored in the method forward_model, which acts on the attribute forward_qs (namely, quantities required for the forward model) and the corresponding coefficients. For the sake of clarity, both gg and gexpg_{\mathrm{exp}} are dictionaries of Numpy arrays split per experiment type exp_typeexp\_type, like for example backbone1_gamma_3J, backbone2_beta_epsilon_3J, sugar_3J (3J scalar couplings computed for several dihedral angles) and NOEs (signals detected through nuclear Overhauser effect), with the attribute names naming each experimental measure. Also forward_qs is a dictionary of different arrays, but its keys do not necessarily correspond to those of gg and gexpg_{\mathrm{exp}}. Both weights, g[exp_type], f and forward_qs[exp_type] are Numpy arrays whose rows correspond to (consecutive) frames xx of the MD trajectory.

Vast freedom is left to the units of measure, provided the experimental values are loaded consistently with the observables (both gg and output quantities of the forward model). Regarding the force-field corrections, the set of data.mol[sys_name] items include a variable named temperature corresponding to the thermal energy kBTk_{\mathrm{B}}T at which the MD simulation was performed. It is kBT=1k_{\mathrm{B}}T = 1 by default, namely, energies are expressed in unit of temperature, and in this way force-field corrections must be defined. Alternatively, one can express temperature in the preferred unit, as long as the force-field corrections are consistently defined. If the same system tem has been simulated at multiple temperatures to match different experiments, it is possible to provide the copies as if they were independent systems, each with its own temperature, as long as they are defined with different sys_names.

Experimental values can be passed either as a “central reference” gi=gi,exp±σig_i = g_{i,\mathrm{exp}} \pm\sigma_i or as upper/lower bound. The latter is often the case for data such as unobserved NOEs, where the experiment only provides an upper threshold for the NOE signal below which the signal cannot be revealed gi<gi,expg_i < g_{i,\mathrm{exp}} with tolerance σi\sigma_i. This is specified by the attribute ref (“reference”), which contains the sign of the inequality to be satisfied (= for central references, < / > for upper/lower thresholds respectively), the same sign for each data.mol[name_sys].g[exp_type] set of observables. To simplify the implementation, we assume that a tolerance σ\sigma is always provided and different from zero, although it can be set to a numerically very small value to reach the regime where the tolerance is negligible.

We included also the case of experimental values given by free energy differences ΔGexp\Delta G_{\mathrm{exp}} between couples of molecules. We built our implementation based on the prototypical case of computing mutation free energies in single- (S) and double- (D) stranded nucleic acids, which can be measured through denaturation experiments24. This has been used in refining force fields for RNA molecules with methylated nucleotides24,25. In order to compare these experimental measures with MD simulations, alchemical transformations[26] [24] are performed transforming oligomers with wild-type adenosine (A) to methylated ones (M) both in the single strand S and duplex D cases. Free-energy differences resulting from MD simulations can then be compared with experimental values in virtue of the thermodynamic cycle ΔGexp,A−ΔGexp,M=ΔGS−ΔGD\Delta G_{\mathrm{exp,A}} - \Delta G_{\mathrm{exp,M}} = \Delta G_{\mathrm{S}} - \Delta G_{\mathrm{D}}. To this aim, we introduced a new class data_cycle_class for the thermodynamic cycles, whose instances data.cycle[cycle_name] contain both the experimental value of ΔΔG\Delta\Delta G (with associated uncertainty) and the temperature. In this case, the data.mol items of the four molecular systems belonging to the cycle cycle_name have to be indicated in infos[‘global’][‘cycle_names’] in the same order as [‘AS’, ‘AD’, ‘MS’, ‘MD’], where one has the experimental ΔG\Delta G between single- (S) and double- (D) -stranded molecules and the alchemical transformation between A and M molecules. In other words, the four systems should be listed in order such that the alchemical transformations are between the first and the third system and between the second and the fourth system, and the reference experimental value reports the difference between these two alchemical free energies. Each of them has a further attribute logZ, which is the natural logarithm of the partition function shifted by a given reference value and related to the alchemical transformation from A to M molecules (either single- or double-stranded). Fixing a reference ensemble P0P_0 for the energy, then it is log⁡ZA=log⁡⟨e−βVA(x)⟩P0\log Z_A = \log\langle e^{-\beta V_A(x)} \rangle_{P_0} and analogous for log⁡ZM\log Z_M, so the free-energy difference is ΔGAM=−kBT(log⁡ZM−log⁡ZA)\Delta G_A^M = -k_B T(\log Z_M - \log Z_A). In most of the cases, one fixes PAP_A as reference ensemble P0=PAP_0 = P_A, so log⁡ZA=0\log Z_A = 0 and ΔGAM=−kBTlog⁡ZM=−kBTlog⁡⟨e−βΔVAM⟩A\Delta G_A^M = -k_B T \log Z_M = -k_B T \log\langle e^{-\beta\Delta V_A^M} \rangle_A, also known as the Zwanzig equation[27].

Two specific methods can be used to inform the algorithm about the preference for adjusting the force-field parameters (ff_correction) and the forward models (forward_model). The function ff_correction takes as input both the full set of force-field correction coefficients ϕ\phi specified by data.properties.names_ff_pars and the f array previously defined and returns the force-field correction for each frame ΔV(x;ϕ)\Delta V(x;\phi). The function forward_model takes as input both the full set of forward-model coefficients θ\theta listed as in forward_coeffs_0 and the dictionary forward_qs and returns calculated observables gi(x;θ)g_i(x;\theta); the output is structured as a dictionary which is going to update data.mol[sys_name].g that can be compared element-wise against the experimental measures data.mol[sys_name].gexp.

Basic calculations and reweighting

Once we have loaded all the required data in the dictionary data, we are now ready to perform basic calculations and reweighting of the ensembles. First of all, we are interested in quantifying how well the ensemble P0P_0 predicted by MD simulations agrees with the experimental measures gi,exp⁡±σig_{i,\exp} \pm\sigma_i. This is usually done using the χ2\chi^2, which depends both on the ensemble P0P_0 and on the forward model parameters θ\theta:

χ2[P0,θ]=∑i(⟨gi(x;θ)⟩P0−gi,exp⁡σi,exp⁡)2,(1)\chi^2[P_0,\theta] = \sum_i \left(\frac{\langle g_i(x;\theta)\rangle_{P_0} - g_{i,\exp}}{\sigma_{i,\exp}}\right)^2, \tag*{(1)}

where ⟨gi(x;θ)⟩P0\langle g_i(x;\theta)\rangle_{P_0} is the average value of the observable gi(x;θ)g_i(x;\theta) on the ensemble P0P_0. This is computed by the function compute_chi2, whose inputs are the weights representative of P0P_0, the observables g gi(x;θ)g_i(x;\theta), the experimental values gexp and the ref dictionary previously defined. This last variable allows for including also the case of experimental values for upper/lower bounds. For example, the values of the item gexp['uNOEs'] (unobserved NOEs) are upper bounds gi,exp⁡g_{i,\exp} for the signal observables g['uNOEs'] with a tolerance σi\sigma_i (ref['uNOEs'] = '<') and the corresponding contribution to the χ2\chi^2 is

∑i∈uNOEs[max⁡(0,⟨gi(x)⟩P0−gi,expσi,exp)]2.(2)\sum_{i\in uNOEs}\left[\max\left(0,\frac{\langle g_i(x)\rangle_{P_0}-g_{i,\mathrm{exp}}}{\sigma_{i,\mathrm{exp}}}\right)\right]^2. \tag*{(2)}

The output values of the function compute_chi2 are: the average quantities ⟨gi(θ;x)⟩P0\langle g_i(\theta;x)\rangle_{P_0}, the χ2\chi^2 for each observable ii, the relative difference ⟨gi(x)⟩P0−gi,expσi,exp\frac{\langle g_i(x)\rangle_{P_0}-g_{i,\mathrm{exp}}}{\sigma_{i,\mathrm{exp}}} and the total χ2\chi^2.

If there is a significant discrepancy, the reference ensemble P0P_0 might require some adjustments, either by varying the empirical coefficients ϕ\phi of the force field or by refining the ensemble P0P_0 with full flexibility, or both19. Once the dimensionless correction βΔV(x)\beta\Delta V(x) (namely, the logarithm of the correction factor) for each frame is given, we can reweight the ensemble by employing the function compute_new_weights, which takes as input the original weights w0(x)w_0(x) and the correction βΔV(x)\beta\Delta V(x) and returns the new (normalized) weights

w(x)=1Zw0(x)e−βΔV(x)(3)w(x)=\frac{1}{Z}w_0(x)e^{-\beta\Delta V(x)} \tag*{(3)}

together with log⁡Z\log Z. For example, the correction might be the output of ff_correction with some coefficients ϕ\phi reasonably chosen.

Once we have got the new (reweighted) ensemble PP, represented by the weights w(x)w(x), we can both compute the new χ2[P]\chi^2[P] and compare PP with the original ensemble P0P_0. In the case of alchemical calculations, the function compute_DeltaDeltaG_terms allows for computing the new free-energy differences ΔGAϕMϕ\Delta G^{M\phi}_{A\phi} and χ2\chi^2 for the ΔΔG\Delta\Delta G of the thermodynamic cycle by passing as input variables the data object and the dictionary of log⁡Zϕ=log⁡⟨e−βΔV(x;ϕ)⟩ϕ\log Z_\phi=\log\langle e^{-\beta\Delta V(x;\phi)}\rangle_\phi values for the reweighted ensembles PϕP_\phi of each molecular system in the cycle.

Regarding the comparison of PP with the reference ensemble P0P_0, if PP is determined by reweighting P0P_0 with some force-field corrections ΔV(x;ϕ)\Delta V(x;\phi), we can evaluate the deviation just by computing the L2L^2 distance in the parameter space ∑iϕi2\sum_i\phi_i^2 (l2_regularization). However, changing by the same quantity some coefficients ϕj\phi_j rather than others may lead to different variations of the ensemble, and the L2L^2 norm itself is undefined if the coefficients are expressed in different units. An alternative possibility without these problems is the Kullback-Leibler divergence:

DKL[P∣P0]=∑xP(x)log⁡P(x)P0(x)=−β⟨ΔV(x)⟩P−log⁡Z(4)D_{\mathrm{KL}}[P|P_0]=\sum_xP(x)\log\frac{P(x)}{P_0(x)}=-\beta\langle\Delta V(x)\rangle_P-\log Z \tag*{(4)}

with Z=⟨e−βΔV(x)⟩0Z=\langle e^{-\beta\Delta V(x)}\rangle_0 the partition function of PP, whose logarithm is returned by compute_new_weights. This quantity is the negative of the relative entropy between the ensemble PP and P0P_0 and is positively definite, the greater it is the further the ensemble PP is from P0P_0. It can be computed through the function compute_D_KL, whose inputs are the new weights P(x)P(x), the correction ΔV(x)\Delta V(x), the temperature β−1\beta^{-1} and log⁡Z\log Z. Now we have all the basic ingredients to compute the loss functions defined in the next section.

Loss functions and search for optimal solutions

The simplest option for refining an ensemble is to search for the ensemble which best fulfils the trade-off between the the experimental measures and the initial hypothesis P0P_0. Building on the maximum entropy principle, this Ensemble Refinement procedure can be performed by minimizing the following loss function[10]:

L[P]=12χ2[P]+αDKL[P∣P0],(5)\mathcal{L}[P] = \frac{1}{2}\chi^2[P] + \alpha D_{KL}[P|P_0], \tag*{(5)}

where α>0\alpha> 0 is a hyperparameter regulating the trade-off. One can show the optimal ensemble P(x)P(x) takes the functional form

P∗(x)=1ZλP0(x)e−λ⃗⋅g⃗(x)(6)P_*(x) = \frac{1}{Z_\lambda}P_0(x)e^{-\vec{\lambda}\cdot\vec{g}(x)} \tag*{(6)}

where

λi=⟨gi⟩P∗−gi,expασi,exp2.(7)\lambda_i = \frac{\langle g_i\rangle_{P_*} - g_{i,exp}}{\alpha\sigma_{i,exp}^2}. \tag*{(7)}

Hence, we can exploit this dimensionality reduction and search for the optimal solution in the subspace described by the parameters λ\lambda (one for each experimental value). Minimizing L[Pλ]\mathcal{L}[P_\lambda] turns out to be equivalent (i.e., same extreme point and corresponding value of the function) to maximize −αΓ(λ)-\alpha\Gamma(\lambda) 13,20, being

Γ(λ)=log⁡Zλ+λ⃗⋅g⃗exp+12α∑iλi2σi2.(8)\Gamma(\lambda) = \log Z_\lambda+ \vec{\lambda}\cdot\vec{g}_{exp} + \frac{1}{2}\alpha\sum_i\lambda_i^2\sigma_i^2. \tag*{(8)}

Therefore, we reduce to determining the optimal ensemble P∗P_* by minimizing Γ(λ)\Gamma(\lambda). Such Ensemble Refinement is implemented in the minimizer function. Notice that a similar functionality is also available in other packages, e.g., https://github.com/KULL-Centre/BME14 and https://github.com/bio-phys/BioEn[10]). A prototype implementation is also available at https://github.com/bussilab/py-bussilab/blob/master/bussilab/maxent.py. The gamma_function here implemented takes as input the λ\lambda, gg, gexpgexp, weights, all as Numpy arrays, and the hyperparameter α\alpha, and returns the value of Γ(λ)\Gamma(\lambda). Notice that this value coincides with L[P]\mathcal{L}[P] at the optimal point P∗P_*. The Γ\Gamma function can be shown to be convex in the parameters λ\lambda, at variance with the function L[P(λ)]\mathcal{L}[P(\lambda)]. This allows for a more robust numerical optimization.

The dimensionality reduction with λ\lambda parameters holds whenever the loss function has the form L[P]=ℓ(⟨gi(x)⟩P)+αDKL[P∣P0]\mathcal{L}[P] = \ell(\langle g_i(x)\rangle_P) + \alpha D_{KL}[P|P_0] with ℓ(⟨gi(x)⟩P\ell(\langle g_i(x)\rangle_P a generic function of the average values. Still, the derivation of the Γ\Gamma function, enabling a more efficient minimization, requires ℓ\ell to be a quadratic function of its arguments. When minimizing Γ\Gamma, experimental values for upper/lower bounds (as in Eq. (3)) can be included by employing boundaries in the λ\lambda space (λi≥0\lambda_i \ge0 for upper limits ref = ‘<’, λi≤0\lambda_i \le0 for lower limits ref = ‘>’).

The loss function described above is the one used in standard ensemble refinement procedures. When comparing MD simulations with experiments, all the errors, both coming from the ensembles, the force field and the forward model, come into play. Hence, we consider the possibility to simultaneously refine all of them. To this aim, and motivated by previous works in these directions19,20, we deem the following loss function to be suitable for our task:

L(P,ϕ,θ)=12χ2[P,θ]+αDKL[P∣Pϕ]+βR1[Pϕ∣P0]+γR2[θ∣θ0](9)\mathcal{L}(P,\phi,\theta) = \frac{1}{2}\chi^2[P,\theta] + \alpha D_{KL}[P|P_{\phi}] + \beta R_1[P_{\phi}|P_0] + \gamma R_2[\theta|\theta_0] \tag*{(9)}

where α,β,γ\alpha,\beta,\gamma are hyperparameters regulating the strength of the corresponding regularization terms, PϕP_{\phi} is the canonical ensemble determined by applying the force-field correction ϕ\phi to the reference ensemble P0P_0, and R1,R2R_1,R_2 are customizable regularizations for the force-field and the forward-model corrections, respectively. The loss function is considered to be implicitly summed over all the investigated molecular systems. This task can be interpreted as a Pareto (or multi-objective) optimization[28], solved through a linear scalarization, with α,β,γ≥0\alpha,\beta,\gamma\ge0 the relative weights of the objective functions. This loss function is quite adaptable to different aims by formally setting some of the hyperparameters to +∞+\infty. For example, if only β\beta is finite we recover force-field refinement. For α<+∞\alpha< +\infty, β<+∞\beta< +\infty, and γ=+∞\gamma= +\infty we fully trust the original forward-model coefficients getting back to19. Similarly, for α<+∞\alpha< +\infty, β=+∞\beta= +\infty, and γ<+∞\gamma< +\infty we recover20.

To minimize this loss function, we exploit the same dimensionality reduction previously introduced (based on λ\lambda coefficients), except that now it appears in a nested optimization. In other words, we determine the optimal λ∗(ϕ,θ)\lambda^*(\phi,\theta) (by minimizing Γ(λ;ϕ,θ)\Gamma(\lambda;\phi,\theta) at fixed ϕ,θ\phi,\theta – inner minimization) at any step of the (outer) minimization in the ϕ,θ\phi,\theta parameters space. Making the dependence λ∗(ϕ,θ)\lambda^*(\phi,\theta) explicit in the loss function L(P,ϕ,θ)\mathcal{L}(P,\phi,\theta) we get

L1(ϕ,θ)=L(λ∗(ϕ,θ),ϕ,θ)=−αΓ(λ∗(ϕ,θ);ϕ,θ)+βR1(ϕ)+γR2(θ).(10)\mathcal{L}_1(\phi,\theta) = \mathcal{L}(\lambda^*(\phi,\theta),\phi,\theta) = -\alpha\Gamma(\lambda^*(\phi,\theta);\phi,\theta) + \beta R_1(\phi) + \gamma R_2(\theta). \tag*{(10)}

and the optimal coefficients are determined by

(ϕ∗,θ∗)=arg⁡min⁡ϕ,θL(ϕ,θ)andλ∗=arg⁡min⁡λΓ(λ;ϕ∗,θ∗)(11)(\phi^{*},\theta^{*}) = \arg\min_{\phi,\theta} \mathcal{L}(\phi,\theta) \quad\text{and} \quad\lambda^{*} = \arg\min_{\lambda} \Gamma(\lambda;\phi^{*},\theta^{*}) \tag*{(11)}

(see Supplementary - Computation of derivatives and Implementation of minimizer for further details).

Besides the data object, we have to define also the regularization terms. These two terms are encoded in the regularization dictionary, with two items: force_field_reg, which can be either a string (KL divergence, plain l2) or a user-defined function acting on ϕ\phi; forward_model_reg, which is a user-defined function acting on θ\theta and θ0\theta_0 (for example, an L2L^2 regularization). Then, the loss_function is minimized following the described strategy by the minimizer routine. In this way, passing to minimizer the data object, the regularization dictionary and the hyperparameters, we get an output object Result containing the optimal solution (P,ϕ,θ)(P,\phi,\theta) and its properties. By default, the hyperparameters α,β,γ\alpha,\beta,\gamma are set to +∞+\infty, implying no refinement in the corresponding directions.

Searching for optimal hyperparameters via cross validation

Suitable ranges of the hyperparameters α,β,γ\alpha,\beta,\gamma can be determined by searching for an intermediate range between underfitting and overfitting. This can be done by splitting the data set into training and validation set and then searching for the hyperparameters which minimize the χ2\chi^2 on the validation set (cross validation). This splitting can be done in several ways. The way we recommend is to select some frames and some observables to belong to the validation set, leaving them out from the search of the optimal coefficients, which is done using only the training set. Keeping frames in the validation set makes sure the corrections can be generalized to a new (or longer) trajectory simulated for the same system, whereas keeping observables in the validation set strengthen the transferability of the correction to new observables[29].

The function select_traintest performs the splitting following these principles. Passing the data object, it splits the data set into training and validation set, with default ratios of the validation frames test_frames_size and validation observables test_obs_size of 20% on the full number of frames and observables for each molecular system. Alternatively, one can also pass two dictionaries test_frames and test_obs with user-defined values. The input variable random_state (an integer number) allows for fixing the seed used in the random splitting, thus making it reproducible. By default, the validation observables are defined only on validation frames, however they can be defined on all the frames just by setting if_all_frames = True.

The validation function, called by minimizer, allows for including in the output object Result also properties referring to the validation set, such as the χ2\chi^2, both for training observables on validation frames and for validation observables.

With the implementation described so far, one can scan over different values of the hyperparameters, minimize the loss function on the training set and evaluate the χ2\chi^2 on the validation set, to identify values of the hyperparameters that maximize transferability of the parameters. Whereas this procedure allows for determining suitable values for the hyperparameters, it suffers from the curse of dimensionality: while an exhaustive search is feasible for 1 or 2 dimensions, making a scan in 3 dimensions or more is cumbersome. To overcome this issue, we implemented an automatic search of the optimal hyperparameters[30].

This search is performed by randomly splitting the full data set into training and validation set several times (as indicated by random_states) and minimizing the average χ2\chi^2 on the validation set, evaluated at the optimal solution found in training. Since both ϕ\phi and θ\theta appear together in the minimization, in the following we will use μ=(ϕ,θ)\mu=(\phi,\theta) as a shortcut. The optimal coefficients depend on the hyperparameters via

λ∗(μ∗;α)=arg min⁡λΓ(λ;μ∗,α)μ∗(α,β,γ)=arg min⁡μL1(μ;α,β,γ),(12)\begin{aligned} \lambda^*(\mu^*;\alpha) &= \underset{\lambda}{\operatorname{arg\,min}}\Gamma(\lambda;\mu^*,\alpha) \\ \mu^*(\alpha,\beta,\gamma) &= \underset{\mu}{\operatorname{arg\,min}}\mathcal{L}_1(\mu;\alpha,\beta,\gamma), \tag*{(12)} \end{aligned}

therefore by the chain rule the derivatives of the χ2(λ∗,μ∗)\chi^2(\lambda^*,\mu^*) with respect to the hyperparameters result

∂χ2∂α=∂χ2∂μi∂μi∗∂α+∂χ2∂λi(∂λi∗∂μj∂μj∗∂α+∂λi∗∂α)(13)\frac{\partial\chi^2}{\partial\alpha} = \frac{\partial\chi^2}{\partial\mu_i}\frac{\partial\mu_i^*}{\partial\alpha} + \frac{\partial\chi^2}{\partial\lambda_i} \left( \frac{\partial\lambda_i^*}{\partial\mu_j}\frac{\partial\mu_j^*}{\partial\alpha} + \frac{\partial\lambda_i^*}{\partial\alpha} \right) \tag*{(13)}
∂χ2∂(β,γ)=∂χ2∂μi∂μi∗∂(β,γ)+∂χ2∂λi∂λi∗∂μj∂μj∗∂(β,γ)(14)\frac{\partial\chi^2}{\partial(\beta,\gamma)} = \frac{\partial\chi^2}{\partial\mu_i}\frac{\partial\mu_i^*}{\partial(\beta,\gamma)} + \frac{\partial\chi^2}{\partial\lambda_i} \frac{\partial\lambda_i^*}{\partial\mu_j} \frac{\partial\mu_j^*}{\partial(\beta,\gamma)} \tag*{(14)}

(see Supplementary - Computation of derivatives for the complete derivation).

This optimization is performed by hyper_minimizer, which requires the data object, the starting values of the hyperparameters which, by default are constrained to be +∞+\infty, the regularization and the random_states. One can also choose among minimizing the χ2\chi^2 for training observables and validation frames (which_set = ‘validation’) or validation observables (which_set = ‘test’). Since the minimization acts on orders of magnitude (namely, in logarithmic scale), the optimal hyperparameters are returned as $\log_{10}(\alpha,\beta,\gamma)`.

All at once: MDRefinement

A single function is defined, named MDRefinement, which encompasses all the functions defined so far, as illustrated in Figure 1. Its flow chart is shown in Figure 2. It loads both the data (from input files according to infos) and the regularization, search for the optimal hyperparameters in cross validation and returns the optimal solution Result on the full data set. The output values are also saved as csv files in a folder named results, including input, min_lambdas, result object, the steps in the hyperparameter search hyper_search and Numpy arrays with the optimized weights for each of the simulated frames.

Figure 1. Software architecture: MDRefinement contains two main blocks minimizer and hyperminimizer, besides load_data and save_txt. The input variables of MDRefinement include infos (dictionary with information about the data set to be loaded), user-defined regularization terms and initial guess for the hyperparameters (selected refinement).

Figure 2. Flow chart of MDRefinement: after loading the data and defining the functions (blue blocks), the cross-validation section (in orange) determines the optimal hyperparameters, which are then used (gray block) to get the most suitable refinement on the data set.

Results

To showcase the capabilities of the MDRefine, we present the analysis of a number of precomputed trajectories. Part of the data replicates results presented in previous paper19,20,24. New analysis are also presented that take advantage of the new capabilities introduced in this package. Full Python notebooks that can be used to reproduce these analyses are available at https://github.com/bussilab/MDRefine.

Force-field refinement with denaturation experiments

In this section we reproduce force-field corrections derived in24 and discuss the effect of using a different regularization strategy based on the relative entropy. This is performed in the notebook

Tutorial.ipynb, Section 2b. The main intent of this refinement is to improve the description of N6-methyladenosine (m6am^{6}a), one of the most common post-transcriptional modifications of RNA, consisting in the methylation of the standard adenosine at position N6. Notably, m6am^{6}a can exist in two possible conformations, depending on the orientation of the methyl group with respect to the rest of the nucleobase: the syn and anti isomers, which are distinguished by the value of the torsional angle η6\eta_{6} defined by the atoms N1-C6-N6-C10. The syn conformation is known to be the most stable for unpaired m6am^{6}a, whereas the anti isomer is the one expected when m6am^{6}a is Watson-Crick paired with uracil in an internal position of a double-stranded RNA.

As a starting parametrization we used the modrna08 force-field[31], developed by Aduri and coworkers using the standard AMBER protocol based on quantum-mechanical calculations and ReSP (Restrained Electrostatic Potential) fitting[32]. This parametrization does not predict the correct syn/anti balance for unpaired m6am^{6}a. We then apply a correction to the force-field using the same prescription outlined in24. This correction includes a sinusoidal term acting on the η6\eta_{6} torsional angle ΔV(η6)=−Vηcos⁡η6\Delta V(\eta_{6}) = -V_{\eta}\cos\eta_{6} (positive values of VηV_{\eta} favour syn conformations over anti) and a reparametrization of the partial charges close to the methyl group (C6, N6, H61, N1, C10, H101/2/3), with the constraint on the total charge to be constant ∑iΔQi=0\sum_i\Delta Q_i = 0 and on the charges of the three equivalent hydrogens (H101/2/3) to be identical. Here ΔQi\Delta Q_i represents the variation of the partial charge of atom ii when compared with the starting parametrization. This results in 6 free parameters: VηV_{\eta} and 5 partial charges ΔQi\Delta Q_i.

The total energy depends quadratically on the charge perturbations ΔQi\Delta Q_i, hence, following24, it can be expressed as

ΔV(x)=∑i=15Ki(x)ΔQi+∑i=15∑j=15Kij(x)ΔQiΔQj−Vηcos⁡η6(x).(15)\Delta V(x) = \sum_{i=1}^{5} K_i(x)\Delta Q_i + \sum_{i=1}^{5}\sum_{j=1}^{5} K_{ij}(x)\Delta Q_i\Delta Q_j - V_{\eta}\cos\eta_{6}(x). \tag*{(15)}

The 20 coefficients KiK_i and KijK_{ij} can be determined through linear algebra operations starting from 20 linearly independent sets of charge perturbations, allowing the computation of the total energy for any choice of the charges ΔQi\Delta Q_i without the need to repeat the computationally expensive electrostatic-energy calculation.

These 6 free parameters (ΔQi\Delta Q_i, VηV_{\eta}) were fitted by comparing the reweighted predictions of MD simulations with a number of denaturation experiments measuring free-energy differences ΔG\Delta G. The molecules used in the training phase include: m6am^{6}a (syn/anti difference), UACG6CUG AUGCUGAC, CGAU6GGU, 6CGC, GCG6, GCUAUCCA, GCG, CGC where 6 stands for the m6am^{6}a nucleoside. This comparison is made by realizing a thermodynamic cycle through alchemical calculations (see section *Structure of data objects and[26, 33] [24] for further details). The corresponding loss function includes a generic regularization term R(ΔQ,Vη)R(\Delta Q,V_{\eta}), which encodes the prior knowledge on the force field:

L(ΔQ,Vη)=12∑i=1Ncycles(ΔΔGi(ΔQ,Vη)−ΔΔGi,exp⁡σi,exp⁡)2+βR(ΔQ,Vη).(16)\mathcal{L}(\Delta Q,V_{\eta}) = \frac{1}{2}\sum_{i=1}^{N_{\mathrm{cycles}}}\left(\frac{\Delta\Delta G_i(\Delta Q,V_{\eta})-\Delta\Delta G_{i,\exp}}{\sigma_{i,\exp}}\right)^2+\beta R(\Delta Q,V_{\eta}). \tag*{(16)}

Strictly speaking, the L2L^2 regularization requires dimensionally homogeneous parameters, which is not the case here. In24 it has been suggested that, for this system, it suffices to regularize the partial charges. We follow the same protocol here, resulting in a L2L^2 regularization that reads:

R(ΔQ,Vη)=∑i=16ΔQi2=∑i=15ΔQi2+(∑i=15ΔQi+2ΔQH101)2.(17)R(\Delta Q,V_{\eta})=\sum_{i=1}^{6}\Delta Q_i^2=\sum_{i=1}^{5}\Delta Q_i^2+\left(\sum_{i=1}^{5}\Delta Q_i+2\Delta Q_{\mathrm{H101}}\right)^2. \tag*{(17)}

As an alternative procedure, we here test the possibility of regularizing using the relative entropy R(ΔQ,Vη)=DKL[P(ΔQ,Vη)∣P0]R(\Delta Q,V_{\eta})=D_{KL}[P(\Delta Q,V_{\eta})\mathbin{|}P_0]18, where the sum over all the systems is implicit. The results are shown in Figure 3.

Figure 3. Refinement of charges and VηV_{\eta} for alchemical calculations; comparison between L2L^2 (a) and relative entropy (b) regularization. (c) Inverse of the relative Kish size K−1=∑xw(x)2/w0(x)K^{-1} = \sum_x w(x)^2/w_0(x), measuring the deviation from the reference ensemble, as a function of the total χ2\chi^2 of the ΔΔG\Delta\Delta G on the thermodynamic cycles, at constant steps in the log⁡β\log\beta scale. (d) Partial charges Q(e)Q(e) for different parametrizations: Amber force field for wild-type adenosine, Aduri force field for methylated adenosine, L2L^2 and relative entropy regularization.

In both cases (Figure 3 a, Figure 3b), starting from a high value of the hyperparameter β\beta and decreasing it, the parameters change abruptly below a certain threshold. This can be interpreted as a transition to overfitting the experimental data. Figure 3c reports the relationship between the discrepancy from the reference ensemble and the discrepancy from the experiment, using both regularization flavors. In both cases, a smaller discrepancy from experiment (χ2\chi^2) can only be obtained at the price of a larger perturbation of the ensemble. As expected, relative entropy regularization results in less perturbed ensembles than L2L^2 regularization for the same χ2\chi^2 value. Interestingly, even if the β\beta value are uniformly spaced in logarithmic scale, an abrupt change to the overfitting regime is observed, leading to a sharp decrease in χ2\chi^2.

Hence, we choose hyperparameter values slightly before this threshold: β=10e−2\beta=10e^{-2} (the same as in Ref.24) and β≃0.5\beta\simeq0.5 for L2L^2 and DKLD_{KL} regularizations, respectively. These values are marked with bold vertical line in Figure 3 a, Figure 3b. Notice that choosing the optimal hyperparameter on the basis of the plots comparing deviation from theory and deviation from experiments has been suggested in some recent works[28]. Having an objective criterion to choose the hyperparameter is critical in this case because it allows us to compare the results obtained with the two regularization strategies, even if the value of the hyperparameters are not directly comparable. An alternative strategy for choosing hyperparameters that we didn’t test here is cross validation, as discussed below.

In Figure 3 we report the partial charges obtained for the chosen hyperparameters, and compare them with other sets of partial charges for the same system. There are important differences when comparing the refinement with L2L^2 or relative entropy regularization. Most importantly, the DKLD_{KL} regularization leaves relatively unconstrained C6 and N6 charges. This is due to the fact that these atoms can not form close contacts with other atoms, and thus their charge can be modified without a significant perturbation of the ensemble. The strengthening of Watson-Crick hydrogen bonds that when using L2L^2 regularization was obtained by making N1 and H61 slightly more polar, is here obtained by making N6 virtually apolar, transferring its charge largely to C10. Indeed, the

L2L^2 regularization keeps the final parameters close to those chosen based on the quantum mechanical calculations in Ref.[31], whereas DKLD_{KL} considers the effect of the parameters on the resulting ensemble.

Simultaneous forward-model and ensemble refinement

In this section we reproduce results from20 (see Tutorial_3.ipynb). The main purpose is to better estimate the empirical coefficients of the Karplus equations, relating the dihedral angles to the 3J{}^{3}J couplings measured in nuclear magnetic resonance experiments. This refinement is made by taking into account at the same time possible inaccuracies in the structural ensembles. By looking at our loss function (Eq. (9)), this choice corresponds to setting β=+∞\beta= +\infty, i.e., combining the refinement of the forward model with that of the ensembles, without further flexibility in the force-field parameters.

In our case study, the molecular systems include several RNA oligomers: AAAA, CAAU, CCCC, GACC, UUUU, UCAAUC. For each of them, we employ some experimental measures such as the 3J{}^{3}J scalar couplings for some dihedral angles, the NOE signals and the upper bound values of unobserved NOE signals. MD simulations have been performed20 with the standard AMBER BSC0 OL3 RNA force-field[34, 35, 36, 37] with the van der Waals modification of phosphate oxygens[38]; the water model is OPC[39]. The sampling has been enhanced with parallel tempering (see Ref.20 for further details).

The forward models here consist in the Karplus equations with empirical parameters A,B,CA,B,C, relating the dihedral angle ϕ\phi to the 3J{}^{3}J scalar coupling:

3J(ϕ)=Acos⁡2ϕ+Bcos⁡ϕ+C.(18){}^{3}J(\phi) = A\cos^{2}\phi+ B\cos\phi+ C. \tag*{(18)}

The employed dihedral angles are: β\beta (P-O5’-C5’-H5’, P-O5’-C5’-H5”), ϵ\epsilon (H3’-C3’-O3’-P), γ\gamma (H5’-C5’-C4’-H4’, H5”-C5’-C4’-H4’) (all along the backbone) and the sugar puckering angles ν1,ν2,ν3\nu_{1},\nu_{2},\nu_{3} (H1’-C1’-C2’-H2’, H2’-C2’-C3’-H3’, H3’-C3’-C4’-H4’). We use as reference coefficients the values reported in[40, 41, 42]. The same coefficients were used for β\beta and ϵ\epsilon dihedral angles, both corresponding to H-C-O-P atom types. The regularization of the forward model here adopted is the square deviation between new and reference 3J{}^{3}J couplings averaged over the angle, which can be obtained from the parameters as:

R(A,B,C)=12π∫02πdϕ(3J(ϕ)−3J0(ϕ))2=38(A−A0)2+12(B−B0)2+(C−C0)2+(A−A0)(C−C0),(19)\begin{aligned} R(A,B,C) &= \frac{1}{2\pi}\int_{0}^{2\pi}d\phi\left({}^{3}J(\phi)-{}^{3}J_{0}(\phi)\right)^{2}\\ &= \frac{3}{8}(A-A_{0})^{2}+\frac{1}{2}(B-B_{0})^{2}+(C-C_{0})^{2}+(A-A_{0})(C-C_{0}), \tag*{(19)} \end{aligned}

This expression is identical to the one used in Ref.^{20}, except for an arbitrary prefactor 2.

We then perform a simultaneous optimization of the parameters AA, BB, and CC (three for each of the three Karplus equations), and of the structural ensembles, as in20. To search for optimal hyperparameters, we perform an automatic search with the hyper_minimizer tool described above through minimization of the χ2\chi^{2} on test observables. Notice that the cross-validation performed in20 employed a slightly different choice for the training/test set, hence we do not expect to get exactly the same hyperparameter values as the optimal ones. In particular, the values corresponding to those reported in20 are α=174.33\alpha= 174.33, γ=6.87 Hz−2\gamma= 6.87\,\mathrm{Hz}^{-2}, whereas those obtained in this work are α=46.31\alpha= 46.31, γ=0.96 Hz−2\gamma= 0.96\,\mathrm{Hz}^{-2}. Then, we compare the parameters found for these two sets of optimal hyperparameters with both the reference values and those determined in20 (Figure 7 and Table I in Supplementary). Overall, our results adjust the reference empirical coefficients of the Karplus equations in the same direction suggested in20. Moreover, the refinement performed with hyperparameters optimized by MDRefine is closer to the results proposed in20. Hence, we report the refinement with this second choice of coefficients in Figure 4.

Figure 4. Refinement of Karplus equations. Comparison between: reference values (Lankhorst[40] for β\beta, ε\varepsilon angles, Davies[41] for γ\gamma angles, Condon[42] for sugar angles), refinement by Fröh(l)king et al.20, this work with Ensemble + Forward-Model Refinement (E+FME + FM) Ref and with the fully combined approach (E+FM+FFE + FM + FF) Ref.

Figure 7. Refinement of the empirical coefficients for the Karplus equations with Ensemble + Forward Model Refinement; comparison between optimized 1 and optimized 2 (see Table I).

Remarkably, these refinements minimally modify the structural ensembles: what matters most is the inaccuracy in the forward model. Indeed, the Kullback-Leibler divergence between reweighted and original ensembles is quite small, and also the histograms of the angles are not significantly modified (see Supplementary). Hence, we conclude that most of the discrepancy between MD trajectories and experiments is a consequence of forward-model errors rather than of genuine structural discrepancies.

Fully combined refinement

In this section we describe an application of the fully combined refinement, which adds the adjustment of the force-field coefficients to the simultaneous refinement of ensembles and forward models shown in the previous Section. This is obtained by minimizing the full loss function in Eq. (9). In this way, we are able to smoothly interpolate between these three different refinements (force field, ensembles and forward model), casting in a single framework several independent works19,20,24. The benchmark case discussed here is fully described in Tutorial_3.ipynb, and builds on the refinement described in the previous section adding some flexibility in the force-field coefficients. In particular, following19, we focus on a sinusoidal correction on α\alpha dihedral angles

ΔV(α)=ϕ1cos⁡α+ϕ2sin⁡α.(20)\Delta V(\alpha) = \phi_1 \cos\alpha+ \phi_2 \sin\alpha. \tag*{(20)}

Then, we search for the optimal hyperparameters by using the hyper_minimizer routine of MDRefine. We perform the same splitting of observables and frames in training/test set as in the previous cross validation (with 5 different choices) and then minimize the average χ2\chi^2 on cross-validated observables. We get as optimal hyperparameters α=959.9\alpha= 959.9, β=167.9\beta= 167.9, γ=0.42 Hz−2\gamma= 0.42\,\mathrm{Hz}^{-2}. Importantly, a grid search in a three-dimensional hyperparameter space would have been extremely costly. In our case, the minimization algorithm converges in only 44 function evaluations, and is able to reach a cross-validation error very close to the minimum value in less than 10 evaluations (see plot 10 in Supplementary).

The resulting refinement of the Karplus equations is reported in Figure 4. It overlaps to that determined in20 very well, except for a slight deviation regarding sugar puckering angles close to ±π/2\pm\pi/2 and π\pi. The resulting force-field corrections are reported in Figure 5a. Interestingly, the correction proposed here appears completely different from the one suggested in19. We also compared the population of the corrected dihedral angle, averaged over all systems, using the different approaches (Figure 5a). In spite of the significant difference in the force-field corrections, the resulting populations are quite similar. This can be rationalized considering the steric hindrance, which allows only some regions for the α\alpha dihedral angles to be populated. In other words, even though the corrections represented in Figure 5a appears different, their effect on the sampled regions of Figure 5b is comparable. Indeed, by comparing the histograms in Figure 5b, we conclude that this refinement shifts the population of α\alpha dihedral angles in the same direction as the one determined in the previous work19 through force-field refinement only or combined with ensemble refinement.

Figure 5. a) Force-field correction on α\alpha dihedral angles; comparison between this study (fully combined refinement) and previous19 one (force-field refinement FFR only or combined with ensemble refinement FFR+ER). b) Average histogram of α\alpha dihedral angles; comparison between original one, this study (both reweighting with force-field correction only or including also contribution from ER) and previous study19 (corresponding to the force-field corrections in Figure 5a).

It is however more conservative due to the combined refinement of the forward model. Further, by comparing the two relative entropies S[Pϕ∣P0]S[P_{\phi}|P_{0}] and S[P∣Pϕ]S[P|P_{\phi}] (Figure 11 in Supplementary), we argue the contribution of flexible ensemble refinement does not further modify the ensembles in a significant way. This means that the force-field correction alone is able to capture a significant fraction of the required correction.

Figure 11. Comparison of the Kullback-Leibler divergences for different molecular systems when performing E+FM refinement (P1P_1) or the fully combined approach, with PffP_{ff} the force-field correction ensemble and P2P_2 the final ensemble in the loss function (Eq. (9)).

It is also possible to obtain an estimation of the performance of the different approaches on new observables using the χ2\chi^{2} evaluated on the cross-validation set. This is reported in Figure 10. Here it can be seen that the combined refinement is expected to perform significantly better than the approach of Ref.20, in the sense that the χ2\chi^{2} on cross-validation observables is much lower. Including an explicit refinement on a carefully-chosen force-field correction allows for suggesting a direction in which modifications to the structural ensembles improve the agreement with experimental data.

Figure 10. Average value of χ2\chi^2 on validating observables in the course of the automatic search for the optimal hyperparameters. Comparison among Ens + FM (Ensemble + Forward Model) Refinement and Ens + FF + FM (the fully combined) Refinement. Starting from the initial values α=β=1\alpha= \beta= 1, γ=1Hz−2\gamma= 1Hz^{-2}, we get the final values χ2=2784.1\chi^2 = 2784.1 for Ens+FM Ref. (α=46.31\alpha= 46.31, γ=0.96Hz−2\gamma= 0.96Hz^{-2}) and χ2=1195.6\chi^2 = 1195.6 for the fully combined approach (α=959.9\alpha= 959.9, β=167.9\beta= 167.9, γ=0.42Hz−2\gamma= 0.42Hz^{-2}).

Discussion

The integration of MD-generated trajectories with experimental measures is useful to both improve the accuracy of MD simulations and to provide a microscopic interpretation to experimental data. Specifically, ensemble refinement methods can be used to minimally modify MD-generated ensembles to match experiments that report averaged information. Several variants of this idea have been proposed and used in the past years, based on the idea of refining either ensembles, force-field parameters, or forward models used to back-calculate experimental data. However, a general tool to perform these types of analysis is missing. We here developed the Python package MDRefine, which can be downloaded and installed from https://pypi.org/project/MDRefine and provides a flexible implementation of the methods above.

MDRefine consists of a number of functions, starting from standard calculations (relative entropy, χ2\chi^{2}) to more elaborate ones (minimization of the loss function and automatic search of optimal hyperparameters). It has been developed with a modular structure: the full input data defines a dictionary whose items are class instances, each of them containing all the information about a specific molecule (or a thermodynamic cycle for refinements with alchemical calculations). MDRefine is fairly customizable: the user can define functional forms for the force-field corrections and/or the forward models which are best suitable for his own cases of interest. The output is then returned as a folder with several files including optimal hyperparameters and coefficients, χ2\chi^{2} and relative entropies, Numpy arrays for the refined weights, and other relevant quantities.

We showed how to use MDRefine to reproduce data from recently published works19,20,24, where analyses were performed using custom scripts that are more difficult to adapt to new systems. These examples include fitting of partial charges of a modified nucleobase using alchemical simulations and fitting structural ensembles of RNA oligomers using various combinations of force-field refinement, ensemble refinement, and forward-model refinement. Jupyter notebooks that can be used to reproduce these analyses and can be used as starting points to analyze new systems are available on GitHub https://github.com/bussilab/MDRefine.

In addition to reproducing existing analyses, we generalized them taking advantage of the flexibility of this new implementation. Specifically, we compare the effect of different regularization strategies, and introduce the idea of tuning the hyperparameters by directly minimizing the cross-validation error. We consider this to be especially valuable in applications where the number of hyperparameters is larger than two and an exhaustive search is unfeasible.

It is important to recall that MDRefine is only designed to analyse and reweight existing trajectories, and not to generate new ones. This results in an important assumption, namely that the modifications required to match experimental measurements are small refinements[43]. This holds whenever the original ensemble has a significant overlap with the experiments. For instance, in the case of force-field refinement, as soon as the deviations become higher than a certain threshold (fixed for example by the relative entropy or the effective sample size), it is advisable to perform a new simulation with the updated parameters[44, 45, 46, 47] [16]. Also ensemble refinement strategies based on the maximum entropy principle can be iterated in this way, by running new simulations where linear restraints are used as biases[48, 49]. Parameters might also be improved on-the-fly, resulting in a much larger statistical significance, at the price of a more complex implementation[11, 50, 51, 52, 53, 54]. Finally, replica-based methods where the time average is replaced with a replica average, might also be used[55, 56, 57, 58].

MDRefine provides an off-the-shelf implementation of complex state-of-the-art algorithms which allow to refine structural ensembles for complex molecular systems. We hope that proving an open source and well-documented tool will facilitate the use of these algorithms in the molecular dynamics community.

Funding

V.P. was supported by the European Union—NextGenerationEU within the project PNRR (PRP@CERIC)

Supplementary

Computation of derivatives

Let’s remind L1\mathcal{L}_1, the loss function with the explicit dependence λ∗(μ)\lambda^*(\mu)

L1(μ)=L(λ∗(μ),μ)=−αΓ(λ∗(μ);μ)+βR1(ϕ)+γR2(θ)(21)\mathcal{L}_1(\mu)=\mathcal{L}(\lambda^*(\mu),\mu)=-\alpha\Gamma(\lambda^*(\mu);\mu)+\beta R_1(\phi)+\gamma R_2(\theta) \tag*{(21)}

where we introduced the shortcut μ=(ϕ,θ)\mu=(\phi,\theta). The optimal parameters are

μ∗=arg⁡min⁡μ(−αmin⁡λΓ(λ;μ)+βR1(ϕ)+γR2(θ));(22)\mu^*=\underset{\mu}{\arg\min}\left(-\alpha\underset{\lambda}{\min}\Gamma(\lambda;\mu)+\beta R_1(\phi)+\gamma R_2(\theta)\right); \tag*{(22)}
λ∗=arg⁡min⁡λΓ(λ;μ∗).(23)\lambda^*=\underset{\lambda}{\arg\min}\Gamma(\lambda;\mu^*). \tag*{(23)}

In order to search for the optimal coefficients λ∗,μ∗\lambda^*,\mu^*, we rely on the BFGS algorithm (or L-BFGS-B if there are boundaries on λ\lambda, due to min⁡,max⁡\min,\max in the χ2\chi^2, like for unobserved NOEs data) implemented by Scipy. This requires the computation of the derivatives, which we can carry out by leveraging the automatic differentiation performed by JAX. However, L1\mathcal{L}_1 depends on μ\mu also through λ∗\lambda^*, namely through the full minimization algorithm employed for Γ\Gamma. To overcome this issue, because λ∗\lambda^* is a point of minimum for L\mathcal{L}, the derivative simplifies to

∂L1(μ)∂μj=∂L(λ,μ)∂λk∣λ∗(μ)∂λk∗(μ)∂μj+∂L(λ,μ)∂μj∣λ∗(μ)=∂L(λ,μ)∂μj∣λ∗(μ)(24)\frac{\partial\mathcal{L}_1(\mu)}{\partial\mu_j}=\left.\frac{\partial\mathcal{L}(\lambda,\mu)}{\partial\lambda_k}\right|_{\lambda^*(\mu)}\frac{\partial\lambda_k^*(\mu)}{\partial\mu_j}+\left.\frac{\partial\mathcal{L}(\lambda,\mu)}{\partial\mu_j}\right|_{\lambda^*(\mu)}=\left.\frac{\partial\mathcal{L}(\lambda,\mu)}{\partial\mu_j}\right|_{\lambda^*(\mu)} \tag*{(24)}

and so it can be implemented via automatic differentiation of loss_function with given λ∗\lambda^* passed as fixed_lambdas.

Our aim is to compute how the χ2\chi^2 in validation, evaluated at the optimal parameters λ∗\lambda^* and μ∗\mu^* found in training, varies with the hyperparameters α,β,γ\alpha,\beta,\gamma, and to compute its derivatives. By employing the chain rule, this task can be split into two parts: compute separately the derivatives of the χ2\chi^2 w.r.t. the optimal coefficients λ∗,μ∗\lambda^*,\mu^* and those of the optimal coefficients λ∗,μ∗\lambda^*,\mu^* w.r.t. the hyperparameters, then multiply opportunely the derivatives. For the sake of clarity, in the following we will use the Einstein notation (sum over repeated index is implicit).

Let’s focus firstly on the second part and let’s make the dependence on the hyperparameters explicit: our aim is to compute the derivatives of the optimal parameters λ∗\lambda^* and μ∗\mu^* w.r.t. the hyperparameters α,β,γ\alpha,\beta,\gamma. The optimal coefficients are determined by the equations

λ∗(μ;α)=arg⁡min⁡λΓ(λ;μ,α);(25)\lambda^*(\mu;\alpha)=\underset{\lambda}{\arg\min}\Gamma(\lambda;\mu,\alpha); \tag*{(25)}
μ∗(α,β,γ)=arg⁡min⁡μ L1(μ;α,β,γ).(26)\mu^{*}(\alpha,\beta,\gamma)=\underset{\mu}{\arg\min}\,\mathcal{L}_{1}(\mu;\alpha,\beta,\gamma). \tag*{(26)}

In absence of boundaries, the optimal parameters are interior to the domain of the loss function.

In such points the gradient is zero:

∂Γ(λ;μ,α)∂λ∣λ∗=0and∂L1(μ;α,β,γ)∂μ∣μ∗=0.(27)\left.\frac{\partial\Gamma(\lambda;\mu,\alpha)}{\partial\lambda}\right|_{\lambda^{*}}=0\quad\text{and}\quad\left.\frac{\partial\mathcal{L}_{1}(\mu;\alpha,\beta,\gamma)}{\partial\mu}\right|_{\mu^{*}}=0. \tag*{(27)}

Hence, we can exploit the implicit function theorem and get to the following relations:

∂λi∗∂(μj,α)=−(Hin−1)ik∂2Γ(λ;μ,α)∂λk∂(μj,α)(28)\frac{\partial\lambda_i^{*}}{\partial(\mu_j,\alpha)} =-(H_{\mathrm{in}}^{-1})_{ik}\frac{\partial^{2}\Gamma(\lambda;\mu,\alpha)}{\partial\lambda_k\partial(\mu_j,\alpha)} \tag*{(28)}
∂μi∗∂(α,β,γ)=−(H−1)ij∂2L1(μ;α,β,γ)∂μj∂(α,β,γ)(29)\frac{\partial\mu_i^{*}}{\partial(\alpha,\beta,\gamma)} =-(H^{-1})_{ij}\frac{\partial^{2}\mathcal{L}_{1}(\mu;\alpha,\beta,\gamma)}{\partial\mu_j\partial(\alpha,\beta,\gamma)} \tag*{(29)}

where HinH_{\mathrm{in}} is the Hessian of the internal minimization (over λ\lambda)

Hinab=∂2Γ(λ;μ,α)∂λa∂λb.(30)H_{\mathrm{in}ab}=\frac{\partial^{2}\Gamma(\lambda;\mu,\alpha)}{\partial\lambda_a\partial\lambda_b}. \tag*{(30)}

and HH is the Hessian of the minimization over μ\mu

Hab=∂2L1(μ;α,β,γ)∂μa∂μb.(31)H_{ab}=\frac{\partial^{2}\mathcal{L}_{1}(\mu;\alpha,\beta,\gamma)}{\partial\mu_a\partial\mu_b}. \tag*{(31)}

The internal Hessian HinH_{\mathrm{in}} can be directly computed through automatic differentiation of Γ(λ;μ,α)\Gamma(\lambda;\mu,\alpha) by JAX (which can be equivalently done for gamma_function or for loss_function/α\alpha with fixed_lambdas not None), while for the second Hessian HH a further calculation is required. Indeed, we have to consider also the dependence of L1\mathcal{L}_{1} on μ\mu through λ∗\lambda^{*}. Consequently, the Hessian results

∂2L1∂μj∂μk=[∂∂λl(∂L∂μj)]λ∗∂λl∗∂μk+∂2L∂μj∂μk=+α∂2Γ∂μj∂λl(Hin−1)lm∂2Γ∂λm∂μk+∂2L∂μj∂μk(32)\begin{aligned} \frac{\partial^{2}\mathcal{L}_{1}}{\partial\mu_j\partial\mu_k} &=\left[\frac{\partial}{\partial\lambda_l}\left(\frac{\partial\mathcal{L}}{\partial\mu_j}\right)\right]_{\lambda^{*}}\frac{\partial\lambda_l^{*}}{\partial\mu_k}+\frac{\partial^{2}\mathcal{L}}{\partial\mu_j\partial\mu_k}\\ &=+\alpha\frac{\partial^{2}\Gamma}{\partial\mu_j\partial\lambda_l}(H_{\mathrm{in}}^{-1})_{lm}\frac{\partial^{2}\Gamma}{\partial\lambda_m\partial\mu_k}+\frac{\partial^{2}\mathcal{L}}{\partial\mu_j\partial\mu_k} \tag*{(32)} \end{aligned}

where the first term has to be summed over the molecular systems used in cross validation, which are possibly different from those used in training. Similarly, it holds

∂2L1∂μj∂α=∂∂α∂L(λ∗(μ,α),μ;α,β,γ)∂μj=∂2L∂μj∂λk∂λk∂α+∂2L∂μj∂α.(33)\frac{\partial^{2}\mathcal{L}_{1}}{\partial\mu_j\partial\alpha} =\frac{\partial}{\partial\alpha}\frac{\partial\mathcal{L}(\lambda^{*}(\mu,\alpha),\mu;\alpha,\beta,\gamma)}{\partial\mu_j} =\frac{\partial^{2}\mathcal{L}}{\partial\mu_j\partial\lambda_k}\frac{\partial\lambda_k}{\partial\alpha} +\frac{\partial^{2}\mathcal{L}}{\partial\mu_j\partial\alpha}. \tag*{(33)}

Also these terms can be computed through automatic differentiation.

Then, let’s focus on the first part, namely, the derivatives of the χ2\chi^2 with respect to the optimal parameters λ∗,μ∗\lambda^*,\mu^*. The full dependence is through the average value of the validating observables g~i(θ∗)\tilde{g}_i(\theta^*) (computed with the optimized forward model θ∗\theta^*) on the ensemble corresponding to the optimal parameters λ∗,μ∗\lambda^*,\mu^*:

⟨g~i(θ∗(α,β,γ))⟩λ∗(μ∗(α,β,γ);α),μ∗(α,β,γ).(34)\left\langle\tilde{g}_i\left(\theta^*(\alpha,\beta,\gamma)\right)\right\rangle_{\lambda^*(\mu^*(\alpha,\beta,\gamma);\alpha),\mu^*(\alpha,\beta,\gamma)}. \tag*{(34)}

These derivatives can be directly computed through automatic differentiation. Let’s conclude our calculation by applying the chain rule:

∂χ2∂α=∂χ2∂μi∂μi∗∂α+∂χ2∂λi(∂λi∗∂μj∂μj∗∂α+∂λi∗∂α)(35)\frac{\partial\chi^2}{\partial\alpha}=\frac{\partial\chi^2}{\partial\mu_i}\frac{\partial\mu_i^*}{\partial\alpha}+\frac{\partial\chi^2}{\partial\lambda_i}\left(\frac{\partial\lambda_i^*}{\partial\mu_j}\frac{\partial\mu_j^*}{\partial\alpha}+\frac{\partial\lambda_i^*}{\partial\alpha}\right) \tag*{(35)}
∂χ2∂(β,γ)=∂χ2∂μi∂μi∗∂(β,γ)+∂χ2∂λi∂λi∗∂μj∂μj∗∂(β,γ).(36)\frac{\partial\chi^2}{\partial(\beta,\gamma)}=\frac{\partial\chi^2}{\partial\mu_i}\frac{\partial\mu_i^*}{\partial(\beta,\gamma)}+\frac{\partial\chi^2}{\partial\lambda_i}\frac{\partial\lambda_i^*}{\partial\mu_j}\frac{\partial\mu_j^*}{\partial(\beta,\gamma)}. \tag*{(36)}

Now, each term on the right side of the equations can be computed through automatic differentiation and we just have to multiply them as indicated in order to get the derivatives of χ2\chi^2 w.r.t. the hyperparameters α,β,γ\alpha,\beta,\gamma. This will facilitate the search for the optimal hyperparameters, without the need for a scan in 3 dimensions, which may be cumbersome. Lastly, the minimization can be sped up considering the fact that one needs to explore several orders of magnitude in the hyperparameter space. It is then convenient to change variable and perform the minimization considering as hyperparameters log⁡α\log\alpha, log⁡β\log\beta, and log⁡γ\log\gamma, using once again the chain rule for derivatives ∂∂log⁡α=α∂∂α\frac{\partial}{\partial\log\alpha}=\alpha\frac{\partial}{\partial\alpha}, and analogous expressions for the other hyperparameters.

These calculations can be adapted to the presence of boundaries for the λ\lambda parameters (like in the case of unobserved NOEs). In these cases, when the optimal solution is on the boundary λj=0\lambda_j=0 for some jj, the derivatives of these λj\lambda_j parameters w.r.t. α,μ\alpha,\mu is zero. To prove this statement, let’s consider for simplicity the case with the constraint λj>0\lambda_j>0 for some jj. When the optimal solution is on the boundary λj=0\lambda_j=0 it means that, if we could remove the boundary, the minimum of the loss function Γ(λ;α,μ)\Gamma(\lambda;\alpha,\mu) would be inner to the forbidden region λj<0\lambda_j<0. Hence, by continuity of the Γ\Gamma function with respect to α\alpha (such as for μ\mu), when varying α\alpha (or μ\mu) by an arbitrarily small value, the minimum will still be in the forbidden region and the value of λj\lambda_j will still be zero, without changing. This holds for every function f(λ;α,μ)f(\lambda;\alpha,\mu) which is continuous in its arguments, independently of its convexity or not. Notice that since the boundaries are in the form of linear inequalities on λ\lambda, the function Γ\Gamma is expected to be convex also on the boundary.

Implementation of minimizer

To determine the optimal λ∗(ϕ,θ)\lambda^{*}(\phi,\theta) at given (ϕ,θ)(\phi,\theta) we can employ the same gamma_function previously described. Notice gamma_function does not include either the computation of the observables through the forward model θ\theta or the reweighting through the force-field correction ϕ\phi (namely, the dependence of Γ\Gamma on θ,ϕ\theta,\phi), rather they should be externally computed and then passed to gamma_function as input observables and weights.

Regarding the full loss function, we implemented L1(ϕ,θ)\mathcal{L}_{1}(\phi,\theta) in loss_function by inserting the search for optimal λ∗(ϕ,θ)\lambda^{*}(\phi,\theta). Its inputs are the Numpy array of (ϕ,θ)(\phi,\theta) coefficients, the data object, the regularization dictionary, the hyperparameters α,β,γ\alpha,\beta,\gamma (by default +∞+\infty, i.e., no refinement in that direction) and some other variables. The regularization dictionary has the two keys force_field_reg, forward_model_reg; the first item can be either a string (KL divergence, plain l2) or a user-defined function acting on ϕ\phi; the second item is a user-defined function acting on θ\theta and θ0\theta_{0} (for example, an L2L^{2} regularization).

The other inputs include: fixed_lambdas (by default None), gtol_inn and bounds (tolerance and boundaries for the inner minimization of λ\lambda; default values 10−310^{-3} and None, respectively), if_save (Boolean variable, by default False). For if_save = True, loss_function does not return just its numerical value, rather an object with all the quantities appearing in Eq. (9), such as the parameters (λ,ϕ,θ)(\lambda,\phi,\theta) (when defined), the new weights, the χ2\chi^{2}, the regularization terms.

Whenever the input variable fixed_lambdas is not None, loss_function implements the computation of L1(ϕ,θ)\mathcal{L}_{1}(\phi,\theta) through substitution of the given λ\lambda into Γ(λ;ϕ,θ)\Gamma(\lambda;\phi,\theta) in place of the inner minimization of Γ\Gamma over λ\lambda (the two computations are the same if α\alpha is infinite, namely, no ensemble refinement). This distinction turns out to be crucial when computing the gradient function ∂L1(ϕ,θ)∂(ϕ,θ)\frac{\partial\mathcal{L}_{1}(\phi,\theta)}{\partial(\phi,\theta)} gradient_fun with automatic differentiation (see Supplementary - Computation of derivatives).

The loss_function and its gradient_fun are evaluated together inside loss_function_and_grad, which is employed in minimizer in order to get the optimal solution. In this way, passing to minimizer the data object, the regularization dictionary and the hyperparameters (by default α,β,γ=+∞\alpha,\beta,\gamma=+\infty, i.e., no refinement in those directions), we get an output object Result containing the optimal solution (P,ϕ,θ)(P,\phi,\theta) and its properties.

Kish sample size and entropy

Let’s consider a sample {x1,…,xn}\{x_1,\ldots,x_n\} (assumed to be uncorrelated) with corresponding normalized weights {w1,…,wn}\{w_1,\ldots,w_n\}. If the weights are uniform, then the effective sample size is simply given by the number of points neff=nn_{eff}=n. Otherwise, we can obtain a good estimation of the effective sample size by using the Kish sample size, defined as the inverse of the average weight

neff=K[{wi}]:=⟨w⟩w−1=(∑iwi2)−1,(37)n_{eff}=K[\{w_i\}]:=\langle w\rangle_w^{-1}=\left(\sum_i w_i^2\right)^{-1}, \tag*{(37)}

This definition of neffn_{eff} reduces to neff=nn_{eff}=n if each sample contributes with uniform weight, while it returns the number of “dominant" frames if some of them count much more than the others. For example, if we have a non-normalized set of weights {1,…,1,N,…,N}\{1,\ldots,1,N,\ldots,N\} with weights 1 and NN repeated n−mn-m and mm times, respectively, then the effective sample size is neff≃mn_{eff}\simeq m if n−m≪Nmn-m\ll Nm (the subset of small weights wi=1w_i=1 dominates over the other) and neff≃n−mn_{eff}\simeq n-m in the opposite limit. Clearly, it is always neff≤nn_{eff}\leq n and the equality holds only for uniform weights; it is also neff>1n_{eff}>1 and small values are achieved when one frame contributes much more than the others.

The relation with the entropy SS is straightforward. It suffices to change the weighted arithmetic average ⟨…⟩\langle\ldots\rangle to the weighted geometric one in Eq. (37) to get

eS[{wi}]=(∏iwiwi)−1,(38)e^{S[\{w_i\}]}=\left(\prod_i w_i^{w_i}\right)^{-1}, \tag*{(38)}

which is always in between 1<eS[{wi}]≤n1<e^{S[\{w_i\}]}\leq n. Hence, the effective number of frames can be estimated also through eS[{wi}]e^{S[\{w_i\}]}, in a way which could be less sensitive to the fact that weights could vary over orders of magnitude. Moreover, by the Jensen’s inequality, it is always eS[{wi}]≥K[{wi}]e^{S[\{w_i\}]}\geq K[\{w_i\}].

Then, the relative entropy SrelS_{rel} can be used to quantify the discrepancy of the distribution PP, represented by the set of weights {wi}\{w_i\}, from P0P_0, represented by {w0i}\{w_{0i}\}:

eSrel[P∣P0]=[∏i(wiw0i)wi]−1.(39)e^{S_{rel}[P|P_0]}=\left[\prod_i\left(\frac{w_i}{w_{0i}}\right)^{w_i}\right]^{-1}. \tag*{(39)}

The relative entropy is always Srel≤0S_{rel}\leq0 but can be very large in absolute value for PP very different from P0P_0, with a lower bound determined by the number of frames. Notice it is the geometric average (over ww) of the ratio w/w0w/w_0; changing it to the arithmetic average we get the relative Kish size1

Krel[P∣P0]=⟨ww0⟩w−1.(40)K_{rel}[P|P_0]=\left\langle\frac{w}{w_0}\right\rangle_w^{-1}. \tag*{(40)}

If the reference ensemble is uniform (w0=1nw_0 = \frac{1}{n} constant), then the relative Kish size (and analogously eSrel[P∣P0]e^{S_{\mathrm{rel}}[P|P_0]}) reduces to the ratio neff/nn_{\mathrm{eff}}/n.

Finally, the Kish size ratio (KSR) for an ensemble PP reweighted from P0P_0 has been defined24 as the ratio between the two Kish sample sizes of PP and P0P_0, respectively:

KSR=⟨w⟩w−1⟨w0⟩w0−1.(41)\mathrm{KSR} = \frac{\langle w\rangle_{w}^{-1}}{\langle w_0\rangle_{w_0}^{-1}}. \tag*{(41)}

By following the analogy between Kish size and entropy, which share the same definition but using arithmetic and geometric averages, respectively, the Kish size ratio can be considered analogous to the exponential of the entropy difference eS[P]−S[P0]e^{S[P]-S[P_0]}.

Force-field refinement with alchemical calculations

In Figure 6 we report the minimum value of the loss function, the χ2\chi^2 for the different thermodynamic cycles and the average Kish size ratio (KSR) as a function of the hyperparameter β\beta. The overfitting transition is quite evident in the case with L2L^2 regularization, while it is smoother in the second case. For the sake of clarity, in § 6.2, we report the definitions of Kish size ratio and relative Kish size, introduced in previous works20,24, and highlight their relationships with the entropy or the relative entropy.

min. loss function for $L^2$ regularization; the overfitting transition is quite evident

(a)

min. loss function for relative entropy regularization

(b)

$\chi^2$ for different thermodynamic cycles and average KSR for $L^2$ regularization

(c)

$\chi^2$ for different thermodynamic cycles and average KSR for relative entropy regularization

(d)

Figure 6. Loss function, average Kish size ratio and χ2\chi^2 for each thermodynamic cycle at the optimal solution found at given hyperparameter β\beta and regularization (L2L^2 on charges or relative entropy). The overfitting transition is quite evident in the case of L2L^2 regularization, while it is smoother for the relative entropy regularization.

Forward-model refinement + max. entropy

In Table I we report the optimized empirical coefficients of the Karplus equations, comparing them with values already known in the literature. In Figure 7 we report the

nameABC
β,ε\beta,\varepsilon
reference15.3-6.11.6
Fröhlking18.34-5.390.11
optimized 116.80-5.660.94
optimized 218.91-5.23-0.21
fully combined18.13-5.290.072
γ\gamma
reference9.7-1.80
Fröhlking10.07-1.87-0.13
optimized 19.77-1.83-0.057
optimized 29.95-1.86-0.11
fully combined9.92-1.76-0.12
sugar
reference9.67-2.030
Fröhlking7.81-2.050.25
optimized 18.68-1.81-0.049
optimized 28.34-1.81-0.069
fully combined6.99-1.640.67

Table I. TABLE I: Empirical coefficients A,B,CA,B,C (in HzHz) of the Karplus equations. Comparison between: reference values; coefficients determined by Fröhlking et al. in 20 (hyperparameters α=174.33288\alpha= 174.33288, γ=6.86664/2Hz−2\gamma= 6.86664/2Hz^{-2} - factor 1/21/2 because of different regularization prefactor); coefficients determined in this work (optimized 1, i.e., with same hyperparameters as in 20; optimized 2, i.e., with optimal hyperparameters found in this work α=46.31\alpha= 46.31, γ=0.96Hz−2\gamma= 0.96Hz^{-2}); coefficients determined in this work with the fully combined approach (α=959.86\alpha= 959.86, β=167.94\beta= 167.94, γ=0.42Hz−2\gamma= 0.42Hz^{-2}).

In Figure 8 we report the Kullback-Leibler divergence of the refined ensembles with respect to the original ones, represented by MD simulations. These values are quite small: the ensembles do not change significantly; this is confirmed by Figure 9 showing weighted histograms of some dihedral angles.

Kullback-Leibler divergences of the refined ensembles

Figure 8. Refinement of Karplus equations: Kullback-Leibler divergences of the refined ensembles with respect to the original ones (optimized 1 with same hyperparameters as in 20; 2 with optimized hyperparameters).

Weighted histograms of some dihedral angles of CCCC and UCAAUC oligomers

Figure 9. Weighted histograms of some dihedral angles of CCCC and UCAAUC oligomers, as examples (comparison between original ensemble and reweighted ones).

Fully combined refinement

Figure 12. Comparison of the χ2\chi^2 for different experimental measures when performing E+FM refinement (P1P_1) or the fully combined approach, with PffP_{ff} the force-field correction ensemble and P2P_2 the final ensemble in the loss function (Eq. (9)) (sum over different molecular systems).

References

  1. [1]1 S. A. Hollingsworth and R. O. Dror, “Molecular dynamics simulation for all,” Neuron 99, 1129–1143 (2018).DOI
  2. [2]2 S. Bottaro and K. Lindorff-Larsen, “Biophysical experiments and biomolecular simulations: A perfect match?” Science 361, 355–360 (2018).DOI
  3. [3]3 E. H. Lee, J. Hsin, M. Sotomayor, G. Comellas, and K. Schulten, “Discovery through the computational microscope,” Structure 17, 1295–1306 (2009).DOI
  4. [4]4 M. Bonomi, G. T. Heller, C. Camilloni, and M. Vendruscolo, “Principles of protein structural ensemble determination,” Curr. Opin. Struct. Biol. 42, 106–116 (2017).DOI
  5. [5]5 S. Orioli, A. H. Larsen, S. Bottaro, and K. Lindorff-Larsen, “How to learn from inconsistencies: Integrating molecular simulations with experimental data,” Prog. Mol. Biol. Transl. Sci. 170, 123–176 (2020).DOI
  6. [6]6 V. A. Voelz, Y. Ge, and R. M. Raddi, “Reconciling simulations and experiments with biceps: a review,” Front. Mol. Biosci. 8, 661520 (2021).DOI
  7. [7]7 M. Bernetti and G. Bussi, “Integrating experimental data with molecular simulations to investigate RNA structural dynamics,” Curr. Opin. Struct. Biol. 78, 102503 (2023).DOI
  8. [8]8 E. T. Jaynes, “Information theory and statistical mechanics,” Phys. Rev. 106, 620 (1957).DOI
  9. [9]9 J. W. Pitera and J. D. Chodera, “On the use of experimental observations to bias simulated ensembles,” J. Chem. Theory Comp. 8, 3445–3451 (2012).DOI
  10. [10]10 G. Hummer and J. Köfinger, “Bayesian ensemble refinement by replica simulations and reweighting,” J. Chem. Phys. 143, 243150 (2015).DOI
  11. [11]11 A. Cesari, A. Gil-Ley, and G. Bussi, “Combining simulations and solution experiments as a paradigm for RNA force field refinement,” J. Chem. Theory Comp. 12, 6192–6200 (2016).DOI
  12. [12]12 A. Cesari, S. Reißer, and G. Bussi, “Using the maximum entropy principle to combine simulations and solution experiments,” Computation 6, 15 (2018).DOI
  13. [26]Shirts, M. R., Mobley, D. L., & Chodera, J. D. (2007). Alchemical free energy calculations: ready for prime time?. In Annual reports in computational chemistry (Vol. 3, pp. 41–59).
  14. [27]R. W. Zwanzig, “High-temperature equation of state by a perturbation method. i. nonpolar gases,” J. Chem. Phys. 22, 1420–1426 (1954).DOI
  15. [28]J. Köfinger and G. Hummer, “Encoding prior knowledge in ensemble refinement,” J. Chem. Phys. 160, 114111 (2024).DOI
  16. [29]T. Fröhlking, V. Mlynský, M. Janeček, P. Kührová, M. Krepl, P. Banáš, J. Šponer, and G. Bussi, “Automatic learning of hydrogen-bond fixes in an AMBER RNA force field,” J. Chem. Theory Comput. 18, 4490–4502 (2022).DOI
  17. [30]J. Lorraine, P. Vicol, and D. Duvenaud, “Optimizing millions of hyperparameters by implicit differentiation,” in Int. Conf. Artif. Intell. Stat. (PMLR, 2020) pp. 1540–1552.arxiv.org/abs/1911.02590
  18. [31]R. Aduri, B. T. Psciuk, P. Saro, H. Taniga, H. B. Schlegel, and J. SantaLucia, “Amber force field parameters for the naturally occurring modified nucleosides in rna,” J. Chem. Theory Comput. 3, 1464–1475 (2007).DOI
  19. [32]C. I. Bayly, P. Cieplak, W. Cornell, and P. A. Kollman, “A well-behaved electrostatic potential based method using charge restraints for deriving atomic charges: the RESP model,” J. Phys. Chem. 97, 10269–10280 (1993).DOI
  20. [33]C. Roost, S. R. Lynch, P. J. Batista, K. Qu, H. Y. Chang, and E. T. Kool, “Structure and thermodynamics of n6-methyladenosine in rna: a spring-loaded base modification,” J. Am. Chem. Soc. 137, 2107–2115 (2015).DOI
  21. [34]W. D. Cornell, P. Cieplak, C. I. Bayly, I. R. Gould, K. M. Merz, D. M. Ferguson, D. C. Spellmeyer, T. Fox, J. W. Caldwell, and P. A. Kollman, “A second generation force field for the simulation of proteins, nucleic acids, and organic molecules,” J. Am. Chem. Soc. 118, 2309–2309 (1996).DOI
  22. [35]J. Wang, P. Cieplak, and P. A. Kollman, “How well does a restrained electrostatic potential (RESP) model perform in calculating conformational energies of organic and biological molecules?” J. Comput. Chem. 21, 1049–1074 (2000).doi.org/10.1002/1096-987x(200009)21:12<1049::aid-jcc3>3.0.co;2-f
  23. [36]A. Pérez, I. Marchán, D. Svozil, J. Šponer, T. E. Cheatham, C. A. Laughton, and M. Orozco, “Refinement of the AMBER force field for nucleic acids: improving the description of α/γ conformers,” Biophys. J. 92, 3817–3829 (2007).pubmed.ncbi.nlm.nih.gov/17351000
  24. [37]37 M. Zgarbová, M. Otyepka, J. Šponer, A. Mládek, P. Banáš, T. E. Cheatham III, and P. Jurecka, “Refinement of the Cornell et al. nucleic acids force field based on reference quantum chemical calculations of glycosidic torsion profiles,” J. Chem. Theory Comp. 7, 2886–2902 (2011).pubmed.ncbi.nlm.nih.gov/21921995
  25. [38]38 T. Steinbrecher, J. Latzer, and D. Case, “Revised AMBER parameters for bioorganic phosphates,” J. Chem. Theory Comp. 8, 4405–4412 (2012).pubmed.ncbi.nlm.nih.gov/23264757
  26. [39]39 S. Izadi, R. Anandakrishnan, and A. V. Onufriev, “Building water models: a different approach,” J. Phys. Chem. Lett. 5, 3863–3871 (2014).pubmed.ncbi.nlm.nih.gov/25400877
  27. [40]40 P. Lankhorst, C. Haasnoot, C. Erkelens, H. Westennk, G. Van der Marel, J. Van Boom, and C. Altona, “Carbon-13 NMR in conformational analysis of nucleic acid fragments. 4. the torsion angle distribution about the C3’–O3’ bond in DNA constituents,” Nucleic Acids Res. 13, 927–942 (1985).pubmed.ncbi.nlm.nih.gov/4000932
  28. [41]41 D. B. Davies, “Conformations of nucleosides and nucleotides,” Prog. Nucl. Magn. Reson. Spectrosc. 12, 135–225 (1978).DOI
  29. [42]42 D. E. Condon, S. D. Kennedy, B. C. Mort, R. Kierzek, I. Yildirim, and D. H. Turner, “Stacking in RNA: NMR of four tetramers benchmark molecular dynamics,” J. Chem. Theory Comp. 11, 2729–2742 (2015).pubmed.ncbi.nlm.nih.gov/26082675
  30. [43]43 R. Rangan, M. Bonomi, G. T. Heller, A. Cesari, G. Bussi, and M. Vendruscolo, “Determination of structural ensembles of proteins: restraining vs reweighting,” J. Chem. Theory Comp. 14, 6632–6641 (2018).DOI
  31. [44]44 A. Cesari, S. Bottaro, K. Lindorff-Larsen, P. Banáš, J. Šponer, and G. Bussi, “Fitting corrections to an RNA force field using experimental data,” J. Chem. Theory Comp. 15, 3425–3431 (2019).DOI
  32. [45]45 S. Thaler and J. Zavadlav, “Learning neural network potentials from experimental data via differentiable trajectory reweighting,” Nat. Commun. 12, 6884 (2021).DOI
  33. [46]46 L. Giorgetti, R. Galupa, E. P. Nora, T. Piolot, F. Lam, J. Dekker, G. Tiana, and E. Heard, “Predictive polymer modeling reveals coupled fluctuations in chromosome conformation and transcription,” Cell 157, 950–963 (2014).DOI
  34. [47]47 G. Tiana, A. Amitai, T. Pollex, T. Piolot, D. Holcman, E. Heard, and L. Giorgetti, “Structural fluctuations of the chromatin fiber within topologically associating domains,” Biophys. J. 110, 1234–1245 (2016).DOI
  35. [48]48 B. Zhang and P. G. Wolynes, “Topology, structures, and energy landscapes of human chromosomes,” Proc. Natl. Acad. Sci. U.S.A. 112, 6062–6067 (2015).DOI
  36. [49]49 B. Zhang and P. G. Wolynes, “Shape transitions and chiral symmetry breaking in the energy landscape of the mitotic chromosome,” Phys. Rev. Lett. 116, 248101 (2016).DOI
  37. [50]50 A. D. White, J. F. Dama, and G. A. Voth, “Designing free energy surfaces that match experimental data with metadynamics,” J. Chem. Theory Comput. 11, 2451–2460 (2015).DOI
  38. [51]51 F. Marinelli and J. D. Faraldo-Gómez, “Ensemble-biased metadynamics: A molecular simulation method to sample experimental distributions,” Biophys. J. 108, 2779–2782 (2015).DOI
  39. [52]52 A. Gil-Ley, S. Bottaro, and G. Bussi, “Empirical corrections to the AMBER RNA force field with target metadynamics,” J. Chem. Theory Comp. 12, 2790–2798 (2016).DOI
  40. [53]53 A. D. White and G. A. Voth, “Efficient and minimal method to bias molecular simulations with experimental data,” J. Chem. Theory Comp. 10, 3023–3030 (2014).DOI
  41. [54]54 G. M. Hocky, T. Dannenhoffer-Lafage, and G. A. Voth, “Coarse-grained directed simulation,” J. Chem. Theory Comput. 13, 4593–4603 (2017).DOI
  42. [55]55 K. Lindorff-Larsen, R. B. Best, M. A. DePristo, C. M. Dobson, and M. Vendruscolo, “Simultaneous determination of protein structure and dynamics,” Nature 433, 128–132 (2005).pubmed.ncbi.nlm.nih.gov/15650731
  43. [56]56 A. Cavalli, C. Camilloni, and M. Vendruscolo, “Molecular dynamics simulations with replica-averaged structural restraints generate structural ensembles according to the maximum entropy principle,” J. Chem. Phys. 138, 094112 (2013).DOI
  44. [57]57 B. Roux and J. Weare, “On the statistical equivalence of restrained-ensemble simulations with the maximum entropy method,” J. Chem. Phys. 138, 084107 (2013).DOI
  45. [58]58 M. Bonomi, C. Camilloni, A. Cavalli, and M. Vendruscolo, “Metainference: A Bayesian inference method for heterogeneous systems,” Sci. Adv. 2, e1501177 (2016).DOI

Paper details

vlnc:W_7yqwf39b
Version
v1 · latest
Published
Fresh — added to the Hub within the last 30 days
Added
License
CC BY 4.0
Usage

views · 11

downloads · 0

A view counts once per browser per day, a download each time the PDF is requested.

  • Physics and Astronomy

Not recorded for this paper

View statement
Looking for related papers…
Contents