# =======================================================================
# phaser_MR.tcl --
#
# Maximum Likelihood Molecular Replacement
#
# CCP4Interface
#
# =======================================================================

#------------------------------------------------------------------------
  proc phaser_MR_setup { typedefVar arrayname } {
#------------------------------------------------------------------------
  upvar #0 $typedefVar typedef
  upvar #0 $arrayname array

  DefineMenu _phaser_mode_mr [list "automated search" \
                                   "rotation search" \
                                   "translation search" \
                                   "refinement and phasing" \
                                   "log-likelihood gain rescoring" \
                                   "packing" \
                                   "anisotropy correction" \
                                   "cell content analysis" ] \
                                   [list "AUTO" \
                                         "ROTATE" \
                                         "TRANSLATE" \
                                         "REFINE" \
                                         "RESCORE" \
                                         "PACK" \
                                         "ANISOTROPY" \
                                         "CONTENT" ]

  DefineMenu _phaser_mode_rot \
    [list "fast rotation function" "brute force ML RF" ] [list "MR_FRF" "MR_BRF"]

  DefineMenu _phaser_mode_tran \
    [list "fast translation function" "brute force ML TF" ] [list "MR_FTF" "MR_BTF" ]

  DefineMenu _phaser_spacegroup_option \
    [list "the mtz space group" "the mtz space group and enantiomorph (if applicable)" "alternative space group(s)" "all choices of alternative space group" ] \
    [list "SG_MTZ" "SG_ENANT" "SG_ALT" "SG_ALL" ]

  DefineMenu _phaser_protnucleic \
    [list "protein" "nucleic acid" ] [list "PROTEIN" "NUCLEIC" ]

  DefineMenu _phaser_rms_option \
   [list "rms difference" "sequence identity" ] [list "RMS" "IDENT" ]

  set typedef(_phaser_ensemble_menu)  \
    { varmenu ENSEMBLE_MENU_LIST ENSEMBLE_MENU_ALIAS 15 }

  DefineMenu _phaser_brf_search_option \
   [list "full" "around" ] [list "FULL" "AROUND" ]

  DefineMenu _phaser_btf_search_option \
   [list "full" "around" "region" "line" "degenerate" ] \
   [list "FULL" "AROUND" "REGION" "LINE" "DEGENERATE"]

  DefineMenu _phaser_ensemble_option \
    [list "pdb file(s)" "mtz file" ] [list "PDB"  "MTZ"]

  set typedef(_phaser_comp_option) \
    { menu  { "molecular weight"  "sequence file" } { "MW"  "FASTA" } }

  set typedef(_phaser_tra_entry_option) \
    { menu { "manually" "from .rlist file" } { "MANUAL" "FILE" } } 

  set typedef(_phaser_frf_target_option) \
    { menu { "LERF1" "LERF2" "Crowther" } { "LERF1" "LERF2" "CROWTHER" } }

  set typedef(_phaser_ftf_target_option) \
    { menu { "LETF1" "Correl" } { "LETF1" "CORREL" } }

  set typedef(_phaser_coord_sys) \
   { menu { "orthogonal" "fractional" } { "ORTHOGONAL"  "FRACTIONAL" } }

  DefineMenu _phaser_plane_option \
    [list "XY" "XZ" "YZ" ] [list "XY" "XZ" "YZ"]

  set typedef(_phaser_rescore_option) \
   { menu { "sigma cutoff" "number of peaks" "percentage of top peak" "all peaks" } \
          { "SIGMA" "NPEAKS" "PERCENT" "ALL" } }

  set typedef(_phaser_save_option) \
   { menu  { "sigma cutoff" "number of peaks" "percentage of top peak" "all peaks" } \
           { "SIGMA" "NPEAKS" "PERCENT" "ALL" } }

  set typedef(_phaser_final_option)  \
    { menu { "sigma cutoff" "number of peaks" "percentage of top peak" "all peaks" }  \
           { "SIGMA"  "NPEAKS"  "PERCENT"  "ALL" } } 

  set typedef(_phaser_onoff_option) \
    { menu { "on" "off" } { ON OFF } }

  set typedef(_phaser_refine_option) \
    { menu { "refine" "fix" } { "REFINE" "FIX" } } 

  set typedef(_phaser_set_entry_option) \
    { menu { "manually" "from .sol file" } { "MANUAL" "FILE" } }

  set typedef(_phaser_dim_option) \
    { menu { "3 dim" "5 dim"  "6 dim" } { "3DIM" "5DIM" "6DIM"  } }

  set typedef(_phaser_set_degen_option) \
    { menu { "X" "Y" "Z" } { "X" "Y" "Z" } }

  set typedef(_phaser_set_coord_option) \
    { menu { "orthogonal" "fractional" } { "ORTH" "FRACT" } }

  set typedef(_phaser_resolution_option) \
    { menu { "dmin only" "dmin and dmax" } { "DMINONLY"  "DMINMAX" } }

  DefineMenu _phaser_bins_option  \
    [list "number of bins" "width of bins" ] [list "NUMBER" "WIDTH" ]

  set typedef(_phaser_boxscale_option)  \
    { menu { "all ensembles" "selected ensemble(s)"  } { "ALL" "SELECTED" } }

  set typedef(_phaser_clmn_option) \
    { menu { "outer limit only" "inner and outer limits" } { "OUTER" "INNER_OUTER" } }

  DefineMenu _phaser_interpolation_option \
   [list "1" "2" "3" ] [list "1" "2" "3" ]

  set typedef(_phaser_macrocycle_fixref) \
    { menu { "fix" "refine" } { "FIX" "REFINE" } }

  set typedef(_laue_space_group) { varmenu LAUE_SPGP_LIST LAUE_SPGP_ALIAS 8 }

  return 1
  }

#------------------------------------------------------------------------
proc phaser_MR_run { arrayname } {
#------------------------------------------------------------------------

  upvar #0 $arrayname array

  if { $array(HKLIN_MAIN) == "" } {
     WarningMessage "The mtz reflection data file has not been set"
     return 0
  }

  for { set n 1 } { $n <= $array(N_COMPONENT) } { incr n } {
    if { ($array(MW,$n) == "") && ([GetValue $arrayname MR_MODE] != "PACK") } {
       WarningMessage "The molecular weight for component # $n is not set"
       return 0
     }
   }

  if { ([GetValue $arrayname MR_MODE] == "ANISOTROPY") } {
     return 1
  }

   for { set n 1 } { $n <= $array(N_ENSEMBLE) } { incr n } {
    if { [ regexp PDB [GetValue $arrayname ENSEMBLE_OPTION,$n ] ] } {
    for { set p 1 } { $p <= $array(N_PDB,$n) } { incr p } {
      if { $array(XYZIN,[subst $n]_$p) == "" } {
         WarningMessage "A pdb model file for
ensemble # $n has not been set"
         return 0
      }
      if { $array(RMS,[subst $n]_$p) == "" } {
         WarningMessage "The RMS error for PDB # $p of ensemble # $n
has not been set"
         return 0
      }
    }
    }
    if { [ regexp MTZ [GetValue $arrayname ENSEMBLE_OPTION,$n ] ] } {
      if { $array(HKLIN,$n) == "" } {
         WarningMessage "The mtz map file for 
ensemble # $n has not been set"
         return 0
      }
      if { $array(ENSEMBLE_PROTMW,$n) == "" } {
         WarningMessage "The protein molecular weight for
ensemble # $n has not been set"
         return 0
      }
      if { $array(ENSEMBLE_NUCLMW,$n) == "" } {
         WarningMessage "The nucleic acid molecular weight for
ensemble # $n has not been set"
         return 0
      }
      if { ($array(ENSEMBLE_EXT_X,$n) == "") 
        || ($array(ENSEMBLE_EXT_Y,$n) == "")
        || ($array(ENSEMBLE_EXT_Z,$n) == "") } {
         WarningMessage "The extent of the model for ensemble # $n
has not been (fully) defined"
         return 0
      } 
      if { $array(ENSEMBLE_RMS_MTZ,$n) == "" } {
         WarningMessage "The RMS error of the model for ensemble # $n
has not been set"
         return 0
      } 
      if { ($array(ENSEMBLE_CEN_X,$n) == "")
        || ($array(ENSEMBLE_CEN_Y,$n) == "")
        || ($array(ENSEMBLE_CEN_Z,$n) == "") } {
         WarningMessage "The centre of the model for ensemble # $n
has not been (fully) defined"
         return 0 
       }
    }
   }

# Check for compulsory brute force rotation function AROUND search parameters
  if { ([GetValue $arrayname MR_MODE] == "ROTATE") 
    && ([GetValue $arrayname MR_MODE_SELECT] == "MR_BRF")
    && ([GetValue $arrayname BRF_SEARCH_OPTION] == "AROUND") } { 
    if { ($array(AROUND_ALPHA) == "") || ($array(AROUND_BETA) == "")
      || ($array(AROUND_GAMMA) == "") || 
         ($array(AROUND_EULER_RANGE) == "") } {
         WarningMessage "The rotation function search parameters
(euler angles and range) 
have not been (fully) defined"
         return 0
    }
   }

# Set up the array of input files: 1 or more mtz and maybe some pdb files
  set array(INPUT_FILES) "HKLIN_MAIN"
  for { set i 1 } { $i <= $array(N_ENSEMBLE) } { incr i } {
   if { [ regexp MTZ [GetValue $arrayname ENSEMBLE_OPTION,$i ] ] } {
    append array(INPUT_FILES) " HKLIN,$i"
   }
   if { [ regexp PDB [GetValue $arrayname ENSEMBLE_OPTION,$i ] ] } {
   for { set j 1 } { $j <= $array(N_PDB,$i) } { incr j } {
    append array(INPUT_FILES) " XYZIN,[subst $i]_$j"
    }
  }
  }
#  puts "$array(INPUT_FILES)"

# The output file array is set up in phaser_MR.script
  set array(OUTPUT_FILES) ""

# All output files with the user specified root will be saved to the project dir#set array(FILENAME_ROOT) [FileJoin [GetDefaultDirPath] $array(ROOT) ]

if { ($array(MR_ROT_ENSEMBLE_ID) == "")
   && ([GetValue $arrayname MR_MODE] == "ROTATE") } {
    WarningMessage "No ensemble has been selected for the rotation search"
    return 0
    }

for { set q 1 } { $q <= $array(N_SEARCH) } { incr q } {
if { ($array(MR_AUTO_ENSEMBLE_ID,$q) == "")
   && ([GetValue $arrayname MR_MODE] == "AUTO") } {
    WarningMessage "No ensemble has been selected for the 
molecular replacement automatic search"
    return 0
    }
} 

for { set n 1 } { $n <= $array(N_SEARCH) } { incr n } {
if {(([lsearch -exact $array(ENSEMBLE_MENU_LIST) $array(MR_ROT_ENSEMBLE_ID)] < 0) &&  ([GetValue $arrayname MR_MODE] == "ROTATE")) 
 || (([lsearch -exact $array(ENSEMBLE_MENU_LIST) $array(MR_AUTO_ENSEMBLE_ID,$n)] < 0) && ([GetValue $arrayname MR_MODE] == "AUTO")) } {
    WarningMessage "The ensemble specified for the mr search is not in
the list of ensembles.

Please select a valid ensemble before running the job."
    return 0
  }
}

# Check for compulsory brute force translation function AROUND search parameters
  if { ([GetValue $arrayname MR_MODE] == "TRANSLATE") 
    && ([GetValue $arrayname MR_MODE_SELECT] == "MR_BTF")
    && ([GetValue $arrayname BTF_SEARCH_OPTION] == "AROUND") } { 
    if { ($array(START_X) == "") || ($array(START_Y) == "")
      || ($array(START_Z) == "") 
      || ($array(AROUND_COORD_RANGE) == "") } {
         WarningMessage "The brute force translation function search parameters
(coordinates and range) have not been (fully) defined" 
         return 0
    }
   }

# Check for compulsory brute force translation function REGION search parameters
  if { ([GetValue $arrayname MR_MODE] == "TRANSLATE") 
    && ([GetValue $arrayname MR_MODE_SELECT] == "MR_BTF")
    && ([GetValue $arrayname BTF_SEARCH_OPTION] == "REGION") } { 
    if { ($array(START_X) == "") || ($array(START_Y) == "")
      || ($array(START_Z) == "") || ($array(END_X) == "")
      || ($array(END_Y) == "") || ($array(END_Z) == "") } {
         WarningMessage "The brute force translation function search parameters
(coordinates) have not been (fully) defined"
         return 0
    }
   }

# Check for compulsory brute force translation function LINE search parameters
  if { ([GetValue $arrayname MR_MODE] == "TRANSLATE") 
    && ([GetValue $arrayname MR_MODE_SELECT] == "MR_BTF")
    && ([GetValue $arrayname BTF_SEARCH_OPTION] == "LINE") } { 
    if { ($array(START_X) == "") || ($array(START_Y) == "")
      || ($array(START_Z) == "") || ($array(END_X) == "")
      || ($array(END_Y) == "") || ($array(END_Z) == "") } {
         WarningMessage "The brute force translation function search parameters
(coordinates) have not been (fully) defined"
         return 0
    }
   }

  if { ( [GetValue $arrayname MR_MODE] == "TRANSLATE" ) && \
           ( $array(TRA_RLIST_FILE) == "" ) } {
      WarningMessage "The rlist file is not set for the translation search"
      return 0
  }

  if { (( [GetValue $arrayname MR_MODE] == "REFINE" ) 
     || ( [GetValue $arrayname MR_MODE] == "RESCORE" ) ) 
     && ( $array(SET_SOL_FILE) == "" ) } {
      WarningMessage "The solution .sol file is not set"
      return 0
   }

## ([GetValue $arrayname CLMN_OUTER] < "5")
  if {     ($array(TOG_CLMN) 
      &&  !($array(CLMN_OUTER) >= 5) )
      && ( ([GetValue $arrayname MR_MODE] == "ROTATE") 
      ||   ([GetValue $arrayname MR_MODE] == "AUTO"  )  )   } {
        WarningMessage "CLMN outer radius of $array(CLMN_OUTER) is set too small
        (Additional Parameters folder)

 Minimum acceptable value is 5.0 A"
      return 0
  }

# If a test space group other than mtz file one has been selected, then extract its space group number.
  if { ![StringSame $array(FILE_SPACEGROUP) \
              [GetValue $arrayname TEST_SPACEGROUP] ] } {
    set array(SPACEGROUP_NUMBER) [GetSpaceGroupNumber $array(TEST_SPACEGROUP)]
} else {
    set array(SPACEGROUP_NUMBER) ""
  }

  return 1
  }

