10111010101011000111010111010101011110101111010111010101011000001010010100010101000101010101010110101010101000101010010101001010101000101010 Scripting.

Slides:



Advertisements
Similar presentations
Linux Shell Script. Shell script The first line is used to specify shell program #!/bin/sh Variables variable=“text” variable=0 variable=`program arguments`
Advertisements

JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
Introduction to Unix – CS 21 Lecture 11. Lecture Overview Shell Programming Variable Discussion Command line parameters Arithmetic Discussion Control.
Tcl and Otcl Tutorial Part I Internet Computing KUT Youn-Hee Han.
Programming Using Tcl/Tk These slides are based upon u several Tcl/Tk text books u material byDr. Ernest J. Friedman-Hill.
CS Lecture 03 Outline Sed and awk from previous lecture Writing simple bash script Assignment 1 discussion 1CS 311 Operating SystemsLecture 03.
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
NS-2 LAB: TCL Semester A Miriam Allalouf.
Programming for Image Processing/Analysis and Visualization using The Visualization Toolkit Week 2: An Introduction to Tcl Xenios Papademetris
XP 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial 10.
Tcl and Tk CSE 470 Fall 1999 Revised by Prasad. Objective To use Tcl Tk to develop GUI and prototype of the project.
Tcl/TK Tutorial Fan Yang Kristy Hollingshead
Writing Tcl Scripts Outline Goal Reading Syntax Data Types
Javascript II Expressions and Data Types. 2 JavaScript Review programs executed by the web browser programs embedded in a web page using the script element.
Introduction to Perl Software Tools. Slide 2 Introduction to Perl l Perl is a scripting language that makes manipulation of text, files, and processes.
Tcl/Tk 2 CS 414, Software Engineering I Mark Ardis Rose-Hulman Institute December 5, 2002.
Guide To UNIX Using Linux Third Edition
Guide To UNIX Using Linux Third Edition
Guide To UNIX Using Linux Third Edition
Introduction to Unix (CA263) Introduction to Shell Script Programming By Tariq Ibn Aziz.
Python. What is Python? A programming language we can use to communicate with the computer and solve problems We give the computer instructions that it.
Innovation Intelligence ® 1 Chapter 1: Introduction to TCL.
1 Operating Systems Lecture 3 Shell Scripts. 2 Shell Programming 1.Shell scripts must be marked as executable: chmod a+x myScript 2. Use # to start a.
1 Operating Systems Lecture 3 Shell Scripts. 2 Brief review of unix1.txt n Glob Construct (metacharacters) and other special characters F ?, *, [] F Ex.
SYST Web Technologies SYST Web Technologies Lesson 6 – Intro to JavaScript.
An Introduction to Unix Shell Scripting
Tcl/Tk: An introduction D. Kim, K. Kundu, and M. Siegel November 26, 2002 CMSC 631.
Writing C-shell scripts #!/bin/csh # Author: Ken Berman # Date: # Purpose: display command and parameters echo $0 echo $argv[*]
XP Tutorial 10New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with JavaScript Creating a Programmable Web Page for North Pole.
Introduction to MATLAB Session 3 Simopekka Vänskä, THL Department of Mathematics and Statistics University of Helsinki 2011.
Advanced EPICS Training, Dirk Zimoch 2008 Channel Access in Tcl/Tk.
Meet Perl, Part 2 Flow of Control and I/O. Perl Statements Lots of different ways to write similar statements –Can make your code look more like natural.
Introduction to PHP A user navigates in her browser to a page that ends with a.php extension The request is sent to a web server, which directs the request.
Tcl/TK Tutorial. 2 Learning Tcl/TK What is Tcl/TK? –An interpreted programming language Build on-the-fly commands, procedures Platform-independent Easy.
PHP Conditional Statements Conditional statements in PHP are used to perform different actions based on different conditions. Conditional Statements Very.
Awk Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology
USING UNITY JAVASCRIPT. CONVENTIONS AND SYNTAX IN JAVASCRIPT Case Sensitivity All keywords like var or function must be in lowercase. All variable names,
Applications Development
JavaScript Syntax, how to use it in a HTML document
A first program 1. #include 2. using namespace std; 3. int main() { 4. cout
Writing Scripts Hadi Otrok COEN 346.
LIN Unix Lecture 5 Unix Shell Scripts. LIN Command Coordination ; && || command1 ; command2 Interpretation: Do command 1. Then do command.
Perl Tutorial. Why PERL ??? Practical extraction and report language Similar to shell script but lot easier and more powerful Easy availablity All details.
TCL TK. Tcl/Tk C functions can become Tcl commands that are invoked interactively Tk = scriptable, portable user interface –Windows, X (Unix), MacOS,
Topic 2: Working with scalars CSE2395/CSE3395 Perl Programming Learning Perl 3rd edition chapter 2, pages 19-38, Programming Perl 3rd edition chapter.
Introduction to Tcl/Tk TraNese Christy U.S. Army Research Laboratory.
Agenda Positional Parameters / Continued... Command Substitution Bourne Shell / Bash Shell / Korn Shell Mathematical Expressions Bourne Shell / Bash Shell.
Dongsoo S. Kim  Tcl: Tool Command Language Interpreted programming (scripting) language Build on-the-fly commands and procedures Embeddable.
JavaScript. JavaScript Introduction JavaScript is the world's most popular programming language. It is the language for HTML and the web, for servers,
Introduction to Programming with Tcl. Introduction Using two languages  C++ for “ data ”  Otcl for control Tcl has been widely used as a scripting language.
 History  Ease of use  Portability  Standard  Security & Privacy  User support  Application &Popularity Today  Ten Most Popular Programming Languages.
