示例#1
0
文件: demo.py 项目: ehthiede/EMUS
# 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)
z_MBAR_1k, F_MBAR_1k = emus.calculate_zs(psis,nMBAR=1000)
# Calculate new PMF
MBARpmf = emus.calculate_pmf(cv_trajs,psis,domain,nbins=60,z=z_MBAR_1k,kT=kT)

# Estimate probability of being in C7 ax basin
fdata =  [(traj>25) & (traj<100) for traj in cv_trajs]
# Calculate the probability and perform error analysis.
iat, probC7ax, probC7ax_contribs = avar.average_ratio(psis,z,F,fdata,iat_method='acor')
probC7ax_std = np.sqrt(np.sum(probC7ax_contribs))
# This command just calculates the probability, without error analysis.
#prob_C7ax = emus.calculate_obs(psis,z,fdata) # Just calculate the probability


### Data Output Section ###

# Plot the EMUS, MBAR pmfs.
centers = np.linspace(-177,177,60)  # Center of the histogram bins
plt.figure()
plt.plot(centers,pmf,label='EMUS PMF')
plt.plot(centers,MBARpmf,label='MBAR PMF')
plt.xlabel('$\psi$ dihedral angle')
plt.ylabel('Unitless FE')
plt.legend()
示例#2
0
文件: wemus.py 项目: ehthiede/EMUS
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.')