#------------------------------------------------------------------------
 proc phaser_MR_sg { arrayname counter_sg } {
#------------------------------------------------------------------------
  upvar #0 $arrayname array
  CreateLine line \
      label "Test space group #$counter_sg" \
      message "Select a test SG (same point group)\
               or ALL to test all.\
               NB mtz SG will NOT now be tested by default."\
      widget PHASER_TEST_SG 
}

#------------------------------------------------------------------------
 proc phaser_MR_save_update { arrayname } {
#------------------------------------------------------------------------
# Refers to the SAVE keyword and the various options possible

  upvar #0 $arrayname array

  if {
     [GetValue $arrayname SAVE_OPTION] == "SIGMA" && \
     [GetValue $arrayname SAVE_CLUSTER_OPTION] == "ON" } {
     set array(SAVE_CLUSTER_COMB) "SIGMA_ON"
     } elseif {
     [GetValue $arrayname SAVE_OPTION] == "SIGMA" && \
     [GetValue $arrayname SAVE_CLUSTER_OPTION] == "OFF" } {
     set array(SAVE_CLUSTER_COMB) "SIGMA_OFF"
     } elseif {
     [GetValue $arrayname SAVE_OPTION] == "NPEAKS" && \
     [GetValue $arrayname SAVE_CLUSTER_OPTION] == "ON" } {
     set array(SAVE_CLUSTER_COMB) "NPEAKS_ON"
     } elseif {
     [GetValue $arrayname SAVE_OPTION] == "NPEAKS" && \
     [GetValue $arrayname SAVE_CLUSTER_OPTION] == "OFF" } {
     set array(SAVE_CLUSTER_COMB) "NPEAKS_OFF"
     } elseif {
     [GetValue $arrayname SAVE_OPTION] == "PERCENT" && \
     [GetValue $arrayname SAVE_CLUSTER_OPTION] == "ON" } {
     set array(SAVE_CLUSTER_COMB) "PERCENT_ON"
     } elseif {
     [GetValue $arrayname SAVE_OPTION] == "PERCENT" && \
     [GetValue $arrayname SAVE_CLUSTER_OPTION] == "OFF" } {
     set array(SAVE_CLUSTER_COMB) "PERCENT_OFF"
     } elseif {
     [GetValue $arrayname SAVE_OPTION] == "ALL" && \
     [GetValue $arrayname SAVE_CLUSTER_OPTION] == "ON" } {
     set array(SAVE_CLUSTER_COMB) "ALL_ON"
     } elseif {
     [GetValue $arrayname SAVE_OPTION] == "ALL" && \
     [GetValue $arrayname SAVE_CLUSTER_OPTION] == "OFF" } {
     set array(SAVE_CLUSTER_COMB) "ALL_OFF"
     }
  }

#------------------------------------------------------------------------
 proc phaser_MR_mode_update { arrayname } {
#------------------------------------------------------------------------
# Update the internal parameter MR_MODE_SELECT
# This very important parameter sets the mode that phaser will run in
  upvar #0 $arrayname array

  if { [GetValue $arrayname MR_MODE] == "AUTO" } {
     set array(MR_MODE_SELECT) "MR_AUTO"
     } elseif {
       [GetValue $arrayname MR_MODE] == "ROTATE" && \
       [GetValue $arrayname MR_MODE_ROT] == "MR_FRF" } {
     set array(MR_MODE_SELECT) "MR_FRF"
     } elseif {
       [GetValue $arrayname MR_MODE] == "ROTATE" && \
       [GetValue $arrayname MR_MODE_ROT] == "MR_BRF" } {
     set array(MR_MODE_SELECT) "MR_BRF"
     } elseif {
       [GetValue $arrayname MR_MODE] == "TRANSLATE" && \
       [GetValue $arrayname MR_MODE_TRAN] == "MR_FTF" } {
      set array(MR_MODE_SELECT) "MR_FTF"
     } elseif {
       [GetValue $arrayname MR_MODE] == "TRANSLATE" && \
       [GetValue $arrayname MR_MODE_TRAN] == "MR_BTF" } {
      set array(MR_MODE_SELECT) "MR_BTF"
     } elseif {
       [GetValue $arrayname MR_MODE] == "REFINE" } {
      set array(MR_MODE_SELECT) "MR_RNP"
     } elseif {
       [GetValue $arrayname MR_MODE] == "RESCORE" } {
      set array(MR_MODE_SELECT) "MR_LLG"
     } elseif {
       [GetValue $arrayname MR_MODE] == "PACK" } {
      set array(MR_MODE_SELECT) "MR_PAK"
     } elseif {
       [GetValue $arrayname MR_MODE] == "ANISOTROPY" } {
      set array(MR_MODE_SELECT) "MR_ANO"
     } elseif {
       [GetValue $arrayname MR_MODE] == "CONTENT" } {
      set array(MR_MODE_SELECT) "MR_CCA"
     }

   phaser_MR_rescore_parameter $arrayname
   phaser_MR_save_update $arrayname

  }       

#------------------------------------------------------------------------
 proc phaser_MR_rescore_parameter { arrayname } {
#------------------------------------------------------------------------
# Update the internal parameter RESCORE_PARAMETER 
# This parameter keeps track of the mode of phaser selected by the user
#  to decide whether the RESCORE keyword is needed in the gui.
#  (Rescoring is only used in MR_FRF and MR_FTF and therefore AUTO)
#  It also monitors whether rescoring is ON/OFF in MR_FRF and MR_FTF.

  upvar #0 $arrayname array

  if { [GetValue $arrayname MR_MODE_SELECT] == "MR_FRF" && \
       [GetValue $arrayname RESCORE_ONOFF] == "ON" } {
     set array(RESCORE_PARAMETER) "ON"
     set array(RESCORE_PARAMETER_ROT) "OFF"
     set array(RESCORE_PARAMETER_TRA) "OFF"
     } elseif {
       [GetValue $arrayname MR_MODE_SELECT] == "MR_FRF" && \
       [GetValue $arrayname RESCORE_ONOFF] == "OFF" } {
     set array(RESCORE_PARAMETER) "OFF"
     set array(RESCORE_PARAMETER_ROT) "OFF"
     set array(RESCORE_PARAMETER_TRA) "OFF"
     } elseif {
       [GetValue $arrayname MR_MODE_SELECT] == "MR_FTF" && \
       [GetValue $arrayname RESCORE_ONOFF] == "ON" } {
     set array(RESCORE_PARAMETER) "ON"
     set array(RESCORE_PARAMETER_ROT) "OFF"
     set array(RESCORE_PARAMETER_TRA) "OFF"
     } elseif {
       [GetValue $arrayname MR_MODE_SELECT] == "MR_FTF" && \
       [GetValue $arrayname RESCORE_ONOFF] == "OFF" } {
     set array(RESCORE_PARAMETER) "OFF"
     set array(RESCORE_PARAMETER_ROT) "OFF"
     set array(RESCORE_PARAMETER_TRA) "OFF"
     } elseif {
       [GetValue $arrayname MR_MODE] == "AUTO" && \
       [GetValue $arrayname RESCORE_ONOFF_ROT] == "ON" && \
       [GetValue $arrayname RESCORE_ONOFF_TRA] == "ON" } {
     set array(RESCORE_PARAMETER) "OFF"
     set array(RESCORE_PARAMETER_ROT) "ON"
     set array(RESCORE_PARAMETER_TRA) "ON"
     } elseif {
       [GetValue $arrayname MR_MODE] == "AUTO" && \
       [GetValue $arrayname RESCORE_ONOFF_ROT] == "ON" && \
       [GetValue $arrayname RESCORE_ONOFF_TRA] == "OFF" } {
     set array(RESCORE_PARAMETER) "OFF"
     set array(RESCORE_PARAMETER_ROT) "ON"
     set array(RESCORE_PARAMETER_TRA) "OFF"
     } elseif {
       [GetValue $arrayname MR_MODE] == "AUTO" && \
       [GetValue $arrayname RESCORE_ONOFF_ROT] == "OFF" && \
       [GetValue $arrayname RESCORE_ONOFF_TRA] == "ON" } {
     set array(RESCORE_PARAMETER) "OFF"
     set array(RESCORE_PARAMETER_ROT) "OFF"
     set array(RESCORE_PARAMETER_TRA) "ON"
     } elseif {
       [GetValue $arrayname MR_MODE] == "AUTO" && \
       [GetValue $arrayname RESCORE_ONOFF_ROT] == "OFF" && \
       [GetValue $arrayname RESCORE_ONOFF_TRA] == "OFF" } {
     set array(RESCORE_PARAMETER) "OFF"
     set array(RESCORE_PARAMETER_ROT) "OFF"
     set array(RESCORE_PARAMETER_TRA) "OFF"
     } else {
     set array(RESCORE_PARAMETER) "NONE"
     }

  }