Dept. of Animal Breeding and Genetics Programming basics & introduction to PERL Mats Pettersson.
Introduction to Javascript. What is javascript?  The most popular web scripting language in the world  Used to produce rich thin client web applications.
PHP Tutorial. What is PHP PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.
PROGRAMMING USING PYTHON LANGUAGE ASSIGNMENT 1. INSTALLATION OF RASPBERRY NOOB First prepare the SD card provided in the kit by loading an Operating System.
JavaScript Tutorial. What is JavaScript JavaScript is the programming language of HTML and the Web Programming makes computers do what you want them to.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Shell scripts – part 1 Cs 302. Shell scripts  What is Shell Script? “Shell Script is series of command written in plain text file. “  Why to Write Shell.
1 Lecture 8 Shell Programming – Control Constructs COP 3353 Introduction to UNIX.
An Introduction To Tcl Scripting John Ousterhout Sun Microsystems Laboratories Tcl/Tk Tutorial, Part II.
TCL/TK Tool Command Language/Tool Kit. What is TCL? u Tool Command Language u An interpreted programming language  Created by John Ousterhout.John Ousterhout.
Perl & TCL Vijay Subramanian, Modified from : perl_basics_06.ppt.
TCL Training Joshi Sravan Kumar K 21-Nov-2011.
Programming Using Tcl Maxwell Created By: Quan Nguyen Created Date: 12/12/2016 TCL Training1.
TCL/TK Tool Command Language/Tool Kit.
NS-2 LAB: TCL Miriam Allalouf Semester A.
C Programming Getting started Variables Basic C operators Conditionals
CSE 303 Concepts and Tools for Software Development
CSCI N317 Computation for Scientific Applications Unit 1 – 1 MATLAB
Tutorial 10: Programming with javascript
Presentation transcript:

Scripting Biomolecular Simulations with Tcl Scripting Biomolecular Simulations with Tcl part of CS590v Michael McLennan Senior Research Scientist Rosen Center for Advanced Computing, Purdue University

