Friday, September 26, 2014

VMD tcl tips


(1) PBC wrap:
      Not these:
           # pbc wrap -center com -centersel "[atomselect top index $idx1]"
                                                                      -first $iframe -last $iframe

           # pbc wrap -center com -centersel "$sel1" -first $iframe -last $iframe

       But this:
           # pbc wrap -center com -centersel "index $idx1"
                                                 -first $iframe -last $iframe

(2) To rotate a group of atoms (g1) about a bond between the centers mass
      of two groups of atoms (g2 and g3) by 'theta' degrees:

       set g1 [atomselect top "serial 388 389 391 392 396 397 398 400 401"]
       set g2 [atomselect top "serial 379 380 385 386 402 404 407"]
       set g3 [atomselect top "serial 411 412 415 417 418 434 436 439"]

       set coor1 [measure center $g1 weight mass]
       set coor2 [measure center $g2 weight mass]
       set coor3 [measure center $g3 weight mass]

       $g1 move [trans bond $coor2 $coor3 theta deg]

(3) To get the minimum and maximum values of x, y, z coordinates of a
      given set of atoms:

       set mmx [measure minmax [atomselect top all]]

       set xmin [lindex $mmx 0 0]
       set ymin [lindex $mmx 0 1]
       set zmin [lindex $mmx 0 2]

       set xmax [lindex $mmx 1 0]
       set ymax [lindex $mmx 1 1]
       set zmax [lindex $mmx 1 2]

     To get the dimensions of a rectangular bounding box circumscribing
      this set of atoms:

        vecsub [lindex $mmx 1] [lindex $mmx 0]

 (4) To open/write/close a file, the name of which contains a common
        string and a variable:

       option 1 (best!):

        open:

        set fname z_time_series_sodium_${idx2}.dat
        set output_file_${idx2} [open "$fname" w]

        write:
 
        puts [expr \$output_file_$idx2] "$tz"

        close:
       
        close output_file_${idx2}    

       option 2:

        open:

        set fname [join "z_time_series_sodium_ $idx2 .dat" ""]
        set [join "output_file_ $idx2" ""] [open "$fname" w]

        write:

        puts [expr \$[join "output_file_ $idx2" ""]] "$tz"

        close:      
         
        close [join "output_file_ $idx2" ""]

 (5) To select a complete fragment or residue in which at least one atom satisfies a given set of conditions:
     Option: same <keyword> as <atomselection> in the atomselect command
     please refer:  http://www.ks.uiuc.edu/Research/vmd/vmd-1.3/ug/node142.html

 example:
       - set sel [atomselect top "same residue as (name OH2 and (sqr(x)+sqr(y)+sqr(z)) <= $r2)"]

       - set waterdrop [atomselect top "same fragment as (name OH2 and (sqr(x)+sqr(y)+sqr(z)) <= $r2)"]

(6) To print log information on the console:
      - open Tk console 
      - type: logfile /dev/tty (to print on the screen)
      (or) type: logfile filename (to print on a logfile)

(7) arguments in vmd tcl:
     vmd -dispdev text < vmd_select.tcl -args argument0 argument1 argument2
      (here < is used for auto-exit)
     set ifile [lindex $argv 0]
     set rangle [lindex $argv 1]
     set ofile [lindex $argv 2]

(8) To load an xtc trajectory:
       mol load pdb file.pdb xtc traj.xtc

(9) serial = index + 1

(10) To load a selected number of frames in a dcd file:
       mol load psf  filename.psf
       mol addfile filename.dcd  first 1 last 100

(11) To create a vmd logfile: (you need to type these commands in tcl/tk console)
        logfile filename  (log is stored in a file named "filename")
        logfile off  (to turn off logging)
        logfile /dev/tty  (to print the log information on the console)

Monday, September 8, 2014

Frequently used Linux commands:

(1) To remove blank lines from a file:

     sed -e '/^ *$/d' inputfile > outputfile

(2) If loop in awk:

     awk '{
         if ($1 > 4)
         print $1,$2
         else
         print $1-10,$2
         }' filename

(3) assigning a value to a variable in the command line:
   
      Do not use : set I 20
      use   :  I=20

(4) If a directory is over-loaded with a large number of files, 'ls', 'mv' and other similar commands may fail to do their respective jobs. For example, if you want to move all the *.pdb files from one directory to another, we normally use the following command: mv *.pdb destination_directory

When the source directory is loaded with too many *.pdb files, the above command would give the following error message: "mv: Argument list too long".

In such circumstances, you could use the following command to complete the task:

 echo !(*.pdb) | xargs mv -t destination_directory

This command will move all other files (not *.pdb) to the destination_directory. The source directory would contain only the *.pdb files.

(5) To find the minimum and maximum values in a column:
      -  minimum value:
         awk '{print $1}' filename | sort -n | head -1

     -  maximum value:
         awk '{print $1}' filename | sort -n | tail -1

(6) Averages and standard deviation:
     Consider a tab delimited file with n columns and m rows.

     - To take an average of all the columns:
      awk '{for(i=1; i<=NF; i++){sum[i]+=$i}} END {for(i=1; i<=NF; i++){printf sum[i]/NR "\t"}}' file

   - To calculate the average and the standard deviation of the second column:
  awk '{sum += $2; sumsq += ($2)^2} END {printf "%f %f \n", sum/NR, sqrt((sumsq-sum^2/NR)/NR)}' file