IMOD - compiling IMOD version 3

From NoskeWiki
Jump to: navigation, search


NOTE: This page is a daughter page of: IMOD

WARNING: This page shows how to build an outdated version of IMOD. This page was written in late 2007, when IMOD was still in version 3, but since then IMOD has moved into version 4 and undergone several significant changes in how it compiles and what libraries are needed. For instructions on how to build the IMOD version 4 you should immediately go the page: IMOD - compiling. I have left this page alive purely for record-keeping purposes.

During my PhD in cell biology and electron tomography I wanted to compile the program IMOD in order to add functionality to help me segment data faster. Compiling the IMOD source code is quite tricky, but in late Nov 2007 I visited David at the University of Colorado in Boulder and he showed me how to set it up on OS X so that I could compile and add a "special module". On this page I documented that process and the libraries I needed.

Installing on OS X

(1) Install libtif

  • Download latest version from here (I used tiff-3.8.2.tar)
  • Unzip anywhere (doesn't matter where you install from and can delete later).
sudo make install
  • NOTE: No need to use flags

(2) Install gfortan

  • Install g77 v 3.4.4 with gfortran from here: David's code (which he adapted from here), and unzip "usr". Then run:
sudo cp -R /Users/a.noske/Desktop/LIBRARIES/usr/ /usr/
sudo ranlib /usr/lib/libfrtbegin.a
sudo ranlib /usr/lib/gcc/powerpc-apple-darwin7.9.0/3.4.4/libgcc.a 
  • The first line copies a whole bunch of files including g77 and "powerpc-apple-darwin7.9.0" to bin, lib and libexec
  • The next lines update the library on the machine
  • NOTE: gfortran was already installed on my MacBook Pro by ITS, so we skipped this step
  • NOTE: you can download the latest gcc source from here: here / ftp - however I have never got this working and I can't find gfortran 4.3.0 experimental anywhere
  • NOTE: on PowerPC you must be careful because OSX has its own Apple version of gcc - and so I installed from here: gfortran-4.2.1.dmg and had to add "/usr/local/bin" to PATH - but I think David's option is better.

(3) Install Qt 3

WARNING: Around late 2008 IMOD change from using Qt version 3.3 to Qt version 4.4.3.

sudo mv qt-mac-free-3.3.6 /usr/local/
cd /usr/local/qt-mac-free-3.3.6/

setenv QTDIR /usr/local/qt
setenv PATH $QTDIR/bin:$PATH

sudo gcc_select 3.3
./configure -fast -no-exception -thread
make -j2
sudo gcc_select 4.0
  • NOTE: you should change to 3.3 compiler BEFORE compiling qt, but probably need to change to 4.0 else get a "cannot exec 'cc1plus' error"
  • NOTE: the -j2 option is if you have a dual processor - make goes faster | -no-exception and -fast you can remove.
  • "sudo make install" shouldn't be necessary because we copied the thing to /usr/local/
  • NOTE: to make these Qt environmental variables instantiate in all new Terminal windows we must add them to .cshrc, which we do in the next step

(4) Use CSV to copy IMOD source code from the SIMBA server in Boulder

  • Assuming you are using tsh/csh (type echo $SHELL to check) we now change .cshrc:
cd ~
pico .cshrc
  • And paste this:
setenv QTDIR /usr/local/qt-mac-free-3.3.6
setenv PATH $QTDIR/bin:$PATH
setenv QMAKESPEC macx-g++

#setenv CVSROOT ''
setenv CVSROOT ':ext:tempuser@simba:/home/cvsroot'
setenv CVS_RSH ssh
  • Close and reopen Terminal -> now environmental variables for Qt will be set and a root for CVS so we can download the latest IMOD source.
  • Open Terminal and copy source into "Documents\MACMOD" (useful to name it this):
cd ~/Documents/
cvs co -P -d MACMOD IMOD
  • NOTE: -P prunes empty directories, -d is the dir name, IMOD is the item to get from the server
  • NOTE: To get this working you will need David to give you a temp user password... furthermore, if you are working outside of the Bio3D institute (as I am) you will need to change the CSVROOT to "" and give David the IP of your computer he can add it to a list of trusted IP addresses and gain access to the SIMBA server (which has the cvs system).
  • NOTE: if you are using bash, you can change to csh by typing csh. Or change your environment variables in bash by entering pico ~/.profile then adding this code instead:
export QTDIR
export PATH
export CVSROOT
export CVS_RSH

(5) Setup and build IMOD

  • Setup and compile code:
cd ~/Documents/MACMOD/
./setup -c gcc
make -j2
make install ./installqtlib
  • NOTE: If you are running IMOD from an install in a source tree, you need to run ./installqtlib after make install, otherwise the help windows won't work
  • And now you can edit code and recompile.
  • To update with latest (changed) code from SIMBA:
cvs update -Pd
  (then enter password)
  • WARNING: Before compiling you should check that QTDIR is correct using echo $QTDIR. If you already have imod installed under /Applications/IMOD/ you will need to change several environmental variables in this Terminal window first:
setenv IMOD_DIR /Users/a.noske/Documents/MACMOD
setenv IMOD_PLUGIN_DIR $IMOD_DIR/lib/imodplug
setenv IMOD_CALIB_DIR /usr/local/ImodCalib
setenv PATH $QTDIR/bin:/usr/local/:$IMOD_DIR/bin:/bin:/sbin:/usr/bin:/usr/sbin
  • To copy back files to the SIMBA server:
cd /Users/a.noske/Documents/MACMOD/plugs/
cvs add drawingtools
cd /Users/a.noske/Documents/MACMOD/plugs/drawingtools/
cvs add drawingtools.h
cvs add drawingtools.cpp
cvs add Makefile
cvs commit


cvs commit -m 'type comment' [filename]
  • NOTE: after "cvs commit" it opens a log file which lets you add comments.... it opens in VIM by default: and to close vim you can type: [esc] (to enter character mode) and then type :w to save, :wq to save and quit, or :q! to quit without saving. VIM cheat sheet
  • You can also commit from within emacs, Ctrl X - Ctrl Q

Creating a new "special plugin"

  • Go to the "plugs" source directory (".../MACMOD/plugs/") and copy the whole folder "beadfix" to "interpolator" (or whatever special module you want) in the same dir
  • Rename everything in the new folder from "beadfixer", "beadfix" and "Bead Fixer" to "interpolator" - including the entries in "Makefile"
  • NOTE: I use Xcode for editing code on a Mac, but anything will do
  • Edit the Makefile in the plugs folder (up a directory) -> add lines to compile the new folder
  • To compile just this new plugin:
cd /Users/a.noske/Documents/MACMOD/plugs/drawingtools/ 
make clean && make install
  • Or if I want to install and test:
make install && 3dmod -C 0 -E P,1,2 /Users/a.noske/Desktop/test.rec /Users/a.noske/Desktop/test.mod 
  • This will compile the plugin into a dynamic library drawingtools.dylib which will be opened when 3dmod is run
  • Unlike a "free standing plugin", which is part of the program (compiled with the rest), these "special plugins" don't include complete structures - just empty definitions which they call from the dynamic libraries.
  • Using the -E optional argument you can open most dialogs and David has added the feature to open every "true plugin" under IMOD_PLUGIN_DIR if you add "-E P". He also added "1" to start in model mode and "2" to suppress query to save on exit.
  • In the new directory is "imodplug.h", "model.h", "imodview.h" and several other useful files which are included... (i.e. plugin has its own version). There were a few functions and constants/defines in cont.h which I needed which were not in "model.h", but adding them was not particularly difficult.

Using your special plugin on other computers

  • To copy your plugin simply go to the lib directory and copy the dynamic library (".../MACMOD/lib/imodplug/drawingtools.dylib"), and copy it to the same directory on another computer.
  • NOTE: You should make sure the same version of IMOD is installed on both computer (or else certain function calls might be missing).
  • NOTE: You will need to compile separately for Intel and PowerPC Macs - which is a pain....

Extra tips

  • David showed me how it was possible to use ssh-keygen such that I don't need to enter my tempuser password each time.
ssh-keygen -t dsa
scp ~/.ssh/ tempuser@simba:
ssh tempuser@imba
  • NOTE: the file is users/anoske/.ssh/ .... and then David needs to somehow approve this on the server..... I don't really understand it but I'm sure Pete does.

(5) Use CSV to copy IMOD source code from the SIMBA server in Boulder (SIMPLER INSTRUCTIONS)

You are now ready to compile IMOD. To get a copy of the IMOD source code, the easiest option is to request david email you zipped file and unzip this it to a directory such as "/Users/anoske/Documents/MACMOD". If, however you would like to contribute code to IMOD you should think about requesting access to the cvs system he has setup... allowing you to check code in and out. Keep in mind this may not be granted to everyone, since there is a chance of stuffing up his code!

To enable CVS we have already added these two lines to .cshrc:

setenv CVSROOT ':ext:tempuser@simba:/home/cvsroot'
setenv CVS_RSH ssh
  • To use CVS to transfer a fresh copy of the latest code you'll need to execute these commands:
cd ~/Documents/
cvs co -P -d MACMOD IMOD

This cvs command creates a new directory called "MACMOD" at "/Users/anoske/Documents/MACMOD" and imports all the latest code from Boulder. Other CVS commands you may want to use are as follows:

  • To update with latest (changed) code from SIMBA:
cd ~/Documents/MACMOD/
cvs update -Pd
  (then enter password)
  • To copy back files to the SIMBA server:
cd /Users/a.noske/Documents/MACMOD/plugs/
cvs add drawingtools
cd /Users/a.noske/Documents/MACMOD/plugs/drawingtools/
cvs add drawingtools.h
cvs add drawingtools.cpp
cvs add Makefile
cvs commit -m 'type comment' [filename]