• R/O
  • SSH

コミット

タグ
未設定

よく使われているワード(クリックで追加)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

コミットメタ情報

リビジョン7a7995b1bc4a93c6f5a7c2d4692edcd722a2bd0f (tree)
日時2008-04-16 00:27:54
作者iselllo
コミッターiselllo

ログメッセージ

I added the code diffusion_many_monomers.py which is useful to study the
diffusion results of the espresso simulations involving monomers only.

変更サマリ

差分

diff -r b4909edfb539 -r 7a7995b1bc4a Python-codes/diffusion_many_monomers.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Python-codes/diffusion_many_monomers.py Tue Apr 15 15:27:54 2008 +0000
@@ -0,0 +1,1327 @@
1+#! /usr/bin/env python
2+
3+import scipy as s
4+import numpy as n
5+import pylab as p
6+#from rpy import r
7+import distance_calc as d_calc
8+import igraph as ig
9+import hydrodynamic_radius_calc as h
10+import calc_rad as c_rad
11+
12+from scipy import stats #I need this module for the linear fit
13+
14+
15+box_size=10000. #here the box size does not depend on the total particle number
16+#but on the total number of particles in a box
17+print "the box size is, ", box_size
18+
19+#NB: now the box size is fixed a priori and is no longer a derivate object
20+
21+n_part=3000
22+#density=0.03
23+
24+size_cluster=1 #number of monomers in each cluster.
25+
26+types=n_part/size_cluster #different kinds of particles i.e. total number of clusters when coagulation
27+# is done
28+
29+print "types is, ", types
30+
31+
32+min_clus_stat=250 # this defines the minimum number of clusters which need to have formed before I start taking some statistics
33+
34+
35+# x_cm=s.zeros(types)
36+# y_cm=s.zeros(types) #positions of the centres of mass of each cluster
37+# z_cm=s.zeros(types)
38+
39+# v_x_cm=s.zeros(types)
40+# v_y_cm=s.zeros(types) #velocities of the centres of mass of each cluster
41+# v_z_cm=s.zeros(types)
42+
43+
44+#Again, I prefer to give the number of particles and the density as input parameters
45+# and work out the box size accordingly
46+
47+
48+ini_config=0
49+fin_config=250 #for large data post-processing I need to declare an initial and final
50+
51+ #configuration I want to read and post-process
52+
53+
54+by=1 #this tells how many configurations there are in the file I am reading
55+
56+figure=0 #whether I sould print many figures or not
57+
58+
59+n_config=(fin_config-ini_config)/by # total number of configurations, which are numbered from 0 to n_config-1
60+my_selection=s.arange(ini_config,fin_config,by)
61+
62+
63+threshold=1.06 #threshold to consider to particles as directly connected
64+
65+
66+
67+
68+time=p.load("time.dat")
69+
70+time=time[my_selection] #I adapt the time to the initial and final configuration
71+
72+p.save("time_red.dat",time)
73+
74+# x_mean=s.zeros(len(time)) # mean position (average on all the clusters) of the cluster CM
75+# y_mean=s.zeros(len(time))
76+# z_mean=s.zeros(len(time))
77+
78+# #y_sq_mean=s.zeros(len(time))
79+# #z_sq_mean=s.zeros(len(time))
80+# #z_sq_mean=s.zeros(len(time))
81+
82+
83+# delta_x_sq=s.zeros(len(time))
84+# delta_y_sq=s.zeros(len(time))
85+# delta_z_sq=s.zeros(len(time))
86+
87+
88+
89+# # v_x_sq_mean=s.zeros(len(time))
90+# # v_y_sq_mean=s.zeros(len(time))
91+# # v_z_sq_mean=s.zeros(len(time))
92+
93+# delta_v_x_sq=s.zeros(len(time))
94+# delta_v_y_sq=s.zeros(len(time))
95+# delta_v_z_sq=s.zeros(len(time))
96+
97+
98+
99+#dist_mat=s.zeros((size_cluster,size_cluster)) # I need to find out when the particles of each kind
100+#coagulate into a single cluster...I am not interested in looking at at all the particles in the system now
101+
102+
103+
104+def R_cm_distr(test_arr,types,n_config,n_part,size_cluster): #I can use this function both for the statistics on position
105+ #and velocity
106+
107+ count_left=s.arange(0,n_part,size_cluster)
108+ count_right=count_left+size_cluster
109+
110+
111+
112+# x_cm=s.zeros(types)
113+# y_cm=s.zeros(types) #positions of the centres of mass of each cluster
114+# z_cm=s.zeros(types)
115+
116+
117+# #print "OK here"
118+# x_pos_temp=test_arr[:,0]
119+# y_pos_temp=test_arr[:,1]
120+# z_pos_temp=test_arr[:,2]
121+
122+ R_cm_arr=s.zeros((types,3)) #this array will contain the distribution of hydrodynamic radia
123+ #calculated for a certain snapshot of the system
124+
125+
126+ for i in xrange(types):
127+ r_pos=test_arr[count_left[i]:count_right[i],:]
128+# x_pos=x_pos_temp[count_left[i]:count_right[i]]
129+# y_pos=y_pos_temp[count_left[i]:count_right[i]]
130+# z_pos=z_pos_temp[count_left[i]:count_right[i]]
131+
132+
133+
134+# print "s.shape(r_pos) is, ", s.shape(r_pos)
135+
136+ R_cm_arr[i,:]=r_pos.mean(axis=0)
137+
138+
139+ return R_cm_arr
140+
141+
142+
143+
144+
145+
146+def R_h_distr(test_arr,types,n_config,n_part,size_cluster): #I can use this function both for the statistics on position
147+ #and velocity
148+
149+ count_left=s.arange(0,n_part,size_cluster)
150+ count_right=count_left+size_cluster
151+
152+
153+
154+ x_cm=s.zeros(types)
155+ y_cm=s.zeros(types) #positions of the centres of mass of each cluster
156+ z_cm=s.zeros(types)
157+
158+
159+ #print "OK here"
160+ x_pos_temp=test_arr[:,0]
161+ y_pos_temp=test_arr[:,1]
162+ z_pos_temp=test_arr[:,2]
163+
164+ R_hydro_arr=s.zeros(types) #this array will contain the distribution of hydrodynamic radia
165+ #calculated for a certain snapshot of the system
166+
167+
168+ for i in xrange(types):
169+ x_pos=x_pos_temp[count_left[i]:count_right[i]]
170+ y_pos=y_pos_temp[count_left[i]:count_right[i]]
171+ z_pos=z_pos_temp[count_left[i]:count_right[i]]
172+
173+ #print "x_pos is, ", x_pos
174+
175+ R_hydro_arr[i]=h.hydro_radius_calc(x_pos,y_pos,z_pos,box_size)
176+ # print "R_hydro_arr[i] is, ", R_hydro_arr[i]
177+
178+ R_h=R_hydro_arr.mean()
179+
180+
181+ return R_h
182+
183+
184+
185+
186+
187+def R_gyr_distr(test_arr,types,n_config,n_part,size_cluster): #I can use this function both for the statistics on position
188+ #and velocity
189+
190+ count_left=s.arange(0,n_part,size_cluster)
191+ count_right=count_left+size_cluster
192+
193+
194+
195+ x_cm=s.zeros(types)
196+ y_cm=s.zeros(types) #positions of the centres of mass of each cluster
197+ z_cm=s.zeros(types)
198+
199+
200+ #print "OK here"
201+ x_pos_temp=test_arr[:,0]
202+ y_pos_temp=test_arr[:,1]
203+ z_pos_temp=test_arr[:,2]
204+
205+ R_gyr_arr=s.zeros(types) #this array will contain the distribution of hydrodynamic radia
206+ #calculated for a certain snapshot of the system
207+
208+
209+ for i in xrange(types):
210+ x_pos=x_pos_temp[count_left[i]:count_right[i]]
211+ y_pos=y_pos_temp[count_left[i]:count_right[i]]
212+ z_pos=z_pos_temp[count_left[i]:count_right[i]]
213+
214+ #print "x_pos is, ", x_pos
215+
216+ R_gyr_arr[i]=c_rad.rad_gyr(x_pos,y_pos,z_pos,box_size)
217+ # print "R_hydro_arr[i] is, ", R_hydro_arr[i]
218+
219+ R_gyr=R_gyr_arr.mean()
220+
221+
222+ return R_gyr
223+
224+
225+
226+
227+def calc_time_stat(test_arr,types,n_config,n_part,size_cluster,box_size): #I can use this function both for the statistics on position
228+ #and velocity
229+
230+ count_left=s.arange(0,n_part,size_cluster)
231+ count_right=count_left+size_cluster
232+
233+
234+
235+ x_cm=s.zeros(types)
236+ y_cm=s.zeros(types) #positions of the centres of mass of each cluster
237+ z_cm=s.zeros(types)
238+
239+
240+ #fold everything inside the box
241+
242+ test_arr=s.remainder(test_arr,box_size)
243+
244+ #print "OK here"
245+ x_pos=test_arr[:,0]
246+ y_pos=test_arr[:,1]
247+ z_pos=test_arr[:,2]
248+
249+
250+ results=s.zeros(7)
251+
252+
253+ for j in xrange(types):
254+ x_cm[j]=s.mean(x_pos[count_left[j]:count_right[j]])
255+ y_cm[j]=s.mean(y_pos[count_left[j]:count_right[j]])
256+ z_cm[j]=s.mean(z_pos[count_left[j]:count_right[j]])
257+
258+
259+
260+
261+
262+ x_mean=x_cm.mean()
263+ y_mean=y_cm.mean()
264+ z_mean=z_cm.mean()
265+
266+ delta_x_sq=x_cm.var()
267+ delta_y_sq=y_cm.var()
268+ delta_z_sq=z_cm.var()
269+
270+ delta_r_sq=delta_x_sq+delta_y_sq+delta_z_sq
271+
272+
273+ results[0]=x_mean
274+ results[1]=y_mean
275+ results[2]=z_mean
276+
277+ results[3]=delta_x_sq
278+ results[4]=delta_y_sq
279+ results[5]=delta_z_sq
280+ results[6]=delta_r_sq
281+
282+
283+ return results
284+
285+def calc_time_stat_vel(test_arr,types,n_config,n_part,size_cluster,box_size): #I can use this function both for the statistics on position
286+ #and velocity
287+
288+ count_left=s.arange(0,n_part,size_cluster)
289+ count_right=count_left+size_cluster
290+
291+
292+
293+ x_cm=s.zeros(types)
294+ y_cm=s.zeros(types) #positions of the centres of mass of each cluster
295+ z_cm=s.zeros(types)
296+
297+#here I have the only difference wrt the position fluctuations: I do not have to fold the velocity!!!
298+ # #fold everything inside the box
299+
300+# test_arr=s.remainder(test_arr,box_size)
301+
302+ #print "OK here"
303+ x_pos=test_arr[:,0]
304+ y_pos=test_arr[:,1]
305+ z_pos=test_arr[:,2]
306+
307+
308+ results=s.zeros(7)
309+
310+
311+ for j in xrange(types):
312+ x_cm[j]=s.mean(x_pos[count_left[j]:count_right[j]])
313+ y_cm[j]=s.mean(y_pos[count_left[j]:count_right[j]])
314+ z_cm[j]=s.mean(z_pos[count_left[j]:count_right[j]])
315+
316+
317+
318+
319+
320+ x_mean=x_cm.mean()
321+ y_mean=y_cm.mean()
322+ z_mean=z_cm.mean()
323+
324+ delta_x_sq=x_cm.var()
325+ delta_y_sq=y_cm.var()
326+ delta_z_sq=z_cm.var()
327+
328+ delta_r_sq=delta_x_sq+delta_y_sq+delta_z_sq
329+
330+
331+ results[0]=x_mean
332+ results[1]=y_mean
333+ results[2]=z_mean
334+
335+ results[3]=delta_x_sq
336+ results[4]=delta_y_sq
337+ results[5]=delta_z_sq
338+ results[6]=delta_r_sq
339+
340+
341+ return results
342+
343+
344+
345+
346+
347+
348+
349+
350+def calc_time_stat_clusters_together(test_arr,types,n_config,n_part,size_cluster): #I can use this function both for the statistics on position
351+ #and velocity
352+
353+ count_left=s.arange(0,n_part,size_cluster)
354+ count_right=count_left+size_cluster
355+
356+
357+
358+ x_cm=s.zeros(types)
359+ y_cm=s.zeros(types) #positions of the centres of mass of each cluster
360+ z_cm=s.zeros(types)
361+
362+
363+ #print "OK here"
364+ x_pos=test_arr[:,0]
365+ y_pos=test_arr[:,1]
366+ z_pos=test_arr[:,2]
367+
368+
369+ results=s.zeros(7)
370+
371+
372+
373+
374+
375+
376+
377+ x_mean=x_pos.mean()
378+ y_mean=y_pos.mean()
379+ z_mean=z_pos.mean()
380+
381+ delta_x_sq=x_pos.var()
382+ delta_y_sq=y_pos.var()
383+ delta_z_sq=z_pos.var()
384+
385+ delta_r_sq=delta_x_sq+delta_y_sq+delta_z_sq
386+
387+
388+ results[0]=x_mean
389+ results[1]=y_mean
390+ results[2]=z_mean
391+
392+ results[3]=delta_x_sq
393+ results[4]=delta_y_sq
394+ results[5]=delta_z_sq
395+ results[6]=delta_r_sq
396+
397+
398+ return results
399+
400+
401+
402+
403+
404+
405+
406+
407+
408+
409+
410+
411+def calc_time_stat_selection(test_arr,types,n_config,n_part,size_cluster,clust_choice):
412+#I can use this function both for the statistics on position
413+ #and velocity
414+
415+
416+
417+ x_cm=s.zeros(len(s.ravel(clust_choice)))
418+ y_cm=s.zeros(len(s.ravel(clust_choice))) #positions of the centres of mass of each cluster
419+ z_cm=s.zeros(len(s.ravel(clust_choice)))
420+
421+
422+ # print "len(clust_choice) is, ", len(clust_choice)
423+ count_left=s.arange(0,(len(s.ravel(clust_choice))*size_cluster),size_cluster)
424+ count_right=count_left+size_cluster
425+
426+
427+
428+
429+ #print "OK here"
430+ x_pos_temp=test_arr[:,0]
431+ y_pos_temp=test_arr[:,1]
432+ z_pos_temp=test_arr[:,2]
433+
434+ #print "len(x_pos_temp) is, ", len(x_pos_temp)
435+
436+ x_pos=s.zeros(len(s.ravel(clust_choice))*size_cluster)
437+ y_pos=s.zeros(len(s.ravel(clust_choice))*size_cluster)
438+ z_pos=s.zeros(len(s.ravel(clust_choice))*size_cluster)
439+
440+ #print "len(x_pos) is,", len(x_pos)
441+
442+ for l in xrange(len(s.ravel(clust_choice))):
443+ # print "count_left and count_right are, ", count_left[l],count_right[l]
444+
445+ #print "clust_choice[l] is, ", clust_choice[l]
446+ x_pos[count_left[l]:count_right[l]]=\
447+ x_pos_temp[(s.ravel(clust_choice)[l]*size_cluster):(s.ravel(clust_choice)[l]*size_cluster+size_cluster)]
448+ y_pos[count_left[l]:count_right[l]]=\
449+ y_pos_temp[(s.ravel(clust_choice)[l]*size_cluster):(s.ravel(clust_choice)[l]*size_cluster+size_cluster)]
450+
451+ z_pos[count_left[l]:count_right[l]]=\
452+ z_pos_temp[(s.ravel(clust_choice)[l]*size_cluster):(s.ravel(clust_choice)[l]*size_cluster+size_cluster)]
453+
454+
455+
456+
457+
458+
459+ #Then all the rest can stay the same
460+
461+ results=s.zeros(7)
462+
463+
464+
465+ for j in xrange(len(s.ravel(clust_choice))): #I iterate on the existing fully-coagulated clusters
466+ #print "j is, ", j
467+ x_cm[j]=s.mean(x_pos[count_left[j]:count_right[j]])
468+ y_cm[j]=s.mean(y_pos[count_left[j]:count_right[j]])
469+ z_cm[j]=s.mean(z_pos[count_left[j]:count_right[j]])
470+
471+
472+
473+
474+
475+ x_mean=x_cm.mean()
476+ y_mean=y_cm.mean()
477+ z_mean=z_cm.mean()
478+
479+ delta_x_sq=x_cm.var()
480+ delta_y_sq=y_cm.var()
481+ delta_z_sq=z_cm.var()
482+
483+ delta_r_sq=delta_x_sq+delta_y_sq+delta_z_sq
484+
485+
486+ results[0]=x_mean
487+ results[1]=y_mean
488+ results[2]=z_mean
489+
490+ results[3]=delta_x_sq
491+ results[4]=delta_y_sq
492+ results[5]=delta_z_sq
493+ results[6]=delta_r_sq
494+
495+
496+ return results
497+
498+
499+
500+
501+
502+
503+
504+def coagulation_clusters(test_arr,types,n_config,box_size,size_cluster,threshold):
505+
506+ count_left=s.arange(0,n_part,size_cluster)
507+ count_right=count_left+size_cluster
508+
509+ coag_arr=s.zeros(types)
510+
511+
512+# x_cm=s.zeros(types)
513+# y_cm=s.zeros(types) #positions of the centres of mass of each cluster
514+# z_cm=s.zeros(types)
515+
516+
517+ #print "OK here"
518+ x_pos=test_arr[:,0]
519+ y_pos=test_arr[:,1]
520+ z_pos=test_arr[:,2]
521+
522+
523+ results=s.zeros(7)
524+
525+
526+ for j in xrange(types):
527+ x_pos_clu=x_pos[count_left[j]:count_right[j]]
528+ y_pos_clu=y_pos[count_left[j]:count_right[j]]
529+ z_pos_clu=z_pos[count_left[j]:count_right[j]]
530+
531+ dist_mat=d_calc.distance_calc(x_pos_clu,y_pos_clu,z_pos_clu, box_size)
532+ cluster_obj=ig.Graph.Adjacency((dist_mat <= threshold).tolist(),\
533+ ig.ADJ_UNDIRECTED)
534+
535+ cluster_obj.simplify()
536+ clustering=cluster_obj.clusters()
537+
538+ #n_clusters[i]=p.load("nc_temp.dat")
539+# print "clustering is, ", clustering
540+
541+ coag_arr[j]=len(clustering)
542+
543+ # print "coag_arr is, ", coag_arr
544+ return coag_arr
545+
546+
547+######################################################################
548+######################################################################
549+######################################################################
550+######################################################################
551+
552+
553+
554+
555+
556+
557+
558+# #print "Ok here"
559+
560+# for i in xrange(0,n_config):
561+
562+# read_pos="read_pos_%1d"%my_selection[i]
563+# read_vel="read_vel_%1d"%my_selection[i]
564+
565+# #print "OK here 2"
566+# #cluster_name="cluster_dist%05d"%my_selection[i]
567+# test_arr=p.load(read_pos)
568+
569+# #print "OK here"
570+# x_pos=test_arr[:,0]
571+# y_pos=test_arr[:,1]
572+# z_pos=test_arr[:,2]
573+
574+# for j in xrange(types):
575+# x_cm[j]=s.mean(x_pos[count_left[j]:count_right[j]])
576+# y_cm[j]=s.mean(y_pos[count_left[j]:count_right[j]])
577+# z_cm[j]=s.mean(z_pos[count_left[j]:count_right[j]])
578+
579+# v_x_cm[j]=s.mean(x_pos[count_left[j]:count_right[j]])
580+# v_y_cm[j]=s.mean(y_pos[count_left[j]:count_right[j]])
581+# v_z_cm[j]=s.mean(z_pos[count_left[j]:count_right[j]])
582+
583+
584+
585+# x_mean[i]=x_cm.mean()
586+# y_mean[i]=y_cm.mean()
587+# z_mean[i]=z_cm.mean()
588+
589+# delta_x_sq[i]=x_cm.var()
590+# delta_y_sq[i]=y_cm.var()
591+# delta_z_sq[i]=z_cm.var()
592+
593+
594+
595+# delta_r_sq=delta_x_sq+delta_y_sq+delta_z_sq
596+
597+
598+# fig = p.figure()
599+# axes = fig.gca()
600+
601+
602+
603+# axes.plot(time,x_mean,"ro",\
604+# label="<x>",linewidth=2.)
605+# axes.plot(time,y_mean,"k+",\
606+# label="<y>")
607+# axes.plot(time,z_mean,"mx",\
608+# label="<z> ",linewidth=2.)
609+# #p.ylim(1.4,2.6)
610+# #axes.legend()
611+# p.xlabel('Time')
612+# p.ylabel('Mean position')
613+# p.savefig("mean_x_y_z.pdf")
614+
615+# p.clf()
616+
617+
618+
619+
620+# fig = p.figure()
621+# axes = fig.gca()
622+
623+
624+
625+# axes.plot(time,delta_r_sq,"ro",\
626+# label="<x>",linewidth=2.)
627+# # axes.plot(time,y_mean,"k+",\
628+# # label="<y>")
629+# # axes.plot(time,z_mean,"mx",\
630+# # label="<z> ",linewidth=2.)
631+# #p.ylim(1.4,2.6)
632+# #axes.legend()
633+# p.xlabel('Time')
634+# p.ylabel('delta position squared')
635+# p.savefig("delta_r_squared.pdf")
636+
637+# p.clf()
638+
639+
640+
641+# #print "the length of x_pos is, ", len(x_pos)
642+
643+
644+#########################################################################################
645+#########################################################################################
646+#########################################################################################
647+
648+#initialization of some arrays I will have to take in & out the loop
649+
650+
651+#pos_results=s.zeros(4) #just to initialize it
652+#pos_results_selection=s.zeros(4) #just to initialize it
653+#pos_statistics_selection=s.zeros(2) # I just need to initialize it!
654+time_selection=s.zeros(2)
655+
656+
657+
658+
659+flag_ini=0 # I will need this flag to check is some other array has been initialized
660+
661+R_h_arr=s.zeros(n_config)
662+
663+R_gyr_arr=s.zeros(n_config)
664+
665+
666+for i in xrange(0,n_config):
667+
668+ read_pos="read_pos_%1d"%my_selection[i]
669+ read_vel="read_vel_%1d"%my_selection[i]
670+
671+ #print "OK here 2"
672+ #cluster_name="cluster_dist%05d"%my_selection[i]
673+ pos_arr=p.load(read_pos)
674+ vel_arr=p.load(read_vel)
675+
676+ pos_statistics=calc_time_stat(pos_arr,types,n_config,n_part,size_cluster, box_size)
677+
678+# pos_statistics_clusters_together=calc_time_stat_clusters_together(pos_arr,types,n_config,n_part,size_cluster)
679+
680+
681+ vel_statistics=calc_time_stat_vel(vel_arr,types,n_config,n_part,size_cluster,box_size)
682+ clust_stat=coagulation_clusters(pos_arr,types,n_config,box_size,size_cluster,threshold)
683+ #print "clust_stat is, ", clust_stat
684+ clust_choice=s.where(clust_stat[:]==1.) #i.e. I select the clusters which have already finished
685+ # coagulating
686+
687+# R_h_arr[i]=R_h_distr(pos_arr,types,n_config,n_part,size_cluster)
688+# R_gyr_arr[i]=R_gyr_distr(pos_arr,types,n_config,n_part,size_cluster)
689+# R_cm=R_cm_distr(pos_arr,types,n_config,n_part,size_cluster)
690+
691+# if (i==0):
692+# R_cm_arr=R_cm
693+# elif (i>0):
694+# R_cm_arr=s.hstack((R_cm_arr,R_cm))
695+
696+ print "R_gyr_arr[i] is, ", R_gyr_arr[i]
697+ print "R_h_arr[i] is, ", R_h_arr[i]
698+
699+ #print "len(clust_choice) is, ", len(s.ravel(clust_choice))
700+ #print "clust_choice is, ", clust_choice
701+
702+ if (len(s.ravel(clust_choice))>=min_clus_stat):
703+ pos_statistics_selection=\
704+ calc_time_stat_selection(pos_arr,types,n_config,n_part,size_cluster,clust_choice)
705+ # print "pos_statistics_selection is, ", pos_statistics_selection
706+
707+
708+
709+
710+
711+ if (i==0):
712+
713+ pos_results=pos_statistics
714+ #R_h=R_h_temp
715+
716+# pos_results_clusters_together=pos_statistics_clusters_together
717+
718+
719+# print "pos_results is, ", pos_results
720+# print "the len of pos_results is, ", len(pos_results)
721+ vel_results=vel_statistics
722+ clust_results=clust_stat
723+ #The following if condition is academic since I'll never have the right number of
724+ #clusters at the beginning
725+ if (len(s.ravel(clust_choice))>=min_clus_stat):
726+ pos_results_selection=pos_statistics_selection
727+ time_selection=[time[i]]
728+
729+
730+
731+ elif(i!=0):
732+# print "now pos_results is, ", pos_results
733+# print "now the shape of pos_results is, ", s.shape(pos_results)
734+# print "now pos_statistics is, ", pos_statistics
735+
736+ pos_results=s.concatenate((pos_results,pos_statistics))
737+ #R_h=s.concatenate((R_h,R_h_temp))
738+# pos_results_clusters_together=s.concatenate((pos_results_clusters_together,pos_statistics_clusters_together))
739+
740+
741+
742+# print "OK here"
743+ vel_results=s.concatenate((vel_results,vel_statistics))
744+ clust_results=s.concatenate((clust_results,clust_stat))
745+
746+
747+ if ((len(s.ravel(clust_choice))>=min_clus_stat) and (flag_ini==0)):
748+ pos_results_selection=pos_statistics_selection
749+ time_selection=[time[i]]
750+ flag_ini=1 #to be sure I am doing this only the fist time, then I can concatenate
751+
752+
753+ elif ((len(s.ravel(clust_choice))>=min_clus_stat) and (flag_ini!=0)):
754+ pos_results_selection=s.concatenate((pos_results_selection,pos_statistics_selection))
755+ time_selection=s.concatenate((time_selection,[time[i]] ))
756+
757+
758+
759+pos_results.shape=(-1,7)
760+vel_results.shape=(-1,7) #where -1 means "do whatever is needed to reshape it right"
761+
762+
763+
764+#pos_results_clusters_together.shape=(-1,7)
765+
766+
767+
768+
769+
770+clust_results.shape=(-1,types)
771+
772+
773+#pos_results_selection.shape=(-1,7)
774+
775+
776+p.save("position_cluster_centres_of_mass.dat", pos_results)
777+p.save("velocity_cluster_centres_of_mass.dat", vel_results)
778+p.save("evolution_coagulation_of_each_particle_kind.dat", clust_results)
779+
780+
781+
782+fig = p.figure()
783+axes = fig.gca()
784+
785+
786+axes.plot(time,pos_results[:,6],"ro",\
787+ label="<delta_x^2+delta_y^2+delta_z^2>",linewidth=2.)
788+# axes.plot(time,y_mean,"k+",\
789+# label="<y>")
790+# axes.plot(time,z_mean,"mx",\
791+# label="<z> ",linewidth=2.)
792+#p.ylim(1.4,2.6)
793+axes.legend()
794+p.xlabel('Time')
795+p.ylabel('delta position squared')
796+p.savefig("delta_r_squared.pdf")
797+
798+p.clf()
799+
800+
801+
802+
803+
804+
805+#print "pos_results_clusters_together is, ", pos_results_clusters_together
806+
807+
808+# fig = p.figure()
809+# axes = fig.gca()
810+
811+
812+# axes.plot(time,pos_results_clusters_together[:,6],"ro",\
813+# label="<delta_x^2+delta_y^2+delta_z^2>",linewidth=2.)
814+# # axes.plot(time,y_mean,"k+",\
815+# # label="<y>")
816+# # axes.plot(time,z_mean,"mx",\
817+# # label="<z> ",linewidth=2.)
818+# #p.ylim(1.4,2.6)
819+# axes.legend()
820+# p.xlabel('Time')
821+# p.ylabel('delta position squared')
822+# p.savefig("delta_r_squared_clusters_together.pdf")
823+
824+# p.clf()
825+
826+
827+
828+
829+
830+
831+# fig = p.figure()
832+# axes = fig.gca()
833+
834+
835+# axes.plot(time_selection,pos_results_selection[:,6],"ro",\
836+# label="<delta_x^2+delta_y^2+delta_z^2>",linewidth=2.)
837+# # axes.plot(time,y_mean,"k+",\
838+# # label="<y>")
839+# # axes.plot(time,z_mean,"mx",\
840+# # label="<z> ",linewidth=2.)
841+# #p.ylim(1.4,2.6)
842+# axes.legend()
843+# p.xlabel('Time')
844+# p.ylabel('delta position squared (selection)')
845+# p.savefig("delta_r_squared_selection.pdf")
846+
847+# p.clf()
848+
849+
850+
851+
852+
853+
854+fig = p.figure()
855+axes = fig.gca()
856+
857+axes.plot(time,pos_results[:,0],"ro",\
858+ label="<x>",linewidth=2.)
859+axes.plot(time,pos_results[:,1],"k+",\
860+ label="<y>")
861+axes.plot(time,pos_results[:,2],"mx",\
862+ label="<z> ",linewidth=2.)
863+#p.ylim(1.4,2.6)
864+#axes.legend()
865+p.xlabel('Time')
866+p.ylabel('Mean position')
867+p.savefig("mean_x_y_z.pdf")
868+
869+p.clf()
870+
871+
872+
873+
874+
875+
876+
877+
878+fig = p.figure()
879+axes = fig.gca()
880+
881+
882+axes.plot(time,vel_results[:,6],"ro",\
883+ label="<v_x^2+v_y^2+v_z^2>",linewidth=2.)
884+# axes.plot(time,y_mean,"k+",\
885+# label="<y>")
886+# axes.plot(time,z_mean,"mx",\
887+# label="<z> ",linewidth=2.)
888+#p.ylim(1.4,2.6)
889+axes.legend()
890+p.xlabel('Time')
891+p.ylabel('delta velocity squared')
892+p.savefig("delta_v_squared.pdf")
893+
894+p.clf()
895+
896+
897+
898+
899+
900+fig = p.figure()
901+axes = fig.gca()
902+
903+axes.plot(time,vel_results[:,0],"ro",\
904+ label="<v_x>",linewidth=2.)
905+axes.plot(time,vel_results[:,1],"k+",\
906+ label="<v_y>")
907+axes.plot(time,vel_results[:,2],"mx",\
908+ label="<v_z> ",linewidth=2.)
909+#p.ylim(1.4,2.6)
910+#axes.legend()
911+p.xlabel('Time')
912+p.ylabel('Mean velocity')
913+p.savefig("mean_vel_x_vel_y_vel_z.pdf")
914+
915+p.clf()
916+
917+
918+
919+fig = p.figure()
920+axes = fig.gca()
921+
922+
923+n_clus=s.sum(clust_results,axis=1)
924+
925+print "the number of clusters is, ", n_clus
926+
927+
928+axes.plot(time,n_clus,"ro",\
929+ label="evolution total number of clusters")
930+types_arr=s.zeros(len(time))
931+types_arr[:]=types
932+
933+axes.plot(time,types_arr,"b",\
934+ label="coagulation of all the individual clusters",linewidth=2.)
935+
936+
937+# axes.plot(time,y_mean,"k+",\
938+# label="<y>")
939+# axes.plot(time,z_mean,"mx",\
940+# label="<z> ",linewidth=2.)
941+#p.ylim(1.4,2.6)
942+axes.legend()
943+p.xlabel('Time')
944+p.ylabel('Number of clusters')
945+p.savefig("Coagulation_individual_clusters.pdf")
946+
947+p.clf()
948+
949+#Now I think about a linear fit of delta_r_sq vs time
950+
951+# lin_fit=stats.linregress(s.log10(n_time_small),s.log10(r_time_small))
952+# my_fra_low[count_config]=1./lin_fit[0]
953+# r_stat_low[count_config]=lin_fit[2]
954+
955+#I select the results only for the case when all the clusters are formed
956+#print "n_clus is, ", n_clus
957+#print "the shape of n_clus is, ", s.shape(n_clus)
958+cluster_formed=s.where(n_clus[:]==types)
959+#print "cluster_formed is, ", cluster_formed
960+#print "the shape of cluster_formed is, ", s.shape(cluster_formed)
961+
962+time_formed=time[cluster_formed]
963+#print "time_formed is, ", time_formed
964+my_delta_r_sq=pos_results[:,6]
965+delta_r_sq_formed=my_delta_r_sq[cluster_formed]
966+
967+
968+lin_fit=stats.linregress(time_formed,delta_r_sq_formed)
969+
970+delta_r_sq_fitted=lin_fit[0]*time_formed+lin_fit[1]
971+
972+
973+
974+Diff_coeff=lin_fit[0]
975+
976+print "the linear coefficient [after cluster formation] is, ", lin_fit[0]
977+
978+
979+
980+
981+# fig = p.figure()
982+# axes = fig.gca()
983+
984+
985+# axes.plot(time,pos_results[:,6],"ro",\
986+# label="<delta_x^2+delta_y^2+delta_z^2>",linewidth=2.)
987+# # axes.plot(time,y_mean,"k+",\
988+# # label="<y>")
989+# # axes.plot(time,z_mean,"mx",\
990+# # label="<z> ",linewidth=2.)
991+# #p.ylim(1.4,2.6)
992+
993+# axes.plot(time_formed, delta_r_sq_fitted,"b",linewidth=2.)
994+
995+# axes.legend()
996+# p.xlabel('Time')
997+# p.ylabel('delta position squared and fit')
998+# p.savefig("delta_r_squared_and_fit.pdf")
999+
1000+# p.clf()
1001+
1002+
1003+
1004+
1005+# my_delta_r_sq=pos_results_clusters_together[:,6]
1006+# delta_r_sq_formed=my_delta_r_sq[cluster_formed]
1007+
1008+
1009+# lin_fit=stats.linregress(time_formed,delta_r_sq_formed)
1010+
1011+# delta_r_sq_fitted=lin_fit[0]*time_formed+lin_fit[1]
1012+
1013+
1014+
1015+# fig = p.figure()
1016+# axes = fig.gca()
1017+
1018+
1019+# axes.plot(time,pos_results_clusters_together[:,6],"ro",\
1020+# label="<delta_x^2+delta_y^2+delta_z^2>",linewidth=2.)
1021+# # axes.plot(time,y_mean,"k+",\
1022+# # label="<y>")
1023+# # axes.plot(time,z_mean,"mx",\
1024+# # label="<z> ",linewidth=2.)
1025+# #p.ylim(1.4,2.6)
1026+
1027+# axes.plot(time_formed, delta_r_sq_fitted,"b",linewidth=2.)
1028+
1029+# axes.legend()
1030+# p.xlabel('Time')
1031+# p.ylabel('delta position squared and fit')
1032+# p.savefig("delta_r_squared_and_fit_clusters_together.pdf")
1033+
1034+# p.clf()
1035+
1036+# print "the linear coefficient is [clusters_together], ", lin_fit[0]
1037+
1038+
1039+#Now the dynamics before the formation of the clusters
1040+
1041+
1042+cluster_unformed=s.where(n_clus[:]!=types)
1043+#print "cluster_formed is, ", cluster_formed
1044+#print "the shape of cluster_formed is, ", s.shape(cluster_formed)
1045+
1046+time_unformed=time[cluster_unformed]
1047+#print "time_formed is, ", time_formed
1048+#my_delta_r_sq=pos_results[:,6]
1049+delta_r_sq_unformed=my_delta_r_sq[cluster_unformed]
1050+
1051+
1052+lin_fit=stats.linregress(time_unformed,delta_r_sq_unformed)
1053+
1054+delta_r_sq_fitted_unformed=lin_fit[0]*time_unformed+lin_fit[1]
1055+
1056+
1057+print "the linear coefficient before forming the clusters is, ", lin_fit[0]
1058+
1059+
1060+
1061+coag_choice=s.where((n_clus/n_clus[0])>0.2)
1062+
1063+
1064+
1065+time_coag=time[coag_choice]
1066+#print "time_formed is, ", time_formed
1067+#my_delta_r_sq=pos_results[:,6]
1068+delta_r_sq_coag=my_delta_r_sq[coag_choice]
1069+
1070+
1071+print "delta_r_sq_coag is, ", delta_r_sq_coag
1072+
1073+
1074+lin_fit=stats.linregress(time_coag,delta_r_sq_coag)
1075+
1076+delta_r_sq_coag_fitted=lin_fit[0]*time_coag+lin_fit[1]
1077+
1078+
1079+
1080+
1081+print "the linear coefficient at the early stages of coagulation is, ", lin_fit[0]
1082+
1083+
1084+
1085+
1086+
1087+
1088+
1089+
1090+fig = p.figure()
1091+axes = fig.gca()
1092+
1093+
1094+axes.plot(time,pos_results[:,6],"ro",\
1095+ label="<delta_x^2+delta_y^2+delta_z^2>",linewidth=2.)
1096+# axes.plot(time,y_mean,"k+",\
1097+# label="<y>")
1098+# axes.plot(time,z_mean,"mx",\
1099+# label="<z> ",linewidth=2.)
1100+#p.ylim(1.4,2.6)
1101+
1102+axes.plot(time_formed, delta_r_sq_fitted,"b",linewidth=2.)
1103+
1104+axes.plot(time_unformed, delta_r_sq_fitted_unformed,"k",linewidth=2.)
1105+
1106+axes.plot(time_coag, delta_r_sq_coag_fitted,"m",linewidth=2.)
1107+
1108+
1109+
1110+axes.legend()
1111+p.xlabel('Time')
1112+p.ylabel('delta position squared and fit')
1113+p.savefig("delta_r_squared_and_fit.pdf")
1114+
1115+p.clf()
1116+
1117+
1118+
1119+
1120+fig = p.figure()
1121+axes = fig.gca()
1122+
1123+
1124+axes.plot(time,R_h_arr,"ro",\
1125+ label="hydrodynamic radius",linewidth=2.)
1126+# axes.plot(time,y_mean,"k+",\
1127+# label="<y>")
1128+# axes.plot(time,z_mean,"mx",\
1129+# label="<z> ",linewidth=2.)
1130+#p.ylim(1.4,2.6)
1131+
1132+# axes.plot(time_formed, delta_r_sq_fitted,"b",linewidth=2.)
1133+
1134+# axes.plot(time_unformed, delta_r_sq_fitted_unformed,"k",linewidth=2.)
1135+
1136+# axes.plot(time_coag, delta_r_sq_coag_fitted,"m",linewidth=2.)
1137+
1138+
1139+
1140+axes.legend()
1141+p.xlabel('Time')
1142+p.ylabel('R_h')
1143+p.savefig("hydrodynamic_radius.pdf")
1144+
1145+p.clf()
1146+
1147+
1148+
1149+
1150+
1151+fig = p.figure()
1152+axes = fig.gca()
1153+
1154+
1155+axes.plot(time,R_gyr_arr,"ro",\
1156+ label="gyration radius",linewidth=2.)
1157+# axes.plot(time,y_mean,"k+",\
1158+# label="<y>")
1159+# axes.plot(time,z_mean,"mx",\
1160+# label="<z> ",linewidth=2.)
1161+#p.ylim(1.4,2.6)
1162+
1163+# axes.plot(time_formed, delta_r_sq_fitted,"b",linewidth=2.)
1164+
1165+# axes.plot(time_unformed, delta_r_sq_fitted_unformed,"k",linewidth=2.)
1166+
1167+# axes.plot(time_coag, delta_r_sq_coag_fitted,"m",linewidth=2.)
1168+
1169+
1170+
1171+axes.legend()
1172+p.xlabel('Time')
1173+p.ylabel('R_gyr')
1174+p.savefig("gyration_radius.pdf")
1175+
1176+p.clf()
1177+
1178+
1179+
1180+
1181+#print "R_h_arr is, ", R_h_arr
1182+
1183+#Now I evaluate the ratio between the hydrodynamic radius and the radius of gyration as time goes by and I
1184+# evaluate the
1185+
1186+
1187+# R_h_over_R_gyr=s.mean(R_h_arr[cluster_formed]/R_gyr_arr[cluster_formed])
1188+
1189+
1190+# R_h_mean=R_h_arr[cluster_formed].mean()
1191+
1192+
1193+# R_gyr_mean=R_gyr_arr[cluster_formed].mean()
1194+
1195+
1196+# print "the ratio hydrodynamic radius over radius of gyration is, " ,R_h_over_R_gyr
1197+
1198+
1199+
1200+
1201+
1202+
1203+#Now I take some time averages for a single cluster.
1204+
1205+if (types==1): #i.e. I have a single cluster
1206+ delta_r_sq_time_aver=s.var(pos_results[:,0:3], axis=0)
1207+ delta_r_sq_time_aver=delta_r_sq_time_aver.sum()
1208+ v_mean_time=s.mean(vel_results[:,0:3],axis=0)
1209+
1210+ print "delta_r_sq_time_aver is, ", delta_r_sq_time_aver
1211+ print "v_mean_time is, ", v_mean_time
1212+ print "vel results are, ", vel_results
1213+
1214+ print "the shape of vel_results is, ", s.shape(vel_results)
1215+
1216+
1217+ print "<delta x squared>, ", pos_results[:,0].var()
1218+ print "<delta y squared>, ", pos_results[:,1].var()
1219+ print "<delta z squared>, ", pos_results[:,2].var()
1220+
1221+ print "<x>, ", pos_results[:,0].mean()
1222+ print "<y>, ", pos_results[:,1].mean()
1223+ print "<z>, ", pos_results[:,2].mean()
1224+
1225+
1226+
1227+
1228+ print "<v_x>, ", vel_results[:,0].mean()
1229+ print "<v_y>, ", vel_results[:,1].mean()
1230+ print "<v_z>, ", vel_results[:,2].mean()
1231+
1232+
1233+ delta_v_sq_time_aver=s.var(vel_results[:,0:3], axis=0)
1234+ delta_v_sq_time_aver=delta_v_sq_time_aver.sum()
1235+
1236+ print "<delta v_x squared>, ", vel_results[:,0].var()
1237+ print "<delta v_y squared>, ", vel_results[:,1].var()
1238+ print "<delta v_z squared>, ", vel_results[:,2].var()
1239+
1240+
1241+
1242+
1243+ print "delta_v_sq_time_aver is, ", delta_v_sq_time_aver
1244+
1245+
1246+#Now I calculate the diffusion coefficient from the collected cluster positions
1247+
1248+print "s.shape(R_cm_arr) is, ", s.shape(R_cm_arr)
1249+
1250+#displacement=(R_cm_arr[:,0]-R_cm_arr)**2.
1251+
1252+
1253+my_len=s.shape(R_cm_arr)[1]/3
1254+
1255+p.save("centre_of_mass_positions.dat", R_cm_arr)
1256+
1257+
1258+displacement=s.zeros((s.shape(R_cm_arr)[0],my_len))
1259+
1260+print "R_cm_arr is, ", R_cm_arr[:,0:10]
1261+
1262+for i in xrange(my_len):
1263+ displacement[:,i]=s.sum(((R_cm_arr[:,0:3]-R_cm_arr[:,(i*3):((i+1)*3)])**2.),axis=1)
1264+
1265+print "displacement is, ", displacement[:, 0:3]
1266+
1267+p.save("displacement.dat", displacement)
1268+
1269+# x_pos=x.zeros(my_len)
1270+# y_pos=x.zeros(my_len)
1271+# z_pos=x.zeros(my_len)
1272+
1273+# for i in xrange(my_len):
1274+# x_pos=
1275+
1276+
1277+displacement=displacement/6./time.max()
1278+
1279+D_distr=displacement.mean(axis=1)
1280+
1281+print "the trajectory-averaged distribution of diffusion coeff is, ", D_distr
1282+
1283+D_mean=D_distr.mean()
1284+
1285+print "the trajectory-averaged diffusion coeff is, ", D_mean
1286+
1287+print "and its std is, ", D_distr.std()
1288+
1289+
1290+
1291+
1292+
1293+def Diff(kT,mu,r_eff):
1294+ D=kT/(6.*s.pi*mu*r_eff)
1295+ return D
1296+
1297+def R_mob(kT,mu, D):
1298+ r_eff=kT/(6.*s.pi*mu*D)
1299+
1300+ return r_eff
1301+
1302+
1303+
1304+
1305+kT=0.5
1306+mu=1./(3.*s.pi)
1307+
1308+# Diff_R_h=Diff(kT,mu,R_h_mean)
1309+
1310+
1311+# Diff_R_gyr=Diff(kT,mu,R_gyr_mean)
1312+
1313+# print "D calculated with R_gyr is, ", Diff_R_gyr
1314+
1315+# print "D calculated with R_h is, ", Diff_R_h
1316+
1317+# R_mobility=R_mob(kT,mu,D_mean)
1318+
1319+# print "The effective mobility radius is ", R_mobility
1320+
1321+# print "the ratio R_mobility/R_gyration is, ", R_mobility/R_gyr_mean
1322+
1323+# print "the ratio R_mobility/R_hydro_mean is, ", R_mobility/R_h_mean
1324+
1325+
1326+
1327+print "So far so good"