Liz Potterton
The relevant bit of the demo1.def file (hint: open this page in another window) is line 34:
NRANGES
_positiveint
0
RESTRAIN_MODE,0
_demo_restrain_mode medium
CHAIN,0
_chain_id
""
FIRST_RES,0
_res_id
""
LAST_RES,0
_res_id
""
NRANGES is the counter variable and should always be of type _positiveint.
The four parameters for
that define refinement ranges are listed RESTRAIN_MODE,CHAIN,FIRST_RES,LAST_RES.
These
variables have index 0 and never appear in the interface but are used to
initialise the variables which are created automatically. The variables
used in the interface with have indices 1,2,3...
In demo1.tcl in the demo_task_window procedure (line 178) the extending frame for the user to enter refinement ranges is set up:
CreateExtendingFrame NRANGES demo_refine_range
\
"Define range(s) of residue ranges to refine" \
"Add Refinement Range" \
[ list RESTRAIN_MODE \
CHAIN \
FIRST_RES \
LAST_RES ]
The arguments to the CreateExtendingFrame
command
are:
In the demo1.tcl file at line 58 is
the procedure referenced in the CreateExtendingFrame
call,
demo1_refine_range
which draws one line of the extending frame:
#---------------------------------------------------------------------
proc demo1_refine_range { arrayname
counter } {
#---------------------------------------------------------------------
#procedure to draw one line of the
'refinement range' extending frame
upvar #0 $arrayname array
CreateLine line \
message "Enter range of residues to refine" \
label "Use" \
widget RESTRAIN_MODE \
label "restraints for chain" \
widget CHAIN \
label "from residue" \
widget FIRST_RES \
label "to residue" \
widget LAST_RES
}
This procedure is called automatically whenever an extra line is drawn. This simple example just draws one line using the CreateLine command. The name of the variables are passed to CreateLine do not have any index number - it 'knows' these values automatically. But remember it is creating the widgets for RESTRAIN_MODE,1 CHAIN,1 etc..
The arguments passed automatically to the demo1_refine_range procedure are the arrayname and the value of the counter variable. In this simple example neither of these are used but the programmer may sometimes need these to make customisations.
At line 180 the CreateInputFileLine command, which creates the line to select the input PDB file
CreateInputFileLine line \
"Enter input coordinate file name (XYZIN)" \
"PDB
in" \
XYZIN DIR_XYZIN \
-fileout XYZOUT DIR_XYZOUT "_refmac" \
-command "demo2_set_range $arrayname"
has extra optional arguments -command "demo2_set_range $arrayname" which means that when a user selects a PDB file the command "demo2_set_range $arrayname" is executed.
The procedure demo2_set_range is defined in demo2.tcl at line 58.
The details of this procedure are explained in the comments but the
important steps are:
The user defined restraint mode names are used to create a menu which appears in the refinement range selection so that one of the user defined restraint modes can be selected for each refinement range. The important part of this example is to demonstrate using a variable menu.
Compared to previous examples there are some additional parameters defined in the demo3.def file. See line 34.
NRESTRAINTMODES
_positiveint
1
RESTRAINT_NAME,0
_text
""
BOND_RESTRAINT,0
_real
""
ANGLE_RESTRAINT,0
_real
""
RESTRAINT_NAME,1
_text
normal
BOND_RESTRAINT,1
_real
0.5
ANGLE_RESTRAINT,1
_real
0.5
These are used to define the possible restraint modes. The NRESTRAINTMODES parameter is the number of defined restraint modes. It is initialised as 1 and the data is provided for one default restraint mode called 'normal'. Each restraint mode has a name RESTRAINT_NAME and two parameters BOND_RESTRAINT and ANGLE_RESTRAINT. The 0'th index instance of these variables is set to "" (i.e. nothing) so the default initial values of these parameters is nothing. The index 1 instance is given some initial values to define the 'normal' restraint mode.
Two additional parameters in the def file (line 42) are:
RESTRAINT_MENU
_list
"normal"
RESTRAINT_ALIAS
_list
"normal"
These are variables which will contain the current allowed items for the restraint mode menu. Most menus have the text which appears on the menu and then a shortened alias which is associated with each item on the menu. We will not be using this facility, the aliases will be the same as the menu items but they must be defined. The variable RESTRAINT_MENU will contain a list of items to appear on the menu and RESTRAINT_ALIAS will contain the aliases for these menu items.
The code to define the restraint mode extending frame in demo3.tcl is similar to that for defining the refinement ranges. There is a call to CreateExtendingFrame at line 266 and the procedure demo3_restraint_modes (line 166) defines the appearance of one line of the extending frame. One feature of this procedure is at line 122, if the RESTRAINT_NAME is blank then it is given a default value of 'restraint_n' where n is the number of the restraint.
The important feature of this example is the procedure demo3_update_restraints_menu (line 139) which is called whenever the defined restraint mode names are changed to update the variable menu. A temporary variable restraint_list is initialised empty and then there is (line 148) a loop over the number of defined restraint modes which appends the name of the restraint mode to the list restraint_list. The procedure UpdateVariableMenu is then called to update the values of the RESTRAINT_MENU and RESTRAINT_ALIAS variables. This procedure also forces the redrawing of all instances of the menu so that they now list the updated menu items.
The procedure is called in several places:
-command "demo3_update_restraints_menu $arrayname"
ensures that the procedure is called every time the user changes a RESTRAINT_NAME
widget.
-update "demo3_update_restraints_menu $arrayname"
ensure that whenever the list of restraint modes is edited via the 'Edit List' button the variable menu gets updated.
So with what is described above we will have a variable menu defined and correctly updated but we must make some small changes to how we handle the refinement range selection parameters to ensure that they present the user with the variable menu list of restraint modes.
In demo3.def (line 49) the definition of the restrain mode for each refinement range is:
RESTRAIN_MODE,0 _demo_restrain_mode normal
The only change from the previous examples is that the initial value has been set to normal to be consistent with the options available in the variable menu.
In demo3.tcl (line 23) the data type _demo_restrain_mode has a new definition:
set typedef(_demo_restrain_mode) [list varmenu RESTRAINT_MENU RESTRAINT_ALIAS 10]
The array typedef contains the
definitions of all data types and this line is setting the _demo_restrain_mode
element of that array to define this data type as a variable menu with
the menu items stored in the variable RESTRAINT_MENU
and the aliases for the menu items stored in RESTRAINT_ALIAS.
The final parameter, 10, sets the width of the menu as a number of characters.
Now that the data type is correctly defined the menus for selecting restraint
modes will always properly reflect the currently defined restrain modes.