///////////////////////////////////////////////////////////////////////////////
//
// cst_mode
// ( new version of enzyme design )
// use input constraints to do design and pose minimization
//
// Lin Jiang
//
// input constraint from two format:
//             single line format: "-cst_from_file <file>"
//             complicate format:  "-cstfile <file>"
//             enzyme cst format:  "-read_enzyme_cst <file>"
//				in the above three options,
//				   if file is empty, read from the starting structure
//				   if file == "auto", read from the ***.cst
//
//   -enable_ligand_aa   turn on the ligaa which treat ligand as a new
//                       amino acid type as a replacement of ligand mode,
//                       indicating that rosetta should assign slightly larger
//                       values to MAX_AA and MAX_ATOM.
//                       Therefor, nothing is special for ligand during
//                       the energy calculation, expect the initial setup for
//                       new amino acid type.
//
//  submode:
//    cst_score            score the input structure with input constraints
//    cst_dockpert         small docking perturbation of ligand
//    cst_opt              optimize the catalytic site
//    cst_loop             loop refinement with input constraints
//    cst_design           design by defined design_matrix with input constraints
//    cst_min              pose type minimization with input constraints
//       if no constraint read successfully, the submode will be running without constriants,
//       it means, go to the normal score, design, minimizing and etc.
//       Also, among the above submode, you can run it by combining several flags
//
//  define the interface:
//    design_residues array define design regions
//    repack_residues array define repack regions and allow_move regions when minimizing
//
//  weight_set:
//    specify scoring weight set from file: "-score_wtsfile <default.weight_set>"
//    specify packer weight set from file:  "-packer_wtsfile <default.weight_set>"
//
//

######################
# benchmark test dir
All the examples are in the benchmark test directory "cst_test"

######################
# constraint example
	single line format: see "cst_from_file_exmaple.pdb"
	complicate format:  see "cstfile_example.cst"	
	enzyme cst format:  see "enzyme_cst_example.pdb"

######################
# catalytic REMARK exmaple	
	"REMARK BACKBONE TEMPLATE A ASP xxxx MATCH MOTIF B HIS xxxxx  1"
	new format ( reside pair definition ): see "cstfile_example.pdb"
	old format ( enzyme_cst format): see "enzyme_cst_example.pdb"

######################
# weight set example
	 see "default.weight_set"

