Tuesday, December 13, 2011

Go to col on vim/vi


You can quickly jump to a specified column in Vim by simply typing the column number followed by a pipe.


80| # go to the 80th column

Thanks to DailyVim

Tuesday, December 6, 2011

Min-Max on R plots

d <- density(rnorm(1000))
plot(d)
d$x[which.max(d$y)]
abline(v=d$x[which.max(d$y)])

http://r.789695.n4.nabble.com/Find-x-value-of-density-plots-td4165926.html

Monday, November 28, 2011

Great source for 'sed' examples

http://sed.sourceforge.net/sed1line.txt

Bash commands in R

x<-as.matrix(read.table(pipe("awk -f cut.awk F120x1")))

Wednesday, November 23, 2011

NAMD inputs from VMD

set all [atomselect top all]
measure minmax $all
set cellxmin [lindex [lindex [measure minmax $all] 0] 0]
set cellxmax [lindex [lindex [measure minmax $all] 1] 0]
set cellymin [lindex [lindex [measure minmax $all] 0] 1]
set cellymax [lindex [lindex [measure minmax $all] 1] 1]
set cellzmin [lindex [lindex [measure minmax $all] 0] 2]
set cellzmax [lindex [lindex [measure minmax $all] 1] 2]

puts "cellOrigin              [format "%7.3f %7.3f %7.3f" [lindex [measure center $all] 0] [lindex [measure center $all] 1] [lindex [measure center $all] 2]]"
puts "cellBasisVector1        [format "%7.3f %7.3f %7.3f"      [vecsub $cellxmax $cellxmin] 0 0]"
puts "cellBasisVector2        [format "%7.3f %7.3f %7.3f"  0   [vecsub $cellymax $cellymin] 0]"
puts "cellBasisVector3        [format "%7.3f %7.3f %7.3f"  0 0 [vecsub $cellzmax $cellzmin] ]"



Pretty primitive, but it works.

Thursday, November 17, 2011

Common VMD Tcl/Tk commands

mol modselect 0 0 resname BGLC and noh
mol modselect 0 1 resname BGLC and noh
mol modselect 0 2 resname BGLC and noh
mol modselect 0 3 resname BGLC and noh

mol smoothrep 0 0 5
mol smoothrep 1 0 5
mol smoothrep 2 0 5
mol smoothrep 3 0 5


mol modstyle 0 0 Licorice 0.300000 10.000000 10.000000

mol addrep 0
mol modselect 1 0 protein
mol modstyle  1 0 Licorice 0.300000 10.000000 10.000000
mol modstyle  1 0 vdw
mol smoothrep 1 1 5

mol off 0
mol off 1
mol off 2
mol off 3

mol showrep 0 0 0
mol showrep 0 0 1

color Display Background white

Tuesday, November 8, 2011

Calculating phi/psi values in VMD

First source the following script:
--- start ---
proc all_dihed_angle { a1 a2 a3 a4 } {
  # Delete all existing Dihdral labels so that the one we add has index 0.
  label delete Dihedrals

  # Use the top molecule
  set molid [molinfo top]

  # Add the dihedral monitor
  label add Dihedrals $molid/$a1 $molid/$a2 $molid/$a3 $molid/$a4

  # Get all values
  return [label graph Dihedrals 0]
}
--- end ---

Then run this script:

mol new enzfibsol.psf
mol addfile md7.dcd first 0 last 10 waitfor all
set phifile [open "cellulose_dihed_phi.tcl" w]
set psifile [open "cellulose_dihed_psi.tcl" w]

set oxygen [atomselect top "resname BGLC and resid 436 and name O1"]
set ox [$oxygen get index]
set h1 [expr {$ox-1}]
set c1 [expr {$ox-2}]
set c4 [expr {$ox-9}]
set h4 [expr {$ox-8}]

puts $phifile [all_dihed_angle $h1 $c1 $ox $c4]
puts $psifile [all_dihed_angle        $c1 $ox $c4 $h4]

close $phifile
close $psifile
quit

Thursday, September 22, 2011

Resize images on a console

sips --resampleWidth 2400 IMG_0062.JPG --out test.jpg
(double dash) resampleWidth and (double dash) out

This Mac command does a fantastic job of resizing large images in to more manageable file sizes.

