+ All Categories
Home > Documents > Scripting in VMD with tclvintage.fh.huji.ac.il/~ais/vmd_tutorial/VMD_tcl.pdf · •Several scripts...

Scripting in VMD with tclvintage.fh.huji.ac.il/~ais/vmd_tutorial/VMD_tcl.pdf · •Several scripts...

Date post: 18-Mar-2020
Category:
Upload: others
View: 34 times
Download: 0 times
Share this document with a friend
24
Scripting in VMD with tcl + 1 My email: [email protected]
Transcript

Scripting in VMD with tcl

+1

My email: [email protected]

VMD becomes ultra powerful with scripts!!!

• VMD has many useful options

• But usually we will require a very specific analysis

• OR we don’t trust what VMD gives us.

• The solution – DIY with a tcl script

2

About tcl

• A simple, easy to use scripting language

• Available also as a shell (tclsh)

• Many good tutorials and resources available online

• Acess to tcl through the Tk console under “Extensions”

3

(Very) short tcl primer

Assigning and using variables:

set <variable> <value>

sets the value of the variable

puts $<variable>

Prints out the vairable.

Examples:% set x 10

% puts "the value of x is:$x"

% set text "some text"

% puts "the value of text is:$text."

4

(Very) short tcl primer

Mathematical expressions:

expr [expression]

Calculates the expression in the brackets

[expr [expression]]

Interprets and sends the actual value of the expression

5

(Very) short tcl primer

Logicals :

if {conditional} {script} elseif

{conditional} {script} else {script}

Example:

% set a 30

% if {$a <= 30} {puts “$a is seq 30”}

else {puts “$a is larger than 30”}

6

(Very) short tcl primer

Loops :for {initialization} {conditional}

{increment} {commands}

Or:foreach <variable name> <list> {commands}

Example:% For {set i 0} {$i < 10} {incr i 1} {puts

“i is $i”}

% Set m {0 1 2 3 4 5}

% Foreach i $m {puts “two times m is [expr

$i *2]”

7

Executing scripts with VMD

• Calling a script from the tcl/Tk window:

% source <script file>

• From command line:

>> vmd –dispdev text <coordinate file> <topology

file> < <script> [&> <log file> &]

8

VMD-specific tcl commands

• VMD contains several facilities that extend tcland make working with pdb’s and trajectories very convinient

9

atomselect

• Atomselections saves a list of atoms, with all properties included, of your selection

% atomselect <mol #> “<selection>” [frame <frame #>]

• selection can be: index, residue, resname, chain, etc.

• If you need help, or want to know why it isn’t working - all selections are viewable from the “representation” window, or by typing

% Atomselect keywords

10

atomselect

• selections can contain more complex expressions:

same <selection> as <selection>

within/exwithin <distance> of <selection>

• any combination with logical and, or, not between the selections.

11

atomselect examples

% atomselect top “index 23”

% atomselect top “resname TIP3 or index 1 to

50” frame 3

% atomselect top “same resid as name OH

exwithin 5 of chain A”

• wildcards possible (slight syntax change):

% atomselect top {name “[O.*]”}

12

Let’s use our atomselect

• In order to save your selection:set <selection name> [<atomselect command>]

• Now we can get some characteristics from our atomselection

<selection name> <function>

• Function list available by typing $<atom selection>

13

Some useful examples

% set a [atomselect top protein]

% $a frame 11

% $a get num

% $a get “x y z”

% $a get index

% $a set chain A

• Remember that all of these results can be put in variables!

14

measure

• Another useful facility that works on atomselect objects or atom indices

• some useful options:

measure center

measure minmax

measure rgyr

measure sasa

measure angle/bond/dihed

15

molinfo

• provides various parameters on the entire molecule.

• allows to set the frame and other properties.molinfo <mol num./top> get/set <keywords>

% molinfo top get a

% molinfo top get filename

% molinfo top get numframes

16

Analysis of a sample script

• This script will measure the end to end distance of a peptide in a 1 ns trajectory.

• The peptide is composed of 16 amino-acids, and we will use the Ca of residues 2 and 17 to measure the end to end distance.

• We assume the trajectory has already been fixed in terms of the periodic boundary (ie, molecules stay whole throughout).

17

end-to-end distance

set outfile [open e2e.dat w]

set n [molinfo top get numframes]

for {set i 1} {$i < $n} {incr i} {

set a [atomselect top "resid 2 and name CA" frame $i]

set apos [lindex [$a get "x y z"] 0]

$a delete

set b [atomselect top "resid 17 and name CA" frame $i]

set bpos [lindex [$b get "x y z"] 0]

$b delete

set e2e [vecdist $apos $bpos]

puts "$i\t$e2e"

}

close $outfile

1

2

3

4

5

6

7

8

9

10

11

12

13

18

Now try it yourself!

1. Load hairpin_inWater_afterEq.psf

2. Into this topology load hairpin_inWater.dcd.

3. Make sure you click the “load all at once” button!

4. Click “load”

19

Examine the trajectory

• Take a look at the trajectory. Notice that it contains a peptide surrounded by a box of water

• The box has PBC, and bonds are extend past the boundary!

20

Now try it yourself!

1. Open the Tk console, and try executing the sample script. (slide 18)

2. Look at the output. It should be in two columns. One is the frame number, and the other is the end to end distance, in Å.

3. Try graphing the result.

21

Some tips

• Tcl is awful for debugging – so put a lot of output references in your script, ie:

% puts “Now on line 12”

% puts “the value of i is $i”

• Make sure you use the proper brackets / parentheses

• There is probably more than one way to get the info you need, though one maybe much more efficient.

22

On your own!

• Some ideas:

1. Use a tcl script to get information about the available trajectory (radius of gyration, sasa, certain bond or dihedral angles). Try to output all this data into one tabulated file.

2. Count the number of waters in a hydration layer 5 A form the peptide surface

3. See what residues are within 5 A of residue 10 for the entire trajectory

23

For advanced users

• Several scripts are available for download at the tutorial’s ftp site:

1. Self_diff.tcl analyzes the self diffusion of the peptide

2. Volumes.tcl gives the volume of an annulus around the peptide

• Dealing with probability binning, PBC borders and other types of problems is simple with tcl. Take a look and try to modify for your problems!

24


Recommended