def _calc_singleLP_exTI_pred_mbar(Es, dEs, LPs_pred, nfr, T=300): assert Es.shape == dEs.shape kT = kb * T mbar = MBAR(Es / kT, nfr) w = mbar.getWeights() wt = w.T dgdl_int = [] for i in range(len(LPs_pred)): dgdl_int.append(np.dot(wt[i], dEs[i])) return np.array(dgdl_int)
def test_mbar_getWeights(): """ testing getWeights """ for system_generator in system_generators: name, test = system_generator() x_n, u_kn, N_k_output, s_n = test.sample(N_k, mode='u_kn') mbar = MBAR(u_kn, N_k) # rows should be equal to zero W = mbar.getWeights() sumrows = np.sum(W, axis=0) eq(sumrows, np.ones(len(sumrows)), decimal=precision)
def test_mbar_getWeights(): """ testing getWeights """ for system_generator in system_generators: name, test = system_generator() x_n, u_kn, N_k_output, s_n = test.sample(N_k, mode='u_kn') mbar = MBAR(u_kn, N_k) # rows should be equal to zero W = mbar.getWeights() sumrows = np.sum(W,axis=0) eq(sumrows, np.ones(len(sumrows)), decimal=precision)
if state_index == len(state_ranges) - 1 and T == state[1]: state_counts[state_index] = state_counts[state_index] + 1 exit state_index = state_index + 1 # print("The distribution with "+str(num_states)+" states is: "+str(state_counts)) # Store the distribution data for this number of states so that we can plot comparisons later for state in range(0, num_states): distributions_for_each_num_states[num_states_index][ state] = state_counts[state] state_temps_for_each_num_states[num_states_index][state] = sum( state_ranges[state]) / 2 T_ranges_for_each_num_states[num_states_index][state] = state_ranges[state] # Initialize MBAR mbar = MBAR(u_kn, state_counts, verbose=False, relative_tolerance=1e-12) # Get the 'weights', or reweighted mixture distribution weights = mbar.getWeights() # Store the weights for plot comparisons later on for sample in range(0, len(weights)): for state in range(0, num_states): # print(weights_for_each_num_states[num_states_index][state][sample]) weights_for_each_num_states[num_states_index][state][ sample] = weights[sample][state] ############# # # 5) Calculate dimensionless free energies with MBAR # ############# # Get the dimensionless free energy differences free_energies, uncertainty_free_energies = mbar.getFreeEnergyDifferences(
############# # # 5) Calculate 'weights' for each thermodynamic state (temp.) with MBAR # ############# # 'u_kn' contains the decorrelated reduced potential energies evaluated at each temperature (state) u_kn = np.array([[float(float(U_uncorrelated[sample])/float(temperature)) for sample in range(0,len(U_uncorrelated))] for temperature in temperatures]) u_kn_same_total_samples = np.array([[float(float(U_uncorrelated_same_total_samples[sample])/float(temperature)) for sample in range(0,len(U_uncorrelated_same_total_samples))] for temperature in temperatures]) # Initialize MBAR mbar = MBAR(u_kn, state_counts, verbose=False, relative_tolerance=1e-12) # Initialize MBAR using u_kn_same_total_samples, constructed from uniform sampling (same total # of samples) mbar_same_total_samples = MBAR(u_kn_same_total_samples, state_counts_same_total_samples, verbose=False, relative_tolerance=1e-12) # Get the 'weights', or reweighted mixture distribution weights = mbar.getWeights() weights_same_total_samples = mbar_same_total_samples.getWeights() # Store the weights for later analysis weights_for_each_num_states.extend([weights]) weights_for_each_num_states_same_total_samples.extend([weights_same_total_samples]) ############# # # 6) Calculate dimensionless free energies with MBAR # ############# # Get the dimensionless free energy differences, and uncertainties in their values free_energies,uncertainty_free_energies = mbar.getFreeEnergyDifferences()[0],mbar.getFreeEnergyDifferences()[1] # Save the free energies free_energies_for_each_num_states.extend([free_energies])
print "Interfaces" # Create Interaces around first and last frame of the first trajectory and use only solute coordinates traj = simulator.storage.trajectory(1)[ [0,-1] ].solute # mat = tis.compute_N_IJ_l_kI() # print mat if simulator.storage.number_of_trajectories() > 100: u_kln, N_k = tis.compute_mbar_array(0, 0, infinite_energy = 1e5) mbar = MBAR(u_kln, N_k, method = 'adaptive', relative_tolerance=1.0e-10, verbose=False) weights = mbar.getWeights() n = np.zeros(weights.shape, dtype='float') print np.exp(-mbar.f_k) print N_k index = 0 for k,n_samples in enumerate(N_k): n[index:index+int(n_samples),0:k+1] = 1.0 index += int(n_samples) print n print weights[:,0] print weights[:,2]