Edit: A width of 2400 is too large. Use 1600 or lower instead.

Tuesday, September 13, 2011

Wildcards in Tcl/Tk

http://phaseit.net/claird/comp.lang.tcl/fmm.html

Very useful link on wildcards in Tcl Tk. This line solved my problem;
mol new [glob fitted*.pdb rev*.pdb]

A little background would help greatly. I had a set of directories each of which had either a fittedxxx.pdb or revxxx.pdb file. I wanted a single tcl script that would go into these directories and read the fitted/rev file and perform calculations. Since the name of the file in each directory was different, I needed a way to select whatever was available. glob does exactly that. 

Wednesday, September 7, 2011

Install packages in R

R CMD INSTALL mypkg -l /my/own/R-packages/

install.packages("mypkg", lib="/my/own/R-packages/")

Friday, September 2, 2011

ssh-keygen

To reset IP and known_host keys, use the following command:

ssh-keygen -R moldyn.ornl.gov -f /home/pkc/.ssh/known_hosts
RSA host key for moldyn.ornl.gov has changed and you have requested strict checking.


Monday, August 29, 2011

That #$%@ beep

1. xset b off
2. set b off
3. Turn off beep on Gmixer (or whatever audio controller you run)

These commands turn off the annoying beep that accompanies [tab], [auto-fill], and errors in the linux environment.


Thursday, August 18, 2011

png figures in a loop in R

This sample script creates 100 png figures with the iteration number included in the name.

for(i in 1:100) {
a<-rnorm(100)
name<-paste("test",i,".png",sep="")
png(name)
plot(a/max(a),type="l")
dev.off()
}

Friday, May 27, 2011

Running multiple serial jobs on clusters

This script describes a way to run multiple serial jobs on clusters.

#PBS -N serial.analysis
#PBS -j oe
#PBS -l walltime=4:00:00,nodes=22:ppn=16,gres=widow2

cd $PBS_O_WORKDIR
date
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PBS_O_WORKDIR

sort $PBS_NODEFILE | uniq > ./TEMP.NODEFILE

n=`wc -l ./TEMP.NODEFILE |awk '{print $1}'`
for((i=1;i<=$n;i++)); do j=`expr $i - 1`; sed -n ''$i','$i'p' ./TEMP.NODEFILE > host.$j; done

$MPI -np 1 --hostfile host.0 $NAMD ./w1_md3_resid_100.namd > ./w1_md3_resid_100.namd.out &
$MPI -np 1 --hostfile host.0 $NAMD ./w1_md3_resid_101.namd > ./w1_md3_resid_101.namd.out &
....
$MPI -np 1 --hostfile host.0 $NAMD ./w1_md3_resid_174.namd > ./w1_md3_resid_174.namd.out &
$MPI -np 1 --hostfile host.1 $NAMD ./w1_md3_resid_175.namd > ./w1_md3_resid_175.namd.out &
....
$MPI -np 1 --hostfile host.1 $NAMD ./w1_md3_resid_246.namd > ./w1_md3_resid_246.namd.out &
$MPI -np 1 --hostfile host.2 $NAMD ./w1_md3_resid_247.namd > ./w1_md3_resid_247.namd.out &
$MPI -np 1 --hostfile host.2 $NAMD ./w1_md3_resid_251.namd > ./w1_md3_resid_251.namd.out &
..

and so on.

Friday, May 6, 2011

Conditional plots in R

This link says it all.

 Al - 19 Jan 2007 15:33 GMT
Hi!
Given a 1000x2 matrix x, i.e. 1000 2d-points. How can I directly (!)
plot/visualize only those which fulfill a certain condition, say
x[,1]>0 & x[,2]>0?
Thanks,
Al
Marc Schwartz - 19 Jan 2007 21:24 GMT
> Hi!
> Given a 1000x2 matrix x, i.e. 1000 2d-points. How can I directly (!)
> plot/visualize only those which fulfill a certain condition, say
> x[,1]>0 & x[,2]>0?
> Thanks,
> Al

First, R specific programming queries are best posted to the r-help
list. More information at:

http://www.r-project.org/

under the Mailing Lists link.

Second, the easiest way to do this is to subset the data while using
plot.formula(), which is a plot method that will be dispatched if the
first argument to plot() is a formula, such as 'y ~ x'. See ?plot and
?plot.formula for more information.

