-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paths_grid.f90
923 lines (581 loc) · 23 KB
/
s_grid.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
module grd
implicit none
real, parameter :: pi = 3.141592654
type vet1
character(len=50) :: atom, resid, ident, code
real :: x, y, z
integer :: n_atom, n_resid
end type vet1
type vet2
real :: x, y, z
end type vet2
end module grd
program grid_project
use grd
logical :: ex, bin, outer, down, rmsd, l_coarse
logical :: begin, end, skip, eval_skip
integer :: i, j, k, ierr, n_grid, frame, aux, num, noi1, noi2
integer :: n_index, n_atom, i_atom, bin_out, bin_coarse, a, b
integer :: fr_in, fr_end, n_skip
integer, dimension(50000) :: in_num
real :: dx, dy, dist, s_grid, r_fit, hour, minu, sec, start, finish
real :: x_max, x_min, y_max, y_min, aux2, gridx, gridy, noir, al
real :: z_max, z_min
character(len=30) :: coord, index, atom
character(len=30), dimension(20) :: get
type(vet1) :: buff
type(vet1), dimension(50000) :: store, coarse
type(vet1), dimension(500000) :: out
type(vet2), dimension(:,:), allocatable :: mat
type(vet2), dimension(1001,1001) :: grid
write(*, *) " .--.--. ,---, ,---,. "
write(*, *) " / / '. ' .' \ ,---. ,' .' | "
write(*, *) "| : /`. / ,--, / ; '. /__./|,---.' | "
write(*, *) "; | |--` ,'_ /|: : \ ,---.; ; || | .' "
write(*, *) "| : ;_ .--. | | :: | /\ \ /___/ \ | |: : |-, "
write(*, *) " \ \ `. ,'_ /| : . || : ' ;. :\ ; \ ' |: | ;/| "
write(*, *) " `----. \| ' | | . .| | ;/ \ \\ \ \: || : .' "
write(*, *) " __ \ \ || | ' | | |' : | \ \ ,' ; \ ' .| | |-, "
write(*, *) " / /`--' /: | : ; ; || | ' '--' \ \ '' : ;/| "
write(*, *) "'--'. / ' : `--' \ : : \ ` ;| | \ "
write(*, *) " `--'---' : , .-./ | ,' : \ || : .' "
write(*, *) " `--`----' `--'' '---: | | ,' "
write(*, *) " `----' "
write(*, *) ""
write(*, *) ""
write(*, *) " ** s_grid **"
write(*, *) ""
write(*, *) " Santos, D. E. S.; Soares, T. A."
write(*, *) ""
write(*, *) "Please cite SuAVE: A Tool for Analyzing Curvature-Dependent"
write(*, *) "Properties in Chemical Interfaces. Denys E. S. Santos,"
write(*, *) "Frederico J. S. Pontes, Roberto D. Lins, Kaline Coutinho,"
write(*, *) "Thereza A. Soares. J. Chem. Inf. Model. 2019."
write(*, *) ""
write(*, *) ""
write(*, *) "s_grid builds a grid per frame throughout a trajectory file."
write(*, *) "Its output is useful to verify how accurate is the fitting of"
write(*, *) "the calculated grid on the chemical surface. "
write(*, *) ""
write(*, *) "Usage: s_grid -in file.pdb -ind file.ndx"
write(*, *) ""
write(*, *) "file.pdb ---- atomic coordinates in PDB format"
write(*, *) "file.ndx ---- index file containing user-selected atoms used"
write(*, *) "to fit the grid points to the chemical surface."
write(*, *) ""
write(*, *) "Options:"
write(*, *) ""
write(*, *) "-bin defines the number of rectangular partition "
write(*, *) "bins along the x- and y-axes"
write(*, *) ""
write(*, *) "-outer automatically selects the "
write(*, *) "surface/interface outmost atoms to fit the grid points. This"
write(*, *) "option overwrites the user-selected index files."
write(*, *) ""
write(*, *) "-grid generates a PDB file containing the grid"
write(*, *) "points used in the fitting for the last frame in the "
write(*, *) "trajectory file."
write(*, *) ""
write(*, *) "-rmsd calculates the RMSD between the fitted"
write(*, *) "grid and the selected atoms in the index files. This"
write(*, *) "estimates how precisely is the grid surface fitted to the"
write(*, *) "chemical surface throughout the trajectory file."
write(*, *) ""
write(*, *) "-coarse generates a coarse grid over the surface"
write(*, *) "index atoms from which a finer grid will be generated. This"
write(*, *) "recommended for surfaces defined by atoms which greatly"
write(*, *) "fluctuate throughout the trajectory. "
write(*, *) ""
write(*, *) "-begin first frame to use in the calculations"
write(*, *) ""
write(*, *) "-end last frame to use in the calculations"
write(*, *) ""
write(*, *) "-skip number of trajectory frames to be skipped"
write(*, *) "during the analysis "
write(*, *) ""
Write(*, *) "-down used to generate a PDB file with the last "
Write(*, *) "external lowest fitting grid. This option is only used when"
Write(*, *) "followed by option –outer."
!
! pegando os arquivos de entrada
!
outer = .false.
bin = .false.
down = .false.
coord = 'miss'
index = 'miss'
rmsd = .false.
l_coarse = .false.
begin = .false.
end = .false.
skip = .false.
do i=1, 20
call getarg(i, get(i))
end do
do i=1, 20
if (get(i)=='-in')then
coord = get(i+1)
end if
if (get(i)=='-ind')then
index = get(i+1)
end if
if (get(i)=='-bin')then
bin= .true.
end if
if (get(i)=='-outer')then
outer= .true.
end if
if (get(i)=='-down')then
down= .true.
end if
if (get(i)=='-rmsd')then
rmsd = .true.
end if
if (get(i)=='-coarse')then
l_coarse = .true.
end if
if (get(i)=='-begin')then
begin = .true.
end if
if (get(i)=='-end')then
end = .true.
end if
if (get(i)=='-skip')then
skip = .true.
end if
end do
if (coord=='miss')then
write(*, *)
write(*, *)'PDB file is missing'
write(*, *)
stop
end if
if (.not.outer)then
if (index=='miss')then
write(*, *)
write(*, *)'Index file is missing'
write(*, *)
stop
end if
end if
!==Lendo os arquivos de index=========================
if (.not.outer)then
open(2, file=index, status='old', iostat=ierr)
if(ierr /= 0) then
write(*, *)
write(*, *) 'Unable to open file', index
write(*, *)
stop
end if
! Inicio da leitura do index ============================
n_index = 1
do while (ierr==0)
read(2, *, iostat=ierr) aux
if (ierr == 0)then
in_num(n_index) = aux
n_index = n_index + 1
end if
end do
n_atom = n_index - 1
if(ierr>0) then
write(*, *)
write(*, *) 'Problem by reading ', index
write(*, *)
stop
end if
do i=n_index, 50000
in_num(i)=-1
end do
write(*, *)
write(*, *) index, " input file is OK"
close(2)
end if
2 format(a10)
if ((bin).or.(outer)) then
write(*, *)
write(*, 2, advance='no') ' bin = '
read(*, *, iostat=ierr) n_grid
end if
if (outer) then
write(*, *)
write(*, 2, advance='no') 'bin_out = '
read(*, *, iostat=ierr) bin_out
end if
!=================definindo frames para inicio e fim========
!=================definindo skip============================
frame = 0
if (begin) then
write(*, *)
write(*, 2, advance='no') " Begin = "
read(*, *) fr_in
else
fr_in = 1
end if
if (end) then
write(*, *)
write(*, 2, advance='no') " End = "
read(*, *) fr_end
else
fr_end = fr_in + 2 !==para que fr_end seja maior que frame
end if
if (skip) then
write(*, *)
write(*, 2, advance='no') " n_skip = "
read(*, *) n_skip
else
n_skip = 0
end if
!============================================================
!=======================================================
! calculando o espaçamento
if (.not.outer)then
bin_coarse = nint(sqrt(real(n_index-1)) - 1)
if (.not.bin)then
n_grid = nint(sqrt(real(n_index-1)) - 1)
write(*, *)
write(*, *) 'STD_BIN = ', n_grid
end if
else
bin_coarse = bin_out
end if
!==================================================
!==================================================
! definição da matriz de pontos externos
if (outer)then
allocate (mat(bin_out+1, bin_out+1), stat = ierr)
if (ierr /= 0) stop 'Not enough memory to initialize mat matrix'
do i=1, bin_out + 1
do j=1, bin_out + 1
if (down)then
mat(i,j)%z = 1000
else
mat(i,j)%z = -1000
end if
end do
end do
end if
!==================================================
write(*, *)
write(*, *) 'Processing ..........' !==============================iniciando processamento
open(1, file=coord, status='old', iostat=ierr)
if(ierr /=0) then
write(*, *)
write(*, *) 'Unable to open file ', coord
write(*, *)
stop
endif
if (rmsd)then
inquire(file='rmsd.xvg', exist=ex)
if (ex) then
call execute_command_line("mv rmsd.xvg rmsd_p.xvg")
write(*, *)
write(*, *) 'Previous rmsd.xvg file is now backed up to rmsd_p.xvg !'
end if
open(3, file='rmsd.xvg', status='new', iostat=ierr)
if(ierr /= 0) then
write(*, *)
write(*, *) 'Unable to open file rmsd.xvg'
write(*, *)
stop
endif
write(3, *) '@ title "RMSD X Frame"'
write(3, *) '@ xaxis label "#Frame"'
write(3, *) '@ yaxis label "RMSD [nm]"'
end if
!==========================================================
inquire(file='grid.pdb', exist=ex)
if (ex) then
call execute_command_line("mv grid.pdb grid_p.pdb")
write(*, *)
write(*, *) 'Previous grid.pdb file is now backed up to grid_p.pdb !'
end if
open(4, file='grid.pdb', status='new', iostat=ierr)
if(ierr /= 0) then
write(*, *)
write(*, *) 'Unable to open file grid.pdb'
write(*, *)
stop
end if
call cpu_time(start)
! Leitura do arquivo .pdb
i_atom = 0
frame = 0
ierr = 0
n_index = 1
x_min = 1000
y_min = 1000
z_min = 1000
x_max = 0
y_max = 0
z_max = 0
do while (ierr>=0)
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
12 format(a6, i5.1, a5, a5, a1, i4.1, a4, 3f8.3)
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 (outer)then
out(i_atom) = 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)
z_max = max(z_max, buff%z)
z_min = min(z_min, buff%z)
else
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)
z_max = max(z_max, buff%z)
z_min = min(z_min, buff%z)
end if
end if
else
if (n_index > 1)then
frame = frame + 1
eval_skip = ((mod((frame-fr_in),(n_skip+1))==0))
if ((frame>fr_in-1).and.(frame<fr_end+1).and.(eval_skip)) then
if (outer)then
dx = (x_max - x_min)/bin_out
dy = (y_max - y_min)/bin_out
do k=1, n_index-1
i = nint((out(k)%x-x_min)/dx + 1)
j = nint((out(k)%y-y_min)/dy + 1)
if (down) then
if (out(k)%z<mat(i,j)%z)then
mat(i,j)%z = out(k)%z
mat(i,j)%x = out(k)%x
mat(i,j)%y = out(k)%y
end if
else
if (out(k)%z>mat(i,j)%z)then
mat(i,j)%z = out(k)%z
mat(i,j)%x = out(k)%x
mat(i,j)%y = out(k)%y
end if
end if
end do
num = n_index
n_index = 1
do i=1,bin_out+1
do j=1,bin_out+1
if (down)then
if (mat(i,j)%z<1000)then
store(n_index)%x = mat(i,j)%x
store(n_index)%y = mat(i,j)%y
store(n_index)%z = mat(i,j)%z
n_index = n_index + 1
end if
else
if (mat(i,j)%z>-1000)then
store(n_index)%x = mat(i,j)%x
store(n_index)%y = mat(i,j)%y
store(n_index)%z = mat(i,j)%z
n_index = n_index + 1
end if
end if
end do
end do
end if! if outer
noi1 = n_index - 1
if (l_coarse) then
!
! Estruturação do grid
aux = 0
dx = (x_max - x_min)/bin_coarse
dy = (y_max - y_min)/bin_coarse
! refinamento do r_fit e do alfa
r_fit = 3*sqrt((x_max - x_min)**2 + (y_max - y_min)**2)/sqrt(real(n_index)-1)
al = (n_index-1)*100/((x_max - x_min)*(y_max - y_min))
al = exp(0.414754490756596*log(al)-1.29378601756983)
do i=1, bin_coarse + 1
do j=1, bin_coarse + 1
aux = aux + 1
coarse(aux)%x = (i-1)*dx + x_min
coarse(aux)%y = (j-1)*dy + y_min
s_grid = 0
coarse(aux)%z = 0
gridx = 0
gridy = 0
do k=1, n_index - 1
dist_x = abs(coarse(aux)%x - store(k)%x)
dist_y = abs(coarse(aux)%y - store(k)%y)
dist = al*al*(dist_x**2 + dist_y**2)
if (sqrt(dist/(al*al))<r_fit)then
s_grid = s_grid + exp(-(dist)/pi)
coarse(aux)%z = coarse(aux)%z + exp(-(dist)/pi)*store(k)%z
gridx = gridx + exp(-(dist)/pi)*store(k)%x
gridy = gridy + exp(-(dist)/pi)*store(k)%y
end if
end do
coarse(aux)%z = coarse(aux)%z/s_grid
coarse(aux)%x = gridx/s_grid
coarse(aux)%y = gridy/s_grid
end do
end do
n_index = aux + 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
! refinamento do r_fit e do alfa
r_fit = 3*sqrt((x_max - x_min)**2 + (y_max - y_min)**2)/sqrt(real(n_index)-1)
al = (n_index-1)*100/((x_max - x_min)*(y_max - y_min))
al = exp(0.414754490756596*log(al)-1.29378601756983)
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_x = abs(grid(i,j)%x - coarse(k)%x)
dist_y = abs(grid(i,j)%y - coarse(k)%y)
dist = al*al*(dist_x**2 + dist_y**2)
if (sqrt(dist/(al*al))<r_fit)then
s_grid = s_grid + exp(-(dist)/pi)
grid(i,j)%z = grid(i,j)%z + exp(-(dist)/pi)*coarse(k)%z
end if
end do
grid(i,j)%z = grid(i,j)%z/s_grid
end do
end do
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
! escreve cada frame da trajetoria do grid
3 format(a8, f7.2, a2, f7.2, a2, f7.2, a35)
write(4, '(a26)') 'REMARK Generated by s_grid'
write(4, '(a34)') 'TITLE Rectangular Regular GRID'
write(4, '(a22)') 'REMARK trajectory file'
write(4, 3) 'CRYST1 ', x_max-x_min, ' ', y_max-y_min, ' ', z_max-z_min, ' 90.00 90.00 90.00 P 1 1 '
write(4, '(a6, i4)') 'MODEL ', frame
do i=1, n_grid+1
do j=1, n_grid+1
write(4, 12, iostat=ierr) 'ATOM ', (i-1)*(n_grid+1) + j, ' DOT', &
' DOT',' ', 1,' ', grid(i,j)%x, &
grid(i,j)%y, grid(i,j)%z
end do
end do
write(4, '(a3)') 'TER'
write(4, '(a6)') 'ENDMDL'
!fim da escrita da trajetoria
end if !======((frame<fr_in-1).and.(frame>fr_end+1))
n_atom = n_index-1
n_index = 1
i_atom = 0
x_min = 1000
y_min = 1000
x_max = 0
y_max = 0
!====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 (outer)then
do i=1, bin_out + 1
do j=1, bin_out + 1
if (down)then
mat(i,j)%z = 1000
else
mat(i,j)%z = -1000
end if
end do
end do
end if
end if
end if
end do
! Fim da estruturação
close(1)
close(4)
if (rmsd)then
close(3)
end if
call cpu_time(finish)
! desenho dos pontos usados no ajuste
inquire(file='adjust.pdb', exist=ex)
if (ex) then
call execute_command_line("mv adjust.pdb adjust_p.pdb")
write(*, *)
write(*, *) 'Previous adjust.pdb file is now backed up to adjust_p.pdb !'
end if
open(3, file='adjust.pdb', status='new', iostat=ierr)
if(ierr /= 0) then
write(*, *)
write(*, *) 'Unable to open file ajuste.pdb'
write(*, *)
stop
end if
write(3, *) 'TITLE Rectangular Regular GRID'
write(3, *) 'REMARK THIS IS A SIMULATION BOX'
write(3, *) 'MODEL 1'
do i=1, noi1
write(3, 12, iostat=ierr) 'ATOM ', i, ' DOT', &
' DOT',' ', 1,' ', store(i)%x, &
store(i)%y, store(i)%z
end do
close(3)
if (l_coarse) then
inquire(file='coarse.pdb', exist=ex)
if (ex) then
call execute_command_line("mv coarse.pdb coarse_p.pdb")
write(*, *)
write(*, *) 'Previous coarse.pdb file is now backed up to coarse_p.pdb !'
end if
open(3, file='coarse.pdb', status='new', iostat=ierr)
if(ierr /= 0) then
write(*, *)
write(*, *) 'Unable to open file coarse.pdb'
write(*, *)
stop
end if
write(3, *) 'TITLE Rectangular Regular GRID'
write(3, *) 'REMARK THIS IS A SIMULATION BOX'
write(3, *) 'MODEL 1'
do i=1, (bin_coarse + 1)*(bin_coarse + 1)
write(3, 12, iostat=ierr) 'ATOM ', i, ' DOT', &
' DOT',' ', 1,' ', coarse(i)%x, &
coarse(i)%y, coarse(i)%z
end do
end if
write(*, *)
write(*, *)'Finished'
! Fim. Arquivo escrito
close(3)
hour = (finish-start)/3600
minu = (hour - int(hour))*60
sec = (minu-int(minu))*60
write(*, *)
write(*, 1) " Processing time : ", int(hour), " h", int(minu), " min", int(sec), " sec"
1 format(a19, i6.3, a2, i6.3, a4, i6.3, a4)
write(*, *)
if (outer)then
deallocate(mat)
end if
end program grid_project