-
Notifications
You must be signed in to change notification settings - Fork 0
/
simtools.py
executable file
·195 lines (155 loc) · 5.46 KB
/
simtools.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
import numpy as np
import os
import numpy as np
import analyzetool
import analyzetool.gas as gasAnalyze
import analyzetool.liquid as liqAnalyze
import warnings
warnings.filterwarnings('ignore') # make the notebook nicer
KB_J = 1.38064852e-23 #J/K
E0 = 8.854187817620e-12
N_vis = 8.91e-4 #Pa.s
R=1.9872036E-3
NA=6.02214129*(1e23)
KB = 1.38064852E-16 #J/K
statC=4.80320425E-10
charge = 1.602176634E-19
deb_conv = ((1e-20)*(charge/statC))
P_PA = 101325.0
#Water constants
MW = 18.01528 #g/mol
def box_size(dens,N=512):
density=dens*(1e-27)
mol_w = MW/NA
bs = np.cbrt((N*mol_w)/density)
return bs
def num_molecules(box_size,MW,dens):
density=dens/(1e24)
mol_w = MW/NA
num_molecules = (np.power(box_size,3)*density)/mol_w
return np.rint(num_molecules)
def calc_density(box_size,n_mol,MW):
mol_w = MW/NA
dens = (n_mol*mol_w)/(np.power(box_size,3))
return dens*(1e24)
def calc_box_s(n_mol,MW,dens):
density=dens/(1e24)
mol_w = MW/NA
box_s = np.cbrt((n_mol*mol_w)/density)
return box_s
### Temperature dependence analysis
def process_liqtemp(base_dir,equil=500,gas_dir=None,exclude=[],angles=False):
sdirs = next(os.walk(base_dir))[1]
temps = []
for fn in sdirs:
try:
t = int(fn.split('_')[1])
temps.append(t)
except:
None
temps = sorted(temps)
resdir = f'{base_dir}/results'
os.system(f'mkdir -p {resdir}')
results = []
stdres = []
prop_mol = []
temp_list = np.array([248.15, 258.15, 268.15, 277.15, 288.15, 298.15, 308.15, 318.15,
328.15, 336.15, 343.15, 353.15, 363.15, 373.15, 383.15, 398.15,
408.15, 423.15, 243.15, 253.15, 263.15, 273.15, 283.15, 293.15,
303.15, 313.15])
for tsav in temps:
#for T in temp_list:
#tsav = int(T)
T = tsav + 0.15
sim_path = f'{base_dir}/sim_{tsav}'
if T in exclude or tsav in exclude:
continue
if gas_dir is not None:
gas_path = f"{gas_dir}/sim_{tsav}"
else:
gas_path = sim_path
PEmol = 0
try:
if os.path.isfile(f'{sim_path}/analysis.log'):
liquid = liqAnalyze.Liquid(sim_path,'liquid.xyz',3,T,equil,
logfile='liquid.log',analyzelog='analysis.log',gaslog=f'{gas_path}/gas.log')
liquid.all_properties(f'{gas_path}/gas.log',f'{sim_path}/analysis.log')
error = False
PEmol = liquid.PEmol
else:
error = True
except:
print(f"Something wrong with {tsav} K simulation")
error = True
try:
liquid.get_diffusion(f'{sim_path}/diffusion.log')
except:
None
avg_angle = 0
if angles:
liquid.get_coordinates(f'{sim_path}/liquid.arc')
liquid.compute_avg_angle()
avg_angle = liquid.avg_angle
if not error:
if np.abs(PEmol) > 0:
results.append([T,liquid.avgRho,liquid.HV,0,0,liquid.kappa,liquid.dielectric,
liquid.median_diffusion,avg_angle])
#stdres.append([T,liquid.stdRho,liquid.stdHV-liquid.stdGasPE,liquid.stdCp, liquid.stdAlpha,
stdres.append([T,liquid.stdRho,liquid.stdHV,liquid.stdCp, liquid.stdAlpha,
liquid.stdKappa,liquid.stdEps,0,0])
prop_mol.append([T,liquid.PEmol,liquid.avgVol])
#print(T,liquid.PEmol,liquid.avgVol)
stdres = np.array(stdres)
PE_temp = np.array(prop_mol)[:,1]
Vol_temp = np.array(prop_mol)[:,2]
temp = np.array(prop_mol)[:,0]
#print(prop_mol)
aa = np.polyfit(temp,(1000*PE_temp),5)
pol = np.poly1d(aa)
ders1 = np.polyder(pol)
cp = ders1(temp)+(9.0/2.0)*(1e3)*R
aa = np.polyfit(temp,Vol_temp,6)
pol = np.poly1d(aa)
ders = np.polyder(pol)
ap = ders(temp)/(Vol_temp)
for k, res in enumerate(results):
results[k][3] = cp[k]
results[k][4] = ap[k]
np.save(f'{resdir}/prop_vs_T.npy',results)
np.save(f'{resdir}/std_vs_T.npy',stdres)
def process_liqpres(base_dir,equil=500):
sdirs = next(os.walk(base_dir))[1]
temps = []
for fn in sdirs:
try:
t = int(fn.split('_')[1])
temps.append(t)
except:
None
temps = sorted(temps)
resdir = f'{base_dir}/results'
os.system(f'mkdir -p {resdir}')
results = []
stdres = []
for tsav in temps:
#for T in temp_list:
#tsav = int(T)
T = tsav + 0.15
sim_path = f'{base_dir}/sim_{tsav}'
PEmol = 0
try:
if os.path.isfile(f'{sim_path}/analysis.log'):
liquid = liqAnalyze.Liquid(sim_path,'liquid.xyz',3,T,equil,
logfile='liquid.log',analyzelog='analysis.log',gaslog=None)
error = False
PEmol = liquid.PEmol
else:
error = True
except:
print(f"Something wrong with {tsav} K simulation")
error = True
if not error:
if np.abs(PEmol) > 0:
results.append([T,liquid.avgRho,liquid.stdRho])
results = np.array(results)
np.save(f'{resdir}/prop_vs_T.npy',results)