Giter Club home page Giter Club logo

bayeswham_python's Introduction

README

Synopsis

BayesWHAM.py - a Bayesian implementation of the weighted histogram analysis method (WHAM) to make statistically optimal estimates of multidimensional molecular free energy surface (FES) from an ensemble of umbrella sampling simulations. The code functions in n-dimensions, natively supports uniform, symmetric Dirichlet, and Gaussian priors, and rigorously estimates uncertainties by Metropolis-Hastings sampling of the Bayes posterior. The source code may be straightforwardly modified to support arbitrary user-defined priors by augmenting two switch statements defining the MAP expression and the Metropolis acceptance criterion.

BayesWHAM_plotter.py - a utility code to plot the 1, 2, and 3-dimensional output of BayesWHAM.py

BayesReweight.py - a tool to project the unbiased FES calculated by BayesWHAM into any number of arbitrary variables beyond those in which umbrella sampling was conducted.

BayesReweight_plotter.py - a utility code to plot the 1, 2, and 3-dimensional output of BayesReweight.py

Version

v1.0 - 08/2016

Installation

No installation required. These are Python 2.7 scripts functions that can be called and executed directly from the Python interpreter.

I/O

Full details of required inputs, input files and formatting, and output files are provided in the headers of each script. Example calculations detailing the execution steps and providing all input and output files are detailed below.

Example 1 - alanine dipeptide 1D umbrella sampling in phi dihedral###

  • Umbrella sampling input data

Ensemble of 18 1D umbrella sampling calculations in phi dihedral

./diala_phi_EXAMPLE/bias/harmonic_biases.txt - list of umbrella simulation ID, location of harmonic biasing center (degrees), and harmonic force constant (kJ/mol.degrees^2), one entry per line

./diala_phi_EXAMPLE/traj - trajectories of umbrella sampling variable phi in each umbrella sampling calculation

./diala_phi_EXAMPLE/hist/hist_binEdges.txt - bin edges of rectilinear grid used to create phi histograms over each umbrella sampling trajectory

./diala_phi_EXAMPLE/hist - phi histograms compiled over phi trajectories in ./diala_phi_EXAMPLE/traj

./diala_phi_EXAMPLE/traj_aux__phi_psi - trajectories of projection variables [phi,psi] into which we wish to reweight the FES recorded over the course of each umbrella sampling calculation at the same frequency as those in ./diala_phi_EXAMPLE/traj; the projection variables are arbitrary and need not contain the umbrella sampling variable

  • BayesWHAM.py

Calculation of 1D FES F(phi) for alanine dipeptide from 18 1D umbrella sampling simulations at values of phi=[-170:20:170]. Phi is a backbone dihedral angle with range [-180 deg, 180 deg] and 360 deg periodicity.

We solve the generalized WHAM equations to a tolerance of 1E-15 under a Dirichlet prior with concentration parameter alpha = 2 (i.e., adding 1 pseudo count to each bin). Uncertainties are estimated by performing 1E6 rounds of Metropolis-Hastings sampling from the Bayes posterior and saving every 1E3 realizations. In practice, many more rounds of sampling should be performed until the log likelihood stabilizes indicating the Markov chain burn-in period has passed and samples are being drawn from the stationary distribution.

Copies of all files generated by this calculation are provided in ./diala_phi_EXAMPLE/BayesWHAM_OUTPUT

Execution:

dim=1;

periodicity=[1];

T=298;

harmonicBiasesFile='./diala_phi_EXAMPLE/bias/harmonic_biases.txt';

histBinEdgesFile='./diala_phi_EXAMPLE/hist/hist_binEdges.txt';

histDir='./diala_phi_EXAMPLE/hist';

tol_WHAM=1E-15;

maxIter_WHAM=1E6;

steps_MH=1E6;

saveMod_MH=1E3;

printMod_MH=1E3;

maxDpStep_MH=5E-4;

seed_MH=200184;

prior='Dirichlet';

alpha=2;

/Users/alf/Library/Enthought/Canopy_64bit/User/bin/python2.7 BayesWHAM.py $dim $periodicity $T $harmonicBiasesFile $histBinEdgesFile $histDir $tol_WHAM $maxIter_WHAM $steps_MH $saveMod_MH $printMod_MH $maxDpStep_MH $seed_MH $prior $alpha

