修訂 | 5e8ffa5a9021639563f64874043fa18c211f95a7 (tree) |
---|---|
時間 | 2008-01-13 12:15:23 |
作者 | iselllo |
Commiter | iselllo |
Now plot_statistics2.py is also able to calculate the radius of gyration
for a given particle configuration.
@@ -3,6 +3,22 @@ | ||
3 | 3 | import scipy as s |
4 | 4 | import numpy as n |
5 | 5 | import pylab as p |
6 | +from rpy import r | |
7 | +import distance_calc as d_calc | |
8 | + | |
9 | + | |
10 | + | |
11 | + | |
12 | +n_part=500 | |
13 | +n_config=1000 | |
14 | + | |
15 | +density=0.01 | |
16 | +box_size=(n_part/density)**(1./3.) | |
17 | +print "the box size is, ", box_size | |
18 | + | |
19 | + | |
20 | +threshold=1.06 | |
21 | + | |
6 | 22 | |
7 | 23 | n_clusters=p.load("number_cluster.dat") |
8 | 24 | time=p.load("time.dat") |
@@ -15,18 +31,6 @@ | ||
15 | 31 | p.savefig('n_cluster_loglog.pdf') |
16 | 32 | p.hold(False) |
17 | 33 | |
18 | -coag=n_clusters[0]/n_clusters-1. | |
19 | - | |
20 | - | |
21 | -p.loglog(time,coag,"ro") | |
22 | -p.xlabel('time') | |
23 | -p.ylabel('N(0)/N(t)-1') | |
24 | -#p.legend(('mean x','mean y','mean z',)) | |
25 | -p.title('Log-log plot of cluster population') | |
26 | -p.grid(True) | |
27 | -p.savefig('coagulation_loglog.pdf') | |
28 | -p.hold(False) | |
29 | - | |
30 | 34 | |
31 | 35 | |
32 | 36 | p.loglog(time,n_clusters,linewidth=2.) |
@@ -40,12 +44,186 @@ | ||
40 | 44 | p.hold(False) |
41 | 45 | |
42 | 46 | #now I choose to plot the histogram of some cluster distributions |
47 | +# and then I investigate its structure | |
48 | +choose_config=140 | |
43 | 49 | |
44 | -choose_config=120 | |
45 | 50 | cluster_name="cluster_dist%05d"%choose_config |
46 | 51 | my_cluster=p.load(cluster_name) |
47 | 52 | p.hist(my_cluster) |
48 | 53 | p.show() |
49 | 54 | |
50 | 55 | |
56 | +#Now I read all the configurations | |
57 | + | |
58 | +tot_config=p.load("total_configuration.dat") | |
59 | + | |
60 | + | |
61 | +#and put them in a suitable shape | |
62 | + | |
63 | + | |
64 | +print "the length of tot_config is, ", len(tot_config) | |
65 | +tot_config=s.reshape(tot_config,(n_config,3*n_part)) | |
66 | + | |
67 | + | |
68 | +#Some arrays I will be using in the following | |
69 | + | |
70 | +x_arr=s.zeros((n_config,n_part)) | |
71 | +y_arr=s.zeros((n_config,n_part)) | |
72 | +z_arr=s.zeros((n_config,n_part)) | |
73 | + | |
74 | + | |
75 | +for i in xrange(0,n_part): | |
76 | + x_arr[:,i]=tot_config[:,3*i] | |
77 | + y_arr[:,i]=tot_config[:,(3*i+1)] | |
78 | + z_arr[:,i]=tot_config[:,(3*i+2)] | |
79 | + | |
80 | +print("OK before r.source") | |
81 | + | |
82 | +r.source("cluster_functions.R") | |
83 | + | |
84 | +dist_mat=s.zeros((n_part,n_part)) | |
85 | + | |
86 | +# test_arr=tot_config[choose_config,:] | |
87 | +# test_arr=s.reshape(test_arr,(n_part,3)) | |
88 | + | |
89 | +x_pos=x_arr[choose_config,:] | |
90 | +y_pos=y_arr[choose_config,:] | |
91 | +z_pos=z_arr[choose_config,:] | |
92 | +dist_mat=d_calc.distance_calc(x_pos,y_pos,z_pos, box_size) | |
93 | + | |
94 | + | |
95 | + | |
96 | + | |
97 | +clust_struc= (r.mycluster2(dist_mat,threshold)) #a cumbersome | |
98 | + | |
99 | +#n_clusters[i]=clust_struc[0] | |
100 | +#print 'the number of clusters in my configuration is, ', clust_struc[0] | |
101 | +print 'and their composition is, ', clust_struc | |
102 | +p.save("cluster_structure.dat",clust_struc) | |
103 | +print 'saved cluster_structure.dat' | |
104 | +print 'the length of cluster_struc is, ', len(clust_struc) #the number | |
105 | +#of particles + 1 entry for the number of clusters | |
106 | + | |
107 | +#Now I try buiding the structure of the individual clusters | |
108 | + | |
109 | + | |
110 | + | |
111 | +#print 'initially clust_struc[0] is',clust_struc[0] | |
112 | + | |
113 | +#clust_struc=s.transpose(clust_struc) | |
114 | + | |
115 | +#cluster_struc=n.integer(clust_struc) | |
116 | + | |
117 | +list_part=s.arange(n_part) | |
118 | +part_in_clust=s.arange(n_part) | |
119 | +print 'the shape of list_part is, ', s.shape(list_part) | |
120 | +print 'the shape of clust_struc is, ', s.shape(clust_struc) | |
121 | + | |
122 | +print 'len(my_cluster) is, ', len(my_cluster) | |
123 | + | |
124 | + | |
125 | +#MMMMMhhhhh....maybe the following part could become some fortran code | |
126 | + | |
127 | +# copy_pos=0 | |
128 | +# for i in xrange(0,len(my_cluster)): | |
129 | +# # part_in_clust[:]= s.where(clust_struc[:]==(i*1.),list_part[:],part_in_clust[:]) | |
130 | +# # count_corr=s.cumsum(my_cluster) | |
131 | +# # find_pos=n.int(0+i*(count_corr[i]-count_corr[0])) | |
132 | +# # print 'find_pos is, ', find_pos | |
133 | +# # find_pos=0 | |
134 | + | |
135 | +# for j in xrange(0,n_part): | |
136 | +# if(clust_struc[j]==i*1.): | |
137 | +# part_in_clust[copy_pos]=j | |
138 | +# copy_pos=copy_pos+1 | |
139 | +# # find_pos=find_pos+1 | |
140 | + | |
141 | +part_in_clust=s.argsort(clust_struc) | |
142 | + | |
143 | +print 'part_in_clust is, ', part_in_clust | |
144 | +#Finally, part_in_clust groups together all the particles which are in the same cluster | |
145 | + | |
146 | + | |
147 | +r_gyr_dist=s.zeros(len(my_cluster)) #this will contain the distribution of the calculated | |
148 | +#radia of gyration | |
149 | + | |
150 | +#pseudocode: loop on each cluster first. | |
151 | +#define 3 arrays of dimensions related to the number of particles in each cluster | |
152 | +#then for each cluster work out the radius of gyration as in the case of the | |
153 | +#plot_statistics.py code. | |
154 | + | |
155 | +my_sum=s.cumsum(my_cluster) | |
156 | +f=s.arange(1) #simply 0 but as an array! | |
157 | +my_lim=s.concatenate((f,my_sum)) | |
158 | + | |
159 | + | |
160 | +#Now a function to calculate the radius of gyration | |
161 | +def calc_radius(x_arr,y_arr,z_arr,Len): | |
162 | + #here x_arr is one-dimensional corresponding to a single configuration | |
163 | + r_0j=s.zeros((len(x_arr)-1)) | |
164 | + for j in xrange(1,len(x_arr)): #so, particle zero is now the reference particle | |
165 | + r_0j[j-1]=x_arr[0]-x_arr[j] | |
166 | + r_0j[j-1]=-(r_0j[j-1]-Len*n.round(r_0j[j-1]/Len)) | |
167 | + #r_ij[count_int]=-r_ij[count_int] #I have better reverse the signs now. | |
168 | + #print 'i and j are, ', (i+1), (j+1) | |
169 | + | |
170 | + | |
171 | + #Now I re-define the x_arr in order to be able to take tha variance correctly | |
172 | + x_arr[0]=0. | |
173 | + x_arr[1:n_part]=r_0j | |
174 | + | |
175 | + #var_x_arr[:]=s.var(r_0j, axis=1) | |
176 | + var_x_arr=s.var(x_arr) | |
177 | + | |
178 | + for j in xrange(1,len(y_arr)): #so, particle zero is now the reference particle | |
179 | + r_0j[j-1]=y_arr[0]-y_arr[j] | |
180 | + r_0j[j-1]=-(r_0j[j-1]-Len*n.round(r_0j[j-1]/Len)) | |
181 | + #r_ij[count_int]=-r_ij[count_int] #I have better reverse the signs now. | |
182 | + #print 'i and j are, ', (i+1), (j+1) | |
183 | + | |
184 | + | |
185 | + #Now I re-define the x_arr in order to be able to take tha variance correctly | |
186 | + y_arr[0]=0. | |
187 | + y_arr[1:n_part]=r_0j | |
188 | + | |
189 | + #var_x_arr[:]=s.var(r_0j, axis=1) | |
190 | + var_y_arr=s.var(y_arr) | |
191 | + | |
192 | + | |
193 | + | |
194 | + for j in xrange(1,len(z_arr)): #so, particle zero is now the reference particle | |
195 | + r_0j[j-1]=z_arr[0]-z_arr[j] | |
196 | + r_0j[j-1]=-(r_0j[j-1]-Len*n.round(r_0j[j-1]/Len)) | |
197 | + #r_ij[count_int]=-r_ij[count_int] #I have better reverse the signs now. | |
198 | + #print 'i and j are, ', (i+1), (j+1) | |
199 | + | |
200 | + | |
201 | + #Now I re-define the x_arr in order to be able to take tha variance correctly | |
202 | + z_arr[0]=0. | |
203 | + z_arr[1:n_part]=r_0j | |
204 | + | |
205 | + #var_x_arr[:]=s.var(r_0j, axis=1) | |
206 | + var_z_arr=s.var(z_arr) | |
207 | + | |
208 | + radius=s.sqrt(var_x_arr+var_y_arr+var_z_arr) | |
209 | + return radius | |
210 | + | |
211 | + | |
212 | + | |
213 | + | |
214 | + | |
215 | + | |
216 | + | |
217 | +for i in xrange(0,len(my_cluster)): | |
218 | + x_pos2=x_arr[choose_config,part_in_clust[my_lim[i]:my_lim[i+1]]] | |
219 | + y_pos2=x_arr[choose_config,part_in_clust[my_lim[i]:my_lim[i+1]]] | |
220 | + z_pos2=x_arr[choose_config,part_in_clust[my_lim[i]:my_lim[i+1]]] | |
221 | + r_gyr_dist[i]=calc_radius(x_pos2,y_pos2,z_pos2,box_size) | |
222 | + | |
223 | +print 'the distribution of Rg is, ', r_gyr_dist | |
224 | +p.hist(r_gyr_dist) | |
225 | +p.show() | |
226 | + | |
227 | + | |
228 | + | |
51 | 229 | print("So far so good") |