As an example, let's create a data frame with 2 columns and 1000 rows,
each column comprised of 1000 random normal deviates:

DF <- data.frame(x = rnorm(1000), y = rnorm(1000))
> str(DF)
'data.frame': 1000 obs. of 2 variables:
$ x: num -0.0265 0.1554 -0.1050 -0.9697 -0.3430 ...
$ y: num 1.386 -1.356 -1.170 0.426 0.204 ...

Now, let's plot the data meeting the criteria you indicated above:

plot(y ~ x, data = DF, subset = (x > 0) & (y > 0))

This says to generate a scatter plot, using 'DF' as the input data set,
and specifying the logical subset where x and y are both > 0. Modify
the subset argument as you require.

Note that in this usage, the 'data' argument must be a data frame. So
you could coerce your matrix (if needed) by using:

DF <- as.data.frame(matrix)

HTH,

Marc Schwartz

And this is the way (ex.) to get the length of the array that satisfies the conditions.
sum((x > 0) & (y > 0), na.rm=TRUE)

Wednesday, May 4, 2011

Custom replacements in VI

Thanks to Steve for this pearl of VI wisdom.
For search and replace operation in VI, parenthesis remembers the item. This can be used for custom replacements later. Try the command below on a file with this data:

29 5 2010
30 6 2011

:1,$s/[0-9]* \([0-9]*\) \([0-9]*\)/\2 \1/
VI can remember 9 such fields.

Monday, April 11, 2011

Potential Energy Scans with NWChem

While performing PES on dihedrals of relatively large molecules using NWchem, one can get stuck during the minimization process. Possible ways to overcome those problems are:
1. Try a smaller step size
2. Use the "tight" function in the driver
3. Redo everything with a smaller molecule that can mimic the dihedral in question

Tuesday, March 1, 2011

Useful "vi" tips

1. If you want to merge rows ( for exp. row 1 to 20 ) do:
:1,20 j
2. To replace string with a new line
:%s/ TI/^MTI
To get ^M use following
Hold down the Ctrl, and press v m
DO NOT USE Shift+6 and Shift+M
3. To move a string to a new line w/o hitting Enter, do this;
:s/string/\r&/g

Friday, February 25, 2011

Flush VMD

While running VMD analysis scripts over large number of trajectories, it is a good idea to free up memory after every step like so:
for {set j 1} {$j < 101} {incr j}
{
mol addfile /.$j.dcd first 0 last -1 waitfor all
set ca [atomselect top "name CA"]
set cb [atomselect top "name CB"]
....
$ca delete
$cb delete
animate delete all
}
The last three lines will make life much better.

Wednesday, January 19, 2011

Using Bit Bucket

Following my friend's recommendation I decided to check out this site called Bit Bucket which is a free code sharing/hosting website where one can essentially store their code and any changes they make to that file. Following are the steps to get things up and running:
1. Install Mercurial (if you don't already have it)
2. Open an account with https://bitbucket.org
3. Create a repository on bitbucket.org. Let's call it bit_repo.
4. Create a /home/user/.hgrc file with the following lines on your desktop.
[ui]
; editor used to enter commit logs, etc. Most text editors will work.
editor = vi
username = firstname lastname
5. cd in to a directory on your desktop which contains codes that you want to backup.
5.1. Type> hg clone https://
bitbucket_user_id@bitbucket.org/bitbucket_user_id/bit_repo
destination directory: bit_repo
http authorization required
...
Then cd
bit_repo
6. To add a specific file to Bitbucket, type
hg add file1.c
hg commit -m "I commit to add this file to bitbucket" [The msg in quotes can by anything]
hg push https://bitbucket_user_id@bitbucket.org/bitbucket_user_id/bit_repo
7. To remove a file type
hg remove file2.c
hg commit -m "I commit to remove this file"
hg push https://bitbucket_user_id@bitbucket.org/bitbucket_user_id/bit_repo
8. To copy files/repositories from bitbucket, type
hg clone https://bitbucket_user_id@bitbucket.org/bitbucket_user_id/bit_repo
9. Here is a Bitbucket 101 http://confluence.atlassian.com/display/BITBUCKET/Bitbucket+101
10. To keep things safe I would just softlink files to their sources on my desktop.