Biomolecular Simulation developed by the Theoretical and Computational Biophysics Group in the Beckman Institute for Advanced Science and Technology at the University of Illinois at Urbana-Champaign Download from

What is scripting?  Type in commands  Write little programs  Like Unix “shell” scripts

What is Tcl?  Developed by John Ousterhout at UC Berkeley  Released in 1989, currently maintained as Open Source  Millions of users worldwide  Used in commercial CAD tools and products (TiVo!)  More info: Tcl: language button.b –text “Hello, World!” pack.b –pady 8 button.b –text “Hello, World!” pack.b –pady 8 Tk: widget toolkit

Application: Ubiquitin Ubiquitin 660 atoms Carbon backbone drawn in green

Application: Ubiquitin Ubiquitin 660 atoms Carbon backbone drawn in green (tube method)

Application: Ubiquitin Ubiquitin 660 atoms = starting point = after simulation

Application: Ubiquitin Ubiquitin 660 atoms = small change = medium change = large change Movement after simulation:

Coloring script for comparing molecules A little script to color according to atomic movements: proc tutorialcoloring {} { set mol1 [lindex [molinfo list] 0] set mol2 [lindex [molinfo list] 1] set sel0 [atomselect $mol1 "alpha and protein"] ;# crystal set sel1 [atomselect $mol2 "alpha and protein"] ;# simulation set mylist {} foreach v0 [$sel0 get {x y z}] v1 [$sel1 get {x y z}] { set dx [expr [lindex $v0 0] - [lindex $v1 0]] set dy [expr [lindex $v0 1] - [lindex $v1 1]] set dz [expr [lindex $v0 2] - [lindex $v1 2]] set disp [expr ($dx*$dx + $dy*$dy + $dz*$dz)] lappend mylist $disp } $sel0 set beta $mylist } proc tutorialcoloring {} { set mol1 [lindex [molinfo list] 0] set mol2 [lindex [molinfo list] 1] set sel0 [atomselect $mol1 "alpha and protein"] ;# crystal set sel1 [atomselect $mol2 "alpha and protein"] ;# simulation set mylist {} foreach v0 [$sel0 get {x y z}] v1 [$sel1 get {x y z}] { set dx [expr [lindex $v0 0] - [lindex $v1 0]] set dy [expr [lindex $v0 1] - [lindex $v1 1]] set dz [expr [lindex $v0 2] - [lindex $v1 2]] set disp [expr ($dx*$dx + $dy*$dy + $dz*$dz)] lappend mylist $disp } $sel0 set beta $mylist } Tcl code!

unix> tclsh % puts “Hello, World!” Hello, World! % puts –nonewline “hello” hello% % % exit unix> unix> tclsh % puts “Hello, World!” Hello, World! % puts –nonewline “hello” hello% % % exit unix> unix> tclsh % puts “Hello, World!” Hello, World! % puts –nonewline “hello” hello% unix> tclsh % puts “Hello, World!” Hello, World! % puts –nonewline “hello” hello% “Hello, World!” in Tcl Start up a Tcl application: unix> tclsh unix> wish unix> vmd unix> tclsh unix> wish unix> vmd or Like Unix shell, but speaks Tcl tclsh + widgets VMD molecular visualization unix> tclsh % puts “Hello, World!” Hello, World! % unix> tclsh % puts “Hello, World!” Hello, World! % For example: Command to write out a string Output written on stdout by default Add options to commands Output written without trailing newline Exit tclsh

Tcl command syntax puts –nonewline “Hello, World!” commandarg …  First word is the command name  Remaining arguments depend on command syntax  Use double-quotes ( “” ) to wrap up text strings  Any line starting with hash ( # ) is a comment  Use semicolon ( ; ) to separate multiple commands on same line  Use backslash ( \ ) to extend a command onto multiple lines # this is a comment puts “Hello”; puts “World!” puts –nonewline \ “Hello, World!”

Tcl Documentation

Tcl Variables Variables hold numbers, strings, and other values: set x “World” puts “Hello, $x!”  Hello, World! Uses the value of variable named x set pi puts “Value of pi is $pi”  Value of pi is Value can be a number set cmd puts $cmd “Hello, World!”  Hello, World! Value can be a command name set var x set $var “Universe” puts “Hello, $x!”  Hello, Universe! Value can be a variable name

Doing Math in Tcl Mathematical Expressions: set pi set r 10 puts “Circumference is 2*$pi*$r” Why didn’t we get a number here?  Circumference is 2* *10 expr 2+2  4 Use the expr command to do math expr 2*$pi*$r  The right way to get circumference puts “Circumference is expr 2*$pi*$r” Oops! Still not quite right!  Circumference is expr 2* *10 puts “Circumference is [expr 2*$pi*$r]” Execute command and substitute result in its place  Circumference is

Tcl Versus Other Languages Pythagorean Theorem expressed in Tcl: a b c c =  a 2 +b 2 set a 3 set b 4 set c [expr sqrt($a*$a + $b*$b)] set a 3 set b 4 set c [expr sqrt($a*$a + $b*$b)]  Use ()’s for functions/grouping  Use C-like math functions In C you might say…In Tcl you say… x = x + 1; set x [expr $x + 1] x += 2; incr x 2 set x [expr $x+2] Y = sin(2*x/(x-1)); set y [expr sin(2*$x/($x-1))]

Tcl Quoting Rules Tcl also supports {} quotes: puts “Hello, World!” puts {Hello, World!} Both keep text together puts “Hello, World!” puts {Hello, World!} Both handle multi-line strings The difference is important when you have substitutions: set x “World” puts “Hello, $x!”  Hello, World! set x “World” puts {Hello, $x!}  Hello, $x! Curly braces prevent substitutions!

Quiz Problem #1 set x 10 puts x  x x Problem #2 set set set puts $set  set Problem #3 set pi set area {expr $pi*$r*$r} puts “Area is: $area”  Area is: expr $pi*$r*$r

Command Scripts Save a series of commands in a command script file: # This is a command script puts –nonewline “What’s your name?” set name [gets stdin] puts “Hello, $name!” # This is a command script puts –nonewline “What’s your name?” set name [gets stdin] puts “Hello, $name!” File: hello.tcl unix> tclsh % source hello.tcl What’s your name? Fred Hello, Fred! % source hello.tcl What’s your name? Load the script interactively:Run as a program: unix> tclsh hello.tcl What’s your name? Fred Hello, Fred! unix>

Programming Statements Conditionals: if {$x > 0} { statements } if {$x > 0} { statements } elseif {$x < 0} { statements } else { statements } switch -regexp $x { a.*z { statements } [0-9]+ { statements } foo – bar { statements } } Looping: while {$x != 0} { statements } for {set x 0} {$x < 10} {incr x} { statements } foreach x {a b c d e} { statements } break continue Break out of loop Go back to top of loop

Lists of Values Variables can hold lists of values set x {a b c d e} llength $x  5 Space-separated list of values set x “a b c d e” llength $x  5 Nothing special about quotes lappend x f lappend x g h puts $x  a b c d e f g h Add to list stored in variable x lindex $x 0  a lindex $x 1  b lindex $x end  h Extract an element from a list

proc lreverse {list} { set rlist “” set max [expr [llength $list]-1] for {set i $max} {$i >= 0} {incr i -1} { set v [lindex $list $i] lappend rlist $v } return $rlist } set x {a b c d e f g} set rx [lreverse $x] proc lreverse {list} { set rlist “” set max [expr [llength $list]-1] for {set i $max} {$i >= 0} {incr i -1} { set v [lindex $list $i] lappend rlist $v } return $rlist } set x {a b c d e f g} set rx [lreverse $x] Empty list Get element from list Add to end of return list proc lreverse {list} { set rlist “” set max [expr [llength $list]-1] for {set i $max} {$i >= 0} {incr i -1} { set v [lindex $list $i] lappend rlist $v } return $rlist } set x {a b c d e f g} set rx [lreverse $x] proc lreverse {list} { set rlist “” set max [expr [llength $list]-1] for {set i $max} {$i >= 0} {incr i -1} { set v [lindex $list $i] lappend rlist $v } return $rlist } set x {a b c d e f g} set rx [lreverse $x] i = max; i >= 0; i-- proc lreverse {list} { set rlist “” set max [expr [llength $list]-1] for {set i $max} {$i >= 0} {incr i -1} { set v [lindex $list $i] lappend rlist $v } return $rlist } set x {a b c d e f g} set rx [lreverse $x] proc lreverse {list} { set rlist “” set max [expr [llength $list]-1] for {set i $max} {$i >= 0} {incr i -1} { set v [lindex $list $i] lappend rlist $v } return $rlist } set x {a b c d e f g} set rx [lreverse $x] Substitutions (innermost to outermost) proc lreverse {list} { set rlist “” set max [expr [llength $list]-1] for {set i $max} {$i >= 0} {incr i -1} { set v [lindex $list $i] lappend rlist $v } return $rlist } set x {a b c d e f g} set rx [lreverse $x] proc lreverse {list} { set rlist “” set max [expr [llength $list]-1] for {set i $max} {$i >= 0} {incr i -1} { set v [lindex $list $i] lappend rlist $v } return $rlist } set x {a b c d e f g} set rx [lreverse $x] nameargument list Procedure declaration Return value from procedure call Functions and Procedures Reverse a list:

VMD Commands VMD is just like tclsh, but with extra Tcl commands: vmd > molinfo list  0 1 vmd > atomselect0 num  660 top molecule vmd > atomselect0 set radius 10 vmd > atomselect0 set radius 2 vmd > atomselect top all  atomselect0 molecules vmd > atomselect top alpha  atomselect1 vmd > atomselect1 set radius 5 vmd > atomselect top hydrophobic  atomselect2 vmd > atomselect2 set radius 10

VMD Commands Use variables to store selections: vmd > set s [atomselect top all] vmd > $s num  660 vmd > $s set radius 2 vmd > set s2 [atomselect top alpha] vmd > $s2 set radius 5 vmd > $s2 num  76

Coloring script for comparing molecules A little script to color according to atomic movements: proc tutorialcoloring {} { set mol1 [lindex [molinfo list] 0] set mol2 [lindex [molinfo list] 1] set sel0 [atomselect $mol1 "alpha and protein"] ;# crystal set sel1 [atomselect $mol2 "alpha and protein"] ;# simulation set mylist {} foreach v0 [$sel0 get {x y z}] v1 [$sel1 get {x y z}] { set dx [expr [lindex $v0 0] - [lindex $v1 0]] set dy [expr [lindex $v0 1] - [lindex $v1 1]] set dz [expr [lindex $v0 2] - [lindex $v1 2]] set disp [expr ($dx*$dx + $dy*$dy + $dz*$dz)] lappend mylist $disp } $sel0 set beta $mylist } proc tutorialcoloring {} { set mol1 [lindex [molinfo list] 0] set mol2 [lindex [molinfo list] 1] set sel0 [atomselect $mol1 "alpha and protein"] ;# crystal set sel1 [atomselect $mol2 "alpha and protein"] ;# simulation set mylist {} foreach v0 [$sel0 get {x y z}] v1 [$sel1 get {x y z}] { set dx [expr [lindex $v0 0] - [lindex $v1 0]] set dy [expr [lindex $v0 1] - [lindex $v1 1]] set dz [expr [lindex $v0 2] - [lindex $v1 2]] set disp [expr ($dx*$dx + $dy*$dy + $dz*$dz)] lappend mylist $disp } $sel0 set beta $mylist }