([sp_pixsiz],[r2],[alignsh],[prjRadius],[iter1],[iterEnd],[sphdecon],[smallangYN],[qsub],[incoreYN],[goldStd],[bpType]) ; ; Sets refinement parameters and files
 ;
 ; SOURCE:  spider/docs/techs/recon1/Procs/refine_settings.spi
 ;          New                                    ArDean Leith Jul 2002
 ;          [] variables                           ArDean Leith Dec 2005
 ;          Rewritten, more stacks                 ArDean Leith Dec 2006
 ;          Variable assignment                    ArDean Leith Jan 2010
 ;          Even-odd replaced                      ArDean Leith Jan 2011
 ;          Dala removal                           ArDean Leith Jan 2012
 ;          [pixsiz] returned, fsc, ofsc...        ArDean Leith Aug 2012
 ;          Skip 3.3,3...                          ArDean Leith Sep 2012
 ;          For CTF corrected images               ArDean Leith Oct 2013
 ;          For gold standard reconstruction       ArDean Leith May 2014
 ;          Added spherical deconvolution          ArDean Leith Jan 2016
 ;          Inlined params, changed dirs           ArDean Leith Mar 2016
 ;
 ; INPUT REGISTERS:    None
 ;
 ; OUTPUT REGISTERS:
 ;   [sp_pixsiz]       Pixel size                    (A) 
 ;   [r2]              Object alignment radius       (pixels)
 ;   [alignsh]         Alignment shift +- allowed    (pixels) 
 ;   [prjRadius]       Object projection radius      (pixels)
 ;   [iter1]           Starting iteration
 ;   [iterEnd]         Ending   iteration
 ;   [sphdecon]        Spherical deconvolution angle (degrees)
 ;   [smallangYN]      Small angle refinement flag   (1 == True)
 ;   [qsub]            Specifies que type            (1 == use PBS)
 ;   [incoreYN]        Incore files                  (1 == true)
 ;   [goldStd]         Use 'gold-standard' work-flow (1 == True)
 ;   [bpType]          Backprojection method         (2 == 'BP 3F')
 ;
 ; 
 ; ------------- Adjust these parameters for your project --------------- EDIT -----

 [qsub]         = 3      ; Specifies queue (1 == use PBS, 2 == PBS with memory estimate, 0 == use PubSub, 3 == PBSPro, <0 == none)
 GLO [pbsFlags] = '-l nodes=1:ppn=8:mem={%i0%[memMb]}mb -q ceitecmu -l walltime=47:59:00'  ; Additional user-defined flags for old PBS
 GLO [proFlags] = '-l select=1:ncpus=8:mem={%i0%[memMb]}mb -q ceitecmu -l walltime=47:59:00'  ; Additional user-defined flags for PBSPro

 [iter1]        = 1      ; Starting alignment step (iteration)
 [iterEnd]      = 15     ; Ending alignment step   (iteration)
  
 [diam]         = -1     ; Diameter of the structure (A) used in alignment search (<0 == from 'params.spi')
 [sp_pixsiz]    = -1     ; Pixel size (A, <0 == from 'params.spi')  
 [sp_winsiz]    = -1     ; Window size (pixels, <0 == from 'params.spi')   
 [winFrac]      = 0.95   ; Fraction of window diameter used in projection (0.95 == 95%)
 [alignsh]      = 8      ; Alignment shift (pixels) searched is +- this value

 [bpType]       = 2      ; Backprojection method (1=='BP CG', 2=='BP 3F', 3=='BP RP', 4=='BP 3N')

 [goldStd]      = 1      ; Use 'gold-standard resolution' work-flow (1 == use gold, 0 == use legacy)

 [incoreYN]     = 1      ; Load input images into incore stack (>0 == yes we have enough memory)
 GLO [userMem]  = 5000   ; Memory (MB) required for normal refinement (-1 == Automatic)
 GLO [smAngMem] = 3611   ; Memory (MB) required for small-angle refinement (-1 == Automatic)
 GLO [spdMem]   = 7271   ; Memory (MB) required for spherical deconvolution (-1 == Automatic)

 ; Following two string variables are used during usual refinement (one value / iteration) (Set for up to: 20 iterations)
 GLO [ang-steps]  = '15,3.3,3, 2,2,  2,1.5,1.5,1.5,1.5,  1.5,1.5,1.5,1.5,1.5,   1.5,1.5,1.5,1.5,1.5' ; Angular separation (degrees)  
 GLO [ang-limits] = '0,0,0,  15,8,  6,5,5,5,5, 5,5,5,5,5, 5,5,5,5,5,5'    ; Angular separation limits (degrees)

 [smallangYN] = 0       ; Use small angle refinement instead of regular (1 == Yes)

 ; Following three global register variables are only used during 'small angle refinement'
 GLO [ang-step-sm] =  5                    ; Angular degree step      
 GLO [theta-sm]    =  2.0                  ; Theta range  
 
 [sphdecon]     = 4.5    ; Spherical deconvolution angle in degreees (0 == Do not deconvolve)
 GLO [spdFlags] = '-l select=8:ncpus=2:mem={%i0%[memMb]}mb -q ceitecmu -l walltime=143:59:00'  ; Additional user-defined flags for spherical deconvolution

 ; Following string variable is used to activate OPTIONAL amplitude enhancement (Set for up to: 20 iterations)
 GLO [amp-enhance-flags] = '0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0'  ; Amplitude enhancement selector 

 ; ----------------- Original input files ---  May have to EDIT these names, These files must exist ------

 GLO [in_dir]              = '../win_1'                             ; Dir. for starting selection files
 GLO [params]              = '../params'                            ; Parameter doc file  (one)  

 GLO [sel_group]           = '[in_dir]/sel_group'                   ; Group selection doc file         (one)

 GLO [sel_parts]           = '[in_dir]/sel_part_{***[grp]}'         ; Particle selection doc files     (one/group)

