-
Notifications
You must be signed in to change notification settings - Fork 1
/
pub_ready_fes_2d.py
executable file
·127 lines (105 loc) · 2.99 KB
/
pub_ready_fes_2d.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import numpy as np
import pickle
import matplotlib as mpl
#mpl.use('Agg')
from matplotlib.ticker import MaxNLocator
import matplotlib.pyplot as plt
import re
fes_file = "fes10.dat"
mpl.rc('image',cmap='magma')
#need the number of bins in each axis of the grid.
cutoffs = [-0.035, 0.035, -0.035, 0.035]
data=np.loadtxt(fes_file)
pattern=re.compile('nbins')
grid_dims=[0,0]
ind=0
x_label_text=''
y_label_text=''
plot_levels=range(0,160,2)
for i, line in enumerate(open(fes_file)):
if i==0:
temp_line=line
temp_line=line.split(' ')
x_label_text=temp_line[2]
y_label_text=temp_line[3]
x_label_text=x_label_text.split('.')[0]
y_label_text=y_label_text.split('.')[0]
for i, line in enumerate(open(fes_file)):
for match in re.finditer(pattern, line):
#print ('Found on line %s: %s' % (i+1, match.group()))
#print(line)
if re.search('nbins',str(line)):
nbin_line=line
nbin_line=nbin_line.split(' ')
nbins=np.int(nbin_line[-1])
grid_dims[ind]=nbins
ind=ind+1
#print(grid_dims)
x,y,z=(data[:,0],data[:,1],data[:,2])
#z = z[x<-0.015]
#z = z[x>0.025]
#
#y = y[x<-0.015]
#y = y[x>0.025]
#
#z = z[y<-0.015]
#z = z[y>0.025]
#
#x = x[y<-0.015]
#x = x[y>0.025]
x=np.reshape(x,grid_dims)
y=np.reshape(y,grid_dims)
z=np.reshape(z,grid_dims)
print(np.shape(z))
#z = z[x<-0.015]
#z = z[x>0.025]
#
#y = y[x<-0.015]
#y = y[x>0.025]
#
#z = z[y<-0.015]
#z = z[y>0.025]
#
#x = x[y<-0.015]
#x = x[y>0.025]
#print (type(x))
#print ((x))
type(x)
# x and y are bounds, so z should be the value *inside* those bounds.
# Therefore, remove the last value from the z array.
#z = z[:-1, :-1]
#z_min, z_max = np.abs(z).max(), -np.abs(z).min()
#
fig, ax = plt.subplots()
#c = ax.contourf(x, y, z, cmap='RdBu', vmin=z_min, vmax=z_max,rasterized=True)
#levels = MaxNLocator(nbins=15).tick_values(z_min, z_max)
print(np.min(z))
z=z-np.min(z)
#c = ax.contour(x, y, z,levels=plot_levels,cornor_mask=True)
c = ax.contour(x, y, z,levels=plot_levels,colors='k',linewidths=0.6)
c = ax.contourf(x, y, z,levels=plot_levels)
ax.set_title('Free Energy Surface of Opening Coordinates.')
# set the limits of the plot to the limits of the data
#ax.axis([x.min(), x.max(), y.min(), y.max()])
ax.axis(cutoffs)
ax.set_xlabel(x_label_text)
ax.set_ylabel(y_label_text)
fig.colorbar(c, ax=ax)
def format_coord(xt, yt):
xarr = x[0,:]
yarr = y[:,0]
if ((xt > xarr.min()) & (xt <= xarr.max()) &
(yt > yarr.min()) & (yt <= yarr.max())):
col = np.searchsorted(xarr, xt)-1
row = np.searchsorted(yarr, yt)-1
zt = z[row, col]
return f'xt={xt:1.4f}, yt={yt:1.4f}, zt={zt:1.4f}'
#return f'zt={zt:1.4f}'
else:
return f''
ax.format_coord = format_coord
#plt.savefig('fes.pdf',dpi=2000)
plt.tight_layout()
#pickle.dump(fig, open('FigureObject.fig.pickle', 'wb')) # This is for Python 3 - py2 may need `file` instead of `open`
#plt.savefig('FES_temp.pdf')
plt.show()