| 1 |
.. _moving_from_pymbar3: |
| 2 |
|
| 3 |
Moving from ``pymbar`` version 3 |
| 4 |
################################ |
| 5 |
|
| 6 |
Pymbar v4.0 contains several changes to improve the API longer |
| 7 |
term. This, however, breaks the API used in 3.x and previous versions. |
| 8 |
|
| 9 |
The main changes include: |
| 10 |
|
| 11 |
* Making various estimators return dictionaries, not tuples, making it easier to return optional information requested at call time. |
| 12 |
* Standardizing on snake_case for function names. |
| 13 |
* Making the built-in solvers work to have an interface closer to like ``scipy`` solvers. |
| 14 |
|
| 15 |
---------- |
| 16 |
Snake case |
| 17 |
---------- |
| 18 |
|
| 19 |
Previous version of `pymbar` had mixed cases in functions. We have |
| 20 |
standardized on snake case, and tried to make the method names that do |
| 21 |
similar things more consistent. Specific changes include: |
| 22 |
|
| 23 |
* ``getFreeEnergyDifferences`` is now ``compute_free_energy_differences`` |
| 24 |
* ``computeExpectations`` is now ``compute_expectations`` |
| 25 |
* ``computeMultipleExpectations`` is now ``compute_multiple_expectations`` |
| 26 |
* ``computePerturbedFreeEnergies`` is now ``compute_perturbed_free_energies`` |
| 27 |
* ``computeEntropyAndEnthalpy`` is now ``compute_entropy_and_enthalpy`` |
| 28 |
|
| 29 |
In the submodule `timeseries`: |
| 30 |
|
| 31 |
* ``statisticalInefficiency`` is now ``statistical_inefficiency`` |
| 32 |
* ``statisticalInefficiencyMltiple`` is now ``statistical_inefficiency_multiple`` |
| 33 |
* ``integratedAutocorrelationTime`` is now ``integrated_autocorrelation_time`` |
| 34 |
* ``normalizedFluctuationCorrelationFunction`` is now ``normalized_fluctuation_correlation_function`` |
| 35 |
* ``normalizedFluctuationCorrelationFunctionMultiple`` is now ``normalized_fluctuation_correlation_function_multiple`` |
| 36 |
* ``subsampleCorrelatedData`` is now ``subsample_correlated_data`` |
| 37 |
* ``detectEquilibration`` is now ``detect_equilibration`` |
| 38 |
* ``statisticalInefficiency_fft`` is now ``statistical_inefficiency_fft`` |
| 39 |
* ``detectEquilibration_binary_search`` is now ``detect_equilibration_binary_search`` |
| 40 |
|
| 41 |
Additionally, the other estimators such as the Bennett Acceptance |
| 42 |
Ratio and exponential averaging/Zwanzig equation have different, more |
| 43 |
consistent, call signatures. All other estimators are now in the |
| 44 |
``other_estimators`` module. |
| 45 |
|
| 46 |
* ``BAR`` is now ``bar`` |
| 47 |
* ``EXP`` is now ``exp`` |
| 48 |
* ``EXPGauss`` is now ``exp_gauss`` |
| 49 |
* ``PMF`` is now ``FEP`` and is greatly expanded (see :ref:`fes_with_pymbar`). |
| 50 |
|
| 51 |
------------------------------------ |
| 52 |
More consistent return functionality |
| 53 |
------------------------------------ |
| 54 |
|
| 55 |
Previously, different pymbar functions returned different information |
| 56 |
as tuples. This became problematic when different functions returned |
| 57 |
different types of information or different numbers of results. We |
| 58 |
have thus consolidated on an API where all functions return a |
| 59 |
dictionary. |
| 60 |
|
| 61 |
As an example of both API changes of API, a short bit of code that |
| 62 |
would load in data and calculate free energies, instead of being |
| 63 |
|
| 64 |
.. code-block:: python |
| 65 |
:caption: Example of initializing ``MBAR`` in 3.0.7 |
| 66 |
|
| 67 |
mbar = MBAR(u_kn, N_k) |
| 68 |
results, errors = mbar.getFreeEnergyDifferences() |
| 69 |
print(results[0]) |
| 70 |
print(errors[0]) |
| 71 |
|
| 72 |
|
| 73 |
Would now be written as: |
| 74 |
|
| 75 |
.. code-block:: python |
| 76 |
:caption: Example of initializing ``MBAR`` in 4.0 |
| 77 |
|
| 78 |
mbar = MBAR(u_kn, N_k) |
| 79 |
results = mbar.compute_free_energy_differences() |
| 80 |
print(results['Delta_f']) |
| 81 |
print(results['dDelta_f']) |
| 82 |
|
| 83 |
|
| 84 |
Other estimators including ``bar`` and ``exp`` also use a dictionary for return data. |
| 85 |
|
| 86 |
The ``pymbar.timeseries`` submodule return patterns have *not* changed |
| 87 |
in 4.0, however, and one should refer to the individual function |
| 88 |
documentations for these return patterns. |
| 89 |
|
| 90 |
.. code-block:: python |
| 91 |
|
| 92 |
results = bar(w_F, w_R) |
| 93 |
print(f'Free energy difference is {results['Delta_f']:.3f} +- {results['Delta_f']:.3f} kT') |
| 94 |
|
| 95 |
|
| 96 |
and: |
| 97 |
|
| 98 |
.. code-block:: python |
| 99 |
|
| 100 |
results = exp(w_F) |
| 101 |
print(f"Forward free energy difference is {results['Delta_f']:.3f} +- {results['dDelta_f']:.3f} kT) |
| 102 |
results = exp(w_R) |
| 103 |
print(f"Reverse free energy difference is {results['Delta_f']:.3f} +- {results['dDelta_f']:.3f} kT) |
| 104 |
|
| 105 |
----------------- |
| 106 |
Simulation output |
| 107 |
----------------- |
| 108 |
|
| 109 |
Previously, ``pymbar`` send all messages to standard out when verbose |
| 110 |
was set to ``True``. ``pymbar`` now uses the logging module to output |
| 111 |
this information. If you wish to set messages, even if the verbose is |
| 112 |
set to ``True``, you will need to turn on logging for your script by |
| 113 |
importing the logging module, and adding the lines: |
| 114 |
|
| 115 |
.. code-block:: python |
| 116 |
:caption: Enabling logging in ``pybmar`` |
| 117 |
|
| 118 |
import logging |
| 119 |
import sys |
| 120 |
logging.basicConfig(stream=sys.stdout, level=logging.INFO) |
| 121 |
|
| 122 |
|
| 123 |
``pymbar`` generally uses the logging levels ``info`` for information |
| 124 |
that previously was set to standard out. Note that for a given method |
| 125 |
to produce extensive information, even with logging, the verbose flag |
| 126 |
still needs to be set to true. |
| 127 |
|
| 128 |
-------------------- |
| 129 |
Free energy surfaces |
| 130 |
-------------------- |
| 131 |
|
| 132 |
Previously, ``pymbar`` had a method ``PMF`` that estimated a free |
| 133 |
energy from a series of umbrella samples using a histogram |
| 134 |
approach. This was semantically problematic in two ways. First, the |
| 135 |
term PMF (potential of mean force) is somewhat of an ambiguous term, |
| 136 |
as the potential of mean force has some dependence on the coordinate |
| 137 |
system in which the mean force is calculated. Since ``pymbar`` does |
| 138 |
not calculate free energies by integration of mean force, this caused |
| 139 |
some confusion. To be clearer, we now have renamed the class |
| 140 |
``FES``, for "free energy surface". |
| 141 |
|
| 142 |
The inclusion of a PMF function also created some confusion where some |
| 143 |
authors referred to MBAR as a method to calculate a free energy |
| 144 |
surface. MBAR can only be used to take biased samples an estimate the |
| 145 |
unbiased weight of each sample. In order to calculate a free energy |
| 146 |
surface, one must also find a way to take the set of discrete weighted |
| 147 |
samples and calculate a continous potential of mean force: see Shirts |
| 148 |
and Ferguson :cite:`shirts_fes_2020` for a further discussion of the |
| 149 |
separation of these two distinct tasks in the construction of free |
| 150 |
energy surfaces. The pymbar code more cleanly separates the |
| 151 |
calculation of biasing weights associated with umbrella samples, and |
| 152 |
the estimation of the free energy surface. |
| 153 |
|
| 154 |
For more information on the options for computing free energy surfaces |
| 155 |
with the code, please see: :ref:`fes_with_pymbar`. |
| 156 |
|
| 157 |
------------ |
| 158 |
Acceleration |
| 159 |
------------ |
| 160 |
|
| 161 |
Previous version of ``pymbar`` include acceleration using explicit C++ |
| 162 |
inner loops. The C++ interface has become out of date. ``pymbar`` |
| 163 |
optimization routines are now accelerated with ``jax``. This provides |
| 164 |
approximately a 2x speed up when performed on most CPUs, and |
| 165 |
additional acceleration when a GPU can be detected (pymbar does not |
| 166 |
install the appropriate GPU libraries). ``jax`` will be installed when |
| 167 |
``pymbar`` in installed via conda, but ``pymbar`` will function with |
| 168 |
or without ``jax`` installed if there are issues with the JAX configuration. |
| 169 |
|
| 170 |
To disable the ``jax`` acceleration, set the environment variable |
| 171 |
``PYMBAR_DISABLE_JAX=TRUE``. This will disable ``jax`` acceleration |
| 172 |
of ``pymbar`` even when the ``jax`` software package is installed. |
| 173 |
|
| 174 |
------------- |
| 175 |
Other changes |
| 176 |
------------- |
| 177 |
|
| 178 |
Additional changes not affecting the API: |
| 179 |
* Removed legacy `old_mbar.py` support. |
| 180 |
* Moved testing framework to pytest, added significant numbers of tests. |
| 181 |
* Improved code linting using `black` |
| 182 |
* Bootstrapping for errors in free energies and expectations is now supported; see :ref:`strategies_for_solution` for more information. |
| 183 |
* Added a `bar_overlap` function to find overlap when using just `bar` |
| 184 |
* Fixed an error in computing expectations of small numbers. |
| 185 |
* Improved automated adaptive choice of samplers; see :ref:`strategies_for_solution` for more information. |
| 186 |
* Many instances of code cleanup. |
| 187 |
* Improved docstring documentation. |
| 188 |
|