Chemharp is a multi-language library written in modern C++ for reading and writing
from and to molecular trajectory files. These files are created by your favorite
theoretical chemistry program, and contains informations about atomic or residues
names and positions. Some format also have additional informations, such as
velocities, forces, energy, …
The main targeted audience of Chemharp (libchemharp) is chemistry researcher
working on their own code to do some kind of awesome science, without wanting to
bother about handling all the format that may exist in the world.
Running simulation (either Quantum Dynamic, Monte Carlo, Molecular Dynamic, or
any other method) often produce enormous amounts of data, which had to be
post-processed in order to extract informations. This post-processing step involve
reading and parsing the data, and computing physical values with the help of
statistical thermodynamic. Chemharp tries to help you on the first point, by providing
the same interface to all the trajectory formats. If you ever need to change your
output format, your analysis tools will still work the same way. Chemharp is
efficient because it allow you to write and debug your code only once, and then
to re-use it as needed.
The Chemharp library tries to:
Chemharp have been tested on the following platforms, with the following compilers :
If you manage to compile Chemharp on any other OS/compiler/architecture
combination, please let me know so that I can add it to this list.
| Format | Read ? | Write ? |
|---|---|---|
| XYZ | yes | yes |
| Amber NetCDF | yes | yes |
The following formats are supported through the VMD molfile plugins, and are read-only:
| Format | Read ? | Write ? |
|---|---|---|
| PDB | yes | no |
| Gromacs .gro | yes | no |
| Gromacs .xtc | yes | no |
| Gromacs .trj | yes | no |
| Gromacs .trr | yes | no |
| CHARMM DCD | yes | no |
See the issue list for
planned formats. If you want a new format to be added to Chemharp, you can either
do it by yourself (it is easy !) and create a pull-request to incorporate your
changes, or create a new issue with a link to the format reference and some
example of well-formed files.
The whole installation is documented here, this page only
show the basic steps. Please refer to the link below in case of problem.
Long story made short, just use the right commands for your system:
# On apt-get based distributions
apt-get update
apt-get install cmake libnetcdf-dev libboost-filesystem-dev libboost-dev
# On yum based distributions
yum install epel-release # The EPEL repository have the netcdf lib
yum install cmake netcdf-devel netcdf-cxx-devel boost-devel boost-filesystem
# On OS X with Homebrew (brew.sh)
brew tap homebrew/science
brew install cmake netcdf boost
You will also need a recent C++ compiler: gcc 4.9, clang 3.5 and icpc 14 are
known to work.
Get the code from the release page,
and extract the archive. Then in a terminal, go to the folder where you put the
code (~/Chemharp is assumed here):
cd ~/Chemharp
Then, cmake is used to build the code. So, create a folder
and go for the build:
mkdir build
cd build
cmake ..
Then, you can build install the library:
make
make install
For more informations about how to configure the build, and how to build the
bindings to Python or Fortran, please read the doc!
The documentation is hosted at readthedocs, but here is an example of how the API feels like in C++:
#include <iostream>
#include "Chemharp.cpp"
using namespace harp;
int main() {
Trajectory traj("filename.xyz");
Frame frame;
traj >> frame;
std::cout << "There is " << frame.natoms() << " atoms in the frame" << std::endl;
auto positions = frame.positions();
// Do stuff here with the positions
}
And in C:
#include <stdint.h>
#include <stdio.h>
#include "chemharp.h"
int main(){
CHRP_TRAJECTORY *traj = chrp_open("filename.xyz", "r");
CHRP_FRAME *frame = chrp_frame(0);
size_t natoms = 0;
int status;
if (!traj) {
printf("Error while reading: %s", chrp_last_error());
}
status = chrp_trajectory_read(traj, frame);
if (!status){
/* handle error here */
}
chrp_frame_size(frame, &natoms);
printf("There is %d atoms in the frame", natoms);
float (*positions)[3] = (float(*)[3])malloc(sizeof(float[natoms][3]));
if (!chrp_frame_positions(frame, positions, natoms)){
/* handle error */
}
/* Do awesome things with the positions here ! */
chrp_frame_free(frame);
chrp_close(traj);
}
All this code is copyrighted by Guillaume Fraux, and put to your disposition
under the terms of the Mozilla Public License v2.0.