-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.f90
1973 lines (1604 loc) · 68.1 KB
/
functions.f90
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
module functions
use commons
#include "control_simulation.h"
implicit none
! integer :: i,j,k,ii,jj,kk ! general counters variables
contains
! Use really these routines if PROFILES is on.
subroutine write_conf(mode,vector,length)
!write xyz files for viewing the system in different ways
! mode = 1 : uses 4 different colors
! mode !=1 : uses only one color
! vector: positions of the atoms
! length: length (number of monomers )of the chain to change the colors
implicit none
real (kind=8), dimension(:,:) :: vector
integer,intent(in) :: mode,length
!character (len=4) ,dimension(size(vector,dim=1)) :: at_names
integer :: n,i,ic
character (len=4) , parameter , dimension(4) :: nam1= (/"Cl ","N ","S ","O "/)
n=size(vector,dim=1)
open(unit=25,file="config.xyz",status="unknown")
select case (mode)
case(1)
write(25,*) n
write(25,*) 'mode=1, long system of 4 colors. chain length = ',length
ic =1
do i = 1,n
if(mod(i-1,length).eq.0) ic = ic + 1
if(ic > size(nam1) ) ic = 1
write(25,'(a4,3f10.4)') nam1(ic),vector(i,:)
end do
case default
! default uses a unique long conf of similar atoms
write(25,*) n
write(25,*) 'mode= default, long system of same color'
write(25,'("Cl ",3f10.4)') (vector(i,:),i=1,n)
end select
!write
close(unit=25)
end subroutine write_conf
! **** Periodic Boudary conditions refolding
!
subroutine refold(mode,n_mon_loc,n_ini,n_end)
! real(kind=8) ,intent(in) ::
! real(kind=8) ,intent(out) :: spabs(:,:)
integer , intent(in) :: mode,n_mon_loc,n_ini, n_end
integer , save :: n_part , n_dim_loc
integer :: i_dim,i_part
select case(mode)
case(0)
# if SYMMETRY == 0
n_dim_loc = 2
# elif SYMMETRY == 1 /* bulki */
n_dim_loc = 3
# endif
case(1)
r0_unfold(:,n_ini:n_end) = r0(:,n_ini:n_end)
do i_part=n_ini,n_end
do i_dim=1,n_dim_loc
if(mod(i_part-1,n_mon_loc).ne.0) then
if(r0_unfold(i_dim,i_part)-r0_unfold(i_dim,i_part-1).gt.half_boundary(i_dim)) then
r0_unfold(i_dim,i_part)=r0_unfold(i_dim,i_part)-boundary(i_dim)
cycle
end if
if(r0_unfold(i_dim,i_part-1)-r0_unfold(i_dim,i_part).gt.half_boundary(i_dim)) then
r0_unfold(i_dim,i_part)=r0_unfold(i_dim,i_part)+boundary(i_dim)
cycle
end if
end if
end do
end do
end select
end subroutine refold
#ifdef PROFILES
!-------------------------------------------------------------------
! Histograms, for monomer profiles
! mode = 0 : initialize counting
! mode = 1 : makes histogram for brushes
! mode = 2 : makes histogram for melt
! mode = 3 : writes out final data
!
subroutine histo(mode,hist_dim)
implicit none
real (kind=8) ,allocatable ,save:: dens_z(:,:),r_scaled(:,:)
real (kind=8) :: r_bin
real (kind=8), save :: z_step,inv_z_step,surf
integer,intent(in) :: mode,hist_dim
integer ,save :: count_obs_b,count_obs_m
integer :: n_max,i_step,i_part,n_step_clau,i_dummy
integer :: z_index
select case (mode)
case(0) ! initialization
! histo(hist_dim,1) : top brush || brush, if notdef BRUSH_SEP
! histo(hist_dim,2) : bottom brush
! histo(hist_dim,2) : melt
! histo(hist_dim,3) : particle 4
#ifdef BRUSH_SEP
allocate(dens_z(hist_dim,4),r_scaled(3,n_mon_tot))
#else
allocate(dens_z(hist_dim,3),r_scaled(3,n_mon_tot))
#endif
r_scaled = 0.
dens_z(:,:) = 0.
z_step = boundary(3) / dble(hist_dim)
inv_z_step = 1./z_step
surf = boundary(1)*boundary(2)
count_obs_b = 0
!ori count_obs_m = 0
case(1) ! Writing files and normalizing
print '(/a,i6/)',' * Density profiles over steps= ',count_obs_b
open(unit=73,file='dens_prof.mide',status='unknown')
dens_z(:,:) = dens_z(:,:) * dble(hist_dim)*inv_boundary(3)/ (dble(count_obs_b)*surf)
histo_out(:,:) = dens_z(:,:) ! global: norm_vel prof and sigma prof are calculated with this vector
r_dummy = boundary(3)/dble(hist_dim)
r_bin = r_dummy/2.
do i_dummy = 1,hist_dim
#ifdef BRUSH_SEP
write(73,'(5f16.7)') r_bin,dens_z(i_dummy,1),dens_z(i_dummy,2),dens_z(i_dummy,3), dens_z(i_dummy,4)
#else
write(73,'(4f16.7)') r_bin,dens_z(i_dummy,1),dens_z(i_dummy,2),dens_z(i_dummy,3)
#endif
r_bin = r_bin + r_dummy
end do
case(2) ! Order N algorithm
count_obs_b = count_obs_b + 1
r_scaled(3,:) = r0(3,:)*inv_z_step
! do i_part = 1,n_mon_tot
! if(r0(3,i_part) > 30. ) print *i_time
! end do
! Brush
#ifdef BRUSH_SEP
do i_part = 1, part_init_d/2
#else
do i_part = 1, part_init_d
#endif
z_index = int (r_scaled(3,i_part) ) + 1
if (z_index<1) z_index = 1
if (z_index>hist_dim) z_index = hist_dim
dens_z(z_index,1) = dens_z(z_index,1) + 1.
end do
! Melt / Droplet
do i_part = part_init_d+1,part_init_e
z_index = int (r_scaled(3,i_part) ) + 1
if (z_index<1) z_index = 1
if (z_index>hist_dim) z_index = hist_dim
dens_z(z_index,2) = dens_z(z_index,2) + 1.
end do
! Particle 4 if applies
#ifdef PARTICLE_4
do i_part = part_init_e+1,n_mon_tot
z_index = int (r_scaled(3,i_part) ) + 1
if (z_index<1) z_index = 1
if (z_index>hist_dim) z_index = hist_dim
dens_z(z_index,3) = dens_z(z_index,3) + 1.
end do
#endif
#ifdef BRUSH_SEP
do i_part = part_init_d/2+1,part_init_d
z_index = int (r_scaled(3,i_part) ) + 1
if (z_index<1) z_index = 1
if (z_index>hist_dim) z_index = hist_dim
dens_z(z_index,4) = dens_z(z_index,4) + 1.
end do
#endif
end select
end subroutine histo
!
! ******** histo_vec *********
!
subroutine histo_vec(vector) ! ,vector,r_interval,histo_clau)
!use commons
implicit none
real , dimension(:), intent(in) :: vector
!real (kind=8), dimension(:), intent(in) :: vector
real (kind=8) :: r_interval
real (kind=8) :: binbox_c,binstep_c
integer :: n_max,i_step,i_part,n_step_clau
real (kind=8) :: histo_v(200),eje_x(200)
!real (kind=8) , dimension(size(histo_v) :: histo_clau
r_interval = maxval(vector) - minval(vector)
n_step_clau=size(histo_v,dim=1)
n_max=size(vector,dim=1) !numebr of particles
binstep_c=r_interval/real(n_step_clau)
binbox_c= minval(vector)
do i_step=1,n_step_clau
binbox_c=binbox_c+binstep_c
eje_x(i_step) = binbox_c
do i_part=1,n_max
if(vector(i_part).lt.binbox_c) then
if(vector(i_part).ge.(binbox_c-binstep_c)) then
histo_v(i_step)=histo_v(i_step)+1
end if
end if
end do
end do
do i_step = 1 , n_step_clau
print *,eje_x(i_step),histo_v(i_step)/real(n_max)
end do
end subroutine histo_vec
!
! **** Velocity profile
! Calculates a mean velocity profile along z coordinate
! mode : routine mode
! z: positions, only z coordinate
! v: velocities
! z_width: sample width
! n_layers: number of layers in which the profile will be done
! velocity profile
#ifdef PROFILES
subroutine velocity_prof(mode,n_layers,z_min,z_width) ! ,v_prof,v_prof_2) ! NOW in commons
implicit none
integer ,intent(in) :: mode,n_layers
real (kind=8) , intent(in) , optional :: z_width,z_min
integer :: i,j,ii,jj,kk,z_count_b,z_count_m
real(kind=8) :: zmin,zmax,v_cell_b(3),v_cell_m(3)
real(kind=8) , allocatable, save :: r_scaled(:,:)
real(kind=8) ,save :: dz,inv_z_step
real(kind=8) :: inv_n_time
integer, save :: n_time
integer :: z_index
select case (mode)
case(0) ! Initialize
v_prof(:,:,:) = 0.
v_prof_2(:,:,:) = 0.
allocate( r_scaled(3,n_mon_tot) )
! n_time = 0
dz = boundary(3) /dble(n_layers)
inv_z_step = 1/dz
print '(/a/)'," * Velocity prof initialized. "
n_time = 0
case(1) ! Final normalization
inv_n_time = 1/dble(n_time)
v_prof(:,:,:) = v_prof(:,:,:) *inv_n_time
v_prof_2(:,:,:) = v_prof_2(:,:,:) *inv_n_time
! velocity profile
open(unit=74,file='vel_prof.mide',status='unknown')
#ifndef PARTICLE_4
write(74,'(13a15)') "#z","vx_brush","vy_brush","vz_brush","vx2_brush","vy2_brush","vz2_brush" &
,"vx_melt","vy_melt","vz_melt","vx2_melt","vy2_melt","vz2_melt"
do i = 1 , n_layers
write(74,'(13e16.7)') z_min+dz/2.+dble(i-1)*dz,v_prof(i,:,1),v_prof_2(i,:,1),v_prof(i,:,2),v_prof_2(i,:,2)
end do
#else
write(74,'(19a16)') "#z","vx_brush","vy_brush","vz_brush","vx2_brush","vy2_brush","vz2_brush" &
,"vx_melt","vy_melt","vz_melt","vx2_melt","vy2_melt","vz2_melt", "vx_part4","vy_part4","vz_part4","vx2_part4","vy2_part4","vz2_part4"
do i = 1 , n_layers
write(74,'(19e16.7)') z_min+dz/2.+dble(i-1)*dz,v_prof(i,:,1),v_prof_2(i,:,1),v_prof(i,:,2),v_prof_2(i,:,2), &
v_prof(i,:,3),v_prof_2(i,:,3)
end do
#endif
case(2) ! Profile calculation
n_time = n_time + 1
r_scaled(3,:) = r0(3,:)*inv_z_step
! Brush
do i_part = 1, part_init_d
z_index = int (r_scaled(3,i_part) ) + 1
if(z_index<1) z_index =1
if(z_index>hist_dim) z_index = hist_dim
v_prof(z_index,:,1) = v_prof(z_index,:,1) + v(:,i_part)
v_prof_2(z_index,:,1) = v_prof_2(z_index,:,1) + v(:,i_part)*v(:,i_part)
end do
! Melt / Droplet
do i_part = part_init_d+1,part_init_e
z_index = int (r_scaled(3,i_part) ) + 1
if(z_index<1) z_index =1
if(z_index>hist_dim) z_index = hist_dim
v_prof(z_index,:,2) = v_prof(z_index,:,2) + v(:,i_part)
v_prof_2(z_index,:,2) = v_prof_2(z_index,:,2) + v(:,i_part)*v(:,i_part)
! print *,v_prof(:,1,2) ; stop
end do
! Particle 4 if applies
#ifdef PARTICLE_4
do i_part = part_init_e+1,n_mon_tot
z_index = int (r_scaled(3,i_part) ) + 1
if(z_index<1) z_index =1
if(z_index>hist_dim) z_index = hist_dim
v_prof(z_index,:,3) = v_prof(z_index,:,3) + v(:,i_part)
v_prof_2(z_index,:,3) = v_prof_2(z_index,:,3) + v(:,i_part)*v(:,i_part)
end do
#endif
! obsolete: order N^2 ! print *,n_time,dz
! obsolete: order N^2 n_time = n_time + 1
! obsolete: order N^2 do i = 1,n_layers
! obsolete: order N^2 v_cell_b(:) = 0.
! obsolete: order N^2 v_cell_m(:) = 0.
! obsolete: order N^2 z_count_b = 0
! obsolete: order N^2 z_count_m = 0
! obsolete: order N^2 zmin = z_min + dz*(real(i) - 1.)
! obsolete: order N^2 zmax = z_min + dz*real(i)
! obsolete: order N^2 do j= 1,n_parti
! obsolete: order N^2
! obsolete: order N^2 if( r0(3,j) < zmax.and. r0(3,j) > zmin) then
! obsolete: order N^2
! obsolete: order N^2 if(a_type(j) == 2 ) then ! If particle belongs to the brush
! obsolete: order N^2 z_count_b = z_count_b + 1
! obsolete: order N^2 v_cell_b(:) = v_cell_b(:) + v(j,:)
! obsolete: order N^2 end if
! obsolete: order N^2
! obsolete: order N^2 if(a_type(j) == 3 ) then ! If particle belongs to the melt
! obsolete: order N^2 z_count_m = z_count_m + 1
! obsolete: order N^2 v_cell_m(:) = v_cell_m(:) + v(j,:)
! obsolete: order N^2 end if
! obsolete: order N^2
! obsolete: order N^2 end if
! obsolete: order N^2 end do
! obsolete: order N^2
! obsolete: order N^2 v_prof(i,:,1) = v_prof(i,:,1) + v_cell_b(:) ! / real(z_count_b)
! obsolete: order N^2v_prof_2(i,:,1) = v_prof_2(i,:,1) + (v_cell_b(:))**2 !/ real(z_count_b)
! obsolete: order N^2
! obsolete: order N^2 v_prof(i,:,2) = v_prof(i,:,2) + v_cell_m(:) ! / real(z_count_m)
! obsolete: order N^2v_prof_2(i,:,2) = v_prof_2(i,:,2) + (v_cell_m(:))**2 ! / real(z_count_m)
! obsolete: order N^2
! obsolete: order N^2 end do
case default
print*,"*mode* must have the values 1,2, or 3. Stop here."
stop
end select
end subroutine velocity_prof
#endif
!
! **** Diffusion coefficient
!
# ifdef DIFF
subroutine diff_coef(mode,time)
integer, intent(in) :: mode
real (kind=8), intent(in) :: time
real (kind=8) :: vec(3),Dm(3),Dt(3)
integer :: i
select case(mode)
case(1) ! init
r0_ref(:,:) = r0_unfold(:,:)
print '(/a/)'," * Initizializing diffusion calculation [by now, only particle 4 ]"
! [Prepared, but not tested] open(unit=400,file='diff_m.mide',status='unknown')
open(unit=401,file='diff_t.mide',status='unknown')
! [Prepared, but not tested] write(400,*) "#real_time", " Diffusion coefficient: dx^2 dy^2 dz^2 "
write(401,*) "#real_time", " Diffusion coefficient: dx^2 dy^2 dz^2 "
case(2) ! for melt [WARN: has not been tested ]
! Diffusion coeficient for the melt only
Dm(:) = 0. ! D is dr^2
do i=part_init_d+ 1,part_init_e ! start in the first atom of the melt
vec(:)= r0_unfold(:,i) - r0_ref(:,i)
Dm(:) = Dm(:) + vec(:)*vec(:)
end do
write(400,'(2f16.7)') time, Dm(:)
case(3) ! ---------------- for tagged particles
Dt(:) = 0. ! D is dr^2
do i = part_init_e+ 1,n_mon_tot ! start in the first atom of the melt
vec(:)= r0_unfold(:,i) - r0_ref(:,i)
Dt(1) = Dt(1) + vec(1)*vec(1)
Dt(2) = Dt(2) + vec(2)*vec(2)
Dt(3) = Dt(3) + vec(3)*vec(3)
end do
write(401,'(4f16.7)') time, Dt(:)/dble(n_tot_e)
end select
end subroutine diff_coef
#endif /* DIFF */
!
! **** Radius of Gyration ****
! WARN: assumes equal masses
subroutine r_gyr(mode,i_case,n_mon,spabs,r_g2)
integer , intent(in) :: mode,n_mon,i_case
real (kind=8) ,intent(in) :: spabs(:,:)
! real (kind=8) ,intent(out) :: r_g_vec(:,:)
real (kind=8) :: r_g2(:,:)
real (kind=8) , allocatable,save :: r_g2_mean(:,:)
integer, allocatable, save :: n_count(:)
real (kind=8) :: v_dummy(3) , r_cm(3), r_dummy(3)
integer :: i_chain, n_chain,i_part,i
integer, save :: n_case
select case(mode)
case(1) ! init
n_case = size(r_g2,dim=1)
allocate( r_g2_mean(n_case,3) , n_count(n_case) )
n_count(:) = 0
r_g2_mean(:,:) = 0.
case(2) ! calculation
n_count(i_case) = n_count(i_case) + 1
n_chain = size (spabs,dim = 1) /n_mon
! print *,"i_case=",i_case,'n_chain=',n_chain
r_g2(i_case,:) = 0.d0
!
! **** Rg^2 ****
!
do i_chain = 1,n_chain
v_dummy(:) = 0.0
r_cm(:) = sum(spabs( (i_chain-1)*n_mon+1:i_chain*n_mon,:),dim=1) / dble(n_mon)
do i_part=n_mon*(i_chain-1)+1 ,i_chain*n_mon
v_dummy(:) = v_dummy(:) + (spabs(:,i_part) - r_cm(:) )**2
end do
v_dummy(:) = v_dummy(:) / dble(n_mon) ! Rg^2 of one polymer
r_g2(i_case,:) = r_g2(i_case,:) + v_dummy(:) ! mean Rg*N
end do
r_g2(i_case,:) = r_g2(i_case,:)/dble(n_chain)! mean Rg
r_g2_mean(i_case,:) = r_g2_mean(i_case,:) + r_g2(i_case,:)
case(3)
do i = 1,n_case
r_g2_mean(i,:) = r_g2_mean(i,:) / real(n_count(i))
end do
print '(/15x,a/)', "Radius of Gyration: "
print '(a30,3f16.7)',"Top brushes, Rg^2= ",r_g2_mean(1,:)
print '(a30,3f16.7)',"Bottom brushes, Rg^2= ",r_g2_mean(2,:)
print '(a30,3f16.7)',"Melt, Rg^2= ",r_g2_mean(3,:)
! r_g2(3,1) = dot_product( r_g2(1,:),r_g2(1,:))
! Rg for Melt
!!!! do i_chain = n_chain+1,n_chain + n_chain_d
!!!! v_dummy(:) = 0.0
!!!! r_cm(:) = sum(spabs((i_chain-1)*n_mon_d+1:i_chain*n_mon_d,:),dim=1) / dble(n_mon_d)
!!!! do i_part= (i_chain-1)*n_mon_d+1,i_chain*n_mon_d
!!!! v_dummy(:) = v_dummy(:) + spabs(:,i_part)**2 - r_cm(:)**2
!!!! end do
!!!! v_dummy(:) = v_dummy(:) / dble(n_mon_d)! Rg of one polymer
!!!! r_g2(2,:) = r_g2(2,:) + v_dummy(:)! sumN Rg
!!!! end do
!!!! r_g2(2,:) = r_g2(2,:)/dble(n_chain_d) ! mean Rg^2
end select
! r_g2_mean(1,:) = r_g2_mean(1,:)+ r_g2(1,:) !brushes
! r_g2_mean(2,:) = r_g2_mean(2,:)+ r_g2(2,:) ! droplet/melt
! r_g2_mean(3,:) = r_g2_mean(3,:)+ (r_g2(1,:) + r_g2(2,:))/2.0 ! total
!
! r_par_per2(1) = r_par_per2(1)+ (r_g2(1,3)- 0.5*(r_g2(1,1)+r_g2(1,2)))/sum(r_g2(1,:))
! r_par_per2(2) = r_par_per2(2)+ (r_g2(2,3)- 0.5*(r_g2(2,1)+r_g2(2,2)))/sum(r_g2(2,:))
! ------------ end gyration stuff
!print*, sqrt(dot_product(r_g2(1,:),r_g2(1,:))), sqrt(dot_product(r_g2(2,:),r_g2(2,:)))
! energies out
end subroutine r_gyr
!
! **** Radius of Gyration 2nd Version ****
! WARN: assumes equal masses
subroutine r_gyr_2v(mode,n_mon,n_chain,n_mon_d,n_chain_d,spabs,r_g2,r_g_vec,r_cm_vec)
integer , intent(in) :: mode,n_mon,n_mon_d,n_chain,n_chain_d
real (kind=8) ,intent(in) :: spabs(:,:)
real (kind=8) ,intent(out) :: r_g_vec(:,:), r_cm_vec(:,:)
real (kind=8) :: r_g2(:,:)
real (kind=8) , allocatable,save :: r_g2_mean(:,:)
integer, save :: n_count
real (kind=8) :: v_dummy(3) , r_cm(3), r_dummy(3)
integer :: i_chain, i_part,i
integer, save :: n_case
select case(mode)
case(1) ! init
n_case = size(r_g2,dim=1)
allocate( r_g2_mean(n_case,3) )
n_count = 0
r_g2_mean(:,:) = 0.
case(2) ! calculation
n_count = n_count + 1
!
! **** Rg^2 ****
! CM calculation
do i_chain = 1,n_chain ! brush
r_cm(:) = sum(spabs( (i_chain-1)*n_mon+1:i_chain*n_mon,:),dim=1) / dble(n_mon)
r_cm_vec(i_chain,:) = r_cm(:)
end do
do i_chain = n_chain+1, n_chain+n_chain_d ! melt
r_cm(:) = sum(spabs( (i_chain-1)*n_mon_d+1:i_chain*n_mon_d,:),dim=1) / dble(n_mon_d)
r_cm_vec(i_chain,:) = r_cm(:)
end do
! R_gyr itself
do i_chain = 1,n_chain ! brushes
v_dummy(:) = 0.0
do i_part=n_mon*(i_chain-1)+1 ,i_chain*n_mon ! loop over particles of the same polymer
v_dummy(:) = v_dummy(:) + (spabs(:,i_part) - r_cm_vec(i_chain,:) )**2
end do
v_dummy(:) = v_dummy(:) / dble(n_mon) ! Rg^2 of one polymer
r_g_vec(i_chain,:) = v_dummy(:)
end do
do i_chain = n_chain+1,n_chain+n_chain_d ! melt
v_dummy(:) = 0.0
do i_part=n_mon_d*(i_chain-1)+1 ,i_chain*n_mon_d ! loop over particles of the same polymer
v_dummy(:) = v_dummy(:) + (spabs(:,i_part) - r_cm_vec(i_chain,:) )**2
end do
v_dummy(:) = v_dummy(:) / dble(n_mon) ! Rg^2 of one polymer
r_g_vec(i_chain,:) = v_dummy(:)
end do
! [system dependent]
r_g2(1,:) = sum (r_g_vec(1:n_chain/2,:),dim=1) /real(n_chain/2)
r_g2(2,:) = sum (r_g_vec(1+n_chain/2:n_chain,:),dim=1) /real(n_chain/2)
r_g2(3,:) = sum (r_g_vec(1+n_chain:n_chain+n_chain_d,:),dim=1) /real(n_chain_d)
do i = 1,n_case
r_g2_mean(i,:) = r_g2_mean(i,:) + r_g2(i,:)
end do
case(3)
do i = 1,n_case
r_g2_mean(i,:) = r_g2_mean(i,:) / real(n_count)
end do
print '(/15x,a/)', "Radius of Gyration: Rg^2 "
print '(a30,4f16.7)',"Top brushes, Rg^2= ", r_g2_mean(1,:),sum( r_g2_mean(1,:))
print '(a30,4f16.7)',"Bottom brushes, Rg^2= ",r_g2_mean(2,:),sum( r_g2_mean(2,:))
print '(a30,4f16.7)',"Melt, Rg^2= ", r_g2_mean(3,:),sum( r_g2_mean(3,:))
end select
end subroutine r_gyr_2v
!
!
! **** End to End Radius **** SECOND VERSION
!
subroutine r_end_to_end_2v(mode,n_mon,n_chain,n_mon_d,n_chain_d,r0_unfold,r_ee,r_ee_mean,r_ee2,r_ee_mean2,r_ee_vec)
integer , intent(in) :: mode,n_mon,n_chain,n_mon_d,n_chain_d
real (kind=8) , intent(in) :: r0_unfold(:,:)
real (kind=8) , intent(out) :: r_ee(:,:),r_ee_mean(:,:),r_ee2(:,:),r_ee_mean2(:,:),r_ee_vec(:,:)
integer, save :: n_count,n_case,n_chain_tot
real (kind=8) :: v_dummy(3) , r_dummy(3),dist
integer :: i_chain, i_part,i,i_case
select case(mode)
case(1) ! init
n_case = 3 ! size(r_ee,dim=1)
! allocate( r_ee_mean(n_case,3) ,n_count(n_case) )
n_count = 0
r_ee_mean(:,:) = 0.
r_ee_mean2(:,:) = 0.
open(unit=76,file='R_ee_dist.mide',status='unknown')
write(76,*) '#Distance of Ree for brushes vs time'
case(2) ! calculation
n_count = n_count + 1
n_chain_tot = n_chain+n_chain_d !size (spabs,dim = 1) /n_mon
! print*,"n_chain=",n_chain
r_ee(:,:) = 0.d0
r_ee2(:,:) = 0.d0
!
! **** R end to end = Ree ****
!
do i_chain = 1,n_chain_tot
v_dummy(:) = spabs(i_chain*n_mon, :) - spabs((i_chain-1)*n_mon+1,:)
! for each chain
r_ee_vec(i_chain,:) = v_dummy(:)
end do
!
! dintiguish top, bottom wall and melt for mean values
! [this might be system dependent ]
do i_chain=1,n_chain/2 ! top
r_ee(1,:)=r_ee(1,:)+ r_ee_vec(i_chain,:)
r_ee2(1,:)=r_ee2(1,:)+ r_ee_vec(i_chain,:)**2
dist = sqrt( dot_product (r_ee_vec(i_chain,:),r_ee_vec(i_chain,:) ) )
write(76,*) n_count,dist
end do
do i_chain=n_chain/2+1 ,n_chain ! bottom
r_ee(2,:)=r_ee(2,:)+ r_ee_vec(i_chain,:)
r_ee2(2,:)=r_ee2(2,:)+ r_ee_vec(i_chain,:)**2
dist = sqrt( dot_product( v_dummy(:),v_dummy(:) ) )
write(76,*) n_count,dist
end do
do i_chain=n_chain +1, n_chain+n_chain_d ! melt
r_ee(3,:)=r_ee(3,:)+ r_ee_vec(i_chain,:)
r_ee2(3,:)=r_ee2(3,:)+ r_ee_vec(i_chain,:)**2
end do
r_ee(1,:) = r_ee(1,:)/dble(n_chain/2)
r_ee(2,:) = r_ee(2,:)/dble(n_chain/2)
r_ee(3,:) = r_ee(3,:)/dble(n_chain_d)
r_ee2(1,:) = r_ee2(1,:)/dble(n_chain/2)
r_ee2(2,:) = r_ee2(2,:)/dble(n_chain/2)
r_ee2(3,:) = r_ee2(3,:)/dble(n_chain_d)
r_ee_mean(:,:) = r_ee_mean(:,:) + r_ee(:,:)
r_ee_mean2(:,:) = r_ee_mean2(:,:) + r_ee2(:,:)
!
case(3)
r_ee_mean(:,:) = r_ee_mean(:,:) / real(n_count)
r_ee_mean2(:,:) = r_ee_mean2(:,:) / real(n_count)
print '(/15x,a/)', "End to End Radius "
print '(a30,3f16.7)',"Top brushes, Ree= ",r_ee_mean(1,:)
print '(a30,3f16.7)',"Bottom brushes, Ree= ",r_ee_mean(2,:)
print '(a30,3f16.7)',"Melt, Ree= ",r_ee_mean(3,:)
! ------ Square end to end distance:
print '(/a30,4f16.7)',"Top brushes, Ree2= ",r_ee_mean2(1,:) ,sum(r_ee_mean2(1,:))
print '(a30,4f16.7)',"Bottom brushes, Ree2= ",r_ee_mean2(2,:) ,sum(r_ee_mean2(2,:))
print '(a30,4f16.7/)',"Melt, Ree2= ",r_ee_mean2(3,:) ,sum(r_ee_mean2(3,:))
end select
end subroutine r_end_to_end_2v
!
! **** End to End Radius ****
!
subroutine r_end_to_end(mode,i_case,n_mon,spabs,r_ee,r_ee_mean,r_ee2,r_ee_mean2)
integer , intent(in) :: mode,n_mon,i_case
real (kind=8) , intent(in) :: spabs(:,:)
real (kind=8) , intent(out) :: r_ee(:,:),r_ee_mean(:,:),r_ee2(:,:),r_ee_mean2(:,:)
integer, save :: n_count(3),n_case
real (kind=8) :: v_dummy(3) , r_dummy(3),dist
integer :: i_chain, n_chain,i_part,i
select case(mode)
case(1) ! init
n_case = 3 ! size(r_ee,dim=1)
! allocate( r_ee_mean(n_case,3) ,n_count(n_case) )
n_count(:) = 0
r_ee_mean(:,:) = 0.
r_ee_mean2(:,:) = 0.
open(unit=46,file='R_ee_dist.mide',status='unknown')
write(46,*) '#Distance of Ree for brushes vs time'
case(2) ! calculation
n_count(i_case) = n_count(i_case) + 1
n_chain = size (spabs,dim = 1) /n_mon
! print*,"n_chain=",n_chain
r_ee(i_case,:) = 0.d0
r_ee2(i_case,:) = 0.d0
!
! **** R end to end = Ree ****
!
do i_chain = 1,n_chain
v_dummy(:) = spabs(i_chain*n_mon, :) - spabs((i_chain-1)*n_mon+1,:)
r_ee(i_case,:)=r_ee(i_case,:)+ v_dummy(:)
r_ee2(i_case,:)=r_ee2(i_case,:)+ v_dummy(:)**2
!!!! WARN: commented for speed-up
! r_ee_vec(i_chain,:) = v_dummy(:)
!!! if(i_case==1.or.i_case==2) then ! for brushes
!!! dist = sqrt( dot_product( v_dummy(:),v_dummy(:) ) )
!!! write(46,*) n_count(i_case),dist
!!! end if
end do
r_ee(i_case,:) = r_ee(i_case,:)/dble(n_chain)
r_ee2(i_case,:) = r_ee2(i_case,:)/dble(n_chain)
r_ee_mean(i_case,:) = r_ee_mean(i_case,:) + r_ee(i_case,:)
r_ee_mean2(i_case,:) = r_ee_mean2(i_case,:) + r_ee2(i_case,:)
!
!
case(3)
do i = 1,n_case
r_ee_mean(i,:) = r_ee_mean(i,:) / real(n_count(i))
r_ee_mean2(i,:) = r_ee_mean2(i,:) / real(n_count(i))
end do
print '(/15x,a/)', "End to End Radius: "
print '(a30,3f16.7)',"Top brushes, Ree= ",r_ee_mean(1,:)
print '(a30,3f16.7)',"Bottom brushes, Ree= ",r_ee_mean(2,:)
print '(a30,3f16.7)',"Melt, Ree= ",r_ee_mean(3,:)
! ------ Square end to end distance:
print '(/a30,4f16.7)',"Top brushes, Ree2= ",r_ee_mean2(1,:) ,sum(r_ee_mean2(1,:))
print '(a30,4f16.7)',"Bottom brushes, Ree2= ",r_ee_mean2(2,:),sum(r_ee_mean2(2,:))
print '(a30,4f16.7/)',"Melt, Ree2= ",r_ee_mean2(3,:) ,sum(r_ee_mean2(3,:))
end select
end subroutine r_end_to_end
!
! ***** Angle with a plane
!
function angle_plane(vector,p_normal) result(angle)
real (kind=8) :: vector(3), p_normal(3),angle
real (kind=8) :: pi
pi = 4.*atan(1.)
angle = pi/2. - acos ( dot_product(p_normal,vector)/ &
sqrt ( dot_product(vector,vector)*dot_product(p_normal,p_normal) ) )
angle = angle* 180./pi
end function angle_plane
!
! ***** Drop to a file the velocity history of the last brush monomer
!
subroutine drop_v_end(mode,r_time,n_chain,n_mon)
integer ,intent(in) :: mode,n_chain,n_mon
real(kind=8) ,intent(in) :: r_time
integer :: i,j
select case (mode)
case(1)
open(unit=47,file='v_end_history.mide',status='unknown')
write(47,*) '# Velocity of the last monomer in the brush '
case(2)
do i=1,n_chain
j = i*n_mon
write(47,'(4f16.7)') r_time,v(j,:) ! Be careful because top and botom walls vel. have diff. signs
end do
end select
end subroutine drop_v_end
!
! ** Bond orientation calculations
!
subroutine bond_orientation(mode,D,n_mon,n_chain,n_mon_d,n_chain_d,r0_unfold,count_bonds,bond_orient_histo)
real (kind=8), intent(in) :: D
integer , intent(in) :: n_mon,n_chain,n_mon_d,n_chain_d,mode
real (kind=8), intent(in) :: r0_unfold(:,:)
real (kind=8),intent(inout) :: bond_orient_histo(:,:)
integer, save :: n_layers,n_chains,l_count,melt0
integer, parameter :: pi= 3.141516
integer :: i_chain,i_mon,i_layer,i,at1,j
! integer, allocatable:: count_bonds(:,:)
! integer :: count_bonds(2,size(bond_orient_histo(:,:),dim=2))= 0
integer :: count_bonds(:,:)
real (kind=8), save :: dz
real (kind=8) :: bond(3),z1,length_2,s1,s2
select case (mode)
case(1)
bond_orient_histo(:,:) = 0.0
n_layers = size(bond_orient_histo(:,:),dim=2)
!debug print *,n_layers ; stop
! allocate( count_bonds(2,n_layers))
! n_chains = size(r0,dim=1)/n_mon
dz = D/real(n_layers)
open(unit=49,file='bond_orient.mide',status='unknown')
write(49,*) '# z 0.5*(3*<cos(theta)^2>-1) angle of bond with the 001 vector'
l_count = 0
melt0 = n_mon*n_chain
count_bonds(:,:) = 0
case(2)
!not used by now l_count = l_count + 1 ! n times we are here
! print*,count_bonds
! stop
! Brush
do i_chain =1,n_chain
do i_mon= 1, n_mon-1
at1 = (i_chain-1)*n_mon+i_mon
! print *,"at1=",at1,at1+1
z1= (r0_unfold(3,at1+1) + r0_unfold(3,at1))/2.
do i_layer = 1 , n_layers
if (z1<real(i_layer)*dz .and. z1>=real(i_layer-1)*dz) then
count_bonds(1,i_layer) = count_bonds(1,i_layer) + 1
bond(:) = r0_unfold(:,at1+1) - r0_unfold(at1 ,:)
length_2 = dot_product(bond,bond)
! print*,'length_2=',length_2
! if(length_2>9.) then
! print *,"bond too high"
! stop
! endif
! bond(:) = bond(:) / sqrt( dot_product(bond,bond) )
bond_orient_histo(1,i_layer) = bond_orient_histo(1,i_layer) + &
bond(3)**2/length_2 ! melt
! print*,"cos^2(theta)=" ,(bond(3))**2/length_2
exit
end if
end do
end do
end do
! Melt
do i_chain =1,n_chain_d
do i_mon= 1, n_mon_d-1
at1 = melt0 + (i_chain-1)*n_mon+i_mon
! print*,at1
z1= (r0_unfold(3,at1+1) + r0_unfold(3,at1))/2.
do i_layer = 1 , n_layers
if (z1<real(i_layer)*dz .and. z1>=real(i_layer-1)*dz) then
count_bonds(2,i_layer) = count_bonds(2,i_layer) + 1
bond(1:3) = r0_unfold(at1 + 1,:) - r0_unfold(:,at1)
length_2 = dot_product(bond,bond)
bond_orient_histo(2,i_layer) = bond_orient_histo(2,i_layer) + &
bond(3)**2/length_2 ! melt
exit
end if
end do
end do
end do
case(3)
! this is gramatically correct
! where(count_bonds /= 0) bond_orient_histo(:,:) = bond_orient_histo(:,:) / real(count_bonds(:,:))
! bond_orient_histo(:,:) = bond_orient_histo(:,:) /real(l_count ) ! redundant with the other normaliz ? YES
print '(/a/)'," * bond orientation note: if not counts in a given layer, S is set to 0 "
do i = 1,n_layers
if(bond_orient_histo(1,i) == 0.) then
s1 = 1./3.
else
s1 = bond_orient_histo(1,i) / real(count_bonds(1,i))
end if
if(bond_orient_histo(2,i) == 0.) then
s2 = 1./3.
else
s2 = bond_orient_histo(2,i)/ real(count_bonds(2,i))
end if
! write file
write(49,'(3f16.7)') dz/2. + real(i-1)*dz, &
0.5*(3.*s1-1.),0.5*(3.*s2 - 1.)
! set up final bond_orient_histo:
bond_orient_histo(1,i) = 0.5*(3.*s1-1.)
bond_orient_histo(2,i) = 0.5*(3.*s2-1.)
end do
end select
end subroutine bond_orientation
!
! Profile calculation routine of order parameter
!
subroutine profile_orient(D,vec_in,r_cms,prof,mean_prof,l_count)
real (kind=8), intent(in) :: vec_in(:,:),r_cms(:,:)
real (kind=8), intent(in) :: D
integer, intent(inout) :: l_count(:)
real (kind=8), intent(out) :: prof(:),mean_prof(:)
real (kind=8) :: dz,length_2
integer :: i_vec,j,k,n_layers,i_layer,vec_dim
n_layers = size(prof)
dz = D/real(n_layers)
vec_dim = size(vec_in,dim=1)
prof(:) = 0.
do i_vec = 1, vec_dim
do i_layer = 1, n_layers
if (r_cms(i_vec,3)<real(i_layer)*dz .and. r_cms(i_vec,3) > real(i_layer-1)*dz ) then
l_count(i_layer) = l_count(i_layer) + 1
! calculation of the order parameter
length_2 = dot_product(vec_in(i_vec,:),vec_in(i_vec,:) )
! I use now this: Rz^2-(Rx^2+Ry^2)/2 / length^2
prof(i_layer) = prof(i_layer) + &
( vec_in(i_vec,3)**2 - 0.5*(vec_in(i_vec,1)**2 + vec_in(i_vec,2)**2) ) / length_2
exit
end if
end do
end do
mean_prof(:) = mean_prof(:) + prof(:)
end subroutine profile_orient
!
! Writes a file of the vector and the name of the argument
subroutine write_file(f_name,comment,x_axes,y_axes)
character (len=*), intent(in) :: f_name, comment
real(kind =8) ,intent(in) :: x_axes(:),y_axes(:)
integer :: i
open(unit=92,file=f_name,status='unknown')
write(92,*) comment
do i=1,size(y_axes,dim=1)
write(92,'(2f16.7)') x_axes(i),y_axes(i)
end do
close(92)
end subroutine write_file
!
! CM histograms
!
subroutine histo_cm(mode,D,n_chain,n_chain_d,vector,histo_out)
implicit none
real (kind=8), dimension(:,:), intent(in) :: vector
real (kind=8) , intent(in) :: D
integer , intent(in) :: mode,n_chain,n_chain_d
real (kind=8) , dimension(:,:), intent(out) :: histo_out
real (kind=8),save :: dz
integer, save :: l_count, n_part, n_dim
integer :: n_max,i_step,i_part,n_step_clau
select case (mode)
case(1)
histo_out(:,:) = 0.
n_dim = size(histo_out,dim=2)
dz = D/real(n_dim)
n_part = size(vector,dim=1)
l_count = 0
case(2)
l_count = l_count + 1
! Brushes
do i_part = 1, n_chain
do i_step = 1, n_dim
if(vector(i_part,3) < dz*i_step .and. vector(i_part,3) >= dz*(i_step-1) ) then
histo_out(1,i_step) = histo_out(1,i_step) + 1
exit
end if
end do
end do
! Melt
do i_part = n_chain, n_chain+n_chain_d
do i_step = 1, n_dim
if(vector(i_part,3) < dz*i_step .and. vector(i_part,3) >= dz*(i_step-1) ) then
histo_out(2,i_step) = histo_out(2,i_step) + 1
exit
end if
end do
end do
! note: the normalization and output is done in the main program
case(3)
histo_out(:,:) = histo_out(:,:) /real (l_count ) ! here is normalized to the number of time steps
end select
end subroutine histo_cm
! Calculates the mean value of Ree or R in the middle of the sample
subroutine mean_R_center_box(z,z_int,R_vec,R_cm,mean_R,count_R)
real (kind=8) , dimension(:,:), intent(in) :: R_vec,R_cm