Building the VMD molfile plugin

I don’t know how many of you have hit that particular snag before, but it’s not my first time trying to compile the molfile plugin from VMD using the source code. Here a step-by-step guide on how to do that on a linux 64 bit machine (Centos 7.4 in my case).

What is the molfile plugin?

VMD is a very popular tool to analyze molecular dynamics, but also run some 3D modeling tasks. It can read a ton of different formats, especially very complicated and diverse MD trajectory formats. And this is achieved using the molfile plugin. So, the day you want to integrate a parser for yet another exotic file format that a PhD student in a lab on the other side of the world developed … well think twice and check if you rather could use a library like the molfile plugin.

For example, we now also use the molfile plugin in fpocket to read XTC, netcdf and dcd trajectories.


Where to get the plugin from:

You should download VMD from the official VMD website. Make sure to download the source code distribution. Here I’m documenting compilation of the molfile plugin included in vmd 1.9.3

Official documentation:

You can find the official plugin install documentation here. It’s pretty sparse and not straightforward to use and not very well adapted for modern linux distributions with package management systems. Anyway, for the sake of completeness you can find the current official documentation here:

https://www.ks.uiuc.edu/Research/vmd/plugins/doxygen/compiling.html#compiling

How to build it on a Centos 7.4 (for Mac OSX see below):

First let’s install a few prerequisites on the system

yum install -y tcl-devel netcdf-devel gcc-c++  

define the two following environment variables in your shell (I use bash here)

export TCLINC=/usr/include
export TCLLIB=/usr/lib64
export NETCDFINC=/usr/include
export NETCDFLIB=/usr/lib64/libnetcdf.so

Extract the tar.gz with the vmd source code. The following commands will be carried out in the plugins directory that you’ll find once you extracted the tar.gz downloaded from the VMD website.

cd plugins
gmake LINUXAMD64 TCLINC=$TCLINC TCLLIB=$TCLLIB/libtcl.so
export PLUGINDIR=/home/peter/molfile/compiled
gmake distrib

The commands above will build (the first gmake) and then copy to a common directory tree (PLUGINDIR) the compiled library files.

Your final result in the copiled/LINUXAMD64/molfile directory should look somehow like this :

Final compiled molfile plugin

Once you have this you can use the libmolfile_plugin.h and static library to link it into your own code. Rather well done and pretty easy to use through a common interface.

Check out how this can be used reading MD formats in mdpocket for instance, just to give you an idea ;)

https://github.com/Discngine/fpocket/blob/master/src/mdpocket.c


Happy compiling. And thanks a lot to the Theoretical and Computational Biophysics Group of the UIUC for making these great things available!


How to build it for Mac OSX 64 bit

On mac things are a bit trickier. Here i went for a self compiled tcl using clang and compiling the molfile plugin using clang as well.

You can get the source code for tcl from here. Note VMD used the hard coded version of 8.5, so please stick to 8.5:

http://www.tcl.tk/software/tcltk/downloadnow85.html

Extract the source tar.gz into a folder of your choice

cd tcl8.5.19/macosx
CC=clang ./configure
make -f Makefile
sudo make install -f Makefile

This will configure the makefile to use clang instead of gcc or cc. Run the make command with the explicit makefile. Else, for whatever reason, the configure script is run again, this time without your choice of compiler and it basically supersedes the choice you just did before.

Last deploy the compiled library and headers to your system (not mandatory, you just need to figure out where the libtcl8.5.dylib and the tcl.h are located.

After the make install command you can define the TCLINC and TCLLIB environment variables:

export TCLINC=/usr/local/include
export TCLLIB=/usr/local/lib

This step if optional, but if you want to have mdpocket support for NETCDF trajectories, then you’d need that. As the netcdf library has dependencies with hdf5 and zlib...I used macports to install this here.

sudo port install netcdf

My macports installs things into /opt/local. You can know where what is by typing "port contents netcdf".

Now we have to make the NETCDF environment variables point to the correct locations before the build:

export NETCDFINC=-I/opt/local/include
export NETCDFLIB=/opt/local/lib/libnetcdf.dylib
export NETCDFLDFLAGS=-lnetcdf

Extract the tar.gz with the vmd source code. The following commands will be carried out in the plugins directory that you’ll find once you extracted the tar.gz downloaded from the VMD website.

cd plugins
gmake MACOSXX86_64 TCLINC=$TCLINC TCLLIB=$TCLLIB/libtcl8.5.dylib
export PLUGINDIR=/home/peter/molfile/compiled
gmake distrib

The commands above will build (the first gmake) and then copy to a common directory tree (PLUGINDIR) the compiled library files.

Your final result in the copiled/MACOSXX86_64/molfile directory should look somehow like this :

Screen Shot 2019-05-26 at 22.10.41.png

Once you have this you can use the libmolfile_plugin.h and static library to link it into your own code. Rather well done and pretty easy to use through a common interface.

Check out how this can be used reading MD formats in mdpocket for instance, just to give you an idea ;)

https://github.com/Discngine/fpocket/blob/master/src/mdpocket.c

Happy compiling. And thanks a lot to the Theoretical and Computational Biophysics Group of the UIUC for making these great things available!


3decision’s blog has been moved!