|
1 | | -! (C) 2004 Uppsala Molekylmekaniska HB, Uppsala, Sweden |
2 | | - |
3 | | -!average co-ordinates from Qdyn trajectory files and write pdb-structure |
4 | | -!Added to Qprep March 2004 by Martin Nervall |
5 | | -!Tested to reproduce average structures from vmd |
6 | | - |
7 | | -module AVETR |
8 | | - use PREP |
9 | | - implicit none |
10 | | - |
11 | | - integer, parameter :: AVE_PDB = 11 |
12 | | - integer(4), private :: ncoords, N_sets = 0 |
13 | | - real(4), allocatable, private :: x_in(:), x_sum(:), x2_sum(:) |
14 | | - real(8), private :: rmsd |
15 | | -contains |
16 | | -!TODO: *choose which frames, add more trajectories, divide x_sum every 100 steps |
17 | | - |
18 | | -!****************************************************** |
19 | | -!Main subroutine |
20 | | -!****************************************************** |
21 | | -subroutine avetr_calc |
22 | | - integer :: i, allocation_status |
23 | | - character(len=1) :: ans |
24 | | - logical :: fin |
25 | | - N_sets = 0 |
26 | | - call trajectory |
27 | | - ncoords = trj_get_ncoords() |
28 | | - allocate(x_in(ncoords), x_sum(ncoords), x2_sum(ncoords), & |
29 | | - stat=allocation_status) |
30 | | - if (allocation_status .ne. 0) then |
31 | | - write(*,*) 'Out of memory!' |
32 | | - return |
33 | | - end if |
34 | | - do while(trj_read_masked(x_in)) !add from first file |
35 | | - call add_coordinates |
36 | | - end do |
37 | | - |
38 | | - !add from multiple files |
39 | | - fin = .false. |
40 | | - do while(.not. fin) |
41 | | - CALL get_string_arg(ans, '-----> Add more frames? (y or n): ') |
42 | | - if (ans .eq. 'y') then |
43 | | - call trajectory |
44 | | - do while(trj_read_masked(x_in)) !add from additional files |
45 | | - call add_coordinates |
46 | | - end do |
47 | | - else |
48 | | - fin = .true. |
49 | | - end if |
50 | | - end do |
51 | | - |
52 | | - |
53 | | - call average |
54 | | - call write_average |
55 | | - deallocate(x_in, x_sum, x2_sum, stat=allocation_status) |
56 | | -end subroutine avetr_calc |
57 | | - |
58 | | -!****************************************************** |
59 | | -!Sum the coordinates and the sqared coordinates |
60 | | -!****************************************************** |
61 | | -subroutine add_coordinates |
62 | | - x_sum = x_sum + x_in |
63 | | - x2_sum = x2_sum + x_in**2 |
64 | | - N_sets = N_sets +1 |
65 | | -end subroutine add_coordinates |
66 | | - |
67 | | -!****************************************************** |
68 | | -!Make average and rmsd |
69 | | -!****************************************************** |
70 | | -subroutine average |
71 | | - x_sum = x_sum / N_sets |
72 | | - x2_sum = x2_sum / N_sets |
73 | | - rmsd = sqrt(sum(x2_sum - x_sum**2)/ncoords) |
74 | | -end subroutine average |
75 | | - |
76 | | -!****************************************************** |
77 | | -!Write average coords to pdb file. |
78 | | -!Variables used from prep: mask |
79 | | -!Variables used from topo: xtop |
80 | | -!****************************************************** |
81 | | -subroutine write_average |
82 | | - !assign masked coordinates to right atom in topology |
83 | | - call mask_put(mask, xtop, x_sum) |
84 | | - call writepdb |
85 | | - write(*,'(a,f6.3,a)') 'Root mean square co-ordinate deviation ', rmsd, ' A' |
86 | | - x_sum = 0 |
87 | | - x2_sum = 0 |
88 | | -end subroutine write_average |
89 | | - |
90 | | -end module AVETR |
| 1 | +! (C) 2004 Uppsala Molekylmekaniska HB, Uppsala, Sweden |
| 2 | + |
| 3 | +!average co-ordinates from Qdyn trajectory files and write pdb-structure |
| 4 | +!Added to Qprep March 2004 by Martin Nervall |
| 5 | +!Tested to reproduce average structures from vmd |
| 6 | + |
| 7 | +module AVETR |
| 8 | + use PREP |
| 9 | + implicit none |
| 10 | + |
| 11 | + integer, parameter :: AVE_PDB = 11 |
| 12 | + integer(4), private :: ncoords, N_sets = 0 |
| 13 | + real(4), allocatable, private :: x_in(:), x_sum(:), x2_sum(:) |
| 14 | + real(8), private :: rmsd |
| 15 | +contains |
| 16 | +!TODO: *choose which frames, add more trajectories, divide x_sum every 100 steps |
| 17 | + |
| 18 | +!****************************************************** |
| 19 | +!Main subroutine |
| 20 | +!****************************************************** |
| 21 | +subroutine avetr_calc |
| 22 | + integer :: i, allocation_status |
| 23 | + character(len=1) :: ans |
| 24 | + logical :: fin |
| 25 | + N_sets = 0 |
| 26 | + call trajectory |
| 27 | + ncoords = trj_get_ncoords() |
| 28 | + allocate(x_in(ncoords), x_sum(ncoords), x2_sum(ncoords), & |
| 29 | + stat=allocation_status) |
| 30 | + if (allocation_status .ne. 0) then |
| 31 | + write(*,*) 'Out of memory!' |
| 32 | + return |
| 33 | + end if |
| 34 | + do while(trj_read_masked(x_in)) !add from first file |
| 35 | + call add_coordinates |
| 36 | + end do |
| 37 | + |
| 38 | + !add from multiple files |
| 39 | + fin = .false. |
| 40 | + do while(fin == .false.) |
| 41 | + CALL get_string_arg(ans, '-----> Add more frames? (y or n): ') |
| 42 | + if (ans .eq. 'y') then |
| 43 | + call trajectory |
| 44 | + do while(trj_read_masked(x_in)) !add from additional files |
| 45 | + call add_coordinates |
| 46 | + end do |
| 47 | + else |
| 48 | + fin = .true. |
| 49 | + end if |
| 50 | + end do |
| 51 | + |
| 52 | + |
| 53 | + call average |
| 54 | + call write_average |
| 55 | + deallocate(x_in, x_sum, x2_sum, stat=allocation_status) |
| 56 | +end subroutine avetr_calc |
| 57 | + |
| 58 | +!****************************************************** |
| 59 | +!Sum the coordinates and the sqared coordinates |
| 60 | +!****************************************************** |
| 61 | +subroutine add_coordinates |
| 62 | + x_sum = x_sum + x_in |
| 63 | + x2_sum = x2_sum + x_in**2 |
| 64 | + N_sets = N_sets +1 |
| 65 | +end subroutine add_coordinates |
| 66 | + |
| 67 | +!****************************************************** |
| 68 | +!Make average and rmsd |
| 69 | +!****************************************************** |
| 70 | +subroutine average |
| 71 | + x_sum = x_sum / N_sets |
| 72 | + x2_sum = x2_sum / N_sets |
| 73 | + rmsd = sqrt(sum(x2_sum - x_sum**2)/ncoords) |
| 74 | +end subroutine average |
| 75 | + |
| 76 | +!****************************************************** |
| 77 | +!Write average coords to pdb file. |
| 78 | +!Variables used from prep: mask |
| 79 | +!Variables used from topo: xtop |
| 80 | +!****************************************************** |
| 81 | +subroutine write_average |
| 82 | + !assign masked coordinates to right atom in topology |
| 83 | + call mask_put(mask, xtop, x_sum) |
| 84 | + call writepdb |
| 85 | + write(*,'(a,f6.3,a)') 'Root mean square co-ordinate deviation ', rmsd, ' A' |
| 86 | + x_sum = 0 |
| 87 | + x2_sum = 0 |
| 88 | +end subroutine write_average |
| 89 | + |
| 90 | +end module AVETR |
0 commit comments