GithubHelp home page GithubHelp logo

bio-phys / pydhamed Goto Github PK

View Code? Open in Web Editor NEW
19.0 4.0 7.0 3.44 MB

Dynamic Histogram Analysis To Determine Free Energies and Rates from Biased Simulations

License: BSD 3-Clause "New" or "Revised" License

Jupyter Notebook 91.65% Python 8.34% Shell 0.01%
md-simulations science python free-energy free-energies kinetics kinetic-modeling molecular-dynamics

pydhamed's People

Contributors

kain88-de avatar lukas-stelzl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

pydhamed's Issues

Division by zero error

Dear Lukas

I am trying to use PyDHAMed to compute a PMF for a small molecule crossing a membrane bilayer. I performed umbrella sampling in 1.5ร… windows, spanning approx. 7nm (57 umbrellas in total).

Following your code, I first created the list of transition matrices for each of the umbrellas:

def create_transition_matrix(traj: npt.NDArray, microstates: npt.NDArray)->npt.NDArray:
    """
    Parameters
    --------------
    traj: np.array of size n
    microstates: np.array of size m

    First, the trajectory is binned into the provided
    microstates. Next, a transition matrix is calculated
    giving the number of transitions between each of the
    microstates.
    
    Returns: m x m matrix with the transitions between 
    all possible pairs of bins in subsequent trajectory frames. 
    """
    traj_binned = np.digitize(traj, microstates)
    n_states = microstates.shape[0]+1 # digitize is 1 indexed.
    mat = np.zeros((n_states, n_states))
    for (x, y), c in six.iteritems(Counter(zip(traj_binned[:-1], traj_binned[1:]))):
        mat[int(y), int(x)] = c
    return mat

colvar_files = glob.glob("../gromacs/plumed_us_*-colvar.dat")

transition_matrices = list()
for i, f in enumerate(colvar_files):
    print("Processing trajectory: ", f)
    traj = np.loadtxt(f)[500:, 1]
    transition_matrices.append(create_transition_matrix(traj, microstates)[1:, 1:])
with open("NFP_membrane_transition_counts.pickle", "wb") as outfile:
    pickle.dump(transition_matrices, outfile)

Next, I calculated the bias grid (in kBT units) as follows:

def create_biasses(q0, kappa, microstates)->npt.NDArray:
    bias = (0.5 * force_constants[:, np.newaxis] * (centers[:, np.newaxis] - microstates)**2).T
    # convert to kBT
    return (bias*1000)/(R*T)

#col0 = bias number
#col1 = bias center position
#col2 = bias force constant

umbrellas = np.loadtxt("../gromacs/wham_input.txt", skiprows=1)
centers = umbrellas[:, 1]
force_constants = umbrellas[:, 2]

biasses = create_biasses(centers, force_constants, microstates)
np.save("NFP_membrane_biasses.npy", biasses)

, where the input file simply contains the centers and force constants of the harmonic potentials. But when I try to use run_dhamedI cannot seem to get sensible results. When I use jit_gradient=False, the calculation finished but I do not get a sensible result (see figure).

afbeelding

When I use jit_gradient=True, I get a division by zero error at '_loop_grad_dhamed_likelihood_0'. Would you have an idea of what is going wrong?

Best,
Warre

Bias potential matrix

Hi,
I wanted to make sure that I understand the definition of the bias potential matrix correctly.
Assuming an umbrella sampling experiment with 4 windows A, B, C, D and 3 states 0, 1, 2. The restraining potential defined as k*(x-x0)^2. Should the cell A0 contain the following?
x=median value of bin 0,
x0=target value of window A

last_g_zero=True sometimes gives an error

ZeroDivisionError                         Traceback (most recent call last)
<ipython-input-36-882a6db4a90e> in <module>()
----> 1 og = run_dhamed(c_l, -np.log(v_ar), g_init=og, numerical_gradients=False, last_g_zero=True)

/Users/lukas/Projects/DHAMed/public-dhamed/PyDHAMed/pydhamed/optimize_dhamed.pyc in grad_dhamed_likelihood_ref_0(g_prime, g, ip, jp, ti, tj, vi, vj, nk, nijp)
     88     grad = np.zeros(g.shape[0] )
     89     grad[:-1]  += nk[:-1]
---> 90     grad = loop_grad_dhamed_likelihood_0(grad,g, ip, jp, ti, tj, vi, vj, nijp)
     91     return grad[:-1]
     92 

ZeroDivisionError: division by zero

Kinetics calculations

To do:

  1. Calculate rates trajectories where dynamics effectively evolve with the "true" dynamics (E.g., sets of short trajectories).
  2. Calculate rates from biased dynamics (e.g., umbrella sampling)...

Numba error

Dear Lukas,
thanks a lot for providing the software to DHAMed.
I am trying to use the program with the following test data:

traj=np.array([0., 0., 1., 2., 1., 0., 2., 2.])
c_l = [count_matrix(traj,n_states=3)]
v_ar=np.array([1, 1.5, 2]).reshape(3,1)

I get the following error:

File "dhamed.py", line 17, in
bl_g = run_dhamed(c_l, -np.log(v_ar))
....
....
InternalError: unsupported array index type float64 in [float64]
[1] During: typing of intrinsic-call at /home/andt88/miniconda2/lib/python2.7/site-packages/pydhamed/optimize_dhamed.py (21)
--%<-----------------------------------------------------------------

File "../../../../miniconda2/lib/python2.7/site-packages/pydhamed/optimize_dhamed.py", line 21

Generating Bias Matrix

I have performed an Umbrella Sampling analysis on a membrane system in gromacs. My collective variable is the distance of a small molecule from the center of a membrane. Using the pullf file generated from gromacs how would I go about generating the bias force matrix for each of my 80 US windows?

Handle disconnected states

  • Transition counts and bias potentials of states not properly connect to the other states need to be excluded in a consistent fashion.
  • Will be important for DHAMed calculations for complex systems.

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.