IMP logo

Developer Guide

This page presents instructions on how to develop code using IMP. Developers who wish to contribute code back to IMP or distribute their code should also read the Contributing code to IMP page.

  1. Getting around
  2. Writing new functions and classes
  3. Debugging and testing your code
  4. Coding conventions
  5. Documenting your code
  6. Useful scripts
  7. Contributing code back to the repository
  8. Good programming practices
  9. Where to go next

1. Getting around

The input files in the IMP directory are structured as follows:

When IMP is built, the build directory is created and filled with the results of the build. build contains a number of subdirectories. They are

Unfortunately, various intermediate files from the build are scattered throughout the module and kernel hierarchies. This messiness is part of the reason we strongly recommend doing an out of source build.

When IMP is installed, the structure from the build directory is moved over more or less intact except that the C++ and python libraries are put in the (different) appropriate locations.

Writing new functions and classes

The easiest way to start writing new functions and classes is to create a new module using the make-module script. This creates a new module in the modules directory, complete with example code.

We highly recommend using a revision control system such as Subversion or GIT to keep track of changes to your module.

If, instead, you choose to add code to an existing module you need to consult with the person who people who control that module. Their names can be found on the module main page.

When designing the interface for your new code, you should

You may want to read the design example for some suggestions on how to go about implementing your functionality in IMP.

Debugging and testing your code

Ensuring that your code is correct can be very difficult, so IMP provides a number of tools to help you out.

The first set are assert-style macros:

See Error reporting/checking page for more details. As a general guideline, any improper usage to produce at least a warning all return values should be checked by such code.

The second is logging macros such as:

Finally, each module has a set of unit tests. These are python scripts which test the behavior of a particular piece of the modules API. The scripts are located in the modules/modulename/test directory. These tests should try, as much as possible to provide independent verification of the correctness of the C++ code. The command

 scons test 
or
 scons modulename-test 
run all modules unit tests or only those for the module modulename, respectively. Any file in that directory or a subdirectory whose name matches test_*.py is considered a test. The python files are scanned for classes which inherit from IMP.test.TestCase. For each such class found, any method whose name starts with test_ is run.

Some tests will require input files or temporary files. Input files should be placed in a directory called input in the test directory. The test script should then call

 self.get_input_file_name(file_name) 
to get the true path to the file. Likewise, appropriate names for temporary files should be found by calling
 self.get_tmp_file_name(file_name) 
. Temporary files will be located in build/tmp. The test should remove temporary files after using them.

Coding conventions

Make sure you read the API conventions page first.

To ensure code consistency and readability, certain conventions must be adhered to when writing code for IMP. Some of these conventions are automatically checked for by source control before allowing a new commit, and can also be checked yourself in new code by running

 scons standards 

Indentation

All C++ headers and code should be indented in 'Linux' style, with 2-space indents. Do not use tabs. This is roughly the output of Artistic Style run like
 astyle --convert-tabs --style=linux --indent=spaces=2 --unpad=paren --pad=oper 
. Split lines if necessary to ensure that no line is longer than 80 characters.

Rationale: Different users have different-sized windows or terminals, and different tab settings, but everybody can read 80 column output without tabs.

All Python code should conform to the Python style guide. In essence this translates to 4-space indents, no tabs, and similar class, method and variable naming to the C++ code. You can ensure that your Python code is correctly indented by using the

 tools/reindent.py 
script, available as part of the IMP distribution.

Names

See the names section of the IMP conventions page. In addition, developers should be aware that Rationale: This makes it easier to tell between class names and function names where this is ambiguous (particularly an issue with the Python interface). The Python guys also mandate CamelCase for their class names, so this avoids any need to rename classes between C++ and Python to ensure clean Python code. Good naming is especially important with preprocessor symbols since these have file scope and so can change the meaning of other people's code.

Passing and storing data

Display

All classes must have a show method which takes an optional std::ostream and prints information about the object (see IMP::Object::show() for an example). The helper macros, such as IMP_RESTRAINT() define such a method. In addition they must have operator<< defined. This can be easily done using the IMP_OUTPUT_OPERATOR() macro once the show method is defined. Note that operator<< writes human readable information. Add a write method if you want to provide output that can be read back in.

Errors

Classes and methods should use IMP exceptions to report errors. See IMP::Exception for a list of existing exceptions. See assert for a list of functions to aid in error reporting and detection.

