Pages

2012-02-12

Installing AmberTools 1.5 on OS X 10.6 (Snow Leopard)

I'm doing some volunteer work in the Meiering lab at UWaterloo this winter, and one of the packages I need to do molecular simulations and analysis is AmberTools, a set of command line tools that complement Amber.  For my purposes, I just need AmberTools in order to manipulate Amber files I get from the lab.  (I don't need Amber itself.)

I'm installing AmberTools 1.5 on my MacBook Pro with OS X Snow Leopard (10.6.8).  Here are some notes about the process.

Warning:  This should not be read as a guide to installation because I'm documenting my mistakes as I go.  Best to read the whole thing first and learn from my mistakes if you're working at installing AmberTools yourself.

Environment Variables
I need to set the AMBERHOME variable and include $AMBERHOME/bin in my path. I added the following lines to my .profile:
export AMBERHOME=[path to my AmberTools dir]
PATH="${AMBERHOME}/bin:${PATH}"

X11
X11 needs to be installed in order to build AmberTools.  In addition, the AmberTool configure script isn't looking in the right place to detect X11 on my machine.  I had to add a line (line 4 below) to the X11 detection code in the configure script:
if [ -r "$xhome/lib/libXt.a"  -o -r "$xhome/lib/libXt.dll.a" \
     -o -r /usr/lib/libXt.so \
     -o -r /usr/lib64/libXt.so \
     -o -r /usr/X11/lib/libXt.dylib \
     -o "$x86_64" = 'yes' -a -r "$xhome/lib64/libXt.a" ]

What?  No gcc?
I guess when I installed Xcode I forgot to include unix developer tools in the installation setup because my machine wasn't able to find gcc.  Blast!  Ok... Download Xcode 4; install, and make sure the Unix Developer Tools option is included in the installation setup.  Good.

Also need gfortran...
So gcc is up and running.  Great.  Back to my AmberTools directory and 
./configure -macAccelerate gnu
which eventually yielded the message
gfortran: command not found
Looks like I need to install a Fortran compiler. Done.

...and libgfortran 
Try the configure command again...a new message:
ld: library not found for -lgfortran
Ah. My Fortran libraries are not being seen. Probably some sort of environment variable / path assumptions not being met. Creating a soft link to the newly installed libgfortran in my /usr/local/lib directory did the trick for me:
sudo ln -s /usr/local/gfortran/lib/gcc/x86_64-apple-darwin10/4.6.2/libgfortran.dylib /usr/local/lib/libgfortran.dylib
Now the configuration step passes!  Woo!

Patch AmberTools 
So then I did a
sudo make install
and the build failed with a bunch of messages like this:
Warning: Type mismatch in argument 'isp' at (1); passed REAL(8) to 
INTEGER(4) 
_amg1r5.f:3619.17: 

   external cgalf,cgeps,ctime 
                 1 
Error: Return type mismatch of function 'cgalf' at (1) (REAL(8)/REAL(4)) 
_amg1r5.f:3619.23: 

   external cgalf,cgeps,ctime 
                       1 
Error: Return type mismatch of function 'cgeps' at (1) (REAL(8)/REAL(4)) 
make[1]: *** [amg1r5.o] Error 1 
make[1]: Leaving directory `/home/own/Documents/amber11/AmberTools/src/pbsa' 
make: *** [serial] Error 2 
Well okay then. After some googling and reading of mailing list threads I found a page of bugfixes for AmberTools from which I downloaded bugfix.all to my AMBERHOME directory and applied with the command
patch -p0 -N <bugfix.all
(There was also some indication that AmberTools does not compile under gfortran 4.6, which is what I just installed, but I decided to just try building after the patches were applied before worrying about building an older fortran compiler.  Happily, the patches seemed to work resolve the above error.)

The build!
And here we go again...
./configure -macAccelerate gnu
...and this time it passes and I notice this message:
The next step is to type 'make serial'
So let's do that:
sudo make serial
Fail:
AMBERHOME is not set.  Assuming it is /Users/rod/Documents/Research/Meiering/amber11
 Using AmberTools' python
Error importing MMPBSA python modules! MMPBSA.py will not work.
But I thought I set AMBERHOME above... grumble grumble google grumble google, aha! The environment isn't retained by default on a sudo; I need to use the -E option, like so:
sudo -E make serial
Aaaaand yes! It builds successfully now.

2012-02-04

A PubNub Stub

Stumbled across PubNub at work the other day.  Neat stuff.  Really easy to create distributed web apps.  Observe:

<html>
<body>
<div id="out">Click subscribe to subscribe to the messages sent by the "Send message" button.</div>
<form>
<button onclick="subscribe(); return false;">Subscribe</button>
<button onclick="sendMessage(); return false;">Send message</button>
</form>

<div pub-key="demo" sub-key="demo" ssl="off" origin="pubsub.pubnub.com" id="pubnub"></div>
<script src="http://cdn.pubnub.com/pubnub-3.1.min.js"></script>
<script src="demo.js"></script>
</body>
</html>
And the javascript:
function subscribe() {
    PUBNUB.subscribe({
        channel     :   "test",
        error       :   function() { alert("Connection lost.  Will auto-reconnect when Online."); },
        callback    :   function(msg) { PUBNUB.$("out").innerHTML = msg; },
        connect     :   function() { alert("Connected!"); }
    });
}
var i = 0;
function sendMessage() {
    PUBNUB.publish({
        channel     :   "test",
        message     :   "You've clicked the button "+i+" time"(i==1?"":"s")+"!"
    }); 
    i = i + 1;
}
Let's break it down a bit:

The HTML's pretty straightforward.  A div that we'll alter with the innerHTML property, and a couple buttons tied to the subscribe and sendMessage functions, respectively.  (We could just as easily subscribe on page load.)

The javascript is the interesting bit.  There are really only two PubNub API calls you need to know:  subscribe and publish.  Both functions take an object requiring a few simple properties.

Subscribe:

  • channel - Any name you like.  You subscribe to a channel, and any messages published to that channel are received as the argument to the function attached to the callback property.
  • error - A callback for when errors occur.
  • callback - The function that gets called when a message is published to that subscribed-to channel
  • connect - A callback that notifies you when the connection to PubNub has been established
Publish:
  • channel - The name of the channel to publish to
  • message - The message to send
Simple as that!  You'll note that they've even provided jQuery-like access to the DOM, so you can do things like
PUBNUB.$("out").innerHTML = msg.

You can get publisher and subscriber keys that you put in the pub-key and sub-key attributes of the pubnub div by going to pubnub.com.  Go ahead and try loading the code above in a couple browsers.  In a couple browsers on different machines, even, and enjoy the simplicity of distributed communication with PubNub!