;; GLO [vol_orig]            = '[in_dir]/reference_volume_fqnp'       ; Initial reference volume         (one)   
 GLO [vol_orig]            = '../rec_1/vol_01_s{*[s]}'              ; Initial reference volumes        (two)   

 ; This variable: [unaligned_images] must be an absolute path to images or a link to an absolute path! 
 GLO [unaligned_images]    = '[in_dir]/data_{***[grp]}'             ; Original unaligned images stack  (one/group)
                
 ; OPTIONAL files needed if using amplitude enhancement
 GLO [scattering_doc]      = '[in_dir]/scattering'                  ; OPTIONAL enhancement doc file    (one)
 GLO [mask]                = '[in_dir]/mask'                        ; OPTIONAL mask for enhancement    (one)

 ; OPTIONAL local dir for speeding up parallel use 
;;;GLO [local_work_dir]      = '/scratch'                              ; OPTIONAL local scratch dir for parallel use (one)
 GLO [local_work_dir]      = 'scratch{***[grp]}'                     ; OPTIONAL local scratch dir for parallel use (one/group)

 ; OPTIONAL doc file needed if using symmetry                         
 GLO [symmetry_doc]        = '*'                                     ; OPTIONAL symmetry doc file for 'back projection' (one)

 ; OPTIONAL initial alignment parameter doc file if starting from reconstruction 
