1    # ======================================================================
2    # demo.tcl --
3    #
4    # CCP4Interface 
5    #
6    # =======================================================================
7    
8    # procedure which is run automatically before drawing the interface
9    # used to set up variables, menus etc
10   #---------------------------------------------------------------------
11   proc demo2_setup { typedefVar arrayname } {
12   #---------------------------------------------------------------------
13     upvar #0  $typedefVar typedef
14     upvar #0 $arrayname array
15   
16   # Define the 'refinement type' and 'input phase' menus
17   
18     DefineMenu _demo_refine_type [list "full refinement" \
19   					"quick refinement" ] \
20   				   [ list FULL \
21   				          FAST ] 
22   
23     DefineMenu _demo_restrain_mode   [ list loose medium tight ]
24   
25     DefineMenu _demo_input_phase [list "input phases" \
26   				         "no phase input" ] \
27   				   [list PHASE \
28   					 NO ]
29   
30   # procedure must return sucess code (1) for drawing task window to continue
31     return 1
32   }
33   					
34   #---------------------------------------------------------------------
35   proc demo2_run { arrayname } {
36   #---------------------------------------------------------------------
37   # this procedure is run when user clicks the 'Run' button
38   # used to check user input and where necessary convert parameters
39   # to form required by the program run script
40   
41     upvar #0 $arrayname array
42   
43   #The labin depends on the INPUT_PHASE mode selected by the user
44   #Get the 'alias' for the currently selected value of INPUT_PHASE
45   # and if it matchs "PHASE" then include the phase labels in the labin
46   
47     if [regexp PHASE [GetValue $arrayname INPUT_PHASE]] {
48       set array(LABIN) "FP SIGFP PHIB FOMB"
49     } else {
50       set array(LABIN) "FP SIGFP"
51     }
52   
53   # procedure must return sucess code (1) for running job to continue
54     return 1
55   }
56   
57   #-----------------------------------------------------------------------
58   proc demo2_set_range { arrayname } {
59   #-----------------------------------------------------------------------
60     upvar #0 $arrayname array
61   
62   # Get the full path name of the PDB file
63     set pdb_filename [GetFullFileName0 $arrayname  XYZIN]
64   
65   # 'Zero' the variables  containing name of chain & res ids in PDB
66     set array(PDB_CHAINS) {}
67     set array(PDB_RES_RANGE) {}
68   
69   # Make sure PdbGetChains procedure is accessible
70     source [SearchPath TOP utils pdb_utils.tcl]
71   
72   # Call PdbGetChains to get chain names and first/last res ids from PDB
73   # Quit here if this procedure fails
74     if {     ![PdbGetChains $pdb_filename  \
75                   array(PDB_CHAINS) array(PDB_RES_RANGE) ] } { return }
76   
77   # Diagnostic - we are getting the right info back?
78     puts "PDB_CHAINS $array(PDB_CHAINS)"
79     puts "PDB_RES_RANGE $array(PDB_RES_RANGE)"
80   
81   # Set the array variables for CHAIN FIRST_RES and LAST_RES
82     set n 0
83     foreach chain $array(PDB_CHAINS) res_range  $array(PDB_RES_RANGE) {
84       incr n
85       set array(CHAIN,$n) $chain
86       set array(FIRST_RES,$n) [lindex $res_range  0]
87       set array(LAST_RES,$n) [lindex $res_range 1]
88     }
89   
90   # Force the redrawing of extending frames
91     UpdateExtendingFrame demo2_refine_range 0 $arrayname [expr $n - $array(NRANGES) ]
92   
93   }
94   
95   
96   #---------------------------------------------------------------------
97   proc demo2_refine_range { arrayname counter } {
98   #---------------------------------------------------------------------
99   #procedure to draw one line of the 'refinement range' extending frame
100    upvar #0 $arrayname array
101  
102    CreateLine line \
103          message "Enter range of residues to refine" \
104          label "Use" \
105          widget RESTRAIN_MODE \
106          label "restraints for chain" \
107          widget CHAIN \
108          label "from residue" \
109          widget FIRST_RES \
110          label "to residue" \
111          widget LAST_RES
112  
113  }
114  
115  # procedure to draw task window
116  #---------------------------------------------------------------------
117  proc demo2_task_window { arrayname } {
118  #---------------------------------------------------------------------
119    upvar #0 $arrayname array
120  
121    if { [CreateTaskWindow $arrayname  \
122      	"Task Template" "Template" \
123          [ list "Required Parameters"  \
124  	"Define Protein Ranges to Refine" \
125  	"Crystal Parameters" ] ] == 0 } return
126  
127  # Set the name of the CCP4 program help file to use
128  # (set it to refmac because it is most suitable program for this example!)
129    SetProgramHelpFile "refmac"
130  
131  #=PROTOCOL==============================================================
132  
133    OpenFolder protocol 
134  
135    CreateTitleLine line TITLE
136  
137    CreateLine line \
138          message "Refinement method (REFI TYPE)" \
139  	help refi_type \
140          label "Do" \
141          widget REFINE_TYPE  \
142          label "using" \
143          widget INPUT_PHASE
144  
145  #=FILES================================================================
146  
147    OpenFolder file 
148    
149    CreateInputFileLine line \
150  	"Enter input MTZ file name (HKLIN)" \
151        "MTZ in" \
152         HKLIN DIR_HKLIN \
153         -fileout HKLOUT DIR_HKLOUT "_demo" \
154         -setfileparam space_group_name SPACE_GROUP \
155  	-setfileparam cell_4 CELL_1 \
156  	-setfileparam cell_4 CELL_2 \
157  	-setfileparam cell_4 CELL_3 \
158  	-setfileparam cell_4 CELL_4 \
159  	-setfileparam cell_5 CELL_5 \
160  	-setfileparam cell_6 CELL_6 \
161  	-setfileparam resolution_min EXCLUDE_RESOLUTION_MIN \
162  	-setfileparam resolution_max EXCLUDE_RESOLUTION_MAX
163  
164    CreateLabinLine line \
165  	"Observed amplitude (FP) and obligatory sigma (SIGFP)" \
166  	HKLIN FP FP  [list FP F_P] \
167          -sigma Sigma SIGFP [list SIGFP SIGF_P SIGP]
168  
169    CreateLabinLine line \
170  	"Input phase (PHIB) and figure of merit (FOMB)" \
171  	HKLIN PHIB PHIB  PHIB \
172          -sigma FOMB FOMB FOMB \
173          -toggle_display INPUT_PHASE open PHASE
174  
175    CreateOutputFileLine line \
176  	"Output MTZ File" \
177  	"MTZ out" \
178  	HKLOUT DIR_HKLOUT
179  
180   CreateInputFileLine line \
181          "Enter input coordinate file name (XYZIN)" \
182        "PDB in" \
183         XYZIN DIR_XYZIN \
184         -fileout XYZOUT DIR_XYZOUT "_refmac" \
185         -command "demo2_set_range $arrayname"
186  
187    CreateOutputFileLine line \
188          "Output coordinate file" \
189          "PDB out" \
190          XYZOUT DIR_XYZOUT
191  
192  #-----------------------------------------------------Required parameters
193  
194    OpenFolder 1
195  
196    CreateLine line \
197  	message "Number of cycles of refinement (NCYC)" \
198  	help refi_ncyc \
199          label "Number of refinement cycles" \
200  	widget NCYCLES \
201  	  -width 3 
202  
203    CreateLine line \
204  	message "Apply resolution limits (REFI RESOlution)" \
205  	help refi_reso \
206  	widget EXCLUDE_RESOLUTION \
207  	message "Minimum resolution" \
208  	label "Resolution range from minimum" \
209  	widget EXCLUDE_RESOLUTION_MIN \
210  	message "Maximum resolution" \
211  	label " to " \
212  	widget EXCLUDE_RESOLUTION_MAX
213  
214  #--------------------------------------------------------refinement range
215  
216    OpenFolder 2
217  
218    CreateExtendingFrame NRANGES demo2_refine_range \
219          "Define range(s) of residue ranges to refine" \
220          "Add Residue Range" \
221         [ list RESTRAIN_MODE \
222  	CHAIN \
223          FIRST_RES \
224          LAST_RES ]
225  
226  
227  #-------------------------------------------------------------cell parameters
228  
229    OpenFolder 3 closed
230  
231    CreateLine line \
232  	message "Space group (default from MTZ) (SYMM)" \
233  	label "Space group" \
234  	widget SPACE_GROUP
235  
236    CreateLine line \
237  	message "Cell dimensions (default from MTZ) (CELL)" \
238  	label "Cell a" \
239  	widget CELL_1 \
240  	label "b" \
241  	widget CELL_2 \
242  	label "c" \
243  	widget CELL_3 \
244  	label "alpha" \
245  	widget CELL_4 \
246  	label "beta" \
247  	widget CELL_5 \
248  	label "gamma" \
249  	widget CELL_6
250  
251  }
252