In [1]:
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.legend_handler import HandlerLine2D
import matplotlib.lines as mlines
from scipy.interpolate import interp1d
from scipy.interpolate import griddata
In [2]:
# phi1 phi2
#This is the phi/psi data from the 2CV PBMetaD simulation, no correction
# phi psi theta zeta vbias phi-ctL phi-ctM psi-ctL psi-ctM
## 0 1 2 3 4 5 6 7 8
data=np.genfromtxt('ALA2/PBMetad-2D/rewfileall',comments='#')
#make 2D histogram then replace all zeros with 1e-15
In [3]:
bins=50
temp=300
beta=1/8.314e-3/temp
# phi psi theta zeta vbias phi-ctL phi-ctM psi-ctL psi-ctM
ang1wt1, xedges, yedges = np.histogram2d(data[:,0],data[:,1], bins=bins,normed=True,weights=np.exp(beta*(data[:,4]-data[:,7])))
#ang1wt1=np.transpose(ang1wt1) #verify the X/Y coord on your own
# this makes a very small prob = very high free-energy (40kT)
ang1wt1[ang1wt1 == 0 ] = 1e-17
ang1wt2, xedges2, yedges2 = np.histogram2d(data[:,0],data[:,1], bins=bins,normed=True,weights=np.exp(beta*(data[:,4]-data[:,8])))
#ang1wt1=np.transpose(ang1wt1) #verify the X/Y coord on your own
# this makes a very small prob = very high free-energy (40kT)
ang1wt2[ang1wt2 == 0 ] = 1e-17
In [4]:
%matplotlib inline
ang1wt1=np.transpose(ang1wt1)
#what spacing do you want?
spacer=1
lines=20 #this goes to kt
levels=np.linspace(0,lines*spacer,num=(lines+1),endpoint=True)
fig=plt.figure(figsize=(10,8))
axes = fig.add_subplot(111)
plt.contourf(xedges[1::], yedges[1::], -1.0*np.log(ang1wt1),levels, cmap=plt.cm.bone,)
plt.colorbar()
plt.xlabel('$\Phi 1$')
plt.ylabel('$\Psi 2$')
plt.title('ALA2 FES, PBMetaD rew from ludovico method ')
#axes.set_ylim([.1,.5])
#axes.set_xlim([0.1,0.5])
plt.rcParams.update({'font.size': 18})
plt.show()
In [14]:
%matplotlib inline
ang1wt1=np.transpose(ang1wt1)
#what spacing do you want?
spacer=1
lines=10 #this goes to kt
levels=np.linspace(0,lines*spacer,num=(lines+1),endpoint=True)
fig=plt.figure(figsize=(10,8))
axes = fig.add_subplot(111)
plt.contourf(xedges2[1::], yedges2[1::], -1.0*np.log(ang1wt2),levels, cmap=plt.cm.bone,)
plt.colorbar()
plt.xlabel('$\Phi 1$')
plt.ylabel('$\Psi 2$')
plt.title('ALA2 FES, PBMetaD rew from max method ')
#axes.set_ylim([.1,.5])
#axes.set_xlim([0.1,0.5])
plt.rcParams.update({'font.size': 18})
plt.show()
In [4]:
%matplotlib inline
#2D FES from PT simulation
#read the data in from a text file
fesdata = np.genfromtxt('ALA2/WTM-2/fes.dat.100',comments='#');
dim1=50
dim2=50
fesdata = fesdata[:,0:3]
enertokcal=8.314e-3*300
#some post-processing to be compatible with contourf
X=np.reshape(fesdata[:,0],[dim1,dim2],order="F") #order F was 20% faster than A/C
Y=np.reshape(fesdata[:,1],[dim1,dim2],order="F")
Z=np.reshape((fesdata[:,2]-np.min(fesdata[:,2])),[dim1,dim2],order="F") #convert to kcal/mol
#what spacing do you want?
spacer=1.0
lines=20 #this goes to 80 kcal/mol (2*40)
levels=np.linspace(0,lines*spacer,num=(lines+1),endpoint=True)
fig=plt.figure(figsize=(6,5))
axes = fig.add_subplot(111)
plt.contourf(X, Y, Z/enertokcal, levels, cmap=plt.cm.bone,)
plt.colorbar()
plt.xlabel('$\Phi$')
plt.ylabel('$\Psi$')
plt.title('ALA2 FES from WTM code')
plt.rcParams.update({'font.size': 18})
plt.show()
In [9]:
%matplotlib inline
#2D FES from PT simulation
#read the data in from a text file
fesdata2 = np.genfromtxt('ALA2/whamfes.dat',comments='#');
dim1=50
dim2=50
fesdata2 = fesdata2[:,0:3]
enertokcal=8.314e-3*300
#some post-processing to be compatible with contourf
#X2=np.reshape(fesdata2[:,0],[dim1,dim2],order="F") #order F was 20% faster than A/C
#Y2=np.reshape(fesdata2[:,1],[dim1,dim2],order="F")
#Z2=np.reshape((fesdata2[:,2]-np.min(fesdata2[:,2])),[dim1,dim2],order="F") #convert to kcal/mol
#what spacing do you want?
spacer=1.0
lines=20 #this goes to 80 kcal/mol (2*40)
levels=np.linspace(0,lines*spacer,num=(lines+1),endpoint=True)
fig=plt.figure(figsize=(3.5,3))
axes = fig.add_subplot(111)
plt.contourf(X2, Y2, Z2/enertokcal, levels, cmap=plt.cm.bone,)
plt.colorbar()
plt.xlabel('$\Phi$')
plt.ylabel('$\Psi$')
#plt.title('ALA2 FES from WHAM2D code')
plt.rcParams.update({'font.size': 12})
plt.show()
In [219]:
%matplotlib inline
#2D FES from PT simulation
#read the data in from a text file
enertokcal=8.314e-3*300
#what spacing do you want?
spacer=0.1
lines=20 #this goes to 80 kcal/mol (2*40)
levels=np.linspace(0,lines*spacer,num=(lines+1),endpoint=True)
fig=plt.figure(figsize=(5,4))
axes = fig.add_subplot(111)
plt.contourf(X, Y, np.abs(Z-Z2)/enertokcal, levels, cmap=plt.cm.bone,)
plt.colorbar()
plt.xlabel('$\Phi$')
plt.ylabel('$\Psi$')
plt.title('diff WTM WHAM ')
plt.rcParams.update({'font.size': 18})
plt.show()
In [20]:
def klD(var,var2,kt):
#where var = current , var2 = ref
RMSD=np.sqrt(np.sum(np.multiply(np.power(((var-var.mean())-(var2-var2.mean()))/kt,2), \
np.exp(-var2/kt)))/np.sum(np.exp(-var2/kt)))
return RMSD
In [22]:
def RMSDcut(var,var2,kt,nu):
#where var = current , var2 = ref
top=0
bot=0
for i,j in np.nditer([var,var2]):
if (j<nu):
#top=top+np.sum( np.power(((var-var.mean())-(var2-var2.mean()))/kt,2) )
top=top+np.sum( np.power(((i-var.mean())-(j-var2.mean()))/kt,2) )
bot=bot+1
RMSD=np.sqrt(top/bot)
return RMSD
In [236]:
gX, gY = np.mgrid[-1.0*np.pi:np.pi:50j, -1.0*np.pi:np.pi:50j]
gX, gY = np.mgrid[-3.0:3.0:50j, -3.0:3.0:50j ]
In [237]:
Znew=griddata(fesdata[:,:2],fesdata[:,2],(gX, gY),method='cubic',fill_value=1000)
Z2new=griddata(fesdata2[:,:2],fesdata2[:,2],(gX, gY),method='cubic',fill_value=1000)
In [244]:
np.sqrt(np.sum(np.power(Znew-Z2new,2)))
klD(Znew,Z2new,enertokcal)
Out[244]:
In [239]:
%matplotlib inline
enertokcal=8.314e-3*300
#
#what spacing do you want?
spacer=0.05
lines=20 #this goes to 80 kcal/mol (2*40)
levels=np.linspace(0,lines*spacer,num=(lines+1),endpoint=True)
fig=plt.figure(figsize=(6,4))
axes = fig.add_subplot(111)
plt.contourf(gX,gY,np.abs(Z2new-Znew)/enertokcal, levels, cmap=plt.cm.bone,)
plt.colorbar()
plt.xlabel('$\Phi$')
plt.ylabel('$\Psi$')
plt.title('diff ALA2 WHAM2D vs WTM in kT')
plt.rcParams.update({'font.size': 18})
plt.show()
In [165]:
def RMSDcut(var,var2,kt,nu):
#where var = current , var2 = ref
top=0
bot=0
for i,j in np.nditer([var,var2]):
if (j<nu):
#top=top+np.sum( np.power(((var-var.mean())-(var2-var2.mean()))/kt,2) )
top=top+np.sum( np.power(((i-var.mean())-(j-var2.mean()))/kt,2) )
bot=bot+1
RMSD=np.sqrt(top/bot)/kt
return RMSD
In [173]:
def klD(var,var2,kt):
#where var = current , var2 = ref
RMSD=np.sqrt(np.sum(np.multiply(np.power(((var-var.mean())-(var2-var2.mean()))/kt,2), \
np.exp(-var2/kt)))/np.sum(np.exp(-var2/kt)))
return RMSD/kt
In [221]:
print RMSDcut(Z,Z2,enertokcal,enertokcal*6)
print klD(Z,Z2,enertokcal)
In [233]:
print RMSDcut(Znew,Z2new,enertokcal,enertokcal*6)
print klD(Znew,Z2new,enertokcal)
In [201]:
fesdata = np.genfromtxt('ALA2/WTM-2/fes.dat.2',comments='#')
#fesdata = fesdata[:,0:3]
fesdata2 = np.genfromtxt('ALA2/whamfes.dat',comments='#')
gX, gY = np.mgrid[-1.0*np.pi:np.pi:50j, -1.0*np.pi:np.pi:50j]
Znew=griddata(fesdata[:,:2],fesdata[:,2],(gX, gY),method='cubic',fill_value=1000)
Z2new=griddata(fesdata2[:,:2],fesdata2[:,2],(gX, gY),method='cubic',fill_value=1000)
print RMSDcut(Z,Z2,enertokcal,enertokcal*6)
print klD(Z,Z2,enertokcal)
In [202]:
print X-X2
In [ ]: