def plotPotential(system, fftype, ax, window, doLegend = False, doXLabel = False, doYLabel = False, doXTickLabel = False):
	r_AA, pot_AA = getPotential(system, 'AA', fftype)
	r_SP, pot_SP = getPotential(system, 'SP', fftype)
	r_SPLD, pot_SPLD = getPotential(system, 'SPLD', fftype)
	ax.plot(r_AA, pot_AA , 'r-', label = r'$u_{\mathrm{AA}}$')
	ax.plot(r_SP, pot_SP, 'b-', label = r'$u_{\mathrm{pair, SP}}$')
	ax.plot(r_SPLD, pot_SPLD, 'g-', label = r'$u_{\mathrm{pair, SPLD}}$')
	ax.plot(np.linspace(window[0], window[1], 20), np.zeros(20), 'k--', linewidth = 2)
	ax.set_xlim([window[0], window[1]])
	ax.set_ylim([window[2], window[3]])
	setup.prune(ax, nbins = 6)
	if doLegend: ax.legend(loc = 'best')
	if doXLabel: ax.set_xlabel('r' + setup.Angstrom1)
	if doYLabel: ax.set_ylabel('potential ' + setup.energy)
	if not doXTickLabel: plt.setp(ax.get_xticklabels(), visible=False)
fig = plt.figure(figsize=(4, 3))
ax = fig.add_subplot(1, 1, 1)
styles = {'AA': 'ro', 'SP': 'b-', 'SPLD': 'k-'}
cgtypes = ['SP', 'SPLD']

for i, rho in enumerate(rhos):
    for j, cgtype in enumerate(cgtypes):
        prefix = os.path.join(data_dir, 'R%dT%d_%s' % (rho, temp, cgtype))
        histfile = pp.parseFileNames(prefix)[1]
        hist = pp.parseHist(histfile)['LD']
        r_t = hist[0]
        h_t = hist[1]
        r_m = hist[2]
        h_m = hist[3]
        if j == 0: ax.plot(r_t + 20 * i, h_t, styles['AA'], label='AA')
        ax.plot(r_m + 20 * i, h_m, styles[cgtype], label=cgtype)
        if i == 0: leg = ax.legend()

# design
ax.set_xlabel(r'$r(\AA)$')
ax.set_ylabel('local density')
setup.prune(ax)

# annotation
ax.annotate('300K', xy=(40, 0.30))

# save figure
plt.savefig('TIP4P_ld_dist.%s' % setup.params['savefig.format'])

if setup.showPlots: plt.show()
        err[i] = np.sqrt(4*rsq*var_r) # Error propagation rules for products of random variables
        Rsq_avgerr += err[i]/rsq

Rsq_avgerr /= len(LDCuts_2)
file('errbar.dat', 'a').write('\n Rsq avg. error = %g %%\n' % Rsq_avgerr)


######################## PLOTTING ############################
# srel_rc plot and design
fig = plt.figure(figsize = (setup.set_width('single'),2.8*2))
ax1 = fig.add_subplot(2,1,1)
ax1.errorbar(LDCuts_1, srel, yerr = err_delta, color = 'black', fmt = '--o', linewidth = 1, markersize = 3)
ax1.plot(LDCuts_1, srel, 'k-')
for i, p in enumerate(crit_points): ax1.plot(p, crit_srel[i], 'ro', markersize = 3, markerfacecolor = 'k', markeredgecolor = 'r', markeredgewidth = 1)
ax1.set_ylabel('$S_{rel}$')
setup.prune(ax1, nbins = 6)
if system == 'methane25':
        ax1.set_ylim([-0.92,0.2])
        ax1.annotate(r'$r_c = 6$' + setup.Angstrom2, xy = (6.0, -0.75), fontsize = 10)
        ax1.annotate(r'$r_c = 7.8$' + setup.Angstrom2, xy = (7.8, -0.86), fontsize = 10)
else:
        ax1.annotate(r'$r_c = 6.5$' + setup.Angstrom2, xy = (6.1, -0.117), fontsize = 10)
        ax1.annotate(r'$r_c = 7.8$' + setup.Angstrom2, xy = (8.0, -0.15), fontsize = 10)

# corrcoeff plot and design
ax2 = fig.add_subplot(2,1,2, sharex = ax1)
ax2.plot(LDCuts_2, Rsq, 'k-')
ax2.errorbar(LDCuts_2, Rsq, yerr = err, color = 'k', fmt = '--o', linewidth = 1.5, markersize = 3)
ax2.plot(LDCuts_2, Rsq, 'k-')
ax2.plot(6.5*np.ones(21), np.linspace(0, Rsq.max(), 21), 'k--', linewidth = 1, markersize = 3)
ax2.plot(6.5, 0, 'ko')
rho, pot = pp.parseLog(sumfile)['LD']
rholist = rho.tolist()