#------------------------------------------------------------------------
 proc phaser_MR_composition { arrayname counter_component } {
#------------------------------------------------------------------------
# The contents of the "Composition" folder, extending frame 
  upvar #0 $arrayname array

  CreateLine line \
      message "Select for protein or DNA/RNA as a component of the asymmetric unit" \
      label "Component #$counter_component" \
      widget PROTDNA \
      message "Enter the molecular weight of protein/nucleic acid #$counter_component" \
      label "" \
      widget COMP_OPTION -oblig \
      widget MW -oblig \
      message "Enter the number of copies of component #$counter_component in the asymmetric unit" \
      label "Number in asymmetric unit" \
      widget ASYM -oblig \
     toggle_display COMP_OPTION,$counter_component open MW hide

  CreateLine line \
      message "Select for protein or DNA/RNA as a component of the asymmetric unit" \
      label "Component #$counter_component" \
      widget PROTDNA \
      message "Enter the file containing sequence in single letter code or fasta format" \
      label "" \
      widget COMP_OPTION -oblig \
      message "Enter the number of copies of component #$counter_component in the asymmetric unit" \
      label "Number in asymmetric unit" \
      widget ASYM -oblig \
     toggle_display COMP_OPTION,$counter_component open FASTA hide

  CreateInputFileLine line \
      "Select the sequence file" "SEQ file" COMP_FILE DIR_COMP_FILE \
     -toggle_display COMP_OPTION,$counter_component open FASTA hide

  }

#------------------------------------------------------------------------
 proc phaser_MR_ensemble { arrayname counter_ensemble } {
#------------------------------------------------------------------------
# Sets up the main ensembles definition folder

  upvar #0 $arrayname array

# puts "$array(ENSEMBLE_ID,$counter_ensemble)"

# Set a default name for ENSEMBLE_ID of ensemb1, ensemb2, ensemb3 etc
  if { $array(ENSEMBLE_ID,$counter_ensemble) == "" } {
       set array(ENSEMBLE_ID,$counter_ensemble) "ensemble$counter_ensemble" }

  CreateLine line \
      message "Enter unique identifier for ensemble #$counter_ensemble" \
      label "Ensemble Name" widget ENSEMBLE_ID \
        -command "update_phaser_MR_ensemble $arrayname" \
        -oblig \
      message "Define the ensemble by PDB file(s) or MTZ file" \
      label "Define ensemble via" widget ENSEMBLE_OPTION \
      toggle_display ENSEMBLE_OPTION,$counter_ensemble open MTZ

  CreateLine line \
      message "Enter unique identifier for ensemble #$counter_ensemble" \
      label "Ensemble Name" widget ENSEMBLE_ID \
        -command "update_phaser_MR_ensemble $arrayname" \
        -oblig \
      message "Define the ensemble by PDB file(s) or MTZ file" \
      label "Define ensemble via" widget ENSEMBLE_OPTION \
      toggle_display ENSEMBLE_OPTION,$counter_ensemble open PDB

OpenSubFrame frame \
      -toggle_display ENSEMBLE_OPTION,$counter_ensemble open MTZ

  CreateInputFileLine line \
      "Enter MTZ map file name (HKLIN) for ensemble # $counter_ensemble" \
      "MTZ     " \
      HKLIN DIR_HKLIN

  CreateLabinLine line \
      "Select calculated amplitude (FC) and calculated phase (PHIC)" \
      HKLIN,$counter_ensemble "FC" FC [list FC] \
      -help labin \
      -sigma "PHIC" PHIC [list PHIC]

  CreateLine line \
      message "Enter molecular weight of protein in the object\
            represented by the map (from MTZ file)" \
      label "Protein MW" widget ENSEMBLE_PROTMW -oblig \
      message "Enter molecular weight of nucleic acid in the object\
               represented by the map (from MTZ file)" \
      label "Nucleic acid MW" widget ENSEMBLE_NUCLMW -oblig \
      message "Enter the extent of the model in the X, Y and Z directions" \
      label "Extent: X" widget ENSEMBLE_EXT_X -oblig \
      label "Y" widget ENSEMBLE_EXT_Y -oblig \
      label "Z" widget ENSEMBLE_EXT_Z -oblig label "Angstroms"

  CreateLine line \
      message "Similarity to the target" \
      label "RMS error" widget ENSEMBLE_RMS_MTZ -oblig \
      message "Enter coordinates of the centre of the model, in Angstroms" \
      label "Centre: X" widget ENSEMBLE_CEN_X -oblig \
      label "Y" widget ENSEMBLE_CEN_Y -oblig \
      label "Z" widget ENSEMBLE_CEN_Z -oblig label "Angstroms" 

CloseSubFrame

# Within the Add Ensemble toggle frame, if PDB is selected for ENSEMBLE_OPTION,
#   then insert an extending frame for adding pdb files for each ensemble

OpenSubFrame frame \
   -toggle_display ENSEMBLE_OPTION,$counter_ensemble open PDB 

  CreateExtendingFrame N_PDB phaser_MR_pdb \
      "Add another PDB file to the ensemble" \
      "Add superimposed PDB file to the ensemble" \
      [list XYZIN DIR_XYZIN RMS_OPTION RMS ] \
       -counter $counter_ensemble

CloseSubFrame

# Check and update the ensemble variable menu
  edit_phaser_MR_ensemble $arrayname $counter_ensemble

  }

#------------------------------------------------------------------------
 proc phaser_MR_search { arrayname counter_search } {
#------------------------------------------------------------------------
# The auto search toggle frame code for adding extra search ensembles
  upvar #0 $arrayname array

  CreateLine line \
      message "Choose an ensemble to be used for this\
               molecular replacement search" \
      label "Perform mr auto search using " \
      widget MR_AUTO_ENSEMBLE_ID \
      message "The number of copies of the ensemble to look for" \
      label "  Number of copies to search for" \
      widget MR_AUTO_ENSEMBLE_NUM

  CreateExtendingFrame N_AUTO_EXTRA phaser_MR_AUTO_extra \
      "Add an alternative ensemble to use in the search" \
      "Add alternative ensemble to test" \
      [list MR_AUTO_ENSEMBLE_ID_EXTRA] \
      -counter $counter_search 

  }

#------------------------------------------------------------------------
 proc phaser_MR_AUTO_extra { arrayname counter_AUTO_extra counter_search } {
#------------------------------------------------------------------------
# The auto search extending frame code for adding extra ensembles to a search 
  upvar #0 $arrayname array
  CreateLine line \
     message "Warning: list the most likely ensemble first\
              (or set PERMUTE ON via the Additional Parameters folder)"\
      label "                           or ensemble" \
      widget MR_AUTO_ENSEMBLE_ID_EXTRA
  }

#------------------------------------------------------------------------
 proc phaser_MR_frf_extra { arrayname counter } {
#------------------------------------------------------------------------
# An extending frame for adding extra ensembles to a FRF search
  upvar #0 $arrayname array
  CreateLine line \
      message "Select an alternative ensemble to use in this search" \
      label "                                              or ensemble" \
      widget MR_FRF_ENSEMBLE_ID_EXTRA
  }

#------------------------------------------------------------------------
 proc phaser_MR_brf_extra { arrayname counter } {
#------------------------------------------------------------------------
# An extending frame for adding extra ensembles to a FRF search
  upvar #0 $arrayname array
  CreateLine line \
      message "Select an alternative ensemble to use in this search" \
      label "                                                                   or ensemble" \
      widget MR_BRF_ENSEMBLE_ID_EXTRA
  }

#------------------------------------------------------------------------
 proc phaser_MR_pdb { arrayname counter_pdb counter_ensemble } {
#------------------------------------------------------------------------
# The ensemble pdb extending frame lines
  upvar #0 $arrayname array

  CreateInputFileLine line \
      "Select a PDB file associated with ensemble #$counter_ensemble " \
      "PDB #$counter_pdb" \
      XYZIN DIR_XYZIN

  CreateLine line \
      message "Specify RMS error explicitly in Angstrom, or implicitly\
               via the sequence identity (percentage or a fraction)" \
      label "Similarity of PDB #$counter_pdb to the target structure" \
      widget RMS_OPTION \
      widget RMS -oblig

  }

#------------------------------------------------------------------------
 proc update_phaser_MR_ensemble { arrayname } {
#------------------------------------------------------------------------

# This is called whenever the user clicks into the widget for an
#   ensemble name 
# It looks like an empty (redundant) procedure but is needed to ensure
#   that $array(N_ENSEMBLE) gets handed correctly to the menu procedure
  upvar #0 $arrayname array
  update_phaser_MR_ensemble_menu $arrayname $array(N_ENSEMBLE)
  }

#------------------------------------------------------------------------
 proc update_phaser_MR_ensemble_menu { arrayname n_ensemble } {
#------------------------------------------------------------------------
# Updates the variable menu of ensembles
  upvar #0 $arrayname array
# Build up list for menu
  set menu {}
  for { set n 1 } { $n <= $n_ensemble } { incr n } { lappend menu $array(ENSEMBLE_ID,$n) }
# Do the update
  UpdateVariableMenu $arrayname initialise 0 ENSEMBLE_MENU_LIST $menu 
  }

#------------------------------------------------------------------------
 proc edit_phaser_MR_ensemble { arrayname counter_ensemble } {
#------------------------------------------------------------------------

# When an ensemble is removed or added, need to update the variable menu
#   for ensemble selection.
# counter_ensemble is passed from the calling procedure. It is the 
#   number of ensembles (= number of frames)
  upvar #0 $arrayname array
  set usermenu {}
  set alias {}
# Create the ensemble menu list and its alias
  for { set n 1 } { $n <= $counter_ensemble } { incr n } { lappend usermenu "$n:  $array(ENSEMBLE_ID,$n)" }
  for { set n 1 } { $n <= $counter_ensemble } { incr n } { lappend alias "$array(ENSEMBLE_ID,$n)" }

# Update ENSEMBLE_ID if an ensemble is deleted and its ENSEMBLE_ID
#   is still set to the default ensemb$counter_ensemble
#   (which will now be out by one (one too high))
# regexp as below on "ensemb1" produces j1_whole=ensemb1
#                                       j2_root=ensemb
#                                       j3_num=1

  if { $counter_ensemble > 0 } {
     for { set p 1 } { $p <= $array(N_ENSEMBLE) } { incr p } {
         if { [regexp "^(ensemb)(\[0-9\])$" $array(ENSEMBLE_ID,$p) \
                        j1_whole j2_root j3_num] } {
            # If the trailing number (j3_num) is different from 
            #   the current molecule number (p) then reset the id
            if { $j3_num != $p } { set array(ENSEMBLE_ID,$p) "ensemb$p" }
         }
     }
  }

# Update the variable menu with the list of ensemble names
  update_phaser_MR_ensemble_menu $arrayname $counter_ensemble

  }