Namespaces

Use the provided IMPMODULE_BEGIN_NAMESPACE, IMPMODULE_END_NAMESPACE, IMPMODULE_BEGIN_INTERNAL_NAMESPACE and IMPMODULE_END_INTERNAL_NAMESPACE macros to put declarations in a namespace appropriate for module MODULE.

Each module has an internal namespace, module_name::internal and an internal include directory modulename/internal. Any function which is

should be declared in an internal header and placed in the internal namespace.

The functionality in such internal headers is

As a result, such functions do not need to obey all the coding conventions (but we recommend that they do).

Documenting your code

IMP is documented using Doxygen. See documenting source code with doxygen to get started. We use //! and /** ... * / blocks for documentation.

Python code should provide Python doc strings.

All headers not in internal directories are parsed through Doxygen. Any function that you do not want documented (for example, because it is not well tested), hide by surrounding with

#ifndef IMP_DOXYGEN
void messy_poorly_thought_out_function();
#endif

We provide a number of extra Doxygen commands to aid in producing nice IMP documentation. The commands are used by writing \commandname{args} or \commandname if there are no arguments.

Useful Scripts

IMP provides a variety of scripts to aid the lives of developers.

Generate SConscripts

The SConscripts in a number of the modules list all of the header and cpp files which are part of the module (those of other modules automatically build this list at compile time). These lists can be generated using the make-sconscripts script. To run it to rebuild the SConscripts for the module modulename do
 ./tools/make-sconscripts modulename 

Making a module

Creating such a module is the easiest way to get started developing code for IMP. First, choose a name for the module. The name should only contain letters, numbers and underscores as it needs to be a valid file name as well as an identifier in Python and C++.

To create the module do

 ./tools/make-module my_module 
Then, if you run scons with localmodules=True, your new module will be built. The new module includes a number of examples and comments to help you add code to the module.

You can use your new module in a variety of ways:

If you feel your module is of interest to other IMP users and developers, see the contributing code to IMP section.

If you document your code, running

 scons doc 
will build documentation of all of the modules including yours. To access the documentation, open doc/html/index.html.

Contributing code back to the repository

In order to be shared with others as part of the IMP distribution, code needs to be of higher quality and more thoroughly vetted than typical research code. As a result, it may make sense to keep the code as part of a private module until you better understand what capabilities can be cleanly offered to others.

The first set of questions to answer are

You are encouraged to post to the imp-dev to find help answering these questions as it can be hard to grasp all the various pieces of functionality already in the repository.

All code contributed to IMP

The next suggestions provide more details about the above choices and how to implement them.

Submitting to a module

Small pieces of functionality or extensions to existing functionality probably should be submitted to an existing module. Please contact the authors of the appropriate module and discuss the submission and how the code will be maintained.

A list of all current modules in the IMP repository can be found in the modules list or from the modules tab at the top of this page.

As always, if in doubt, post to imp-dev.

Patches to modules for which you have write access can be submitted directly by doing:

 svn commit -m "message describing the patch" files or directories to submit 

Submitting to a module

If you have a large group of related functionality to submit, it may make sense to create a new module in svn. Please post to imp-dev to discuss your plans.

Once you have submitted code

Once you have submitted code, you should monitor the Nightly build status to make sure that your code builds on all platforms and passes the unit tests. Please fix all build problems as fast as possible.

The following sorts of changes must be announced on the imp-dev mailing list before being made

We recommend that changes be posted to the list a day or two before they are made so as to give everyone adequate time to comment.

In addition to monitoring the imp-dev list, developers who have a module or are committing patches to svn may want to subscribe to the imp-commits email list which receives notices of all changes made to the IMP SVN repository.

Good programming practices

The contents of this page are aimed at C++ programmers, but most apply also to python.

General resources

Two excellent sources for general C++ coding guidelines are

IMP endeavors to follow all the of the guidelines published in those books. The Sali lab owns copies of both of these books that you are free to borrow.

IMP gotchas

Below are a suggestions prompted by bugs found in code submitted to IMP.

    #include <IMP/mymodule/mymodule_exports.h>
    #include <IMP/mymodlule/MyRestraint.h>
    #include <IMP/Restraint.h>
    #include <vector>

Where to go next


Generated on Mon Mar 8 23:08:32 2010 for IMP by doxygen 1.5.8