Quantcast
Viewing all articles
Browse latest Browse all 138

Hydrogen bonding autocorrelations

I am currently analyzing hydrogen bonding behaviour and kinetics with molecular dynamics simulations. I've been trying to compute autocorrelation functions for hydrogen bonds in a water system. Some authors use different definitions of the HB autocorrelation function (for example, Gowers' definition has been implemented in the MDAnalysis package), but let's say I'll be using Luzar's definition:

$$c(t) = \frac{\langle h(0) h(t) \rangle}{\langle h \rangle}$$$$h(t)=\begin{cases}1 : \text{hydrogen bond at time } t \\0 : \text{otherwise}\end{cases}$$

I'm looking for some ideas on how to code this on Python. By slightly modifying the MDAnalysis library, I managed to have an array of arrays list_of_sets containing, for each frame of the simulation, the atom ids that form an hydrogen bond. Then, I do something like:

def calculate_c(list_of_sets, tau_max, window_step):    frames = len(list_of_sets)    tau_timeseries = list(range(0, tau_max))    data = [[] for _ in range(tau_max)]    # calculate correlation function    for t in range(0, frames, window_step):        print(f'Analyzing frame {t}...')        Nt = len(list_of_sets[t])        for tau in tau_timeseries:            if t + tau >= frames:                break            # calculate correlation function for each pair of frames in the window            Ntau = len(set.intersection(*list_of_sets[t:t + tau + 1]))            data[tau].append(Ntau * Nt)    # calculate the average correlation function over all frames for each tau    average_timeseries = [np.mean(x) for x in data]    average_timeseries /= average_timeseries[0]    return tau_timeseries, average_timeseries

In this case, I didn't take into account the $\langle h \rangle$ parameter for now.

I also tried:

def c_t_luzar(list_of_sets, tau_max=40, window_step=1):    frames = len(list_of_sets)    tau_timeseries = list(range(tau_max))  # start at 0    timeseries_data = [[] for _ in range(tau_max)]    # calculate correlation function    for t in range(0, frames, window_step):        for pair_set in list_of_sets[t]:            h_t0 = 1 if pair_set else 0  # h(0)            for tau in tau_timeseries:                if t + tau >= frames:                    break                # calculate correlation function for each pair of frames in the window                h_t = 1 if pair_set in list_of_sets[t + tau] else 0  # 1 if common pair, else 0                timeseries_data[tau].append(h_t)    # calculate the average correlation function over all frames for each tau    average_timeseries = [np.mean(x) for x in timeseries_data]    return tau_timeseries, average_timeseries, timeseries_data

Do you have any opinions on these codes? I've never coded "averages" so I don't know if my train of thought is correct.


Viewing all articles
Browse latest Browse all 138

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>