#------------------------------------------------------------------------
 proc update_ensemble_menu { arrayname n_ensemble } {
#------------------------------------------------------------------------
# Updates the variable menu of ensembles
  upvar #0 $arrayname array
# Build list for menu
  set menu {}
  for { set n 1} {$n <= $n_ensemble } { incr n } { lappend menu $array(ENSEMBLE_ID,$n) }
  UpdateVariableMenu $arrayname initialise 0 ENSEMBLE_MENU_LIST $menu
  }


#------------------------------------------------------------------------
 proc phaser_MR_set_test_space_group { arrayname } {
#------------------------------------------------------------------------
# To set up the choice of test space groups possible (those in the same
#   point group) given the space group from the mtz file
  upvar #0 $arrayname array
  set spgp_list {}
  set spgp_alias {}
  set laue_no [GetLaueGroupNumber $array(FILE_SPACEGROUP)]
# laue_no is zero if FILE_SPACEGROUP is not in the standard list
# update the list of spacegroups varlabel
  phaser_MR_updatevarlabel $arrayname FILE_SPACEGROUP
  if { $laue_no <= 0 } {
    lappend spgp_list $array(FILE_SPACEGROUP)
    lappend spgp_alias [GetSpaceGroupNumber $array(FILE_SPACEGROUP)]
  } else {
    set spgp_alias [GetLaueGroup $laue_no]
    foreach gp_no $spgp_alias {
      lappend spgp_list [GetSpaceGroupCode $gp_no]
    }
  }
# GetLaueGroup returns a list of space groups for the given Laue Group

  UpdateVariableMenu $arrayname initialise [llength $array(LAUE_SPGP_LIST)] \
        LAUE_SPGP_LIST $spgp_list \
        MODEL_ALIAS_LIST $spgp_alias

  set array(PHASER_TEST_SG) [GetSpaceGroupCode $array(FILE_SPACEGROUP)]

}

#------------------------------------------------------------------------
 proc phaser_MR_updatevarlabel { arrayname FILE_SPACEGROUP } {
#------------------------------------------------------------------------
# procedure to update the FILE_SPACEGROUP varlabel
  upvar #0 $arrayname array
  set field_list [GetWidget $arrayname FILE_SPACEGROUP]
  foreach field $field_list {
    if { [winfo exists $field] } {
      $field configure -text $array(FILE_SPACEGROUP) }
    }
  }

#------------------------------------------------------------------------
  proc phaser_MR_tog_activate {arrayname} {
#------------------------------------------------------------------------
  upvar #0 $arrayname array
  if { [StringSame $array(MR_MODE_SELECT) MR_FRF] } { 
    set array(TOG_FRF_TARGET) "1"
  } elseif { [StringSame $array(MR_MODE_SELECT) MR_FTF] } {
    set array(TOG_FTF_TARGET) "1"
  } else {
    set array(TOG_LIKELIHOOD_TARGET) "1"
  }

  }

#------------------------------------------------------------------------
  proc phaser_MR_set_reso {arrayname} {
#------------------------------------------------------------------------
  upvar #0 $arrayname array
  if { ( $array(RESOLUTION_DMIN) >= 2.5 ) } {
     set array(RESOLUTION_DMIN_MR) [GetValue $arrayname RESOLUTION_DMIN]
     } else {
     set array(RESOLUTION_DMIN_MR) 2.5
     }
}

