-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paths_shell_s.f90
591 lines (374 loc) · 17.9 KB
/
s_shell_s.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
program suave_shell
use types
use variables
use funcproc
use gmxfort_trajectory
use gmxfort_utils
!============================
type(Trajectory) :: trj
real :: copy(3)
!============================
call startup(outer, bin, p_grid, coord, ind, ind2, rmsd, map, ind3, &
l_coarse, begin, end, skip, lipid, rough, slices, inside, range, &
n_grid, bin_out, fr_in, fr_end, n_skip, n_lipid, get, div, 's_shell ', version)
!Leitura do PDB
12 format(a6, i5.1, a5, a5, a1, i4.1, a4, 3f8.3)
if (ind2=='miss')then
write(*, *)
write(*, *)'Second index file is missing'
write(*, *)
stop
end if
!==Lendo os arquivos de index=========================
if (.not.outer)then
call abre_ndx(ind, in_num, n_index)
call abre_ndx(ind2, in_num2, n_index)
end if
!=================definindo frames para inicio e fim========
call def_frame(frame, fr_in, fr_end, skip, n_skip, end, begin)
!=================calculando o espaçamento==================
call def_bin_sph(bin_coarse, n_index, bin, n_grid)
!==================== abrindo trajetórias =====================
traj_type = coord(len(trim(coord))-2:len(trim(coord)))
if (traj_type=='xtc') call trj%open(coord)
if (traj_type=='pdb') call abre_trj(1, coord)
!==================== abrindo outputs =========================
call abre('thick ', 2, 'xvg', back)
write(2, '(a7, a7)') "#SuAVE ", version
write(2, '(a14)') '#Command Line:'
write(2, '(a10)', advance='no') '#s_shell '
write(2, *) (trim(get(i))," ", i=1, 20)
write(2, *) '@ title "Thickness X Frame"'
write(2, *) '@ xaxis label "#Frame"'
write(2, *) '@ yaxis label "Average Thickness [nm]"'
if (rmsd)then
call abre('rmsd ', 3, 'xvg', back)
write(3, '(a7, a7)') "#SuAVE ", version
write(3, '(a14)') '#Command Line:'
write(3, '(a10)', advance='no') '#s_shell '
write(3, *) (trim(get(i))," ", i=1, 20)
write(3, *) '@ title "RMSD X Frame"'
write(3, *) '@ xaxis label "#Frame"'
write(3, *) '@ yaxis label "RMSD [nm]"'
end if
call abre('volume ', 4, 'xvg', back)
write(4, '(a7, a7)') "#SuAVE ", version
write(4, '(a14)') '#Command Line:'
write(4, '(a10)', advance='no') '#s_shell '
write(4, *) (trim(get(i))," ", i=1, 20)
write(4, *) '@ title "Volume X Frame"'
write(4, *) '@ xaxis label "#Frame"'
write(4, *) '@ yaxis label "Total Spherical Shell Volume[nm\S3\N]"'
! =====================================================================
allocate (xpm1((n_grid - int(n_grid/2)), n_grid), stat = ierr)
if (ierr /= 0) stop 'Not enough memory to initialize xpm matrix'
allocate (r_xpm1((n_grid - int(n_grid/2)), n_grid), stat = ierr)
if (ierr /= 0) stop 'Not enough memory to initialize xpm matrix'
do i=1, n_grid - int(n_grid/2)
do j=1, n_grid
r_xpm1(i,j) = 0
end do
end do
call system_clock(start, clock_rate, clock_max)
! Leitura do arquivo .pdb
i_atom = 0
n_index = 1
ierr = 0
num = 1
num2 = 1
cent_x = 0
cent_y = 0
cent_z = 0
minv = 100000
maxv = -100000
tot_frame = 0
do while (ierr >= 0)
if (traj_type=='pdb') then
next_frame = .false.
do while (.not.next_frame)
read(1, 12, iostat=ierr) atom, buff%n_atom, buff%atom, &
buff%resid, buff%ident, buff%n_resid, buff%code, buff%x, &
buff%y, buff%z
if (ierr<0) exit
if ((atom.eq.'ATOM '))then
if(ierr > 0) then
write(*, *)
write(*, *) 'Problem reading atomic position!'
write(*, *)
stop
endif
i_atom = i_atom + 1
buff%n_atom = i_atom
if ((i_atom == in_num(num)))then
spher(n_index) = buff
cent_x = (cent_x*(n_index-1) + buff%x)/(n_index)
cent_y = (cent_y*(n_index-1) + buff%y)/(n_index)
cent_z = (cent_z*(n_index-1) + buff%z)/(n_index)
num = num + 1
n_index = n_index + 1
end if
if ((i_atom == in_num2(num2)))then
spher(n_index) = buff
cent_x = (cent_x*(n_index-1) + buff%x)/(n_index)
cent_y = (cent_y*(n_index-1) + buff%y)/(n_index)
cent_z = (cent_z*(n_index-1) + buff%z)/(n_index)
num2 = num2 + 1
n_index = n_index + 1
end if
end if
next_frame = ((atom.ne.'ATOM ').and.(n_index > 1))
end do
frame = frame + 1
end if
! ===================================
if (traj_type=='xtc') then
frame = frame + trj%read_next(1)
do while (i_atom < trj%natoms())
i_atom = i_atom + 1
if (i_atom == in_num(num)) then
copy = trj%x(1, i_atom)
spher(n_index)%n_atom = i_atom
spher(n_index)%x = copy(1)*10
spher(n_index)%y = copy(2)*10
spher(n_index)%z = copy(3)*10
cent_x = (cent_x*(n_index-1) + copy(1)*10)/(n_index)
cent_y = (cent_y*(n_index-1) + copy(2)*10)/(n_index)
cent_z = (cent_z*(n_index-1) + copy(3)*10)/(n_index)
num = num + 1
n_index = n_index + 1
end if
if ((i_atom == in_num2(num2)))then
copy = trj%x(1, i_atom)
spher(n_index)%n_atom = i_atom
spher(n_index)%x = copy(1)*10
spher(n_index)%y = copy(2)*10
spher(n_index)%z = copy(3)*10
cent_x = (cent_x*(n_index-1) + copy(1)*10)/(n_index)
cent_y = (cent_y*(n_index-1) + copy(2)*10)/(n_index)
cent_z = (cent_z*(n_index-1) + copy(3)*10)/(n_index)
num2 = num2 + 1
n_index = n_index + 1
end if
end do
end if
! Fitting process =============================================================
eval_skip = ((mod((frame-fr_in),(n_skip+1))==0))
if ((frame>fr_in-1).and.(frame<fr_end+1).and.(eval_skip).and.(ierr>=0)) then
tot_frame = tot_frame + 1 ! para programas que calculam propriedades medias
num = 1
num2 = 1
r_med1 = 0
r_med2 = 0
! transformando em Coordenadas Esfericas ======================================================
do i=1, n_index - 1
if ((spher(i)%n_atom == in_num(num))) then
call cart2sphe(num, r_med1, cent_x, cent_y, cent_z, store(num), spher(i))
else
call cart2sphe(num2, r_med2, cent_x, cent_y, cent_z, store2(num2), spher(i))
end if
end do
!! A partir desse ponto as coordenadas são esféricas e estão com o centro transladado para
!! o centro da micela. Logo, quando retornarmos para as coordenadas cartesianas teremos que
!! transladar novamente
noi1 = num - 1
noi2 = num2 - 1
if (l_coarse) then
! Estruturação do primeiro coarse grid=============================================
dph = (2*pi)/(2*(bin_coarse - int(bin_coarse/2)))
dth = (2*pi)/bin_coarse
call param_esf(r_med1, num, r_fit, al, rough)
!$OMP parallel do private(s_grid, dist, j, k, aux)
do i=1, (bin_coarse - int(bin_coarse/2)) + 1
do j=1, bin_coarse + 1
aux = (j-1)*(bin_coarse - int(bin_coarse/2) + 1) + i
coarse(aux)%phi = (i-1)*dph
coarse(aux)%theta = (j-1)*dth
s_grid = 0
coarse(aux)%rho = 0
do k=1, num - 1
dist = sin(coarse(aux)%phi)*sin(store(k)%phi)*cos(coarse(aux)%theta-store(k)%theta)
dist = dist + cos(coarse(aux)%phi)*cos(store(k)%phi)
dist = store(k)%rho*acos(dist)
dist = al*dist
if (dist/al<r_fit)then
s_grid = s_grid + exp(-dist*dist/pi)
coarse(aux)%rho = coarse(aux)%rho + exp(-dist*dist/pi)*store(k)%rho
end if
end do
coarse(aux)%rho = coarse(aux)%rho/s_grid
end do
end do
!$OMP end parallel do
num = (bin_coarse + 1)*(bin_coarse - int(bin_coarse/2) + 1) + 1
! Estruturação do segundo coarse grid=======================================
call param_esf(r_med2, num2, r_fit, al, rough)
!$OMP parallel do private(s_grid, dist, j, k, aux)
do i=1, (bin_coarse - int(bin_coarse/2)) + 1
do j=1, bin_coarse + 1
aux = (j-1)*(bin_coarse - int(bin_coarse/2) + 1) + i
coarse2(aux)%phi = (i-1)*dph
coarse2(aux)%theta = (j-1)*dth
s_grid = 0
coarse2(aux)%rho = 0
do k=1, num2 - 1
dist = sin(coarse2(aux)%phi)*sin(store2(k)%phi)*cos(coarse2(aux)%theta-store2(k)%theta)
dist = dist + cos(coarse2(aux)%phi)*cos(store2(k)%phi)
dist = store2(k)%rho*acos(dist)
dist = al*dist
if (dist/al<r_fit)then
coarse2(aux)%rho = coarse2(aux)%rho + exp(-dist*dist/pi)*store2(k)%rho
s_grid = s_grid + exp(-dist*dist/pi)
end if
end do
coarse2(aux)%rho = coarse2(aux)%rho/s_grid
end do
end do
!$OMP end parallel do
num2 = (bin_coarse + 1)*(bin_coarse - int(bin_coarse/2) + 1) + 1
else
coarse = store
coarse2 = store2
end if
! estruturação do prmeiro grid de alta resolução========================
dph = (2*pi)/(2*(n_grid - int(n_grid/2)))
dth = (2*pi)/n_grid
call param_esf(r_med1, num, r_fit, al, rough)
!$OMP parallel do private(s_grid, dist, j, k)
do i=1, (n_grid - int(n_grid/2)) + 1
do j=1, n_grid+1
grid(i,j)%phi = (i-1)*dph
grid(i,j)%theta = (j-1)*dth
s_grid = 0
grid(i,j)%rho = 0
do k=1, num - 1
dist = sin(grid(i,j)%phi)*sin(coarse(k)%phi)*cos(grid(i,j)%theta-coarse(k)%theta)
dist = dist + cos(grid(i,j)%phi)*cos(coarse(k)%phi)
dist = coarse(k)%rho*acos(dist)
dist = al*dist
if (dist/al<r_fit)then
s_grid = s_grid + exp(-dist*dist/pi)
grid(i,j)%rho = grid(i,j)%rho + exp(-dist*dist/pi)*coarse(k)%rho
end if
end do
grid(i,j)%rho = grid(i,j)%rho/s_grid
end do
end do
!$OMP end parallel do
! estruturação do segundo grid de alta resolução========================
call param_esf(r_med2, num2, r_fit, al, rough)
!$OMP parallel do private(s_grid, dist, j, k)
do i=1, (n_grid - int(n_grid/2)) + 1
do j=1, n_grid + 1
grid2(i,j)%phi = (i-1)*dph
grid2(i,j)%theta = (j-1)*dth
s_grid = 0
grid2(i,j)%rho = 0
do k=1, num2 - 1
dist = sin(grid2(i,j)%phi)*sin(coarse2(k)%phi)*cos(grid2(i,j)%theta-coarse2(k)%theta)
dist = dist + cos(grid2(i,j)%phi)*cos(coarse2(k)%phi)
dist = coarse2(k)%rho*acos(dist)
dist = al*dist
if (dist/al<r_fit)then
s_grid = s_grid + exp(-dist*dist/pi)
grid2(i,j)%rho = grid2(i,j)%rho + exp(-dist*dist/pi)*coarse2(k)%rho
end if
end do
grid2(i,j)%rho = grid2(i,j)%rho/s_grid
end do
end do
!$OMP end parallel do
! Fim da estruturação========================================
! Calculando o volume do grid==============================
call sphe2cart((n_grid-int(n_grid/2))+1, n_grid+1, cent_x, cent_y, cent_z, grid, grid3)
call calc_area_sph((n_grid-int(n_grid/2))+1, n_grid+1, s_area, s_vol, dph, dth, grid, grid3)
! Calculando o volume do grid2 ============================
call sphe2cart((n_grid-int(n_grid/2))+1, n_grid+1, cent_x, cent_y, cent_z, grid2, grid3)
call calc_area_sph((n_grid-int(n_grid/2))+1, n_grid+1, s_area2, s_vol2, dph, dth, grid2, grid3)
write(4, *) frame, abs(s_vol - s_vol2)/(1000)
! Fim do calculo ==========================================
! Calculando o thickness médio=============================
call calc_thick_sph((n_grid-int(n_grid/2))+1, n_grid+1, aver, aver2, r_xpm1, grid, grid2)
desv = sqrt(aver2 - aver*aver)
minv = min(aver-2*desv, minv)
maxv = max(aver+2*desv, maxv)
write(2, *) frame, aver
! Calculando o RMSD========================================
if (rmsd)then
write(3, *) calc_rmsd_sph(noi1, noi2, store, store2, grid, grid2, dph, dth)/10
end if
! Fim do calculo do RMSD===================================
n_index = 1
i_atom = 0
num = 1
num2 = 1
if (ierr<0) then
cent_x = center%x
cent_y = center%y
cent_z = center%z
end if
center%x = cent_x
center%y = cent_y
center%z = cent_z
cent_x = 0
cent_y = 0
cent_z = 0
end if !======((frame<fr_in-1).and.(frame>fr_end+1))
!====garante que fr_end sempre seja maior que frame ===
!====caso essa variável não tenha sido fixada==========
if (.not.end)then
fr_end = frame + 1
end if
!======================================================
if ((frame>=trj%NFRAMES).and.(traj_type=='xtc')) ierr = -1 ! apenas quando lendo o tipo XTC
end do
call system_clock (finish, clock_rate, clock_max)
! Fim da leitura do arquivo .pdb
if (traj_type=='xtc') call trj%close()
if (traj_type=='pdb') close(1)
close(2)
if (rmsd)then
close(3)
end if
close(4)
if (range) then
write(*, *)
write(*, *) 'Calculated range = [', minv, ';', maxv, ']'
write(*, *)
write(*, '(a19)', advance='no') ' Inferior limit : '
read(*, *) minv
write(*, *)
write(*, '(a19)', advance='no') ' Superior limit : '
read(*, *) maxv
end if
call abre('thick ', 4, 'xpm', back)
write(4, '(a7, a7)') "#SuAVE ", version
write(4, '(a14)') '#Command Line:'
write(4, '(a10)', advance='no') '#s_shell '
write(4, *) (trim(get(i))," ", i=1, 20)
write(4, *) '/* XPM */'
write(4, *)'/* This matrix is generated by s_shell.f90 */'
write(4, *)'/* title: "Thickness" */'
write(4, *)'/* x-label: "Theta angle " */'
write(4, *)'/* y-label: "Phi angle " */'
write(4, *)'/* type: "Continuous" */'
write(4, *)'static char * gv_xpm[] = {'
write(4, *) '"',n_grid, (n_grid - int(n_grid/2)),' 7 1",'
do i=1, n_grid - int(n_grid/2)
do j=1, n_grid
r_xpm1(i,j) = r_xpm1(i,j)/tot_frame/10
end do
end do
del = (maxv - minv)/6
call print_xpm_sph(n_grid-int(n_grid/2), n_grid, del, dth, dph, xpm1, r_xpm1, minv, 'b')
close(4)
!Creating grid files ==============================================================
if (p_grid)then
call sphe2cart((n_grid-int(n_grid/2))+1, n_grid+1, center%x, center%y, center%z, grid, grid3)
call print_grid_xpm(grid3, r_xpm1, (n_grid-int(n_grid/2)), n_grid, 'grid1', back)
call sphe2cart((n_grid-int(n_grid/2))+1, n_grid+1, center%x, center%y, center%z, grid2, grid3)
call print_grid_xpm(grid3, r_xpm1, (n_grid-int(n_grid/2)), n_grid, 'grid2', back)
end if
call ending(back, finish, start, clock_rate) ! Finaliza programa e mostra tempo de processamento
deallocate(r_xpm1)
deallocate(xpm1)
end program suave_shell