-
Notifications
You must be signed in to change notification settings - Fork 4
/
run_Hautman.m
190 lines (163 loc) · 5.87 KB
/
run_Hautman.m
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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This file runs the calculation of contact angle of a liquid droplet
% on a solid surface through the method of Hautman and Kelin (1991)
%
% Author: Mohammad Khalkhali, Sep 2016
% References:
% Khalkhali et al. J. Chem. Phys. (2017)
% J. Hautman and M. L. Klein, Physical Review Letters 67, 1763 (1991).
%
% This program is a free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published
% by the Free Software Foundation, either version 3 of the License, or
% any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details: http://www.gnu.org/licenses/
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc;
clear all;
fclose ('all');
close('all');
addpath('../MK');
trajName = '../Graphite_Water(3nm)/Graphite_Water.lammpstrj';
% This format_spec is needed when reading lammps trajectories in
% read_LAMMPS_traj function. There are 5 entries at each line of our
% trajectories
format_spec = '%f %f %f %f %f';
StartStep = 4990000;
EndStep = 5000000;
step = 1000;
% Parameters of hit-and-count function (refer to the publication for details)
binsize=2;
numer_atom_in_bin=5;
% Parameters of fine_percision function (refer to the publication for details)
% fine presicion step of identifying droplet limits is usually redundant
% (hit and count step is sufficient).
fine_percision_check = 0; % calls fine_percision function if is 1
delta_R = 5;
R_step = 1;
% Draws graphs corresponding to each step for the first time step. It is
% recommended to check if parameters droplet identification process are
% ajusted properly.
graphcheck = 0;
Angle=[];
ii = 0;
Ro_0 = 0.033; %Number density of water in bulk
Z_cm = 0;
syms x
PATH = pwd;
PI = 3.14159265359;
theta = zeros((EndStep-StartStep)/step+1,1);
ii = 0;
for tt = StartStep:step:EndStep
ii = ii + 1;
fprintf('Current time step = %d\r', tt);
Filename = sprintf('%s.%d',trajName,tt); %trajectory file name
% Reading box dimentions to calculates centre of mass of water
% molecules correctly: some water molecules may pass the boundary.
% Since it is a NVT simulation we just need to read box dimentions
% once.
if (tt == StartStep)
fileID = fopen(Filename,'r');
if (fileID < 0)
fprintf('can not open %s file',Filename);
break;
end
%reading box sizes
header = textscan(fileID, '%s',9,'delimiter', '\n');
data = textscan(header{1}{6},'%f %f');
Box_x = data{2}-data{1};
data = textscan(header{1}{7},'%f %f');
Box_y = data{2}-data{1};
data = textscan(header{1}{8},'%f %f');
Box_z = data{2}-data{1};
fclose(fileID);
end
[fileID,x_org,y_org,z_org] = read_LAMMPS_traj(Filename,Box_x,...
Box_y,Box_z,format_spec);
if (fileID < 0)
fprintf('can not open %s file',Filename);
break;
end
% Drawing the droplet before applying hit-and-run
if (tt == StartStep && graphcheck == 1)
figure;
scatter3(x_org,y_org,z_org,...
'MarkerEdgeColor','k',...
'MarkerFaceColor',[0 .25 .25]);
view(45,45)
title('original');
size1 = size(x_org,1);
axis tight
end
% Applying hit and count method to remove outliers
[x_final,y_final,z_final] = hit_and_count(x_org,...
y_org,z_org,binsize,numer_atom_in_bin);
if (tt == StartStep && graphcheck == 1)
figure;
scatter3(x_final,y_final,z_final,...
'MarkerEdgeColor','k',...
'MarkerFaceColor',[0 .25 .25]);
view(45,45)
size2 = size(x_final,1);
str = sprintf('After hit-and-count (%d points were removed)', ...
size1-size2);
title(str);
axis tight
end
% Applying fine precission method to remove near droplet outliers
if (fine_percision_check == 1)
[x_final,y_final,z_final] = fine_percision(x_final,y_final,...
z_final,R_step,delta_R);
end
if (tt == StartStep && graphcheck == 1)
figure;
scatter3(x_final,y_final,z_final,...
'MarkerEdgeColor','k',...
'MarkerFaceColor',[0 .25 .25]);
view(45,45)
size3 = size(x_final,1);
str = sprintf('After hit-and-count and fine-percision (%d points were removed)', ...
size2-size3);
title(str);
axis tight
end
Z_cm = Z_cm + mean(z_final);
R_0 = (3*size(z_final,1)/(4*pi*Ro_0))^(1/3);
S = vpasolve(2^(-4/3)*R_0*((1-x)/(2+x))^(1/3)*(3+x)/(2+x)...
-mean(z_final),x,[-1.0,0.9]);
theta(ii) = acos(S)*180/pi;
end
fprintf('\n');
theta_ave_1 = mean(nonzeros(theta));
range = 0:180;
[his] = histc(theta,range);
s0=his;
s1=conv(s0,hanning(30),'same');
file(:,1)=0:180;
file(:,2)=s0;
file(:,3)=s1;
dlmwrite('../Results/Hautman.txt',file,'delimiter','\t');
Z_cm = Z_cm/((EndStep-StartStep)/step+1);
R_0 = (3*size(z_final,1)/(4*pi*Ro_0))^(1/3);
S = vpasolve(2^(-4/3)*R_0*((1-x)/(2+x))^(1/3)*(3+x)/(2+x)-...
Z_cm,x,[-1.0,0.9]);
% This average contact angle may be different from the average value
% calculated from the contact angle distribution. This value calculated the
% ensemble average of the centre of mass of droplet similar to the original
% publication
theta_ave_2 = double(acos(S)*180/PI);
% drawing angular distribution
figure;
plot(0:180,100*s1/sum(s1));
xlabel('Contact Angle (degree)');
ylabel('Probability (%)');
str(1) = {'Hautman and Klein meathod'};
str(2) = {sprintf('\\theta_{ave}(from distribution)=%f',theta_ave_1)};
str(3) = {sprintf('\\theta_{ave}(original publication)=%f',theta_ave_2)};
title(str);
cd (PATH);