#------------------------------------------------------------------------
  proc phaser_MR_task_window {arrayname} {
#------------------------------------------------------------------------

  upvar #0 $arrayname array
  global configure

  if { [CreateTaskWindow $arrayname \
        "Maximum Likelihood Molecular Replacement"\
        "Phaser" \
        [ list "Define data (anistropy correction)" \
               "Define data (cell content analysis)" \
               "Define data" \
               "Composition of the asymmetric unit" \
               "Define ensembles (each comprising possible model(s)\
                  for a protein/nucleic acid component)" \
               "Fast rotation function search" \
               "Brute force rotation function search" \
               "Fast translation function search" \
               "Brute force translation function search" \
               "Solution refinement" \
               "Solution rescoring" \
               "Solution packing" \
               "Auto search (fast rotation function,\
                  fast translation function and packing)" \
               "Define search SETs (any already known rotations/translations)" \
               "Additional parameters (ensure a parameter's\
                  toggle button is on to activate changes made)" ] \
       ] == 0 } return

# SetProgramHelpFile phaser


#=PROTOCOL===============================================================

  OpenFolder protocol

  CreateTitleLine line TITLE

# Sets up the central menus for choosing the mode of phaser
#   whether rotation, translation or refinement/rescoring searches

  CreateLine line \
      label "Mode for molecular replacement" \
      message "The central menu: select the molecular replacement\
               mode for phaser to run" \
      widget MR_MODE \
        -command "phaser_MR_mode_update $arrayname" \
      toggle_display MR_MODE open [list ANISOTROPY REFINE RESCORE PACK AUTO CONTENT ]

  CreateLine line \
      label "Mode for molecular replacement" \
      message "The central menu: select the molecular replacement\
               mode for phaser to run" \
      widget MR_MODE \
        -command "phaser_MR_mode_update $arrayname" \
      message "RF: rotation function;\
               ML: maximum likelihood" \
      label "using" \
      widget MR_MODE_ROT \
        -command "phaser_MR_mode_update $arrayname" \
      toggle_display MR_MODE open ROTATE

  CreateLine line \
      label "Mode for molecular replacement" \
      message "The central menu: select the molecular replacement\
               mode for phaser to run" \
      widget MR_MODE \
        -command "phaser_MR_mode_update $arrayname" \
      message "TF: translation function;\
               ML: maximum likelihood" \
      label "using" \
      widget MR_MODE_TRAN \
        -command "phaser_MR_mode_update $arrayname" \
      toggle_display MR_MODE open TRANSLATE


#=FILE===================================================================

# OpenFolder file

#========================================================================
# The "Define data (anistropy correction)" folder

  OpenFolder 1 MR_MODE open ANISOTROPY hide

  CreateInputFileLine line \
      "Enter MTZ file name (HKLIN)" \
      "MTZ in     " \
      HKLIN_MAIN DIR_HKLIN_MAIN \
        -setfileparam resolution_min RESOLUTION_DMAX \
        -setfileparam resolution_max RESOLUTION_DMIN \
        -setfileparam space_group_name FILE_SPACEGROUP \
        -command "phaser_MR_set_test_space_group $arrayname"

   CreateLabinLine line \
       "Select amplitude (F) and sigma (SIGF)" \
       HKLIN_MAIN "F" F [list F] \
       -help labi \
       -sigma "SigmaF" SIGF {}


#========================================================================
# The "Define data (cell content analysis)" folder

  OpenFolder 2 MR_MODE open [list CONTENT ] hide

  CreateInputFileLine line \
      "Enter MTZ file name (HKLIN)" \
      "MTZ in     " \
      HKLIN_MAIN DIR_HKLIN_MAIN \
        -setfileparam resolution_min RESOLUTION_DMAX \
        -setfileparam resolution_max RESOLUTION_DMIN \
        -setfileparam space_group_name FILE_SPACEGROUP \
        -command "phaser_MR_set_reso $arrayname"

# $line.l2 configure -width 7 -background $configure(COLOUR_BACKGROUND)

   CreateLabinLine line \
       "Select amplitude (F) and sigma (SIGF)" \
       HKLIN_MAIN "F" F {NULL} \
       -sigma "SIGF" SIGF {NULL}

  CreateLine line \
      message "Default is to take all data" \
      widget TOG_RESOLUTION -toggleon \
      label "Resolution range" \
      message "Enter dmax, in Angstroms" \
      widget RESOLUTION_DMAX \
      label "A to" \
      widget RESOLUTION_DMIN \
      label "A" \
      toggle_display MR_MODE hide PACK


#========================================================================
# The "Define data" folder

  OpenFolder 3 MR_MODE hide [list ANISOTROPY CONTENT ] open

  CreateInputFileLine line \
      "Enter MTZ file name (HKLIN)" \
      "MTZ in     " \
      HKLIN_MAIN DIR_HKLIN_MAIN \
        -setfileparam resolution_min RESOLUTION_DMAX \
        -setfileparam resolution_max RESOLUTION_DMIN \
        -setfileparam space_group_name FILE_SPACEGROUP \
        -command "phaser_MR_set_test_space_group $arrayname" \
        -command "phaser_MR_set_reso $arrayname"

# $line.l2 configure -width 7 -background $configure(COLOUR_BACKGROUND)

   CreateLabinLine line \
       "Select amplitude (F) and sigma (SIGF)" \
       HKLIN_MAIN "F" F {NULL} \
       -sigma "SIGF" SIGF {NULL}

  CreateLine line \
      message "Default is to take all data from low resolution limit\
               to the greater of dmin and 2.5 A" \
      widget TOG_RESOLUTION -toggleon \
      label "Resolution range" \
      message "Enter dmax, in Angstroms" \
      widget RESOLUTION_DMAX \
      label "A to" \
      message "If the dataset goes to higher than 2.5 A resolution,\
               then a default dmin of 2.5 A is set." \
      widget RESOLUTION_DMIN_MR \
      label "A" \
      toggle_display MR_MODE hide PACK

OpenSubFrame frame

  CreateLine line \
      message "Space group read from mtz file.\
               By default, phaser is run with this space group" \
      label "Space group read from mtz file" \
      varlabel FILE_SPACEGROUP \
      message "Run Phaser with a different space group" \
      label "; run Phaser with space group" \
      widget TEST_SPACEGROUP \
      toggle_display MR_MODE open [list ROTATE REFINE RESCORE PACK]

  CreateLine line \
      message "Space group read from mtz file." \
      label "Space group read from mtz file" \
      varlabel FILE_SPACEGROUP \
      toggle_display MR_MODE hide [list ROTATE REFINE RESCORE PACK]

  CreateLine line \
      message "Specify the space group(s) to run Phaser with" \
      label "Run Phaser with" \
      widget SPACEGROUP_OPTION \
      toggle_display MR_MODE open [list AUTO TRANSLATE]

CloseSubFrame

OpenSubFrame frame \
   -toggle_display SPACEGROUP_OPTION open SG_ALT

  CreateExtendingFrame N_SG phaser_MR_sg \
       "Add another test space group" \
       "Add another space group" \
       [list PHASER_TEST_SG ] \
   toggle_display MR_MODE open [list AUTO TRANSLATE]

CloseSubFrame

  CreateLine line \
      message "Default number of top pdbfiles or mtzfiles is 1" \
      label "Number of top solutions to output as PDB and MTZ files"\
      widget TOPFILES \
      label "NB: MTZ files not output for all modes"

# $line.l2 configure -width 7 -background $configure(COLOUR_BACKGROUND)


#========================================================================
# The "Composition of the asymmetric unit" folder

  OpenFolder 4 MR_MODE hide [list PACK] open

  CreateExtendingFrame N_COMPONENT phaser_MR_composition \
      "Define another protein or nucleic acid component" "Define another component" \
      [list PROTDNA  MW  ASYM COMP_OPTION COMP_FILE DIR_COMP_FILE ]


#========================================================================
# The "Define ensembles" folder

  OpenFolder 5 MR_MODE hide [list ANISOTROPY CONTENT ] open

  CreateToggleFrame N_ENSEMBLE phaser_MR_ensemble \
      "Define another ensemble" \
      "Ensemble #" \
      "Add ensemble" \
      [list ENSEMBLE_ID ENSEMBLE_OPTION HKLIN DIR_HKLIN LABIN FC PHIC N_PDB ] \
       -edit_proc edit_phaser_MR_ensemble \
       -child phaser_MR_pdb

#========================================================================
# The "Fast rotation function search" folder

  OpenFolder 6 MR_MODE_SELECT open MR_FRF hide

  CreateLine line \
      message "Choose an ensemble to be used for the rotation search" \
      label "Perform mr rotation search using ensemble" \
      widget MR_ROT_ENSEMBLE_ID

  CreateExtendingFrame N_FRF_EXTRA phaser_MR_frf_extra \
      "Add an alternative ensemble to be searched for" \
      "Add an alternative search ensemble" \
      [list MR_FRF_ENSEMBLE_ID_EXTRA]

  CreateLine line \
      message "FINAL: the final selection criterion for peaks" \
      widget TOG_FINAL -toggleon \
      label "Final selection criterion for peaks" \
      message "Select the criterion to be used at the final selection of peaks \
               Default is PERCENT 75" \
      widget FINAL_OPTION \
      message "Enter the sigma value to use in the final selection process" \
      widget FINAL_SIGMA \
      toggle_display FINAL_OPTION open SIGMA 

  CreateLine line \
      message "FINAL: the final selection criterion for peaks" \
      widget TOG_FINAL -toggleon \
      label "Final selection criterion for peaks" \
      message "Select the criterion to be used at the final selection of peaks \
               Default is PERCENT 75" \
      widget FINAL_OPTION \
      message "Enter the number of peaks to use in the final selection process" \
      widget FINAL_NPEAKS \
      toggle_display FINAL_OPTION open NPEAKS 

  CreateLine line \
      message "FINAL: the final selection criterion for peaks" \
      widget TOG_FINAL -toggleon \
      label "Final selection criterion for peaks" \
      message "Select the criterion to be used at the final selection of peaks \
               Default is PERCENT 75" \
      widget FINAL_OPTION \
      message "Enter the percent value of the top peak to use for\
               the final selection process" \
      message "Enter the percentage value of the top peak to use in the\
               final selection process" \
      widget FINAL_PERCENT \
      toggle_display FINAL_OPTION open PERCENT 

  CreateLine line \
      message "FINAL: the final selection criterion for peaks" \
      widget TOG_FINAL -toggleon \
      label "Final selection criterion for peaks" \
      message "Select the criterion to be used at the final selection of peaks \
               Default is PERCENT 75" \
      widget FINAL_OPTION \
      toggle_display FINAL_OPTION open ALL 


#========================================================================
# The "Brute force rotation function search" folder

  OpenFolder 7 MR_MODE_SELECT open MR_BRF hide

  CreateLine line \
      message "Select to perform a full or restricted search" \
      label "Perform" \
      widget BRF_SEARCH_OPTION \
      message "Choose the ensemble to be used for molecular replacement" \
      label "mr rotation search using ensemble" \
      widget MR_ROT_ENSEMBLE_ID

  CreateExtendingFrame N_BRF_EXTRA phaser_MR_brf_extra \
      "Add an alternative ensemble to be searched for" \
      "Add an alternative search ensemble" \
      [list MR_BRF_ENSEMBLE_ID_EXTRA]

  CreateLine line \
      message "Restrict the search to region around this set of Euler angles" \
      label "Euler angles for search: alpha" \
      widget AROUND_ALPHA -oblig \
      label "beta" \
      widget AROUND_BETA -oblig \
      label "gamma" \
      widget AROUND_GAMMA -oblig \
      message "Rotational distance around the given Euler angle set" \
      label "with search range" \
      widget AROUND_EULER_RANGE -oblig \
      toggle_display BRF_SEARCH_OPTION open AROUND 

  CreateLine line \
      message "FINAL: the final selection criterion for peaks" \
      widget TOG_FINAL -toggleon \
      label "Final selection criterion for peaks" \
      message "Select the criterion to be used at the final selection of peaks \
               Default is PERCENT 75" \
      widget FINAL_OPTION \
      message "Enter the sigma value to use in the final selection process" \
      widget FINAL_SIGMA \
      toggle_display FINAL_OPTION open SIGMA 

  CreateLine line \
      message "FINAL: the final selection criterion for peaks" \
      widget TOG_FINAL -toggleon \
      label "Final selection criterion for peaks" \
      message "Select the criterion to be used at the final selection of peaks \
               Default is PERCENT 75" \
      widget FINAL_OPTION \
      message "Enter the number of peaks to use in the final selection process" \
      widget FINAL_NPEAKS \
      toggle_display FINAL_OPTION open NPEAKS 

  CreateLine line \
      message "FINAL: the final selection criterion for peaks" \
      widget TOG_FINAL -toggleon \
      label "Final selection criterion for peaks" \
      message "Select the criterion to be used at the final selection of peaks \
               Default is PERCENT 75" \
      widget FINAL_OPTION \
      message "Enter the percent value of the top peak to use for\
               the final selection process" \
      message "Enter the percentage value of the top peak to use in the\
               final selection process" \
      widget FINAL_PERCENT \
      toggle_display FINAL_OPTION open PERCENT 

  CreateLine line \
      message "FINAL: the final selection criterion for peaks" \
      widget TOG_FINAL -toggleon \
      label "Final selection criterion for peaks" \
      message "Select the criterion to be used at the final selection of peaks \
               Default is PERCENT 75" \
      widget FINAL_OPTION \
      toggle_display FINAL_OPTION open ALL 

#========================================================================
# The "Fast translation function search" folder

  OpenFolder 8 MR_MODE_SELECT open MR_FTF hide

  CreateLine line \
      message "A .rlist file is a Phaser rotation search results file" \
      label "Define orientations for translation search\
             and any known rotations/translations (SETs) from a .rlist file"

  CreateInputFileLine line \
      "A .rlist file is a Phaser rotation search results file" \
      ".rlist file" \
      TRA_RLIST_FILE DIR_TRA_RLIST_FILE

  CreateLine line \
      message "FINAL: the final selection criterion for peaks" \
      widget TOG_FINAL -toggleon \
      label "Final selection criterion for peaks" \
      message "Select the criterion to be used at the final selection of peaks \
               Default is PERCENT 75" \
      widget FINAL_OPTION \
      message "Enter the sigma value to use in the final selection process" \
      widget FINAL_SIGMA \
      toggle_display FINAL_OPTION open SIGMA 

  CreateLine line \
      message "FINAL: the final selection criterion for peaks" \
      widget TOG_FINAL -toggleon \
      label "Final selection criterion for peaks" \
      message "Select the criterion to be used at the final selection of peaks \
               Default is PERCENT 75" \
      widget FINAL_OPTION \
      message "Enter the number of peaks to use in the final selection process" \
      widget FINAL_NPEAKS \
      toggle_display FINAL_OPTION open NPEAKS 

  CreateLine line \
      message "FINAL: the final selection criterion for peaks" \
      widget TOG_FINAL -toggleon \
      label "Final selection criterion for peaks" \
      message "Select the criterion to be used at the final selection of peaks \
               Default is PERCENT 75" \
      widget FINAL_OPTION \
      message "Enter the percent value of the top peak to use for\
               the final selection process" \
      message "Enter the percentage value of the top peak to use in the\
               final selection process" \
      widget FINAL_PERCENT \
      toggle_display FINAL_OPTION open PERCENT 

  CreateLine line \
      message "FINAL: the final selection criterion for peaks" \
      widget TOG_FINAL -toggleon \
      label "Final selection criterion for peaks" \
      message "Select the criterion to be used at the final selection of peaks \
               Default is PERCENT 75" \
      widget FINAL_OPTION \
      toggle_display FINAL_OPTION open ALL 

#========================================================================
# The "Brute force translation function search" folder

  OpenFolder 9 MR_MODE_SELECT open MR_BTF hide

  CreateLine line \
      message "Select search type: full, around a point,\
              within a region, along a line or within a plane" \
      label "Perform" \
      widget BTF_SEARCH_OPTION \
#     message "Choose the ensemble to be used for molecular replacement" \
      label "mr translation search"

  CreateLine line \
      message "Select the coordinate system" \
      label "Search around" \
      widget COORD_SYS \
      message "Enter the search coordinates" \
      label "coordinates X" \
      widget START_X -oblig \
      label "Y" \
      widget START_Y -oblig \
      label "Z" \
      widget START_Z -oblig \
      message "Enter in Angstroms the range around XYZ to search" \
      label "with search range" \
      widget AROUND_COORD_RANGE -oblig \
      toggle_display BTF_SEARCH_OPTION open AROUND

  CreateLine line \
      message "Select the coordinate system the region is defined in" \
      label "Region:" \
      widget COORD_SYS \
      message "Enter the start coordinates X,Y,Z for the region" \
      label "coords X" \
      widget START_X -oblig \
      label "Y" \
      widget START_Y -oblig \
      label "Z" \
      widget START_Z -oblig \
      message "Enter the end coordinates X,Y,Z for the region" \
      label "and X" \
      widget END_X -oblig \
      label "Y" \
      widget END_Y -oblig \
      label "Z" \
      widget END_Z -oblig \
      toggle_display BTF_SEARCH_OPTION open REGION

  CreateLine line \
      message "Select the coordinate system the line is defined in" \
      label "Line:" \
      widget COORD_SYS \
      message "Enter the start coordinates X,Y,Z for the line definition" \
      label "coords X" \
      widget START_X -oblig \
      label "Y" \
      widget START_Y -oblig \
      label "Z" \
      widget START_Z -oblig \
      message "Enter the end coordinates X,Y,Z for the line definition" \
      label "to X" \
      widget END_X -oblig \
      label "Y" \
      widget END_Y -oblig \
      label "Z" \
      widget END_Z -oblig \
      toggle_display BTF_SEARCH_OPTION open LINE 

  CreateLine line \
      message "Enter the direction X,Y,Z for the degenerate search"\
      label "Search in the plane perpendicular to the direction of " \
      widget DEGEN_DIR \
      toggle_display BTF_SEARCH_OPTION open DEGENERATE

  CreateLine line \
      message "A .rlist file is a Phaser rotation search results file" \
      label "Define orientations for translation search\
             and any known rotations/translations (SETs) from a .rlist file"

  CreateInputFileLine line \
      "Define rotation angles for the translation search from a .rlist file\
       (Phaser rotation search results file)" \
      ".rlist file" \
      TRA_RLIST_FILE DIR_TRA_RLIST_FILE

  CreateLine line \
      message "FINAL: the final selection criterion for peaks" \
      widget TOG_FINAL -toggleon \
      label "Final selection criterion for peaks" \
      message "Select the criterion to be used at the final selection of peaks \
               Default is PERCENT 75" \
      widget FINAL_OPTION \
      message "Enter the sigma value to use in the final selection process" \
      widget FINAL_SIGMA \
      toggle_display FINAL_OPTION open SIGMA 

  CreateLine line \
      message "FINAL: the final selection criterion for peaks" \
      widget TOG_FINAL -toggleon \
      label "Final selection criterion for peaks" \
      message "Select the criterion to be used at the final selection of peaks \
               Default is PERCENT 75" \
      widget FINAL_OPTION \
      message "Enter the number of peaks to use in the final selection process" \
      widget FINAL_NPEAKS \
      toggle_display FINAL_OPTION open NPEAKS 

  CreateLine line \
      message "FINAL: the final selection criterion for peaks" \
      widget TOG_FINAL -toggleon \
      label "Final selection criterion for peaks" \
      message "Select the criterion to be used at the final selection of peaks \
               Default is PERCENT 75" \
      widget FINAL_OPTION \
      message "Enter the percent value of the top peak to use for\
               the final selection process" \
      message "Enter the percentage value of the top peak to use in the\
               final selection process" \
      widget FINAL_PERCENT \
      toggle_display FINAL_OPTION open PERCENT 

  CreateLine line \
      message "FINAL: the final selection criterion for peaks" \
      widget TOG_FINAL -toggleon \
      label "Final selection criterion for peaks" \
      message "Select the criterion to be used at the final selection of peaks \
               Default is PERCENT 75" \
      widget FINAL_OPTION \
      toggle_display FINAL_OPTION open ALL 

#========================================================================
# The "Solution refinement" protocol folder

  OpenFolder 10 MR_MODE_SELECT open MR_RNP hide

  CreateInputFileLine line \
      "Define any known rotations/translations from a .sol file\
       (Phaser search results file)" \
      ".sol file" \
      SET_SOL_FILE DIR_SET_SOL_FILE


#========================================================================
# The "Solution rescoring" protocol folder

  OpenFolder 11 MR_MODE_SELECT open MR_LLG hide

# CreateLine line \
      message "" \
      label "Rescore target function" \
      widget RESCORE_TARGET_OPTION

  CreateInputFileLine line \
      "Define any known rotations/translations from a .sol file\
       (Phaser search results file)" \
      ".sol file" \
      SET_SOL_FILE DIR_SET_SOL_FILE


#========================================================================
# The "Solution packing" protocol folder

  OpenFolder 12 MR_MODE_SELECT open MR_PAK hide

  CreateLine line \
       message "Default for allowed C-alpha clashes is 0;\
                increase for low-homology models" \
       label "Packing tolerance: number of clashes allowed" \
       widget PACK

#      label "Packing tolerance: number of C-alpha clashes allowed" \

  CreateInputFileLine line \
      "Define any known rotations/translations from a .sol file\
       (Phaser search results file)" \
      ".sol file" \
      SET_SOL_FILE DIR_SET_SOL_FILE


#========================================================================
# The "Auto search" protocol folder

  OpenFolder 13 MR_MODE_SELECT open MR_AUTO hide

  CreateToggleFrame N_SEARCH phaser_MR_search \
      "Perform another mr auto search" \
      "Search #" \
      "Add another search" \
      [list MR_AUTO_ENSEMBLE_ID \
            MR_AUTO_ENSEMBLE_NUM \
            MR_AUTO_ENSEMBLE_ID_EXTRA \
            N_AUTO_EXTRA ] \
      -child phaser_MR_AUTO_extra

  CreateLine line \
       message "Default for allowed C-alpha clashes is 0;\
                increase for low-homology models" \
       widget TOG_PACK -toggleon \
       label "Packing tolerance: number of clashes allowed" \
       widget PACK

#      label "Packing tolerance: number of C-alpha clashes allowed" \

  OpenSubFrame frame -toggle_display MR_MODE open [list AUTO]

  CreateLine line \
      message "FINAL: the final selection criterion for the rotation search peaks" \
      widget TOG_FINAL_ROT -toggleon \
      label "Final selection criterion for ROTATION search peaks" \
      message "Select the criterion to be used at the final selection of peaks\
               for the rotation search. Default is PERCENT 75" \
      widget FINAL_OPTION_ROT \
      message "Enter the sigma value to use in the final selection process\
               for the rotation search" \
      widget FINAL_SIGMA_ROT \
      toggle_display FINAL_OPTION_ROT open SIGMA 

  CreateLine line \
      message "FINAL: the final selection criterion for the rotation search peaks" \
      widget TOG_FINAL_ROT -toggleon \
      label "Final selection criterion for ROTATION search peaks" \
      message "Select the criterion to be used at the final selection of peaks\
               for the rotation search. Default is PERCENT 75" \
      widget FINAL_OPTION_ROT \
      message "Enter the number of peaks to use in the final selection process\
               for the rotation search" \
      widget FINAL_NPEAKS_ROT \
      toggle_display FINAL_OPTION_ROT open NPEAKS 

  CreateLine line \
      message "FINAL: the final selection criterion for the rotation search peaks" \
      widget TOG_FINAL_ROT -toggleon \
      label "Final selection criterion for ROTATION search peaks" \
      message "Select the criterion to be used at the final selection of peaks\
               for the rotation search. Default is PERCENT 75" \
      widget FINAL_OPTION_ROT \
      message "Enter the percentage value of the top peak to use in the\
               final selection process of the rotation search" \
      widget FINAL_PERCENT_ROT \
      toggle_display FINAL_OPTION_ROT open PERCENT 

  CreateLine line \
      message "FINAL: the final selection criterion for the rotation search peaks" \
      widget TOG_FINAL_ROT -toggleon \
      label "Final selection criterion for ROTATION search peaks" \
      message "Select the criterion to be used at the final selection of peaks\
               for the rotation search. Default is PERCENT 75" \
      widget FINAL_OPTION_ROT \
      toggle_display FINAL_OPTION_ROT open ALL 

  CreateLine line \
      message "FINAL: the final selection criterion for the translation search peaks" \
      widget TOG_FINAL_TRA -toggleon \
      label "Final selection criterion for TRANSLATION search peaks" \
      message "Select the criterion to be used at the final selection of peaks\
               for the transl. search. Default is PERCENT 75" \
      widget FINAL_OPTION_TRA \
      message "Enter the sigma value to use in the final selection process\
               for the translation search" \
      widget FINAL_SIGMA_TRA \
      toggle_display FINAL_OPTION_TRA open SIGMA 

  CreateLine line \
      message "FINAL: the final selection criterion for the translation search peaks" \
      widget TOG_FINAL_TRA -toggleon \
      label "Final selection criterion for TRANSLATION search peaks" \
      message "Select the criterion to be used at the final selection of peaks\
               for the transl. search. Default is PERCENT 75" \
      widget FINAL_OPTION_TRA \
      message "Enter the number of peaks to use in the final selection process\
               for the translation search" \
      widget FINAL_NPEAKS_TRA \
      toggle_display FINAL_OPTION_TRA open NPEAKS 

  CreateLine line \
      message "FINAL: the final selection criterion for the translation search peaks" \
      widget TOG_FINAL_TRA -toggleon \
      label "Final selection criterion for TRANSLATION search peaks" \
      message "Select the criterion to be used at the final selection of peaks\
               for the transl. search. Default is PERCENT 75" \
      widget FINAL_OPTION_TRA \
      message "Enter the percentage value of the top peak to use in the\
               final selection process of the translation search" \
      widget FINAL_PERCENT_TRA \
      toggle_display FINAL_OPTION_TRA open PERCENT 

  CreateLine line \
      message "FINAL: the final selection criterion for the translation search peaks" \
      widget TOG_FINAL_TRA -toggleon \
      label "Final selection criterion for TRANSLATION search peaks" \
      message "Select the criterion to be used at the final selection of peaks\
               for the transl. search. Default is PERCENT 75" \
      widget FINAL_OPTION_TRA \
      toggle_display FINAL_OPTION_TRA open ALL 

  CloseSubFrame

#========================================================================
# The "Define search SETs" folder 

  OpenFolder 14 MR_MODE closed [list AUTO ROTATE] hide

  CreateInputFileLine line \
      "Define any known rotations/translations from a .sol file\
       (Phaser search results file). This is optional." \
      ".sol file" \
      SET_SOL_FILE DIR_SET_SOL_FILE

#========================================================================
# The "Additional parameters" folder

# Miscellaneous options which most users will not need to change

  OpenFolder 15 MR_MODE closed

  OpenSubFrame frame -toggle_display MR_MODE open AUTO hide

  CreateLine line \
      label ""

  CreateLine line \
      label "Criteria for the rotation search" -italic \

  CreateLine line \
      message "SAVE: criterion for selecting the highest peaks to be saved.\
               Default is PERCENT 75" \
      widget TOG_SAVE_SELECT_ROT -toggleon \
      label "Save peak criterion" \
      widget SAVE_OPTION_ROT \
        -command "phaser_MR_save_update $arrayname" \
      message "Enter the sigma cutoff value" \
      widget SAVE_SIGMA_ROT \
      toggle_display SAVE_OPTION_ROT open SIGMA

  CreateLine line \
      message "SAVE: criterion for selecting the highest peaks to be saved.\
               Default is PERCENT 75" \
      widget TOG_SAVE_SELECT_ROT -toggleon \
      label "Save peak criterion" \
      message "Default is PERCENT 75" \
      widget SAVE_OPTION_ROT \
        -command "phaser_MR_save_update $arrayname" \
      message "Enter the number of top peaks to save" \
      widget SAVE_NPEAKS_ROT \
      toggle_display SAVE_OPTION_ROT open NPEAKS 

  CreateLine line \
      message "SAVE: criterion for selecting the highest peaks to be saved.\
               Default is PERCENT 75" \
      widget TOG_SAVE_SELECT_ROT -toggleon \
      label "Save peak criterion" \
      message "Default is PERCENT 75" \
      widget SAVE_OPTION_ROT \
        -command "phaser_MR_save_update $arrayname" \
      message "Peaks above this percentage of the top are saved" \
      widget SAVE_PERCENT_ROT \
      toggle_display SAVE_OPTION_ROT open PERCENT 

  CreateLine line \
      message "SAVE: criterion for selecting the highest peaks to be saved.\
               Default is PERCENT 75" \
      widget TOG_SAVE_SELECT_ROT -toggleon \
      label "Save peak criterion" \
      message "Default is PERCENT 75" \
      widget SAVE_OPTION_ROT \
        -command "phaser_MR_save_update $arrayname" \
      toggle_display SAVE_OPTION_ROT open ALL 

  CreateLine line \
      message "SAVE: specify clustering to be on or off" \
      widget TOG_SAVE_CLUSTER_ROT -toggleon \
      label "Save: clustering" \
      message "Select whether raw or clustered peaks are to be saved" \
      widget SAVE_CLUSTER_OPTION_ROT \
        -command "phaser_MR_save_update $arrayname" \
      message "With clustered peaks, NDUMP raw peaks will be dumped\
               to the output" \
      label "Dump" \
      widget SAVE_NDUMP_ROT \
      toggle_display SAVE_CLUSTER_OPTION_ROT open ON hide

  CreateLine line \
      message "SAVE: specify clustering to be on or off" \
      widget TOG_SAVE_CLUSTER_ROT -toggleon \
      label "Save: clustering" \
      message "Select whether raw or clustered peaks are to be saved" \
      widget SAVE_CLUSTER_OPTION_ROT \
        -command "phaser_MR_save_update $arrayname" \
      message "If not saving clustered peaks, clustering can still be performed\
               with the results logged to the log file" \
      label "Log" \
      widget SAVE_LOG_OPTION_ROT \
      toggle_display SAVE_CLUSTER_OPTION_ROT open OFF hide

  CreateLine line \
      message "RESCORE: select whether or not to apply rescoring\
               (rescoring parameters continued on line below)" \
      widget TOG_RESCORE_ROT -toggleon \
      label "Rescoring" \
      widget RESCORE_ONOFF_ROT \
      -command "phaser_MR_rescore_parameter $arrayname" \
      toggle_display RESCORE_PARAMETER_ROT open OFF

# CreateLine line \
      label "" \
      toggle_display RESCORE_PARAMETER_ROT open OFF

  CloseSubFrame

  OpenSubFrame frame -toggle_display RESCORE_PARAMETER_ROT open ON hide

  CreateLine line \
      message "RESCORE: select whether or not to apply rescoring\
               (rescoring parameters continued on line below)" \
      widget TOG_RESCORE_ROT -toggleon \
      label "Rescoring" \
      widget RESCORE_ONOFF_ROT \
      -command "phaser_MR_rescore_parameter $arrayname"

  CreateLine line \
      message "RESCORE: select the criterion for rescoring peaks."\
      widget TOG_RESCORE_SELECT_ROT -toggleon \
      label "Rescore criterion" \
      widget RESCORE_OPTION_ROT \
      message "Enter the sigma cutoff value for rescoring" \
      widget RESCORE_SIGMA_ROT \
      toggle_display RESCORE_OPTION_ROT open SIGMA 

  CreateLine line \
      message "RESCORE: select the criterion for rescoring peaks."\
      widget TOG_RESCORE_SELECT_ROT -toggleon \
      label "Rescore criterion" \
      widget RESCORE_OPTION_ROT \
      message "Enter the number of peaks for rescoring" \
      widget RESCORE_NPEAKS_ROT \
      toggle_display RESCORE_OPTION_ROT open NPEAKS

  CreateLine line \
      message "RESCORE: select the criterion for rescoring peaks."\
      widget TOG_RESCORE_SELECT_ROT -toggleon \
      label "Rescore criterion" \
      widget RESCORE_OPTION_ROT \
      message "Enter the percent value of the top peak to use for rescoring" \
      widget RESCORE_PERCENT_ROT \
      toggle_display RESCORE_OPTION_ROT open PERCENT

  CreateLine line \
      message "RESCORE: select the criterion for rescoring peaks."\
      widget TOG_RESCORE_SELECT_ROT -toggleon \
      label "Rescore criterion" \
      widget RESCORE_OPTION_ROT \
      toggle_display RESCORE_OPTION_ROT open ALL 

  CreateLine line \
      message "RESCORE: select whether raw or clustered peaks are to be used\
              in the rescoring" \
      widget TOG_RESCORE_CLUSTER_ROT -toggleon \
      label "Rescore clustering" \
      widget RESCORE_CLUSTER_OPTION_ROT \
      message "With clustered peaks, NDUMP raw peaks will be dumped\
              to the output" \
      label "Dump" \
      widget RESCORE_NDUMP_ROT \
      toggle_display RESCORE_CLUSTER_OPTION_ROT open ON

  CreateLine line \
      message "RESCORE: select whether clustered or raw peaks are to be used\
              in the rescoring" \
      widget TOG_RESCORE_CLUSTER_ROT -toggleon \
      label "Rescore clustering" \
      widget RESCORE_CLUSTER_OPTION_ROT \
      message "With clustering off, clustering may still be performed with\
              the results logged to the log file" \
      label "Log" \
      widget RESCORE_LOG_OPTION_ROT \
      toggle_display RESCORE_CLUSTER_OPTION_ROT open OFF

  CloseSubFrame

  OpenSubFrame frame -toggle_display MR_MODE open AUTO hide

  CreateLine line \
      label ""

  CreateLine line \
      label "Criteria for the translation search" -italic \

  CreateLine line \
      message "SAVE: criterion for selecting the highest peaks to be saved.\
               Default is PERCENT 75" \
      widget TOG_SAVE_SELECT_TRA -toggleon \
      label "Save peak criterion" \
      widget SAVE_OPTION_TRA \
        -command "phaser_MR_save_update $arrayname" \
      message "Enter the sigma cutoff value" \
      widget SAVE_SIGMA_TRA \
      toggle_display SAVE_OPTION_TRA open SIGMA

  CreateLine line \
      message "SAVE: criterion for selecting the highest peaks to be saved.\
               Default is PERCENT 75" \
      widget TOG_SAVE_SELECT_TRA -toggleon \
      label "Save peak criterion" \
      message "Default is PERCENT 75" \
      widget SAVE_OPTION_TRA \
        -command "phaser_MR_save_update $arrayname" \
      message "Enter the number of top peaks to save" \
      widget SAVE_NPEAKS_TRA \
      toggle_display SAVE_OPTION_TRA open NPEAKS 

  CreateLine line \
      message "SAVE: criterion for selecting the highest peaks to be saved.\
               Default is PERCENT 75" \
      widget TOG_SAVE_SELECT_TRA -toggleon \
      label "Save peak criterion" \
      message "Default is PERCENT 75" \
      widget SAVE_OPTION_TRA \
        -command "phaser_MR_save_update $arrayname" \
      message "Peaks above this percentage of the top are saved" \
      widget SAVE_PERCENT_TRA \
      toggle_display SAVE_OPTION_TRA open PERCENT 

  CreateLine line \
      message "SAVE: criterion for selecting the highest peaks to be saved.\
               Default is PERCENT 75" \
      widget TOG_SAVE_SELECT_TRA -toggleon \
      label "Save peak criterion" \
      message "Default is PERCENT 75" \
      widget SAVE_OPTION_TRA \
        -command "phaser_MR_save_update $arrayname" \
      toggle_display SAVE_OPTION_TRA open ALL 

  CreateLine line \
      message "SAVE: specify clustering to be on or off" \
      widget TOG_SAVE_CLUSTER_TRA -toggleon \
      label "Save: clustering" \
      message "Select whether raw or clustered peaks are to be saved" \
      widget SAVE_CLUSTER_OPTION_TRA \
        -command "phaser_MR_save_update $arrayname" \
      message "With clustered peaks, NDUMP raw peaks will be dumped\
               to the output" \
      label "Dump" \
      widget SAVE_NDUMP_TRA \
      toggle_display SAVE_CLUSTER_OPTION_TRA open ON hide

  CreateLine line \
      message "SAVE: specify clustering to be on or off" \
      widget TOG_SAVE_CLUSTER_TRA -toggleon \
      label "Save: clustering" \
      message "Select whether raw or clustered peaks are to be saved" \
      widget SAVE_CLUSTER_OPTION_TRA \
        -command "phaser_MR_save_update $arrayname" \
      message "If not saving clustered peaks, clustering can still be performed\
               with the results logged to the log file" \
      label "Log" \
      widget SAVE_LOG_OPTION_TRA \
      toggle_display SAVE_CLUSTER_OPTION_TRA open OFF hide

  CreateLine line \
      message "RESCORE: select whether or not to apply rescoring\
               (rescoring parameters continued on line below)" \
      widget TOG_RESCORE_TRA -toggleon \
      label "Rescoring" \
      widget RESCORE_ONOFF_TRA \
      -command "phaser_MR_rescore_parameter $arrayname" \
      toggle_display RESCORE_PARAMETER_TRA open OFF

  CreateLine line \
      label "" \
      toggle_display RESCORE_PARAMETER_TRA open OFF

  CloseSubFrame

  OpenSubFrame frame -toggle_display RESCORE_PARAMETER_TRA open ON hide

  CreateLine line \
      message "RESCORE: select whether or not to apply rescoring\
               (rescoring parameters continued on line below)" \
      widget TOG_RESCORE_TRA -toggleon \
      label "Rescoring" \
      widget RESCORE_ONOFF_TRA \
      -command "phaser_MR_rescore_parameter $arrayname"

  CreateLine line \
      message "RESCORE: select the criterion for rescoring peaks."\
      widget TOG_RESCORE_SELECT_TRA -toggleon \
      label "Rescore criterion" \
      widget RESCORE_OPTION_TRA \
      message "Enter the sigma cutoff value for rescoring" \
      widget RESCORE_SIGMA_TRA \
      toggle_display RESCORE_OPTION_TRA open SIGMA 

  CreateLine line \
      message "RESCORE: select the criterion for rescoring peaks."\
      widget TOG_RESCORE_SELECT_TRA -toggleon \
      label "Rescore criterion" \
      widget RESCORE_OPTION_TRA \
      message "Enter the number of peaks for rescoring" \
      widget RESCORE_NPEAKS_TRA \
      toggle_display RESCORE_OPTION_TRA open NPEAKS

  CreateLine line \
      message "RESCORE: select the criterion for rescoring peaks."\
      widget TOG_RESCORE_SELECT_TRA -toggleon \
      label "Rescore criterion" \
      widget RESCORE_OPTION_TRA \
      message "Enter the percent value of the top peak to use for rescoring" \
      widget RESCORE_PERCENT_TRA \
      toggle_display RESCORE_OPTION_TRA open PERCENT

  CreateLine line \
      message "RESCORE: select the criterion for rescoring peaks."\
      widget TOG_RESCORE_SELECT_TRA -toggleon \
      label "Rescore criterion" \
      widget RESCORE_OPTION_TRA \
      toggle_display RESCORE_OPTION_TRA open ALL 

  CreateLine line \
      message "RESCORE: select whether raw or clustered peaks are to be used\
              in the rescoring" \
      widget TOG_RESCORE_CLUSTER_TRA -toggleon \
      label "Rescore clustering" \
      widget RESCORE_CLUSTER_OPTION_TRA \
      message "With clustered peaks, NDUMP raw peaks will be dumped\
              to the output" \
      label "Dump" \
      widget RESCORE_NDUMP_TRA \
      toggle_display RESCORE_CLUSTER_OPTION_TRA open ON

  CreateLine line \
      message "RESCORE: select whether clustered or raw peaks are to be used\
              in the rescoring" \
      widget TOG_RESCORE_CLUSTER_TRA -toggleon \
      label "Rescore clustering" \
      widget RESCORE_CLUSTER_OPTION_TRA \
      message "With clustering off, clustering may still be performed with\
              the results logged to the log file" \
      label "Log" \
      widget RESCORE_LOG_OPTION_TRA \
      toggle_display RESCORE_CLUSTER_OPTION_TRA open OFF

  CreateLine line \
      label ""

  CloseSubFrame

  OpenSubFrame frame -toggle_display MR_MODE_SELECT open [list MR_FRF MR_FTF] hide

  CreateLine line \
      label ""

  CreateLine line \
      message "SAVE: criterion for selecting the highest peaks to be saved.\
               Default is PERCENT 75" \
      widget TOG_SAVE_SELECT -toggleon \
      label "Save peak criterion" \
      widget SAVE_OPTION \
        -command "phaser_MR_save_update $arrayname" \
      message "Enter the sigma cutoff value" \
      widget SAVE_SIGMA \
      toggle_display SAVE_OPTION open SIGMA

  CreateLine line \
      message "SAVE: criterion for selecting the highest peaks to be saved.\
               Default is PERCENT 75" \
      widget TOG_SAVE_SELECT -toggleon \
      label "Save peak criterion" \
      message "Default is PERCENT 75" \
      widget SAVE_OPTION \
        -command "phaser_MR_save_update $arrayname" \
      message "Enter the number of top peaks to save" \
      widget SAVE_NPEAKS \
      toggle_display SAVE_OPTION open NPEAKS 

  CreateLine line \
      message "SAVE: criterion for selecting the highest peaks to be saved.\
               Default is PERCENT 75" \
      widget TOG_SAVE_SELECT -toggleon \
      label "Save peak criterion" \
      message "Default is PERCENT 75" \
      widget SAVE_OPTION \
        -command "phaser_MR_save_update $arrayname" \
      message "Peaks above this percentage of the top are saved" \
      widget SAVE_PERCENT \
      toggle_display SAVE_OPTION open PERCENT 

  CreateLine line \
      message "SAVE: criterion for selecting the highest peaks to be saved.\
               Default is PERCENT 75" \
      widget TOG_SAVE_SELECT -toggleon \
      label "Save peak criterion" \
      message "Default is PERCENT 75" \
      widget SAVE_OPTION \
        -command "phaser_MR_save_update $arrayname" \
      toggle_display SAVE_OPTION open ALL 

  CreateLine line \
      message "SAVE: specify clustering to be on or off" \
      widget TOG_SAVE_CLUSTER -toggleon \
      label "Save: clustering" \
      message "Select whether raw or clustered peaks are to be saved" \
      widget SAVE_CLUSTER_OPTION \
        -command "phaser_MR_save_update $arrayname" \
      message "With clustered peaks, NDUMP raw peaks will be dumped\
               to the output" \
      label "Dump" \
      widget SAVE_NDUMP \
      toggle_display SAVE_CLUSTER_OPTION open ON hide

  CreateLine line \
      message "SAVE: specify clustering to be on or off" \
      widget TOG_SAVE_CLUSTER -toggleon \
      label "Save: clustering" \
      message "Select whether raw or clustered peaks are to be saved" \
      widget SAVE_CLUSTER_OPTION \
        -command "phaser_MR_save_update $arrayname" \
      message "If not saving clustered peaks, clustering can still be performed\
               with the results logged to the log file" \
      label "Log" \
      widget SAVE_LOG_OPTION \
      toggle_display SAVE_CLUSTER_OPTION open OFF hide

  CreateLine line \
      message "RESCORE: select whether or not to apply rescoring\
               (rescoring parameters continued on line below)" \
      widget TOG_RESCORE -toggleon \
      label "Rescoring" \
      widget RESCORE_ONOFF \
      -command "phaser_MR_rescore_parameter $arrayname" \
      toggle_display RESCORE_ONOFF open OFF

  CreateLine line \
      label "" \
      toggle_display RESCORE_ONOFF open OFF

  CloseSubFrame

  OpenSubFrame frame -toggle_display RESCORE_PARAMETER open ON hide
 
  CreateLine line \
      message "RESCORE: select whether or not to apply rescoring\
               (rescoring parameters continued on line below)" \
      widget TOG_RESCORE -toggleon \
      label "Rescoring" \
      widget RESCORE_ONOFF \
      -command "phaser_MR_rescore_parameter $arrayname"

  CreateLine line \
      message "RESCORE: select the criterion for rescoring peaks."\
      widget TOG_RESCORE_SELECT -toggleon \
      label "Rescore criterion" \
      widget RESCORE_OPTION \
      message "Enter the sigma cutoff value for rescoring" \
      widget RESCORE_SIGMA \
      toggle_display RESCORE_OPTION open SIGMA 

  CreateLine line \
      message "RESCORE: select the criterion for rescoring peaks."\
      widget TOG_RESCORE_SELECT -toggleon \
      label "Rescore criterion" \
      widget RESCORE_OPTION \
      message "Enter the number of peaks for rescoring" \
      widget RESCORE_NPEAKS \
      toggle_display RESCORE_OPTION open NPEAKS

  CreateLine line \
      message "RESCORE: select the criterion for rescoring peaks."\
      widget TOG_RESCORE_SELECT -toggleon \
      label "Rescore criterion" \
      widget RESCORE_OPTION \
      message "Enter the percent value of the top peak to use for rescoring" \
      widget RESCORE_PERCENT \
      toggle_display RESCORE_OPTION open PERCENT

  CreateLine line \
      message "RESCORE: select the criterion for rescoring peaks."\
      widget TOG_RESCORE_SELECT -toggleon \
      label "Rescore criterion" \
      widget RESCORE_OPTION \
      toggle_display RESCORE_OPTION open ALL 

  CreateLine line \
      message "RESCORE: select whether raw or clustered peaks are to be used\
              in the rescoring" \
      widget TOG_RESCORE_CLUSTER -toggleon \
      label "Rescore clustering" \
      widget RESCORE_CLUSTER_OPTION \
      message "With clustered peaks, NDUMP raw peaks will be dumped\
              to the output" \
      label "Dump" \
      widget RESCORE_NDUMP \
      toggle_display RESCORE_CLUSTER_OPTION open ON

  CreateLine line \
      message "RESCORE: select whether clustered or raw peaks are to be used\
              in the rescoring" \
      widget TOG_RESCORE_CLUSTER -toggleon \
      label "Rescore clustering" \
      widget RESCORE_CLUSTER_OPTION \
      message "With clustering off, clustering may still be performed with\
              the results logged to the log file" \
      label "Log" \
      widget RESCORE_LOG_OPTION \
      toggle_display RESCORE_CLUSTER_OPTION open OFF

  CreateLine line \
      label ""

  CloseSubFrame

  CreateLine line \
      message "Default is to apply an anisotropy correction" \
      widget TOG_ANISO \
      label "Perform anisotropy correction" \
      toggle_display MR_MODE hide [list CONTENT PACK]

  CreateLine line \
      message "Controls output of PDB files containing potential solutions.\
               Default depends on mode." \
      widget TOG_XYZOUT -toggleon \
      label "XYZ (PDB) file output" \
      widget XYZOUT_ONOFF \
      toggle_display MR_MODE hide [list CONTENT]

  CreateLine line \
      message "Controls output of MTZ files with phase information from solutions.\
               Default depends on mode." \
      widget TOG_HKLOUT -toggleon \
      label "HKL (MTZ) file output" \
      widget HKLOUT_ONOFF \
      toggle_display MR_MODE hide [list CONTENT PACK]

  CreateLine line \
      message "TARGET: select the rotation target function to be used" \
      widget TOG_FRF_TARGET \
      label "Rotation target function" \
      widget FRF_TARGET_OPTION \
      -command "phaser_MR_tog_activate $arrayname" \
      toggle_display MR_MODE_SELECT open [list MR_FRF MR_AUTO] hide

  CreateLine line \
      message "TARGET: select the translation target function to be used" \
      widget TOG_FTF_TARGET \
      label "Translation target function" \
      widget FTF_TARGET_OPTION \
      -command "phaser_MR_tog_activate $arrayname" \
      toggle_display MR_MODE_SELECT open [list MR_FTF MR_AUTO] hide

  OpenSubFrame frame -toggle_display MR_MODE hide [list PACK CONTENT]

  CreateLine line \
      message "BINS: specify how the binning to all reflections will apply"\
      widget TOG_BINS -toggleon \
      label "Binning of data" \
      message "BINS: specify binning by the number or width of bins" \
      widget BINS_OPTION \
      message "Default number is the number of reflections divided by 1000\
               subject to a minimum of 6 bins" \
      widget BINS_N \
      message "Binning function: AS^3 + BS^2 + CS\
               where S=1/reso.\
               A,B,C must all be +ve and A=B=0 or A=0 or B=0"\
      label "Coeffs for binning fn: A" \
      widget BINS_A \
      label "B" \
      widget BINS_B \
      label "C" \
      widget BINS_C \
      toggle_display BINS_OPTION open NUMBER hide

  CreateLine line \
      message "BINS: specify how the binning to all reflections will apply"\
      widget TOG_BINS -toggleon \
      label "Binning of data" \
      message "BINS: specify binning by the number or width of bins" \
      widget BINS_OPTION \
      message "Default width is 1000 reflections" \
      widget BINS_W \
      message "Binning function: AS^3 + BS^2 + CS\
               where S=1/reso.\
               A,B,C must all be +ve and A=B=0 or A=0 or B=0"\
      label "Coeffs for binning fn: A" \
      widget BINS_A \
      label "B" \
      widget BINS_B \
      label "C" \
      widget BINS_C \
      toggle_display BINS_OPTION open WIDTH hide

  CreateLine line \
      message "BOXSCALE: specify how finely the ensemble structure factors\
               are sampled in reciprocal space" \
      widget TOG_BOXSCALE -toggleon \
      label "Box scale factor" \
      message "The ensemble 'cell' is <BOXSCALE>*(extent of molecule).\
               The default value of BOXSCALE is 4" \
      widget BOXSCALE

  CloseSubFrame

  OpenSubFrame frame -toggle_display MR_MODE_SELECT open [list MR_FRF MR_AUTO] hide

  CreateLine line \
      message "CLMN: radius for decomposition of the Patterson" \
      widget TOG_CLMN -toggleon \
      label "CLMN sphere outer radius " \
      message "Specify outer radius in Angstroms. Min acceptable value is 5 A" \
      widget CLMN_OUTER

  CloseSubFrame

  OpenSubFrame frame -toggle_display MR_MODE hide [list PACK CONTENT]

  CreateLine line \
      message "OUTLIER: choose whether to reject large, unlikely E-values" \
      widget TOG_OUTLIER -toggleon \
      label "Outlier rejection" \
      widget OUTLIER_OPTION \
      label "outlier probability" \
      message "Enter cutoff probability, where outliers with a probability\
               less than the cutoff are rejected" \
      widget OUTLIER_PROB \
      toggle_display OUTLIER_OPTION open ON 

  CreateLine line \
      message "OUTLIER: choose whether to reject large, unlikely E-values.\
               Default is ON with probability 0.00001" \
      widget TOG_OUTLIER -toggleon \
      label "Outlier rejection" \
      widget OUTLIER_OPTION \
      toggle_display OUTLIER_OPTION open OFF

  CloseSubFrame

  CreateLine line \
      message "Choose whether to permute the order of the search set.\
               Default is OFF." \
      widget TOG_PERMUTATIONS -toggleon \
      label "Permute search set" \
      widget PERMUTATIONS_ONOFF \
      toggle_display MR_MODE open [list AUTO] 

  CreateLine line \
      message "SAMPLING: sampling of search space" \
      widget TOG_SAMPLING -toggleon \
      label "Sampling for rotation search" \
      message "Sampling for rotation search given in degrees" \
      widget SAMPLING_ROT \
      toggle_display MR_MODE open ROTATE

  CreateLine line \
      message "SAMPLING: sampling of search space" \
      widget TOG_SAMPLING -toggleon \
      label "Sampling for translation search" \
      message "Sampling for translation search given in Angstroms" \
      widget SAMPLING_TRA \
      toggle_display MR_MODE open TRANSLATE 

  CreateLine line \
      message "SAMPLING: sampling of search space" \
      widget TOG_SAMPLING -toggleon \
      label "Sampling for rotation search" \
      message "Sampling for rotation search given in degrees" \
      widget SAMPLING_ROT \
      label "Sampling for translation search" \
      message "Sampling for translation search given in Angstroms" \
      widget SAMPLING_TRA \
      toggle_display MR_MODE open AUTO 

  CreateLine line \
      message "SHANNON: specify the Shannon rate for sampling the\
               ensemble coordinate maps" \
      widget TOG_SHANNON -toggleon \
      label "Shannon factor" \
      message "Shannon sampling given by (2*SHARAT). Default value is 1.5.\
               Increase SHARAT to 2 to sharpen the sampling" \
      widget SHANNON \
      toggle_display MR_MODE hide [list PACK CONTENT] 

  CreateLine line \
      message "VERBOSE: more information included in log file than by default" \
      widget TOG_VERBOSE \
      label "Verbose output to log file" \
      message "Verbose extra option: even more information included in log file" \
      widget TOG_VERBOSE_EXTRA \
      label "extra"

# $line.l2 configure -width 7 -background $configure(COLOUR_BACKGROUND)

  }
