; Multiplies a reference volume by the CTF & creates ref projections
;
; refproj.bat
;
; PURPOSE: Multiplies a reference volume by the CTF for each defocus group, then
;          creates reference projections from each CTFvolume.
;
;Inputs
;   ../params		; the parameter doc file
;   reference_volume	; reference volume
;   radius		; parameter for PJ 3Q (if the value is -1, a default
;                         value will be computed that is .69 * actual size.)
;
;Outputs
;   refangles    ; doc file with reference angles
;   projlist     ; doc file with list of projections
;   df***/prj		; template for 2D projections
;   df***/refctf	; reference multiplied by CTF
;
; the following values are computed from the params file
;x12 = number of defocus groups
;x72 = electron wavelength (Angstroms)
;x73 = pixel size, Angstroms
;x75 = array dimension, pixels
;
;
; MASTER COPY: /net/bali/usr1/spider/docs/techs/recon/newprogs/
;
; I/O PARAMETERS AND FILES ARE SET HERE:
;
;  ------------ Parameters ---------------------------------------

x15 = 15	; delta theta : 15 gives 83 projections
x39 = -1 	; radius : use -1 for default value

;    ------------ Input files ---------------------------------------

FR G
[params]../params    ; the parameter file

FR G
[refvol]../reference_volume  ;  input reference volume

FR G
[defocus]../Power_Spectra/order_defgrps ; average defocus group values

; --------------- Output files  -------------------------------------
FR G
[refangles]refangles   ; output doc file of angles

FR G
[projlist]projlist   ; output list of projections

FR G
[df]df{***x22}   ; directory template for defocus groups

FR G
[prj]prj****   ; output template for 2D projections


; -------------- END BATCH HEADER ---------------------------------

; delete output document files and get parameters
DE
[refangles]
DE
[projlist]

UD 5,x73    ; pixel size
[params]
x74=0.5/x73 	; max. spatial frequency

UD 6,x71    ; electron energy
[params]
x72 = 12.398 / SQR(x71 * (1022.0 + x71))    ; lambda

UD 7,x79     ; spherical aberration
[params]
UD 8,x61     ; source size
[params]
UD 9,x62     ; defocus spread
[params]
UD 12,x63     ; amplitude contrast ratio
[params]
UD 13,x64     ; Gaussian envelope halfwidth
[params]
UD 17,x75    ; window size
[params]

IF (x39.LT.0) THEN    ; get actual size and compute radius
    UD 18,x41
    [params] 
    x39 = 0.69 * x41
ENDIF

UD N,x12    ; number of defocus groups
[defocus]

; create the document files
VO EA,x83
x15        ; delta theta
0,0        ; range of theta
0,0        ; range of phi
[refangles]  ; output doc file of angles

x83=x83-1

DOC CREATE    
[projlist]   ; output doc file
1            ; column to be filled
1-x83        ; numbers to put in column

;------------------------------------------
; For each defocus group, multiply the reference volume by the
; appropriate defocus, then use this ctf-reference to generate
; 83 projection images
DO LB1 x21=1,x12 

   UD x21,x22,x71 ; get defocus group # (x22) and defocus value (x71)
   [defocus]

   VM
   mkdir -p [df]

   TF C3
   _7       ; output file (complex model CTF)
   x79      ; spherical aberration
   x71,x72  ; defocus,lambda
   x75      ; array dimension
   x74      ; maximum spatial frequency
   x61,x62  ; source size, defocus spread
   (0,0)    ; astigmatism, azimuth
   x63,x64  ; amplitude contrast ratio, envelope 1/2-width
   (-1)     ; sign

   FT
   [refvol]
   _2

   MU
   _2
   _7
   _4
   *

   FT
   _4
   _7    ; output = ctf_multiplied volume

   PJ 3Q          ; generate projections of a volume
   _7             ; input volume
   x39            ; radius
   [projlist]     ; file numbers
   [refangles]    ; angles doc file
   [df]/[prj]    ; template for output projection images

LB1

EN
;