/Users/alf/Library/Enthought/Canopy_64bit/User/bin/python2.7 BayesWHAM_plotter.py

  • BayesReweight.py

Reweighting of the biased simulation data and the free energy shifts calculated from solution of the generalized WHAM equations under the Dirichlet prior to estimate F(phi,psi). Phi and psi are backbone dihedral angles with range [-180 deg, 180 deg] and 360 deg periodicity. Within this projection we anticipate good sampling in the driven variable phi but not so in psi where exploration is reliant on spontaneous thermal fluctuations.

Copies of all files generated by this calculation are provided in ./diala_phi_EXAMPLE/BayesReweight_OUTPUT

Execution:

T=298;

dim_UMB=1;

periodicity_UMB=[1];

harmonicBiasesFile_UMB='./diala_phi_EXAMPLE/bias/harmonic_biases.txt';

trajDir_UMB='./diala_phi_EXAMPLE/traj';

histBinEdgesFile_UMB='./diala_phi_EXAMPLE/hist/hist_binEdges.txt';

histDir_UMB='./diala_phi_EXAMPLE/hist';

fMAPFile_UMB='f_MAP.txt';

fMHFile_UMB='f_MH.txt';

trajDir_PROJ='./diala_phi_EXAMPLE/traj_aux__phi_psi';

histBinEdgesFile_PROJ='./diala_phi_EXAMPLE/hist_binEdges_phi_psi.txt';

/Users/alf/Library/Enthought/Canopy_64bit/User/bin/python2.7 BayesReweight.py $T $dim_UMB $periodicity_UMB $harmonicBiasesFile_UMB $trajDir_UMB $histBinEdgesFile_UMB $histDir_UMB $fMAPFile_UMB $fMHFile_UMB $trajDir_PROJ $histBinEdgesFile_PROJ

/Users/alf/Library/Enthought/Canopy_64bit/User/bin/python2.7 BayesReweight_plotter.py

Example 2 - alanine dipeptide 2D umbrella sampling in [phi,psi] dihedrals###

  • Umbrella sampling input data

Ensemble of 36 2D umbrella sampling calculations in [phi,psi] dihedrals

./diala_phi_psi_EXAMPLE/bias/harmonic_biases.txt - list of umbrella simulation ID, location of harmonic biasing centers (degrees), and harmonic force constants (kJ/mol.degrees^2), one entry per line

./diala_phi_psi_EXAMPLE/traj - trajectories of umbrella sampling variables [phi,psi] in each umbrella sampling calculation

./diala_phi_psi_EXAMPLE/hist/hist_binEdges.txt - bin edges of rectilinear grid used to create [phi,psi] histograms over each umbrella sampling trajectory

./diala_phi_psi_EXAMPLE/hist - [phi,psi] histograms compiled over [phi,psi] trajectories in ./diala_phi_psi_EXAMPLE/traj in row major order

./diala_phi_psi_EXAMPLE/traj_aux__phi_psi_theta - trajectories of projection variables [phi,psi,theta] into which we wish to reweight the FES recorded over the course of each umbrella sampling calculation at the same frequency as those in ./diala_phi_psi_EXAMPLE/traj; the projection variables are arbitrary and need not contain the umbrella sampling variables

  • BayesWHAM.py

Calculation of 2D FES F(phi,psi) for alanine dipeptide from 36 2D umbrella sampling simulations at values of phi=[-170:20:170] and psi=[150:20:130]. Phi and psi are backbone dihedral angles with range [-180 deg, 180 deg] and 360 deg periodicity.

We solve the generalized WHAM equations to a tolerance of 1E-15 under a uniform prior. Uncertainties are estimated by performing 1E6 rounds of Metropolis-Hastings sampling from the Bayes posterior and saving every 1E3 realizations. In practice, many more rounds of sampling should be performed until the log likelihood stabilizes indicating the Markov chain burn-in period has passed and samples are being drawn from the stationary distribution.

Copies of all files generated by this calculation are provided in ./diala_phi_psi_EXAMPLE/BayesWHAM_OUTPUT

Execution:

dim=2;

periodicity=[1,1];

T=298;

harmonicBiasesFile='./diala_phi_psi_EXAMPLE/bias/harmonic_biases.txt';

histBinEdgesFile='./diala_phi_psi_EXAMPLE/hist/hist_binEdges.txt';

