Overview of pymbar
mainpymbar is a Python implementation of the Multistate Bennett Acceptance Ratio (MBAR) method. It is used for estimating expectations and free energy differences across multiple states.repository·main·Indexed 43 days ago
https://github.com/choderalab/pymbarA Python implementation of the multistate Bennett acceptance ratio (MBAR) method used to estimate expectations and free energy differences from equilibrium samples across multiple probability densities. It includes applications for alchemical free energy, constant-force optical traps, harmonic oscillators, heat capacity calculations, parallel tempering, and umbrella sampling.
pymbar is a Python implementation of the Multistate Bennett Acceptance Ratio (MBAR) method. It is used for estimating expectations and free energy differences across multiple states.This dataset contains parallel tempering simulation data for alanine dipeptide in explicit solvent, based on the protocol described in Chodera et al. (2006).
The following files and structures are available in the dataset:
| Key | Description |
|---|---|
temperatures | A list of all temperatures (in K) used in the simulation, ordered from smallest to largest. |
replica-indices | A 2D array where row i, column j corresponds to the index (from 0..39) of the replica at temperature index j at iteration i. |
energies/potential-energies | A 2D array where row i, column j corresponds to the potential energy of snapshot i from temperature index j. |
backbone-torsions/ | Directories containing trajectories of phi (*.phi) and psi (*.psi) backbone torsions for a given temperature index. |
end-to-end-distance/ | Trajectories of the end-to-end distance at a given temperature index. |
The pymbar-examples repository provides various implementations of MBAR for computational and experimental chemistry applications. Key use cases include:
https://github.com/MobleyLab/alchemical-analysis)pymbar functionality, including validation of error estimate distributions.The heat-capacity.py script implements three distinct methods for computing heat capacity ($C_V$):
-t flag.MBAR solves for the free energies of $K$ states. Because solutions are unique only up to an overall constant, pymbar sets the first free energy to zero, leaving $K-1$ free energies.
scipy.optimize.minimize() and scipy.optimize.roots(). Supported methods include L-BFGS-B, dogleg, CG, BFGS, Newton-CG, TNC, trust-ncg, trust-krylov, trust-exact, and SLSQP for minimization, and hybr and lm for root finding. Methods requiring a Hessian receive the analytical Hessian.min_sc_iter iterations (default is 2) to improve stability when overlap is poor.To handle different convergence properties of various algorithms, pymbar uses solver protocols. A protocol is a sequence of optimization operations applied one after another.
solver_protocol='default' or solver_protocol='robust'.method and an optional continuation boolean (whether to start from the previous method's result or restart from initial values).# Example of a custom solver protocol
solver_protocol = (
dict(method="hybr", continuation=True),
dict(method="adaptive", options=dict(min_sc_iter=0)),
)The PMF (Potential of Mean Force) class from version 3 has been renamed to FES (Free Energy Surface) to better reflect its purpose and avoid semantic ambiguity.
It is important to distinguish between two tasks:
pymbar now cleanly separates these tasks. The FES class is used for the latter.
To verify your installation, you can run the test suite using pytest. The test suite requires pytest, statsmodels, and pytables.
First, install the necessary dependencies via conda:
$ conda install pytest statsmodelsThen, run the tests from within the pymbar directory:
$ pytest -v pymbarYou can construct a custom solver_protocol as a tuple of dictionaries to chain different optimization methods.
method: The name of the solver (e.g., 'hybr', 'L-BFGS-B', 'adaptive').continuation: A boolean. If True, the next method starts from the free energies resulting from the previous method. If False, it restarts from the initialized free energies.options: A dictionary of arguments passed directly to the underlying solver (e.g., maxiter, min_sc_iter).tol: The tolerance level. Note that tol is a direct option to the solver and is passed directly in the protocol, not inside the options dictionary.If a method in the sequence fails, pymbar will attempt to continue with the next method using the last known free energies (if continuation=True) and will issue a warning.
solver_protocol = (
dict(method="hybr"),
dict(method="L-BFGS-B", tol=1.0e-5, continuation=True, options=dict(maxiter=1000)),
dict(method="adaptive", tol=1.0e-12, options=dict(maxiter=1000, min_sc_iter=5))
)Beyond the standard MBAR implementation, pymbar provides access to other reweighting estimators through the pymbar.other_estimators module. These include:
You can access these estimators by importing the relevant functions or classes from the pymbar.other_estimators module.
To build and push conda packages to binstar (conda-forge), you must generate an authentication token. Use the binstar auth command with the following flags to create a token for the repex-travis user with api:write scopes:
-n repex-travis: Specifies the user.-o conda-forge: Specifies the channel.--max-age 22896000: Sets the token expiration.-c: Generates a command that can be used to encrypt the token.--scopes api:write: Grants write access to the API.The resulting token should be stored in the BINSTAR_TOKEN environment variable.
binstar auth -n repex-travis -o conda-forge --max-age 22896000 -c --scopes api:writeTo use pymbar, import the MBAR class and initialize it with the reduced potential and the number of samples per state.
Required Inputs:
u_kn: A matrix of reduced potentials with shape (nstates, nsamples).N_k: An array containing the number of samples per state.from pymbar import MBAR
# Initialize with reduced potentials (u_kn) and samples per state (N_k)
mbar = MBAR(u_kn, N_k)In version 4.0, pymbar uses the Python logging module for output. Setting verbose=True is still required for extensive information, but you must also configure the logging module in your script to see the messages in stdout.
import logging
import sys
# Configure logging to output to stdout
logging.basicConfig(stream=sys.stdout, level=logging.INFO)import logging
import sys
logging.basicConfig(stream=sys.stdout, level=logging.INFO)