# start potential from zero
pot-= pot[0]
start = [rholist.index(x) for x in rholist if rholist.__contains__(x) and x >=1.][0]

# normalized f(rho)
fig1 = plt.figure(figsize = (setup.set_width('single'),2.8))	
ax1 = fig1.add_subplot(1,1,1)
ax1.plot(rho, pot, 'r-')

# normalized f(rho)/rho
fig2 = plt.figure(figsize = (setup.set_width('single'),2.8))
ax2 = fig2.add_subplot(1,1,1)
ax2.plot(rho, pot/rho, 'r-')


# Design
ax1.set_ylim([-2.5, 0.7])
for ax in [ax1,ax2]: setup.prune(ax, nbins = 8)
ax1.set_xlabel('local density of methane')
ax1.set_ylabel('potential ' + r'$(kcal/mol)$')
ax2.set_xlabel('local density of methane ' + r'$(\rho)$')
ax2.set_ylabel(r'$\frac{f(\rho)}{\rho}$' + ' ' + r'$(kcal/mol)$')


# save figure
setup.showPlots = True
if setup.showPlots: plt.show()
Esempio n. 5
0
	avgerr += err[i]/rsq

avgerr /= len(LDCuts)
file('errbar.dat', 'a').write('\n Rsq avg. error = %g %%\n' % avgerr)

# master plot and design
fig = plt.figure(figsize = (setup.set_width('single'),3))
ax = fig.add_subplot(1,1,1)
ax.plot(LDCuts, Rsq, 'k-')
ax.errorbar(LDCuts, Rsq, yerr = err, color = 'k', ecolor = 'k')
ax.plot(6.5*np.ones(21), np.linspace(0, Rsq.max(), 21), 'k--', linewidth = 1, markersize = 3)
ax.plot(6.5, 0, 'ko')
ax.set_xlabel(r'$r_c$' + setup.Angstrom1)
ax.set_ylabel(r'$R^2$')
ax.set_ylim([0., 0.45])
setup.prune(ax, nbins = 6)

# inset plot and design
setup.params['xtick.labelsize'] = 6 ; setup.params['ytick.labelsize'] = 6
matplotlib.rcParams.update(setup.params)
ax_inset = fig.add_axes([0.74, 0.735, 0.2, 0.2])
ax_inset.plot(ld, fsw ,'rx', markersize = 1)
ax_inset.plot(ld, slope*ld+intercept, 'k-', linewidth = 1)
ax_inset.set_xlabel('monomer\ndensity', fontsize = 10)
ax_inset.set_ylabel('water\ndensity', fontsize = 10)
ax_inset.set_xlim([5,25]); ax_inset.set_ylim([0, 30])
setup.prune(ax_inset, nbins = 6)

# annotation
ax.annotate(r'$r_c = 6.5$' + setup.Angstrom2, xy = (6.6, 0.015))
ax_inset.annotate(r'$R^2 = $' + '%1.2f' % maxcoeff, xy = (7.1,21), fontsize = 7, fontweight = 'bold') 
Esempio n. 6
0
import matplotlib.pyplot as plt 
import matplotlib
from matplotlib.ticker import FixedLocator
import numpy as np
import sys

sys.path.append('../')
import setup
matplotlib.rcParams.update(setup.params)

x = [0,1,2,3,20,21,22,23,24,25]
y = [0.,1.0, 0.,0., 0.1, 0.15, 0.2, 0.3, 0.22, 0.08]

fig = plt.figure(figsize = (setup.set_width('single'), 2.5))
ax1 = fig.add_subplot(1,2,1)
ax2 = fig.add_subplot(1,2,2, sharey = ax1)
ax1.plot(x,y) ; ax2.plot(x,y)
ax1.set_xlim([0, 2]); ax2.set_xlim([20,25])

#ax1.set_ylim([0, 1.2]) ; ax2.set_ylim([0., 0.3])

setup.prune(ax1, nbins = 5) ; setup.prune(ax2, nbins = 5)
ax1.spines['right'].set_visible(False)
ax2.spines['left'].set_visible(False)
ax1.tick_right()

plt.show()
p = p1+p2+p3
labels = [this_p.get_label() for this_p in p]
if system == 'methane25': loc = 1
else: loc = 1
axL.legend(p, labels, loc = loc)

