-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKB.py
165 lines (111 loc) · 3.15 KB
/
KB.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/usr/bin/python
import numpy as np
import copy as copy
import math
import matplotlib.pyplot as plt
for file in ['Original_FF','minus_6','minus_4','16','12','8']:
if file == 'Original_FF':
V=65.1065
#break #average volume of simulatin box
elif file == 'minus_6':
V=53.2044
#break
elif file=='minus_4':
V=54.3159
#break
elif file=='8':
V=56.7635
#break
elif file=='12':
V=57.5747
#break
elif file=='16':
V=58.5029
#break
inp=open('rdf_%s_25.xvg' % file,'r')
in_name='RDF'
R=[]
g=[]
for line in inp:
line=line.split()
R.append(float(line[0]))
g.append(float(line[1]))
print 'R'
print len(R)
##############################delta Nsw(r)############################################
g_m=[] #the function of [gsw(r)-1]*r^2
delta_N=[] # the integration of [gsw(r)-1]*r^#
#d_delta_N=[] #deviation of delta_N
N=1056 #number of water molecule in box
Avg_density = N/V #molecular density
f1=4*math.pi*Avg_density #constate
f3=4*math.pi
# calculating f1*[gsw(r)-1]*r^2, named as g_m
i=0
while i<len(R):
tem1=f1*(g[i]-1)*((R[i])**2)
g_m.append(tem1)
i=i+1
# integral of f1*[gsw(r)-1]*r^2, named as delta_N
j=1
sum=0
while j<len(R):
sum=sum+(g_m[j-1]+g_m[j])*(R[j]-R[j-1])*0.5
delta_N.append(sum)
j=j+1
print 'delta_N'
print len(delta_N)
out=open('delta_N_%s.xvg' % file,'w')
k=0
while k<len(delta_N):
out.write(str(R[k])+' '+str(delta_N[k])+'\n')
k=k+1
out.close()
##############################corrected rdf########################################
g_c=[] #correction of radail distribution function
f2=(4/3)*math.pi #constant
k=0
# calculation of corrected radial distribution function, named as g_correct
while k<len(R)-1:
Volume_rate =1-(f2*(R[k]**3)/43.2952)
tem3=(g_m[k])*N*Volume_rate/((N*Volume_rate)-delta_N[k])
g_c.append(tem3)
k=k+1
print 'g_c'
print len(g_c)
################################RKBI calculation#######################################
G=[] # Kirkwood buff integral
delta_G=[] # integrating function [g_c-1]*r^2
f3=4*math.pi #constant
#calculation of integrating function [g_c-1]*r^2, named as delta_G
u=0
while u<len(g_c):
tem4=f3*(g_c[u]-1)*((R[u])**2)
delta_G.append(tem4)
u=u+1
print 'delta_G'
print len(delta_G)
#calculation of RKBI, named as G
h=1
sum=0
while h<len(delta_G):
sum=sum+(delta_G[h-1]+delta_G[h])*(R[h]-R[h-1])*0.5
G.append(sum)
h=h+1
print 'G'
print len(G)
##############################save and plot the corrected RDF#######################
R_1=[] # since the dimension of R and g_c isn't same, let's make a new R_1
m=0
while m<len(G):
R_1.append(R[m])
m=m+1
plt.plot(R_1,G,'r-')
plt.show()
R_2=[]
m=0
while m<len(delta_N):
R_2.append(R[m])
m=m+1
plt.plot(R_2,delta_N,'r-')
plt.show()