histDir='./diala_phi_psi_EXAMPLE/hist';

tol_WHAM=1E-15;

maxIter_WHAM=1E6;

steps_MH=1E6;

saveMod_MH=1E3;

printMod_MH=1E3;

maxDpStep_MH=5E-5;

seed_MH=200184;

prior='none';

alpha=0;

/Users/alf/Library/Enthought/Canopy_64bit/User/bin/python2.7 BayesWHAM.py $dim $periodicity $T $harmonicBiasesFile $histBinEdgesFile $histDir $tol_WHAM $maxIter_WHAM $steps_MH $saveMod_MH $printMod_MH $maxDpStep_MH $seed_MH $prior $alpha

/Users/alf/Library/Enthought/Canopy_64bit/User/bin/python2.7 BayesWHAM_plotter.py

  • BayesReweight.py

Reweighting of the biased simulation data and the free energy shifts calculated from solution of the generalized WHAM equations under the uniform prior to estimate F(phi,psi,theta). Phi, psi, and theta are backbone dihedral angles with range [-180 deg, 180 deg] and 360 deg periodicity. Within this projection we anticipate good sampling in the driven variables phi and psi but not so in theta where exploration is reliant on spontaneous thermal fluctuations.

Copies of all files generated by this calculation are provided in ./diala_phi_psi_EXAMPLE/BayesReweight_OUTPUT

Execution:

T=298;

dim_UMB=2;

periodicity_UMB=[1,1];

harmonicBiasesFile_UMB='./diala_phi_psi_EXAMPLE/bias/harmonic_biases.txt';

trajDir_UMB='./diala_phi_psi_EXAMPLE/traj';

histBinEdgesFile_UMB='./diala_phi_psi_EXAMPLE/hist/hist_binEdges.txt';

histDir_UMB='./diala_phi_psi_EXAMPLE/hist';

fMAPFile_UMB='f_MAP.txt';

fMHFile_UMB='f_MH.txt';

trajDir_PROJ='./diala_phi_psi_EXAMPLE/traj_aux__phi_psi_theta';

histBinEdgesFile_PROJ='./diala_phi_psi_EXAMPLE/hist_binEdges_phi_psi_theta.txt';

/Users/alf/Library/Enthought/Canopy_64bit/User/bin/python2.7 BayesReweight.py $T $dim_UMB $periodicity_UMB $harmonicBiasesFile_UMB $trajDir_UMB $histBinEdgesFile_UMB $histDir_UMB $fMAPFile_UMB $fMHFile_UMB $trajDir_PROJ $histBinEdgesFile_PROJ

/Users/alf/Library/Enthought/Canopy_64bit/User/bin/python2.7 BayesReweight_plotter.py

Citing

If you use the BayesWHAM.py and BayesReweight.py codes, please read and cite:

A.L. Ferguson "BayesWHAM: A Bayesian approach for free energy estimation, reweighting, and uncertainty quantification in the weighted histogram analysis method" J. Comput. Chem. 38 18 1583-1605 (2017)

Contact

Andrew Ferguson, PhD

Assistant Professor of Materials Science and Engineering

University of Illinois at Urbana-Champaign

[email protected]

http://ferguson.matse.illinois.edu

bayeswham_python's People

Contributors

andrewlferguson avatar jsheppard95 avatar

Watchers

 avatar

bayeswham_python's Issues

python2.7, matplotlib, and Mac OSX

Found BayesWHAM_plotter.py to give Segmentation Fault 11 on initial run. Initial environment created as follows:

conda create -n py27 python=2.7 anaconda

Initial run of BayesWHAM.py works, but plotter script had issues with with matplotlib version 2.2.3. Followed this article to fix, which updated matplotlib to 2.2.5.

Trying python BayesWHAM_plotter.py again, get the following runtime error:

RuntimeError: Python is not installed as a framework. The Mac OS X backend will not be able to function correctly if Python is not installed as a framework. See the Python documentation for more information on installing Python as a framework on Mac OS X. Please either reinstall Python as a framework, or try one of the other backends. If you are using (Ana)Conda please install python.app and replace the use of 'python' with 'pythonw'. See 'Working with Matplotlib on OSX' in the Matplotlib FAQ for more information.

Luckily python.app/pythonw already installed, so running pythonw BayesWHAM_plotter.py then fixed solved the issue.

Need to just update everything to Python3!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.