Next: 16.4 Currently picked molecule/atom
Up: 16 Advanced Script Writing
Previous: 16.2 Analysis of PDB
One of the more frequently requested options is the ability to save
the current state of VMD to a file so it can be recovered. It is
possible to log the core commands to a file and play them back later,
and reconstruct everything that way. However, that is quite
cumbersome and slow, so a better way is needed.
Because we are making much of the VMD data accessible at the
Tcl script level, we decided to implement the save/restore option as
a Tcl command. This is actually a rather complicated process and some
of the things to watch out for are:
- A loaded molecule could be from a coordinate file or a coordinate and a topology file
- The molecule could have been converted with Babel
- The molecule could be a ``graphics'' molecule
(see Chapter §)
- Each molecule has a list of selections, colors, and drawing methods
- The mapping of a color category item to color can be changed
- Color definitions can be redefined
- Each molecule has its own viewing matrix
- Loading a new molecule resets all the viewing matrices
Ivo Hofacker has graciously struggled through all the above caveats to
write a set of Tcl commands which will save nearly all of the current
VMD state to a file, and restore it back again. The commands are
- save_state file_name
- saves the vmd state in the form of a script in file file_name.
Restarting vmd as
vmd -e file_name should restore most of the previous session.
Essentially everything that can be changed from the graphics and mol and
color forms will be saved, but nothing else.
In particular, the script will restore:
- molecules read in from files
- graphics objects (spheres, cylinders...)
- all representations
- the transformation matrices for each molecule
- which color to use for which representation,
definitions of colors 0..33
It will not restore:
- trajectories loaded via the edit menu
- labels
- interactive MD sessions
- anything in the display form, such as lighting, axes, stage, ...
- save_viewpoint
- saves the center, rotation, scaling and global matrices (in this order)
in a global variable viewpoints
- restore_viewpoint
- restores the viewpoint saved in variable viewpoints
- save_reps
- saves the current molecule(s) representations in a global array
representations.
- restore_reps
- replaces current representations by the representations stored in the
global array representations. Note, that save_reps saves
molecule Ids along with the representations, so if the molId of a
currently loaded molecule is different from that saved, this command
will not work properly.
- save_colors file_descriptor
- writes color definitions to a file specified by a file_descriptor.
This file can later be sourced to restore the definitions.
To save the color definitions, the following procedure can be used.
# save the color definitions in a file
# argument: file name
proc savcol {file} {
save_colors [open $file w]
close $filedesc
}
This procedure takes the file name as a parameter (as opposed to file
descriptor in save_colors).
If you plan to write scripts which interact with VMD itself (not
just the analysis commands), you are highly advised to look at the
commands, which are defined in $VMDDIR/scripts/vmd/save_state.tcl
(The code is too long to be included in this section.)
Next: 16.4 Currently picked molecule/atom
Up: 16 Advanced Script Writing
Previous: 16.2 Analysis of PDB
Sergei Izrailev
Fri Jul 25 17:07:27 CDT 1997