# Design
if system == 'c25': 
        mon = 'monomer'
        axR.set_ylim([0, 0.15])
        axL.set_ylim([-1.2, 0.1])
        axL.set_xlim([0, 24])
else: 
        mon = 'methane'
        axL.set_ylim([-1.6, 0.7])
for ax in [axL,axR]: setup.prune(ax, nbins = 6)
axL.set_xlabel('local density of %s' % mon)
axL.set_ylabel('potential ' + setup.energy)
axR.set_ylabel('distribution')
axL.yaxis.label.set_color('red'); axR.yaxis.label.set_color('blue')
axRFormat = FormatStrFormatter('%1.2f')
axR.yaxis.set_major_formatter(axRFormat)

# save figure
if system == 'c25': figname = 'c25_ld_dist_%s_%g.%s' % (fftype, LDCut, setup.params['savefig.format'])
else: figname = 'methane25_ld_dist_%s_%g.%s' % (fftype, LDCut, setup.params['savefig.format'])

fig.savefig(figname)

if setup.showPlots: plt.show()
Esempio n. 8
0
cgtypes = ['AA', 'SP', 'SPLD', 'LD']
styles = ['ro', 'k:', 'k-', 'k--']
fig = plt.figure(figsize = (setup.set_width('single'),2.8))
ax = fig.add_subplot(1,1,1)
for i, cgtype in enumerate(cgtypes):
        pickleName = os.path.join(data_dir, '%s_%s_%s.pickle' % (prop, fftype, cgtype))
        bin_centers, bin_vals = pickle.load(open(pickleName, 'r'))
        ax.plot(bin_centers, bin_vals, styles[i], label = cgtype)

# design
if prop == 'kappa': ax.set_xlim([0,0.3])
elif prop == 'Rg': ax.set_xlim([3,6.])

units = {'Rg': setup.Angstrom1, 'R_EE': setup.Angstrom1, 'kappa': '', 'SASA_atom': r'$\left(\mathrm{\AA}^2\right)$'}
prop_labels = {'Rg': r'$Rg$', 'R_EE': r'$R_{EE}$', 'kappa': r'$\kappa$', 'SASA_atom': r'$SASA \Big/ atom$'}
ax.set_xlabel(prop_labels[prop] + ' ' + units[prop])
ax.set_ylabel('distribution')
setup.prune(ax, nbins = 6)
if makeLegend: ax.legend()

# JCP_reviewer_suggestion
if prop == 'SASA_atom':
	ax.yaxis.set_major_formatter(FormatStrFormatter('%1.2f'))
	setup.prune(ax, nbins = 5)

# save figure
plt.savefig('c25_%s_%s_%g.%s' % (prop, fftype, LDCut, setup.params['savefig.format']))

if setup.showPlots: plt.show()
Esempio n. 9
0
	                  
	z = gaussian_filter(z_raw, sigma = smoothing_level[fftype])
	im2 = ax[i].contour(z, levels = levels, colors = contour_clr[cgtype], origin = 'lower', aspect = 'auto',
	                    interpolation = 'none', extent = [MIN_X, MAX_X, MIN_Y, MAX_Y])

	# superimpose AA contours on CG contours - request by JCP reviewer
	if cgtype == 'AA': AAdata = {'z': z, 'MAX_X': MAX_X, 'MIN_X': MIN_X, 'MAX_Y': MAX_Y, 'MIN_Y': MIN_Y}

	if not cgtype == 'AA':
		im3 = ax[i].contour(AAdata['z'], levels = levels, colors = contour_clr['AA'], origin = 'lower', aspect = 'auto',
						    interpolation = 'none', extent = [MIN_X, MAX_X, MIN_Y, MAX_Y])

	                	   	
# Design
for i in range(4): 
        setup.prune(ax[i], nbins = 6)
        if fftype == 'wca':
                ax[i].set_xlim([3.48,5.2])
                ax[i].set_ylim([4.0,9.2])
        if fftype == 'lj': 
                ax[i].set_xlim([3.48, 5.5])
                ax[i].set_ylim([4, 9.8])
        
ax[0].set_xticklabels([]); ax[1].set_xticklabels([])
ax[1].set_yticklabels([]); ax[3].set_yticklabels([])
ax[1].set_ylabel(''); ax[3].set_ylabel('')
plt.figtext(0.45, 0.0095, r'$Rg$' + setup.Angstrom1, fontsize = 10)
plt.figtext(0.00005, 0.55, r'$R_{EE}$' + setup.Angstrom1, fontsize = 10, rotation = 90)