##############
# usage
cst_mode ( new version of enzyme design ):
-------------------------------------------------------------------------------
-cst_mode                       use input constraints to do design
				and pose minimization ( new version of enzyme design )

   -enable_ligand_aa            turn on the ligaa which treat ligand as a new
                                amino acid type as a replacement of ligand mode,
                                indicating that rosetta should assign slightly larger
                                values to MAX_AA and MAX_ATOM.
                                Therefor, nothing is special for ligand during
                                the energy calculation, expect the initial setup for
                                new amino acid type.
      -use_atom_weights         if enable_ligaa, read the atomic weight from occ
      -read_input_charge        if enalbe_ligaa, read the atomic charge from bfactor
      -attach_by_bond           if enable_ligaa, attach ligand by bond
      -mdlfile                  if enable_ligaa, read ligand from mdl format
      -use_mdl_connect          if enable_ligaa, use mdl connectivity from mdl file
      -lig2_file <file>         read the second ligand as aa
      -fix_lig2                 fix the second ligand during minimization
				and the coordinates from pdb file
   -multi_chain                 treat the protein complex

   -s <file>                    input pdb file
   -l <file>                    input pdb list
				creat "CHECKPOINT" file into output path,
				and output "***:BEGIN" if cst_mode begin to process the current str
				    output "***:END" if cst_mode end to process the current str
   -read_patches                read the subset structures which can patch to the orginal scaffold
      -ps <file>                   input patch file
      -pl <file>                   input patch list

   -nstruct <n>                 how many runs
   -ndruns  <n>                 how many design (packer) runs, and only final model output
   -iterative_run               keep the last run structure as the initial structures
				default is to always use the input structure as the starting structures 

   -check_finish		if check "***:END" before process the current str
				default is to check "***:BEGIN" before process the current str
   -overwrite			ignore "CHECKPOINT" file and the overwrite the pdb
   -pdbout <name>               the output name, the default <name> is "des"
   -log_file <file>             redirect the std::cout to log_file
				if file == "auto", redirect to ***.log

   -debug_output                If output the debug information
   -dump_structures             If dump out all structures in the different stages

   -cst_from_file <file>        input constraint from single line format
   -cstfile <file>              input constraint from complicate mapping format
   -read_enzyme_cst <file>      input constraint from the input pdb file and using
                                old enzyme constraint format
				in the above three options,
				   if file is empty, read from the starting structure
				   if file == "auto", read from the ***.cst
   -read_old_header             use the old header format to define the catalytic map
				default is to use the new format compatiable with cst   

   -detect_covalent_bond        if !read_enzyme_cst, detect the atom pair is covalent
				otherwise take the covalent bond info from
				cst file "is_covalent"
   -covalent_from_cstfile       if read_enzyme_cst, take the covalent bond info
				from cst file "is_covalent"

   -resfile <file>              if define design and repack residues by resfile
				if file == "auto", read the ***.resfile
   -short_interface             define the interface by ca->cb vector ( if not resfile )
        -cut1 <i> -cut2 <j> -cut3 <k> -cut4 <l>
                                The i j k l are the distance parameters to define the
                                redesigned and repacked regions around the cluster.
                                Actually they defines four shells around the ligand
                                ( the default is 5.0 7.0 11.0 12.0 ):  if the distance
                                between protein CB atoms and close ligand atom within
                                the first shell, all positions are redesigned neighbors;
                                if the distances between the first shell and second shell,
                                only protein ca->cb vector points into ligand are
                                redesigned neighbor; if the distances within third shell,
                                all positions are repacked neighbors; if the distances
                                between the first shell and second shell, only protein
                                ca->cb vector points into ligand are repacked neighbors;
                                otherwise, they are not neighbors.
   -loop_file                   use the loop file to guide the pose fold tree, and it is 
				useful for allowing backbone movement

   -cst_score                   score the input structure with input constraint
   -cst_design                  design the interface with input constraints
   -cst_loop                    loop refinement with input cst and ligand
   -cst_dockpert n r            small docking perturbation
				n, r are Perturbation size
                                (n)ormal perturbation in Angstroms
                                (r)otational perturbation in degrees

   -cst_min                     pose type minimization with input constraints
      -rb_move                  allow ligand rigid body movement
      -chi_move                 allow protein sc torsional movement
      -bb_move                  allow protein bb torsional movement
      -vary_cb_bond             allow protein ca->cb bond movement
      -bonds                    allow minimizing ligand bond
      -angles                   allow minimizing ligand bond angle
      -torsions                 allow minimizing ligand torsional angle
   -cst_opt                     minimize the catalytic site
      -poly_ala                 crop pocket to poly ala
                                default is to crop pocket to poly gly
      -limit_cstopt             only output the good structures after cst_opt
         -repE_limit            default is 10.0
	 -cstE_limit            default is 50.0
	 -chainbreakE_limit     default is 3.0
   -zero_constraint_sd          zero the cst sd when cst_min and cst_opt
   -cst_min_cycles <n>          how many minimization cycles when cst_min and cst_opt

   -score_wtsfile <file>        specify score weight set from file
   -packer_wtsfile <file>       specify packer weight set from file

   -fix_catalytic_aa		fix the aa in the catalytic positions

-------------------------------------------------------------------------------

###############
# Command line

# score with new format constraint...
../rosetta.$compiler -pose1 -cst_mode -enable_ligand_aa -cst_score -cstfile cstfile_example.cst -s cstfile_example.pdb -paths ../cst_test/paths.txt > & cst_score.log

# design with the old enzyme format constraint...
../rosetta.$compiler -pose1 -cst_mode -enable_ligand_aa -cst_design -attach_by_bond -cst_opt -short_interface -cut1 4.0 -cut2 6.0 -cut3 7.0 -cut4 8.0 -read_enzyme_cst -read_all_chains -use_pdb_numbering -use_atom_weights -packer_wtsfile default.weights_set -s enzyme_cst_example.pdb -paths ../cst_test/paths.txt > & cst_enzyme_design.log

# minmizing with single line format cst...
../rosetta.$compiler -pose1 -cst_mode -enable_ligand_aa -cst_min -cst_from_file -score_wtsfile default.weights_set -s cst_from_file_example.pdb -paths ../cst_test/paths.txt > & cst_min.log

# minimization with resfile and without ligand...
../rosetta.$compiler -pose1 -cst_mode -cst_min -rb_move -chi_move -auto_resfile -pdbout cst_nolig -log_file cst_nolig_2.log -s cstfile_example.pdb -paths ../cst_test/paths.txt > & cst_min_with_resfile.log;
cat cst_nolig_2.log >> cst_min_with_resfile.log; rm -f cst_nolig_2.log

