from emus import emus, avar import matplotlib matplotlib.use('Qt4Agg') import matplotlib.pyplot as plt # Define Simulation Parameters T = 310 # Temperature in Kelvin k_B = 1.9872041E-3 # Boltzmann factor in kcal/mol kT = k_B * T meta_file = 'wham_meta.txt' # Path to Meta File dim = 1 # 1 Dimensional CV space. period = 360 # Dihedral Angles periodicity # Load data psis, cv_trajs, neighbors = uu.data_from_WHAMmeta('wham_meta.txt',dim,T=T,k_B=k_B,period=period) # Calculate the partition function for each window z, F = emus.calculate_zs(psis,neighbors=neighbors,) # Calculate error in each z value from the first iteration. zerr, zcontribs, ztaus = avar.partition_functions(psis,z,F,iat_method='acor') # Calculate the PMF domain = ((-180.0,180.)) # Range of dihedral angle values pmf = emus.calculate_pmf(cv_trajs,psis,domain,z,nbins=60,kT=kT) # Calculate the pmf # Calculate z using the MBAR iteration. z_MBAR_1, F_MBAR_1 = emus.calculate_zs(psis,nMBAR=1) z_MBAR_2, F_MBAR_2 = emus.calculate_zs(psis,nMBAR=2) z_MBAR_5, F_MBAR_5 = emus.calculate_zs(psis,nMBAR=5)
def main(): a = _parse_args() # Get Dictionary of Arguments kT = a['k_B'] * a['T'] # Load data psis, cv_trajs, neighbors = uu.data_from_WHAMmeta(a['meta_file'],a['ndim'],T=a['T'], k_B=a['k_B'],period=a['period'],nsig=a['sigma']) if a['fxn_file'] is not None: fdata = uu.data_from_fxnmeta(a['fxn_file']) else: fdata = None # Calculate the partition function for each window z, F= emus.calculate_zs(psis,neighbors=neighbors,nMBAR=a['nMBAR']) # Calculate the PMF pmf = emus.calculate_pmf(cv_trajs,psis,a['domain'],z,nbins=a['nbins'],kT=kT) # Calculate any averages of functions. if fdata is not None: favgs = [] for n, fdata_i in enumerate(fdata): favgs.append(emus.calculate_obs(psis,z,fdata_i)) # Perform Error analysis if requested. if a['error'] is not None: zEMUS, FEMUS= emus.calculate_zs(psis,neighbors=neighbors,nMBAR=0) zvars, z_contribs, z_iats = avar.partition_functions(psis,zEMUS,FEMUS,neighbors=neighbors,iat_method=a['error']) # Perform analysis on any provided functions. if fdata is not None: favgs_EM = [] ferrs = [] fcontribs = [] nfxns = len(fdata[0][0]) for n in xrange(nfxns): fdata_i = [fi[:,n] for fi in fdata] iat, mean, variances = avar.average_ratio(psis,zEMUS,FEMUS,fdata_i,neighbors=neighbors,iat_method=a['error']) favgs_EM.append(mean) fcontribs.append(variances) ferrs.append(np.sum(variances)) # Save Data if a['ext'] == 'txt': np.savetxt(a['output']+'_pmf.txt',pmf) np.savetxt(a['output']+'_z.txt',z) np.savetxt(a['output']+'_F.txt',F) if fdata is not None: np.savetxt(a['output']+'_f.txt',favgs) if a['error'] is not None: np.savetxt(a['output']+'_zvars.txt',zvars) if fdata is not None: np.savetxt(a['output']+'_fvars.txt',ferrs) elif a['ext'] == 'hdf5': import h5py f = h5py.File(a['output']+'_out.hdf5',"w") # Save PMF pmf_grp = f.create_group("PMF") pmf_dset = pmf_grp.create_dataset("pmf",pmf.shape,dtype='f') dmn_dset = pmf_grp.create_dataset("domain",np.array(a['domain']).shape,dtype='f') pmf_dset[...] = pmf dmn_dset[...] = np.array(a['domain']) # Save partition functions z_grp = f.create_group("partition_function") z_dset = z_grp.create_dataset("z",z.shape,dtype='f') z_dset[...] = z F_dset = z_grp.create_dataset("F",F.shape,dtype='f') F_dset[...] = F if a['error'] is not None: zerr_dset = z_grp.create_dataset("z_vars",np.array(zvars).shape,dtype='f') zerr_dset[...] = np.array(zvars) if fdata is not None: f_grp = f.create_group('function_averages') f_dset = f_grp.create_dataset("f",np.shape(favgs),dtype='f') f_dset[...] = np.array(favgs) if a['error'] is not None: fvar_dset = f_grp.create_dataset("f_variances",np.shape(fvars),dtype='f') fvar_dset[...] = ferrs f.close() else: raise Warning('No valid output method detected.')