!GLO [group_align_orig]    = '[in_dir]/align_{**[iter]}_{***[grp]}' ; OPTIONAL Initial alignment parameter file (one/group) 
 GLO [group_align_orig]    = '*'                                     ; OPTIONAL Initial alignment parameter file (one/group) 

 ; -------------- Output files -----------------------------------------------------------------------

 GLO [out_dir]             = 'final_1'                                    ; Dir. for significant output files
 
 ; --- Usually no need to edit for default refinement ------------------------------------------------

 GLO [work_dir]            = 'work/'                                      ; Work dir                           (one)

 GLO [sel_parts_s]         = '[sel_parts]_s{*[s]}'                        ; Particle subset selection doc file (two/group)

 GLO [vol]                 = '[out_dir]/vol_{**[iter]}'                   ; Current volume   
 GLO [vol_s]               = '[vol]_s{*[s]}'                              ; Current subset volume              (two/iter)  

 GLO [next_vol]            = '[out_dir]/vol_{**[next-iter]}'              ; Next volume                        (one/iter)
 GLO [next_vol_s]          = '[next_vol]_s{*[s]}'                         ; Next subset volume                 (two/iter)

 GLO [group_vol_stem]      = '[work_dir]/vol_{**[iter]}_{***[grp]}_***'   ; Current group volume               (one/group/iter)           
 GLO [group_vol_s]         = '[work_dir]/vol_{**[iter]}_{***[grp]}_s{*[s]'; Current group subset volumes       (two/group/iter) 

 GLO [next_group_vol]      = '[work_dir]/vol_{**[next-iter]}_{***[grp]}'  ; Next group volume                  (one/group/iter)
   
 GLO [next_group_vol_stem] = '[work_dir]/vol_{**[next-iter]}_***_s{*[s]}' ; Next subset group volume stem       
 GLO [next_group_vol_s]    = '[next_group_vol]_s{*[s]}'                   ; Next subset group volume           (two/group/iter) 

 GLO [group_align]         = '[out_dir]/align_{**[iter]}_{***[grp]}'      ; Group alignment doc file   
 GLO [group_align_s]       = '[group_align]_s{*[s]}'                      ; Group subset alignment doc files   (two/group/iter)
 GLO [next_group_align]    = '[out_dir]/align_{**[next-iter]}_{***[grp]}' ; Next group alignment doc file  
 GLO [next_group_align_s]  = '[next_group_align]_s{*[s]}'                 ; Next group subset alignment doc file (one/group/iter)

 GLO [iter_refangs]        = '[work_dir]/ref_angs_{**[iter]}'             ; Reference angle file               (one/iter)
 GLO [iter_refangs_grp]    = '[work_dir]/ref_angs_{**[iter]}_{***[grp]}'  ; Reference projection angles doc file  (one/group/iter) (deleted)

 GLO [ref_projs_s]         = '[work_dir]/ref_projs_{**[iter]}_s{*[s]}'    ; Subset reference projections       (one/iter)
 GLO [ref_projs_s_grp]     = '[ref_projs_s]_{***[grp]}@'                  ; Subset group reference projections (two/group/iter) (deleted)

 GLO [fsc_mask]            = '[out_dir]/fsc_mask'                         ; Mask for FSC                       (one) 
 GLO [next_u_fsc]          = '[out_dir]/fscdoc_u_{**[next-iter]}'         ; Unmasked FSC curve doc file        (one/iter)
 GLO [next_m_fsc]          = '[out_dir]/fscdoc_m_{**[next-iter]}'         ; Masked   FSC curve doc file        (one/iter)
 GLO [m_fsc]               = '[out_dir]/fscdoc_m_{**[iter]}'              ; Masked   FSC curve doc file        (one/iter)
 GLO [fsc_plots]           = 'fsc_iter.gpl'                               ; Gnuplot script for FSC plotting    (one) 

 GLO [iter_resol]          = '[out_dir]/resolutions'                      ; Overall resolution doc file        (one)
       
 GLO [ang_voea]            = '[out_dir]/angvoea'                          ; OPTIONAL, Small angle refinement ref. angles        (one/group/iter)
 GLO [ang_vora]            = '[out_dir]/angvora_{**[iter]}_{***[grp]}'    ; OPTIONAL, Small angle refinement ref. angles        (one/group/iter)
 GLO [temp_ref_projs]      = '_5@'                                        ; OPTIONAL, Small angle refinement local scratch file (deleted)
 
 GLO [enhance_doc]         = '[work_dir]/enhance_doc_{**[next-iter]}'     ; OPTIONAL, Enhancement doc file output      (one/iter)

 GLO [ref_rings]           = '[work_dir]/SCR_{**[iter]}_{***[grp]}'       ; OPTIONAL, Reference rings files output     (one/group/iter)
 GLO [wait_file]           = 'jnk_waited_***'                             ; OPTIONAL, Created when local copy finished (one/group)

 GLO [finished_file]       = 'jnk_sync_{****[rn]}_'                       ; OPTIONAL, Created when parallel segment finished (one/group)

 GLO [temp_in_images]      = '_8@'                                        ; OPTIONAL, Used by alignment & back projection internally
 GLO [temp_out_images]     = '[work_dir]/dala_{***[grp]}@'                ; OPTIONAL, Used if [incoreYN] == 0  or small angle ref. (deleted)

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

 ; ---- Should not need to adjust following parameters --------------------------

 ; Get values from params
 IF ([sp_pixsiz] .LE. 0) THEN
   UD IC 5, [sp_pixsiz]
     [params]
 ENDIF
 
 IF ([sp_winsiz] .LE. 0) THEN
   UD IC 17, [sp_winsiz]
     [params]
 ENDIF
 
 ; Get particle size (pixels) from PARAMS, or calculate
 IF ([diam] .LE. 0) THEN
   UD IC 18, [sp_partsiz]
     [params]
   ELSE
     [sp_partsiz] = [diam]/[sp_pixsiz]
 ENDIF
 
 UD ICE
   [params]

 [r2] = INT([sp_partsiz]/2.0)           ; Alignment radius (pixels) used in alignment search

 ; Ensure that sum of alignment radius + translation is within window dimensions 
 [ringsh] = [r2] + [alignsh]          ; Last ring + translation step
 [maxrad] = INT([sp_winsiz]/2) - 1    ; Max radius of object in window

 IF ( [ringsh] >= [maxrad] ) THEN
   ; Must reduce radius of outer ring, not translation step
   [r2] = [maxrad] - [alignsh] - 2     ; Reduces rotational search radius 
 ENDIF

 [prjRadius] = INT(([winFrac]*[sp_winsiz])/2.0 )  ; Convert fraction to pixel radius

 RE
 ;