Thursday, January 31, 2013

Sweave, R and Latex

If you use R for your statistical analysis and graph plotting needs and then use those figures in your Latex documents, you will find this interesting. Sweave is a package in R which lets takes in an .rnw file (which contains usual text from a tex document with R commands embedded in it), compiles it (in R) and gives out a tex file. This tex file can in turn be compiled by pdflatex (if you have figures) or plain latex to get a properly formatted pdf/ps/dvi file with relevant R output. There are many excellent examples on the interwebs and I strongly recommend using Sweave right away.  The beauty of this approach is that on can save a lot of time by not spending on choosing the appropriate dimensions of a a png or an eps output. Sweave does it for you.

Edit: If you want to insert a R-generated figure then add this to your tex file:

\begin{figure}
\begin{center}
<
\end{center}
\end{figure}


If you want to insert text from R but properly tabbed and with all the ampersands added, then add these lines to your tex file:

<

Tuesday, January 29, 2013

Manipulating dihedral angles in VMD

VMD's scripting interface is quite powerful. It has a trans bond command which gives the transformation matrix required to achieve desired dihedral rotation. If you want to edit the dihedral 1-2-3-4 (i.e. rotate around bond 2-3), then you first select the set of atoms on which the transformation is to be applied; 1,2,5,6,7,8,9 in this case. To this selection you apply the transformation;

$moveselection move [trans bond [lindex [$a1 get {x y z}] 0] [lindex [$a2 get {x y z}] 0] 10 deg]

trans bond expects only the atom indices. The value 10 indicates the magnitude and sign of change to the dihedral 1-2-3-4. deg says the change should be in degrees and not radians. To get a nice picture of rotation around a bond use this script:

set movesel [atomselect top "index 1 2 5 6 7 8 9"]
for {set i 0} {$i <360 } {incr i 10}

{
$movesel move [trans bond [lindex [$a1 get {x y z}] 0] [lindex [$a2 get {x y z}] 0] 10 deg]
render TachyonInternal [format "rotate%03d.tga" $i]
}

Friday, January 25, 2013

Joining multiple pdf files in Linux

gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=finished.pdf file[1-3].pdf

This is a great way to join many pdf files into one file. Mac's Preview has another way to do the same but in a much easier drag-and-drop fashion. The line below in my .bashrc file helps automate the concatenation process.

alias join='gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=awkwardName.pdf'

Thursday, January 24, 2013

time and script

These are great commands in Linux while debugging and timing codes.

Monday, January 21, 2013

Combining figures into one PDF file


convert -compress JPEG *.jpg output.pdf
convert -compress Zip *.jpg output.pdf

Both the commands join a bunch of jpeg files into one pdf file. This came in handy recently. Dropping the compress flag and its options gave a smaller file. Might look into it later.

convert *.jpg output.pdf

Sunday, January 6, 2013

Bibtex being bibtex

Do you notice any difference between this:


@article{Dashnau2007Computational,
    abstract = {.....}
    author = {Dashnau, J. L. and Vanderkooi, J. M.},
    journal = {J. Food Sci.},
    month = jan,
    number = {1},
    pages = {R001--R010},
    title = {{Computational Approaches to Investigate How Biological Macromolecules Can Be Protected in Extreme Conditions}},
    volume = {72},
    year = {2007}
}

and this:


@article{Dashnau2007Computational,
    abstract = {.....}
    author = {Dashnau, J. L. and Vanderkooi, J. M.},
    journal = {J. Food Sci.}
    month = jan,
    number = {1},
    pages = {R001--R010},
    title = {{Computational Approaches to Investigate How Biological Macromolecules Can Be Protected in Extreme Conditions}},
    volume = {72},
    year = {2007}
}

Well, I couldn't either. Notice the comma at the end of the journal entry? Well without the comma Bibtex ignores the ensuing metadata creating problems when compiling your document. Something to be careful about.