- Notifications
You must be signed in to change notification settings - Fork93
Python implementation of the multistate Bennett acceptance ratio (MBAR)
License
choderalab/pymbar
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Python implementation of themultistate Bennett acceptance ratio (MBAR) method for estimating expectations and free energy differences from equilibrium samples from multiple probability densities.See ourdocs.
The easiest way to install thepymbar
release is viaconda:
conda install -c conda-forge pymbar
which will come with JAX to speed up the code. Or to get the non-JAX accelerated version:
conda install -c conda-forge pymbar-core
You can also install JAX acceleratedpymbar
from thePython package indexusingpip
:
pip install pymbar[jax]
or the non-jax-accelerated version with
pip install pymbar
Whether you install the JAX accelerated or non-JAX-accelerated version does notchange any calls or how the code is run. The non-Jax version is smaller on disk due to smallerdependencies, but may not run as fast.
The development version can be installed directly from github viapip
:
# Get the compressed tarballpip install https://github.com/choderalab/pymbar/archive/master.tar.gz# Or obtain a temporary clone of the repo with gitpip install git+https://github.com/choderalab/pymbar.git
Basic usage involves importingpymbar
and constructing anMBAR
object from thereduced potential of simulation or experimental data.
Suppose we sample a 1D harmonic oscillator from a few thermodynamic states:
>>>frompymbarimporttestsystems>>>x_n,u_kn,N_k,s_n=testsystems.HarmonicOscillatorsTestCase().sample()
We have thensamples
sampled oscillator positionsx_n
(with samples from all states concatenated),reduced potentials in the(nstates,nsamples)
matrixu_kn
, number of samples per state in thensamples
arrayN_k
, and indicess_n
denoting which thermodynamic state each sample was drawn from.
To analyze this data, we first initialize theMBAR
object:
>>>mbar=MBAR(u_kn,N_k)
Estimating dimensionless free energy differences between the sampled thermodynamic states and their associated uncertainties (standard errors) simply requires a call tocompute_free_energy_differences()
:
>>>results=mbar.compute_free_energy_differences()
Hereresults
is a dictionary with keysDeltaf_ij
,dDeltaf
, andTheta
.Deltaf_ij[i,j]
is the matrix of dimensionless free energy differencesf_j - f_i
,dDeltaf_ij[i,j]
is the matrix of standard errors in this matrices estimate, andTheta
is a covariance matrix that can be used to propagate error into quantities derived from the free energies.
Expectations and associated uncertainties can easily be estimated for observablesA(x)
for all states:
>>>A_kn=x_kn# use position of harmonic oscillator as observable>>>results=mbar.compute_expectations(A_kn)
whereresults
is a dictionary with keysmu
,sigma
, andTheta
, wheremu[i]
is the array of the estimate for the average of the observable for in state i,sigma[i]
is the estimated standard deviation of themu
estimates, andTheta[i,j]
is the covariance matrix of the log weights.
See the docstring help for these individual methods for more information on exact usage; in Python or IPython, you can view the docstrings withhelp()
.
PyMBAR needs 64-bit floats to provide reliable answers. JAX by default uses32-bit (Single) bitsize.PyMBAR will turn on JAX's 64-bit mode, which may cause issues with some separate uses of JAX in the same code as PyMBAR,such as existing Neural Network (NN) Models for machine learning.
- Kyle A. Beauchampkyle.beauchamp@choderalab.org
- John D. Choderajohn.chodera@choderalab.org
- Levi N. Nadenlnaden@vt.edu
- Michael R. Shirtsmichael.shirts@colorado.edu
Please cite the original MBAR paper:
Shirts MR and Chodera JD. Statistically optimal analysis of samples from multiple equilibrium states. J. Chem. Phys. 129:124105 (2008).DOI
Some timeseries algorithms can be found in the following reference:
Chodera JD, Swope WC, Pitera JW, Seok C, and Dill KA. Use of the weighted histogram analysis method for the analysis of simulated and parallel tempering simulations. J. Chem. Theor. Comput. 3(1):26-41 (2007).DOI
The automatic equilibration detection method provided in
pymbar.timeseries.detectEquilibration()
is described here:Chodera JD. A simple method for automated equilibration detection in molecular simulations. J. Chem. Theor. Comput. 12:1799, 2016.DOI
pymbar
is free software and is licensed under the MIT license.
We would especially like to thank a large number of people for helping us identify issuesand ways to improvepymbar
, including Tommy Knotts, David Mobley, Himanshu Paliwal,Zhiqiang Tan, Patrick Varilly, Todd Gingrich, Aaron Keys, Anna Schneider, Adrian Roitberg,Nick Schafer, Thomas Speck, Troy van Voorhis, Gupreet Singh, Jason Wagoner, Gabriel Rocklin,Yannick Spill, Ilya Chorny, Greg Bowman, Vincent Voelz, Peter Kasson, Dave Caplan, Sam Moors,Carl Rogers, Josua Adelman, Javier Palacios, David Chandler, Andrew Jewett, Stefano Martiniani, and Antonia Mey.
alchemical-analysis.py
described inthis publication has beenrelocated here.
About
Python implementation of the multistate Bennett acceptance ratio (MBAR)