• Tidak ada hasil yang ditemukan

Tcl callbacks

Dalam dokumen VMD User's Guide (Halaman 118-124)

When certain events occur, VMD notifies the Tcl interpreter by setting certain Tcl variables to new values. You can use this feature to customize VMD, for instance, by causing new graphics to appear when the user picks an atom, or recalculating secondary structure on the fly.

To make these new feature happen at the right time, you need to write a script that takes a certain set of arguments, and register this script with the variable you are interested. Registering

scripts is done with the built-in Tcl commandtrace; seehttp://www.tcl.tk/man/tcl8.4/TclCmd/trace.htm for documentation on how to use this command. The idea is that after you register your callback,

when VMD changes the value of the variable, your script will immediately be called with the new value of the variable as arguments. Table 8.4 summarizes the callback variables available in VMD.

In the VMD script library athttp://www.ks.uiuc.edu/Research/vmd/script_library/, you can find a number of scripts that take advantage of Tcl variable tracing. Below, we give a very simple example.

The following procedure takes the picked atom and finds the molecular weight of residue it is on.

proc mol_weight {} {

# use the picked atom’s index and molecule id global vmd_pick_atom vmd_pick_mol

set sel [atomselect $vmd_pick_mol "same residue as index $vmd_pick_atom"]

set mass 0

foreach m [$sel get mass] { set mass [expr $mass + $m]

}

# get residue name and id

set atom [atomselect $vmd_pick_mol "index $vmd_pick_atom"]

lassign [$atom get {resname resid}] resname resid

# print the result

puts "Mass of $resname $resid = $mass"

}

Once an atom has been picked, run the commandmol weightto get output like:

Mass of ALA 7 : 67.047

Since VMD sets the vmd pick atom and vmd pick mol variables, they can be traced.

proc mol_weight_trace_fctn {args} { mol_weight

}

(This function is needed because the functions registered with trace take three arguments, but

“mol weight” only takes one.)

The trace function is registered as:

trace variable vmd_pick_atom w mol_weight_trace_fctn

And now the residue masses will be printed automatically when an atom is picked. To turn this off,

trace vdelete vmd_pick_atom w mol_weight_trace_fctn

First Word Description animate Play/Pause/Rewind a molecular trajectory.

atomselect Create atom selection objects for analysis.

axes Position a set of XYZ axes on the screen.

color Change the color assigned to molecules, or edit the colormap.

colorinfo (Tcl) Obtain color properties for various objects

display Change various aspects of the graphical display window.

exit, quit Quit VMD.

gettimestep Retrieve a timestep as a binary Tcl array (use for plugins) help Display an on-line help file with an HTML viewer.

imd Control the connection to a remote simulation.

label Turn on/off labels for atoms, bonds, angles, dihedral angles, or springs.

light Control the light sources used to illuminate graphical objects.

logfile Turn on/off logging a VMD session to a file or the console.

material Create new material definitions and modify their settings.

measure Measure properties of moleculear structures.

menu Control or query the on-screen GUI menu forms.

molecule or mol Load, modify, or delete a molecule.

molinfo Get information about a molecule or loaded file.

mouse Change the current state (mode) of the mouse.

play Start executing text commands from a specified file.

render Output the currently displayed image (scene) to a file.

rock Rotate the current scene continually at a specified rate.

rotate Rotate the current scene around a given axis by a certain angle.

scale Scale the current scene up or down.

stage Position a checkerboard stage on the screen.

tool Initialize and control external spatial tracking devices.

translate Translate the objects in the current scene.

user Add new keyboard commands.

vmdinfo (Tcl) Get information about this version of VMD volmap Create volumetric data based on molecular information

wait Wait a number of seconds before reading another command. Animation continues.

sleep Sleep a number of seconds before reading another command. Animation is frozen.

Table 8.1: Summary of core text commands in VMD.

Source Associated URL raster3d http://www.bmsc.washington.edu/raster3d/

msms http://www.scripps.edu/pub/olson-web/people/sanner/html/msms home.html faq http://www.ks.uiuc.edu/Research/vmd/allversions/vmd faq.html

biocore http://www.ks.uiuc.edu/Research/biocore/

tachyon http://jedi.ks.uiuc.edu/~johns/raytracer/

babel http://www.eyesopen.com/babel/

homepage http://www.ks.uiuc.edu/Research/vmd/

quickhelp http://www.ks.uiuc.edu/Research/vmd/vmd help.html radiance http://radsite.lbl.gov/radiance/HOME.html

maillist http://www.ks.uiuc.edu/Research/vmd/mailing list/

scripts http://www.ks.uiuc.edu/Research/vmd/script library/

namd http://www.ks.uiuc.edu/Research/namd/

vrml http://www.web3d.org/

rayshade http://www-graphics.stanford.edu/~cek/rayshade/rayshade.html povray http://www.povray.org/

