#!/bin/csh

set echo on

gunzip ../tteftu_with_tRNA.pdb.gz

sxpdb2em.py ../tteftu_with_tRNA.pdb tmp.hdf --apix=5.2 --box=64

e2proc3d.py tmp.hdf ../fmodel_structure.hdf --process=filter.lowpass.tanh:cutoff_abs=0.15:fall_off=0.2 || exit

e2proc3d.py tmp.hdf ../model_structure.hdf --process=filter.lowpass.tanh:cutoff_abs=0.45:fall_off=0.1 || exit

rm tmp.hdf

# Generating 2D projections of a 3D model from an input hdf file.
# It simulates the procedure of EM image acquisition process.
# The output projections were disturbed with Gaussian noise.
sxprocess.py ../model_structure.hdf data mic --generate_projections format="bdb":apix=5.2

sxprocess.py demoparms --makedb 'gauss_width'=1.0:'pixel_input'=5.2:'pixel_output'=5.2:'thr_low'=4.0:'thr_hi'=60.0:"invert_contrast"=False:"use_variance"=True:"boxsize"=64
e2boxer.py --gauss_autoboxer=demoparms --write_ptcl --boxsize=64 --norm=normalize.ramp.normvar mic*.hdf
sxcpy.py bdb:particles/mic0_ptcls bdb:particles/mic1_ptcls bdb:particles/mic2_ptcls bdb:particles/mic3_ptcls bdb:particles/mic4_ptcls bdb:data2

sxheader.py bdb:data --params=active --one
sxheader.py bdb:data --params=xform.align2d --zero
mpirun -np 4 sxisac.py bdb:data --stab_ali=2 --init_iter=1 --main_iter=1 --match_second=1 --ou=30 --max_round=5 --img_per_grp=120 --thld_err=5.1 --generation=1 --MPI 
###################################################################
# To run gui version of sxisac, enter the following in the command line:
# 	sxgui.py --demo=mpibdb &
# and then press the 'sxisac' button in the main menu. A separate window will pop up with the input fields already initialized to the proper values. 
# Press the green 'Run sxisac' button to execute the command.
# Note thatif sxgui.py is invoked without the --demo option, the input fields will not be automatically initialized with the approprite values, in 
# which case the proper values must be entered manually.
###################################################################

# Determination of the initial structure using class averages and common-lines
mpirun -np 4 sxfind_struct.py class_averages_generation_1.hdf structure --ou=30 --delta=6 --lf=0.05 --hf=0.3 --maxit=20 --rand_seed=200 --trials=4 --MPI || exit
###################################################################
# To run gui version, enter the following in the command line:
# 	sxgui.py --demo=mpibdb &
# and then press the 'sxfind_struct' button in the main menu. A separate window will pop up with the input fields already initialized to the proper values. 
# Press the green 'Run sxfind_struct' button to execute the command.
# Note thatif sxgui.py is invoked without the --demo option, the input fields will not be automatically initialized with the approprite values, in 
# which case the proper values must be entered manually.
###################################################################

# 3D reconstruction to compute initial structure based on Euler angles determined in the previous step 
mpirun -np 4 sxrecons3d_n.py structure/structure.hdf ab_initio_vol.hdf --MPI || exit

# Low-pass filtration of the initial structure
e2proc3d.py ab_initio_vol.hdf ab_initio_volf.hdf --process=filter.lowpass.tanh:cutoff_abs=0.15:fall_off=0.2 || exit

# 2D alignment parameters are transformed to 3D alignment parameters
sxparams_2D_to_3D.py bdb:data || exit

# 3D projection alignment - refinement of the initial structure
mpirun -np 4 sxali3d.py bdb:data ab_initio_volf.hdf ali3d_d --ou=30 --xr='2.0 1.0 0.5' --ts='1.0 1 0.5' --delta='31 10 2' --an='-1 12 6' --maxit=2 --ref_a=P  --function="[..,demo_user_funcs,ali3d_reference3]"  --MPI || exit
###################################################################
# To run gui version, enter the following in the command line:
# 	sxgui.py --demo=mpibdb &
# and then press the 'sxali3d' button in the main menu. A separate window will pop up with the input fields already initialized to the proper values. 
# Press the green 'Run sxali3d' button to execute the command.
# Note thatif sxgui.py is invoked without the --demo option, the input fields will not be automatically initialized with the approprite values, in 
# which case the proper values must be entered manually.
###################################################################

# Refinement of the 3D structure using high accuracy alignment
mpirun -np 4 sxlocal_ali3d.py bdb:data ali3d_e --ou=30 --delta=2 --maxit=1 --chunk=0.25 --function="[..,demo_user_funcs,localali3d_reference4]" --MPI  --debug || exit
###################################################################
# To run gui version, enter the following in the command line:
# 	sxgui.py --demo=mpibdb &
# and then press the 'sxlocal_ali3d' button in the main menu. A separate window will pop up with the input fields already initialized to the proper values. 
# Press the green 'Run sxlocal_ali3d' button to execute the command.
# Note thatif sxgui.py is invoked without the --demo option, the input fields will not be automatically initialized with the approprite values, in 
# which case the proper values must be entered manually.
###################################################################

