-
Notifications
You must be signed in to change notification settings - Fork 0
/
s_order_c.f90
459 lines (287 loc) · 11.8 KB
/
s_order_c.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
program suave_order
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_order ', version)
!Leitura do PDB
12 format(a6, i5.1, a5, a5, a1, i4.1, a4, 3f8.3)
!==Lendo os arquivos de index=========================
if (.not.outer)then
call abre_ndx(ind, in_num, 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(outer, bin_coarse, n_index, bin, n_grid, bin_out)
!==================== 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 arquivo do parâmetro de ordem médio=========================
call abre('order_aver', 2,'xvg', back)
write(2, '(a7, a7)') "#SuAVE ", version
write(2, '(a14)') '#Command Line:'
write(2, '(a10)', advance='no') '#s_order '
write(2, *) (trim(get(i))," ", i=1, 30)
write(2, *) '@ title "Average Curvature Order Parameter X Frame"'
write(2, *) '@ xaxis label "#Frame"'
write(2, *) '@ yaxis label "Average Curvature Order Parameter"'
!=================== alocando memoria do XPM====================
allocate (xpm(n_grid, n_grid), stat = ierr)
if (ierr /= 0) stop 'Not enough memory to initialize xpm matrix'
allocate (r_xpm1(n_grid, n_grid), stat = ierr)
if (ierr /= 0) stop 'Not enough memory to initialize xpm matrix'
do i=1, n_grid
do j=1, n_grid
r_xpm1(i,j) = 0
end do
end do
do k=1, 100
hist(k) = 0
end do
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_order '
write(3, *) (trim(get(i))," ", i=1, 30)
write(3, *) '@ title "RMSD X Frame"'
write(3, *) '@ xaxis label "#Frame"'
write(3, *) '@ yaxis label "RMSD [nm]"'
end if
call system_clock(start, clock_rate, clock_max)
! Leitura do arquivo .gro
i_atom = 0
n_index = 1
frame = 0
ierr = 0
x_min = 1000
y_min = 1000
x_max = 0
y_max = 0
tot_frame = 0
frame = 0
minv = 100000
maxv = -100000
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(n_index)) then
store(n_index) = buff
n_index = n_index + 1
x_max = max(x_max, buff%x)
x_min = min(x_min, buff%x)
y_max = max(y_max, buff%y)
y_min = min(y_min, buff%y)
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(n_index)) then
copy = trj%x(1, i_atom)
store(n_index)%x = copy(1)*10
store(n_index)%y = copy(2)*10
store(n_index)%z = copy(3)*10
n_index = n_index + 1
x_max = max(x_max, store(n_index-1)%x)
x_min = min(x_min, store(n_index-1)%x)
y_max = max(y_max, store(n_index-1)%y)
y_min = min(y_min, store(n_index-1)%y)
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
noi1 = n_index - 1
if (l_coarse) then
! Estruturação do grid
dx = (x_max - x_min)/bin_coarse
dy = (y_max - y_min)/bin_coarse
! adaptação dos valores de r_fit e alfa
call param(x_max, x_min, y_max, y_min, n_index, r_fit, al, rough)
!$OMP parallel do private(s_grid, dist, peso, k, aux, j)
do i=1, bin_coarse + 1
do j=1, bin_coarse + 1
aux = (i-1)*(bin_coarse + 1) + j
coarse(aux)%x = (i-1)*dx + x_min
coarse(aux)%y = (j-1)*dy + y_min
s_grid = 0
coarse(aux)%z = 0
do k=1, n_index - 1
dist = (coarse(aux)%x - store(k)%x)**2
dist = dist + (coarse(aux)%y - store(k)%y)**2
if (dist<r_fit*r_fit)then
peso = exp(-(dist*al*al)/pi)
s_grid = s_grid + peso
coarse(aux)%z = coarse(aux)%z + peso*store(k)%z
end if
end do
coarse(aux)%z = coarse(aux)%z/s_grid
end do
end do
!$OMP end parallel do
n_index = (bin_coarse + 1)**2 + 1
else
coarse = store
end if
! estruturação do prmeiro grid de alta resolução
dx = (x_max - x_min)/n_grid
dy = (y_max - y_min)/n_grid
call param(x_max, x_min, y_max, y_min, n_index, r_fit, al, rough)
!$OMP parallel do private(s_grid, dist, peso, k, j)
do i=1, n_grid+1
do j=1, n_grid+1
grid(i,j)%x = (i-1)*dx + x_min
grid(i,j)%y = (j-1)*dy + y_min
s_grid = 0
grid(i,j)%z = 0
do k=1, n_index - 1
dist = (grid(i,j)%x - coarse(k)%x)**2
dist = dist + (grid(i,j)%y - coarse(k)%y)**2
if (dist<r_fit*r_fit)then
peso = exp(-(dist*al*al)/pi)
s_grid = s_grid + peso
grid(i,j)%z = grid(i,j)%z + peso*coarse(k)%z
end if
end do
grid(i,j)%z = grid(i,j)%z/s_grid
end do
end do
!OMP end parallel do
! Fim da estruturação
! Cálculo do ângulo de inclinação
call calc_order(n_grid, grid, r_xpm1, aver, aver2, hist)
desv = sqrt(aver2 - aver*aver)
minv = min(aver-2*desv, minv)
maxv = max(aver+2*desv, maxv)
! esses termos extras são por conta da distribuição
! não ser simétrica o que causava valores maiores que 1
! e menores que -0.5 para os limites do intervalo
minv = max(minv, -0.5)
maxv = min(maxv, 1.0)
!=============================================
! n_grid*n_grid é o número de células do grid
write(2, *) frame, aver
if (rmsd)then
noir = 0
do i=1, noi1
a = nint((store(i)%x-x_min)/dx) + 1
b = nint((store(i)%y-y_min)/dy) + 1
dist_z = store(i)%z-grid(a,b)%z
noir = noir + dist_z*dist_z/noi1
end do
noir = sqrt(noir)
write(3, *) noir/10
end if
!! ******* Fim do cálculo
gx = x_min
gy = y_min
n_index = 1
i_atom = 0
x_min = 1000
y_min = 1000
x_max = 0
y_max = 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
if (traj_type=='xtc') call trj%close()
if (traj_type=='pdb') close(1)
close(2)
if (rmsd) then
close(3)
end if
call system_clock(finish, clock_rate, clock_max)
! escrita do arquivo XPM========================================
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('order ', 4, 'xpm', back)
write(4, '(a7, a7)') "#SuAVE ", version
write(4, '(a14)') '#Command Line:'
write(4, '(a10)', advance='no') '#s_order '
write(4, *) (trim(get(i))," ", i=1, 30)
write(4, *) '/* XPM */'
write(4, *)'/* This matrix is generated by s_order.f90 */'
write(4, *)'/* title: "Order Parameter" */'
write(4, *)'/* x-label: "x axis [nm]" */'
write(4, *)'/* y-label: "y axis [nm]" */'
write(4, *)'/* type: "Continuous" */'
write(4, *)'static char * gv_xpm[] = {'
write(4, *) '"',n_grid,n_grid,' 7 1",'
do i=1, n_grid
do j=1, n_grid
r_xpm1(i,j) = r_xpm1(i,j)/tot_frame
end do
end do
del = (maxv - minv)/6
call print_xpm(n_grid, del, dx, dy, gx, gy, xpm, r_xpm1, minv, 'r')
close(4)
! Final da escrita do XPM
!=========escrita do histograma===========================
call abre('hist ', 4, 'xvg', back)
write(4, '(a7, a7)') "#SuAVE ", version
write(4, '(a14)') '#Command Line:'
write(4, '(a10)', advance='no') '#s_order '
write(4, *) (trim(get(i))," ", i=1, 30)
write(4, *) '@ title "Curvature angles"'
write(4, *) '@ xaxis label "Angles [\So\N]"'
write(4, *) '@ yaxis label "%"'
do i=1, 100
graph = hist(i)
graph = graph/(tot_frame*1*n_grid*n_grid)
write(4, *) i-1, graph*100
end do
close(4)
!== escrita do GRID========================================
if (p_grid)then
call print_grid_xpm(grid, r_xpm1, n_grid, n_grid, 'grid1', back)
end if
call ending(back, finish, start, clock_rate) ! Finaliza programa e mostra tempo de processamento
deallocate(r_xpm1)
deallocate(xpm)
end program suave_order