plugins http://www.ks.uiuc.edu/Research/vmd/plugins/

python http://www.python.org/

software http://www.ks.uiuc.edu/Research/vmd/allversions/related programs.html tcl http://www.tcl.tk/

userguide http://www.ks.uiuc.edu/Research/vmd/vmd-1.8.1/ug/ug.html Table 8.2: On-line Help Sources

Keyword Aliases Arg Set Description

id int N molecular id

index int N index on the molecule list

numatoms int N number of atoms

name str N the name of the molecule (usually the name of the file) filename str N list of filenames for all files loaded for this molecule filetype str N list of file types for this molecule

database str N list of databases for this molecule

accession str N list of database accession codes for this molecule remarks str N list of freeform remarks for this molecule

active bool Y is/make the molecule active

drawn displayed bool Y is/make the molecule drawn

fixed bool Y is/make the molecule fixed

top bool Y is/make the molecule top

center vector Y get/set the coordinate used as the center center matrix matrix Y get/set the centering matrix

rotate matrix matrix Y get/set the rotation matrix scale matrix matrix Y get/set the scaling matrix

global matrix matrix Y get/set the global (rotation/scaling) matrix view matrix matrix N get/set the overall viewing matrix

numreps int N the number of representations

selectioni string N the string for the i’th selection repi string N the string for the i’th representation color i colour string N the string for the i’th coloring method

numframes int N number of animation frames

frame int Y current frame number

timesteps int Y number of elapsed timesteps in an interactive simulation bond float N the bond energy (for the current frame)

angle float N the angle energy

dihedral float N the dihedral energy

improper float N the improper energy

vdw float N the van der Waal energy

electrostatic elec float N the electrostatic energy

hbond float N the hydrogen bond energy

kinetic float N the total kinetic energy

potential float N the total potential energy

energy float N the total energy

temperature temp float N the overall temperature

pressure float Y the simulation pressure

volume float Y the simulation volume

efield float Y efield

alpha float Y unit cell angle alpha in degrees (for the current frame) beta float Y unit cell angle beta in degrees (for the current frame) gamma float Y unit cell angle gamma in degrees (for the current frame) a float Y unit cell length a in Angstroms (for the current frame) b float Y unit cell length b in Angstroms (for the current frame) c float Y unit cell length c in Angstroms (for the current frame)

Table 8.4: Description of Tcl callback variables in VMD.

When called Name New value

Molecule molidwas deleted vmd molecule(molid) 0

Molecule molid was created (data may not have been loaded yet)

vmd molecule(molid) 1

Molecule molidwas renamed vmd molecule(molid) 2

Structure file loaded vmd initialize structure(molid) 1

Coordinate file loaded vmd trajectory read(molid) name of coordinate file Molecule molid changed animation

frames

vmd frame(molid) new animation frame

Any VMD command executed vmd logfile Tcl text equivalent of

command

Bond, angle or dihedral label added vmd pick value Value of geometry la- bel

Atom picked vmd pick mol id of picked molecule

Atom picked vmd pick atom id of picked atom

Pointer moved. vmd pick client name of pointer

Pointer moved. vmd pick mol silent id of nearby mol

Pointer moved. vmd pick atom silent id of nearby atom

Atom picked vmd pick shift state 1 if shift key down dur-

ing pick, 0 otherwise IMD coordinate set received vmd timestep(molid) frame containing new

coordinates

Set of labels to be graphed vmd graph label {labeltype labelid} {labeltype labelid} ...

Tcl interpreter is shutting down vmd quit 1

Chapter 9

Python Text Interface

VMD 1.6 and later contain an embedded, fully-functional Python interpreter. The interpreter acts just like the Python command line: you can import your own modules and run them from with the text console of VMD. In addition, VMD provides a number of modules for loading molecules and controlling their display.

VMD currently uses Python version 2.2.

9.1 Using the Python interpreter within VMD

When you start VMD, the VMD text console normally uses the Tcl command interpreter to process what you type. In order to use the Python interpreter, you have to tell VMD to switch to ’Python mode’. There are three ways to do this: (1) Type gopython in the console window; (2) pass -python as a command line option; or (3) put gopython on the last line of your .vmdrc file. If VMD prints an error message reporting that the Python interpreter is not available, your version of VMD was not compiled with Python support; contact the VMD developers for help. If all goes well, you should see Python command prompt ’>>> ’ in the console window. To switch back to the Tcl interpreter, press Ctrl-D as though you were exiting Python. Switching back and forth between Python and Tcl does not destroy any of your work; all variables and modules will still be defined until you exit VMD.

Typing ’gopython <filename>’, where<filename>is the name of a file containing Python code will cause VMD to switch to Python mode, process the file, then switch back to Tcl. In this way, you can embed Python functions inside your Tcl scripts!

You can also type ’gopython -command ”your code here” to run an arbitrary line of python code.

Dalam dokumen VMD User's Guide (Halaman 118-124)