-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple_fgridvol.f90
More file actions
executable file
·295 lines (277 loc) · 10.8 KB
/
simple_fgridvol.f90
File metadata and controls
executable file
·295 lines (277 loc) · 10.8 KB
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
module simple_fgridvol
use simple_eulers
use simple_params
use simple_math
use simple_build
use simple_fplane
implicit none
save
private :: e_one, bp, mat, grid_fplane_comp_1, grid_fplane_comp_2, that, prep_new_fvols, calc_weight
public
interface grid_fplane
module procedure grid_fplane_1
module procedure grid_fplane_2
end interface
type(eulers) :: e_one
type(build), pointer :: bp
real :: mat(3,3)
character(len=3) :: that
contains
subroutine make_fgridvol( b, which )
! associates pointer to builder, makes single Euler, and allocates data
type(build), intent(in), target :: b
character(len=*), intent(in) :: which
bp => b
call set_fgridvol( which )
e_one = new_eulers(1)
end subroutine make_fgridvol
subroutine set_fgridvol( which )
character(len=*), intent(in) :: which
if( which == 'new' )then
that = 'new'
else
that = 'old'
endif
end subroutine set_fgridvol
subroutine grid_fvol_comp_1( h, k, l, s )
! grids a Fourier volume component to the new Fourier volume
integer, intent(in) :: h, k, l, s
integer :: i, j, m, istart, istop, jstart, jstop, mstart, mstop
real :: tmp, vec(3), loc(3)
vec(1) = real(h)
vec(2) = real(k)
vec(3) = real(l)
loc = matmul(vec,mat)
! make window
call recwin_3d( loc(1), loc(2), loc(3), xdim, winsz,&
istart, istop, jstart, jstop, mstart, mstop )
! interpolate
do i=istart,istop
do j=jstart,jstop
do m=mstart,mstop
! calculate weight (Gaussian windowed sinc)
tmp = calc_weight( i, j, m, loc )
! grid the Fourier data
bp%s3d(s)%fvol_new(i,j,m) = bp%s3d(s)%fvol_new(i,j,m)+&
cmplx(real(bp%s3d(s)%fvol(h,k,l))*tmp,aimag(bp%s3d(s)%fvol(h,k,l))*tmp)
end do
end do
end do
end subroutine grid_fvol_comp_1
subroutine grid_fplane_comp_1( h, k, s )
! grids a plane component to the Fourier volume
integer, intent(in) :: h, k, s
integer :: i, j, m, istart, istop, jstart, jstop, mstart, mstop
real :: tmp, vec(3), loc(3)
vec(1) = real(h)
vec(2) = real(k)
vec(3) = 0.
loc = matmul(vec,mat)
! make window
call recwin_3d( loc(1), loc(2), loc(3), xdim, winsz,&
istart, istop, jstart, jstop, mstart, mstop )
! interpolate
do i=istart,istop
do j=jstart,jstop
do m=mstart,mstop
! calculate weight (Gaussian windowed sinc)
tmp = calc_weight( i, j, m, loc )
! grid the Fourier data
if( that == 'old' )then
bp%s3d(s)%fvol(i,j,m) = bp%s3d(s)%fvol(i,j,m)+&
cmplx(real(bp%f(ptcl)%arr(h,k))*tmp,aimag(bp%f(ptcl)%arr(h,k))*tmp)
else
bp%s3d(s)%fvol_new(i,j,m) = bp%s3d(s)%fvol_new(i,j,m)+&
cmplx(real(bp%f(ptcl)%arr(h,k))*tmp,aimag(bp%f(ptcl)%arr(h,k))*tmp)
endif
! grid the kernel
bp%s3d(s)%kernel(i,j,m) = bp%s3d(s)%kernel(i,j,m)+tmp
end do
end do
end do
end subroutine grid_fplane_comp_1
subroutine grid_fplane_comp_2( h, k, s, w )
! grids a plane component to the Fourier volume with input weight
integer, intent(in) :: h, k, s
real, intent(in) :: w
integer :: i, j, m, istart, istop, jstart, jstop, mstart, mstop
real :: tmp, vec(3), loc(3)
vec(1) = real(h)
vec(2) = real(k)
vec(3) = 0.
loc = matmul(vec,mat)
! make window
call recwin_3d( loc(1), loc(2), loc(3), xdim, winsz,&
istart, istop, jstart, jstop, mstart, mstop )
! interpolate
do i=istart,istop
do j=jstart,jstop
do m=mstart,mstop
! calculate weight (Gaussian windowed sinc)
tmp = calc_weight( i, j, m, loc )*w
! grid the Fourier data
if( that == 'old' )then
bp%s3d(s)%fvol(i,j,m) = bp%s3d(s)%fvol(i,j,m)+&
cmplx(real(bp%f(ptcl)%arr(h,k))*tmp,aimag(bp%f(ptcl)%arr(h,k))*tmp)
else
bp%s3d(s)%fvol_new(i,j,m) = bp%s3d(s)%fvol_new(i,j,m)+&
cmplx(real(bp%f(ptcl)%arr(h,k))*tmp,aimag(bp%f(ptcl)%arr(h,k))*tmp)
endif
! grid the kernel
bp%s3d(s)%kernel(i,j,m) = bp%s3d(s)%kernel(i,j,m)+tmp
end do
end do
end do
end subroutine grid_fplane_comp_2
function calc_weight( i, j, m, loc ) result( w )
integer, intent(in) :: i, j, m
real, intent(in) :: loc(3)
real :: tmp1, tmp2, tmp3, btmp1, btmp2, btmp3, w
tmp1 = sinc(real(i)-loc(1))
tmp2 = sinc(real(j)-loc(2))
tmp3 = sinc(real(m)-loc(3))
btmp1 = gauwfun(real(i)-loc(1), winsz, 0.5)
btmp2 = gauwfun(real(j)-loc(2), winsz, 0.5)
btmp3 = gauwfun(real(m)-loc(3), winsz, 0.5)
w = tmp1*tmp2*tmp3*btmp1*btmp2*btmp3
end function calc_weight
subroutine grid_fplane_1( e1, e2, e3, x, y, s )
real, intent(in) :: e1, e2, e3, x, y
integer, intent(in) :: s
integer :: h, k
! set the euler to make the rotation matrix
call set_euler(e_one, 1, e1, e2, e3)
! get the matrix
call get_euler_mat(e_one, 1, mat)
! shift the fplane
call shift_fplane(bp%f(ptcl)%arr, x, y)
! grid it onto the Fourier volume
!$omp parallel do default(shared) private(h,k) schedule(static)
do h=-xdim,xdim
do k=-xdim,xdim
call grid_fplane_comp_1( h, k, s )
end do
end do
!$omp end parallel do
end subroutine grid_fplane_1
subroutine grid_fplane_2( e1, e2, e3, x, y, s, w )
real, intent(in) :: e1, e2, e3, x, y
integer, intent(in) :: s
real, intent(in) :: w
integer :: h, k
! set the euler to make the rotation matrix
call set_euler(e_one, 1, e1, e2, e3)
! get the matrix
call get_euler_mat(e_one, 1, mat)
! shift the fplane
call shift_fplane(bp%f(ptcl)%arr, x, y)
! grid it onto the Fourier volume
!$omp parallel do default(shared) private(h,k) schedule(static)
do h=-xdim,xdim
do k=-xdim,xdim
call grid_fplane_comp_2( h, k, s, w )
end do
end do
!$omp end parallel do
end subroutine grid_fplane_2
subroutine kernel_div
real :: fwght
integer :: h, k, l, s
write(*,'(A)') '>>> DIVIDING WITH THE GRIDDED KERNEL & ANTIALIASING'
do s=1,nstates
do h=-xdim,xdim
do k=-xdim,xdim
do l=-xdim,xdim
if( bp%s3d(s)%kernel(h,k,l) /= 0. )then
fwght = taperedge( dstep, h, k, l, fny, 1.5 )
if( that == 'old' )then
bp%s3d(s)%fvol(h,k,l) = cmplx(fwght*real(bp%s3d(s)%fvol(h,k,l))/bp%s3d(s)%kernel(h,k,l),&
fwght*aimag(bp%s3d(s)%fvol(h,k,l))/bp%s3d(s)%kernel(h,k,l))
else
bp%s3d(s)%fvol_new(h,k,l) = cmplx(fwght*real(bp%s3d(s)%fvol_new(h,k,l))/bp%s3d(s)%kernel(h,k,l),&
fwght*aimag(bp%s3d(s)%fvol_new(h,k,l))/bp%s3d(s)%kernel(h,k,l))
endif
else
bp%s3d(s)%fvol(h,k,l) = cmplx(0,0)
endif
end do
end do
end do
end do
end subroutine kernel_div
subroutine prep_new_fvols( e1, e2, e3 )
real, intent(in) :: e1, e2, e3
integer :: s
do s=1,nstates
! zero the target Fourier volumes
bp%s3d(s)%fvol_new = cmplx(0.,0.)
! zero the kernels
bp%s3d(s)%kernel = 0.
end do
! set the euler to make the rotation matrix
call set_euler(e_one, 1, e1, e2, e3)
! get the matrix
call get_euler_mat(e_one, 1, mat)
end subroutine prep_new_fvols
subroutine rot_fvol_lp( e1, e2, e3, s )
! is for rotating the Fourier volumes according to input orientation
real, intent(in) :: e1, e2, e3
integer, intent(in) :: s
integer :: h, k, l, target_to
call prep_new_fvols( e1, e2, e3 )
! determine the dynamic low-pass Fourier index
target_to = int(dstep/lp_dyn)
if( target_to > tofny ) then
target_to = tofny
else if( target_to < 3 ) then
target_to = 3
endif
!$omp parallel do default(shared) private(h,k,l) schedule(static)
do h=-target_to,target_to
do k=-target_to,target_to
do l=-target_to,target_to
call grid_fvol_comp_1( h, k, l, s )
end do
end do
end do
!$omp end parallel do
end subroutine rot_fvol_lp
subroutine rot_fvol( e1, e2, e3, s )
! is for rotating the Fourier volumes according to input orientation
real, intent(in) :: e1, e2, e3
integer, intent(in) :: s
integer :: h, k, l
call prep_new_fvols( e1, e2, e3 )
!$omp parallel do default(shared) private(h,k,l) schedule(static)
do h=-xdim,xdim
do k=-xdim,xdim
do l=-xdim,xdim
call grid_fvol_comp_1( h, k, l, s )
end do
end do
end do
!$omp end parallel do
end subroutine rot_fvol
subroutine fgrid( nincl )
! for gridding Fourier volumes according to the orientations and states in oris
integer, intent(in) :: nincl
integer :: i, s
do s=1,nstates
! zero the Fourier volumes
bp%s3d(s)%fvol = cmplx(0.,0.)
! zero the kernels
bp%s3d(s)%kernel = 0.
end do
! loop over particles
write(*,'(A)') '>>> GRIDDING FOURIER PLANES'
do i=1,nincl
call print_bar(i, nincl, '=')
! read the Fourier plane from stack
call read_fplane(bp%f(ptcl)%arr, fstk, pinds(i))
! grid it
call grid_fplane(oris(pinds(i),1), oris(pinds(i),2), oris(pinds(i),3),&
oris(pinds(i),4), oris(pinds(i),5), int(oris(pinds(i),6)))
end do
call kernel_div
end subroutine fgrid
end module simple_fgridvol