# Annotation
lblpos = {'wca': [(4.4, 8.2), (4.0, 8.6), (4.6, 8.2), (4.6, 8)],
	        ind += 1
	      	      
#design
plt.figtext(0.5, 0.0005, prop_labels[prop] +' '+ units[prop] , fontsize = 10)
plt.figtext(0.0007, 0.65, 'distribution', fontsize = 10, rotation = 90)
for n, ax in enumerate(axs):
		ax.set_aspect('auto')
		ax.xaxis.labelpad = 0
		ax.yaxis.labelpad = 0
		if prop == 'Rg':
			nbins = 4
			if n == 0 or n == 5 or n == 10: ax.set_xlim([1, 4.0])
			if n == 1 or n == 6 or n == 11: ax.set_xlim([2.5, 5.5])
			if n == 2 or n == 7 or n == 12: ax.set_xlim([3., 5.])
			if n == 3 or n == 8 or n == 13: ax.set_xlim([3., 6.])
			if n == 4 or n == 9 or n == 14: ax.set_xlim([4., 6.5])
		elif prop == 'R_EE':
			nbins = 4
			if n == 5 or n == 10: ax.set_ylim([0., 0.4])
		else:
			nbins = 4

		setup.prune(ax = ax, nbins = nbins)
		if n == 0 or n == 5 or n == 10: ax.legend(loc = 'best')
		if n < 5: ax.set_title(clen[n])

# save figure
plt.savefig('rev_trans_%s_%s_%g.%s' % (prop, fftype, LDCut, setup.params['savefig.format']))

if setup.showPlots: plt.show()
cgtypes = ['AA', 'SP', 'SPLD']
styles = ['ro', 'k:', 'k-']

# plot and design of master 
fig = plt.figure(figsize = (setup.set_width('single'),2.8))
ax = fig.add_subplot(1,1,1)
for i, cgtype in enumerate(cgtypes):
        pickleName = '%s_%s.pickle' % (prefix, cgtype)
        data = pickle.load(open(pickleName, 'r'))
        bin_centers = data[0]; bin_vals = data[1]
        ax.plot(bin_centers, bin_vals, styles[i], label = cgtype)

ax.set_xlabel('size of methane cluster')
ax.set_ylabel('distribution')
ax.xaxis.set_major_formatter(FormatStrFormatter('%d'))
setup.prune(ax)
ax.legend()

# plot and design of inset
setup.params['xtick.labelsize'] = 6 ; setup.params['ytick.labelsize'] = 6
matplotlib.rcParams.update(setup.params)
ax_inset = fig.add_axes([0.5, 0.3, 0.3, 0.3])
for i, cgtype in enumerate(cgtypes):
        pickleName = '%s_%s.pickle' % (prefix, cgtype)
        data = pickle.load(open(pickleName, 'r'))
        bin_centers = data[0]; bin_vals = data[1]
        ax_inset.plot(bin_centers[-6:], bin_vals[-6:], styles[i])

ax_inset.xaxis.set_major_formatter(FormatStrFormatter('%d'))
setup.prune(ax = ax_inset, nbins = 4)
Esempio n. 12
0
data_dir = os.path.join(setup.data_dir, 'JCP_review_data')
Nmon = [25, 40, -1]
styles = {25: 'r-', 40: 'b-', -1: 'g-'}
lbls = {25: 'c25 AA', 40: 'c40 AA', -1: 'c40 SPLD'}


fig = plt.figure(figsize = (setup.set_width('single'),3))
ax = fig.add_subplot(1,1,1)

for n in Nmon:
	if n == -1: ldpickle = os.path.join(data_dir, 'c40_SPLD_ld.pickle')
	else: ldpickle = os.path.join(data_dir, 'c%d_ld.pickle' % n)
	r,g,e,f,x = pickle.load(open(ldpickle, 'r'))
	if n == 25: 
		r = r[:-4]
		g = g[:-4]
	ax.plot(r,g, styles[n], label = lbls[n])

ax.set_xlabel('local density of monomer')
ax.set_ylabel('distribution')
ax.legend(loc = 'best')

ax.set_xlim([0, 45])
ax.set_ylim([0, 0.12])
ax.yaxis.set_major_formatter(FormatStrFormatter('%1.2f'))
setup.prune(ax, nbins = 8)

figname = 'ld_comp.%s' % setup.params['savefig.format']
fig.savefig(figname)

plt.show()