def getPotential(system, cgtype, fftype):
	if cgtype == 'AA': cgtype = 'LD'
	if cgtype == 'LD': pType = '%s_AA' % fftype.upper()
	else: pType = 'SP'
	filePrefix = os.path.join(data_dir_potentials[system], '%s_%s_%s' % (system, fftype, cgtype))
	logfile, histfile, sumfile = pp.parseFileNames(filePrefix)
	r, pot = pp.parseLog(sumfile)[pType]
	r = np.append(r, np.linspace(r[-1], r[-1]*5.0, 20))
	pot = np.append(pot, np.zeros(20))
	return r, pot
Exemplo n.º 2
0
#!/usr/bin/env python
import os, sys
import matplotlib
import matplotlib.pyplot as plt

# Build dependencies
sys.path.append('../')
import setup
import parse_potential as pp
matplotlib.rcParams.update(setup.params)

# data paths
prefix = '/home/tanmoy/projects/paper1_plots/data/FORCEFIELDS/cgff_methane25_newrc_50LDKnots/methane25_wca_SPLD'
logfile, histfile, sumfile = pp.parseFileNames(prefix)
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-')
import matplotlib
import matplotlib.pyplot as plt

sys.path.append('../')
import setup
import parse_potential as pp
data_dir = os.path.join(setup.data_dir, 'JCP_review_data', 'cgff_methane_errorbar')
setup.params['lines.linewidth'] = 1.0
matplotlib.rcParams.update(setup.params)

runs = [1,2,3,5]
r_set = []
p_set = []
for run in runs:
    sumfile = os.path.join(data_dir, 'm25_%d_SPLD_sum.txt' % run)
    r, p = pp.parseLog(sumfile)['LD']
    p -= p[0]
    r_set.append(r)
    p_set.append(p)

r = np.array(r_set)
p = np.array(p_set)
mu = np.mean(p, axis = 0)
sigma = np.std(p, axis = 0, ddof = 1)

fig = plt.figure(figsize = (setup.set_width('single'), 2.4))
ax = fig.add_subplot(1,1,1)
ax.errorbar(r[0,:], mu, yerr = sigma, color = 'black')
ax.set_xlim([0, 5])
ax.set_ylim([-0.8, 0.6])
ax.set_xlabel('local density of methane')
import setup
matplotlib.rcParams.update(setup.params)
data_dir = os.path.join(setup.data_dir, 'TIP4P')

rhos = [1020, 1100, 1170, 1250]
temp = 300
cgtype = 'SP'
styles = ['r-', 'g-', 'b-', 'k-']
		
fig = plt.figure(figsize = (4,3))
ax= fig.add_subplot(1,1,1)
for j, rho in enumerate(rhos):
        prefix = os.path.join(data_dir, 'R%dT%d_%s' % (rho, temp, cgtype))
        sumfile = pp.parseFileNames(prefix)[2]
        r, potential = pp.parseLog(sumfile)['SP']
        ax.plot(r, potential, styles[j], label = r'$\rho = $' + str(rho) + r'$(kg/m^3)$')
       
	# design
	ax.set_xlabel(r'$r (\AA)$'); ax.set_ylabel('potential '+ r'$(kcal/mol)$')
	ax.set_xlim([2, 4.5]); ax.set_ylim([-1.5, 5])
	ax.set_xticks(np.arange(2,4.5, 10)); ax.set_yticks(np.arange(-1.5, 5, 10))
	setup.prune(ax)
	leg = ax.legend()
				
# annotation
ax.annotate('300 K', xy =  (3.5, 1))

# save figure					
fig.savefig('TIP4P_cg_potential.%s' % setup.params['savefig.format'])
fftype = sys.argv[1]
LDCut = sys.argv[2]

if LDCut == 7.8: suffix = 'new'
else: suffix = 'old'

data_dir = '../data/FORCEFIELDS/cgff_c25_%src' % suffix
SPLog = os.path.join(data_dir, 'c25_%s_SP_sum.txt' % fftype)
SPLDLog = os.path.join(data_dir, 'c25_%s_SPLD_sum.txt' % fftype)
LDLog = os.path.join(data_dir, 'c25_%s_LD_sum.txt' % fftype)

fig = plt.figure(figsize = (8,4))
ax1 = fig.add_subplot(1,2,1)
ax2 = fig.add_subplot(1,2,2)

r_SP = pp.parseLog(SPLog)['SP'][0] ; p_SP = pp.parseLog(SPLog)['SP'][1]
r_SPLD_SP = pp.parseLog(SPLDLog)['SP'][0] ; p_SPLD_SP = pp.parseLog(SPLDLog)['SP'][1]
r_SPLD_LD = pp.parseLog(SPLog)['LD'][0] ; p_SPLD_LD = pp.parseLog(SPLDLog)['LD'][1]
r_LD = pp.parseLog(LDLog)['LD'][0] ; p_LD = pp.parseLog(LDLog)['LD'][1]
r_LJ = pp.parseLog(LDLog)['%s_AA' % fftype.upper()][0] ; p_LJ = pp.parseLog(LDLog)['%s_AA' % fftype.upper()][1]

ax1.plot(r_LJ, p_LJ, 'ro-', markersize = 2, label = '%s_{AA}' % fftype.upper())
ax1.plot(r_SP, p_SP, 'b-', label = 'SP only')
ax1.plot(r_SPLD_SP, p_SPLD_SP, 'k-', label = 'SP (SPLD)')
if fftype == 'lj': ax1.set_xlim([3., 9.]); 
else: ax1.set_xlim([3., 6.])
ax1.set_ylim([-0.2, 0.5])

p_SPLD_LD -= p_SPLD_LD[0]
p_LD -= p_LD[0]
ax2.plot(r_SPLD_LD, p_SPLD_LD, 'k-', label = 'LD (SPLD)')
linest = ['r-', 'b-', 'g--', 'k:']
for i, cgtype in enumerate(cgtypes):
	prefix = os.path.join(ffdir, 'c25_%s_%s' % (fftype, cgtype))
	logname, histname = pp.parseFileNames(prefix)
	hist = pp.parseHist(histname, '', []) 
	hist = hist['LD']
	r_t = hist[0]; h_t = hist[1]; r_m = hist[2]; h_m = hist[3]
	if (i==0):
		ax1.plot(r_t, h_t, linest[0], markersize = 10, label = 'AA')
	ax1.plot(r_m, h_m, linest[i+1], label = cgtypes[i])
	

for cgtype in ['SPLD', 'LD']:
	prefix = os.path.join(ffdir, 'c25_%s_%s' % (fftype, cgtype))
	logname, histname = pp.parseFileNames(prefix)
	log = pp.parseLog(logname)
	log = log['LD']
	r = log[0]; pot = log[1]
	if cgtype == 'SPLD':
		pot_linest = 'g-'
	elif cgtype == 'LD':
		pot_linest = 'k-'
	ax2.plot(r, pot, pot_linest, label = cgtype)
	
# Design
for ax in [ax1,ax2]:
	leg = ax.legend()
	leg.get_frame().set_linewidth(0.0)
	ax.set_xlabel('local density of monomer')
	ax.xaxis.set_major_locator(MaxNLocator(nbins = 8, prune = 'both'))
	ax.yaxis.set_major_locator(MaxNLocator(nbins = 8, prune = 'both'))